Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xp;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- public class xp extends JavaPlugin implements Listener {
- public void onEnable(){
- Bukkit.getPluginManager().registerEvents(this,this);
- }
- public void onDisable(){
- }
- @EventHandler
- public static void ConvertXP(PlayerInteractEvent e)
- {
- Player p=e.getPlayer();
- String nameXpWand="§4Палка-починялка";
- ItemStack xpWand=new ItemStack(Material.STICK,1);
- ItemMeta xpWandMeta=xpWand.getItemMeta();
- xpWandMeta.setDisplayName(nameXpWand);
- xpWand.setItemMeta(xpWandMeta);
- if(e.getItem().getItemMeta().getDisplayName().equals(nameXpWand)){
- if(p.getLevel()>=20)
- {
- int xpOnLevel=(int)(p.getExp()*p.getExpToLevel());
- if(xpOnLevel>10)
- p.giveExp(-10);
- else
- if(xpOnLevel==10){
- p.setExp(0);
- }
- else
- if(xpOnLevel<10){
- int num=10-xpOnLevel;
- p.setExp(0.0f);
- p.setLevel(p.getLevel()-1);
- float newXp=((float)(p.getExpToLevel()-num)/(float)p.getExpToLevel());
- p.setExp(newXp);
- }
- p.getWorld().spawnEntity(p.getLocation(), EntityType.THROWN_EXP_BOTTLE);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement