Solved How would I add levels to a bottle.

Discussion in 'Plugin Development' started by Twisted_Panda, Jan 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Twisted_Panda

    Currently having issues on setting custom levels on a bottle.
    My code:

    Code:
        @EventHandler(priority = EventPriority.HIGHEST)
        public void craft(CraftItemEvent e) {
        Player p = (Player)e.getWhoClicked();
            ItemStack result = e.getRecipe().getResult();
            if(result.getType() == Material.EXP_BOTTLE) {
           
                ItemStack bottle = new ItemStack(Material.EXP_BOTTLE);
                ItemMeta mbottle = bottle.getItemMeta();
                mbottle.setDisplayName("§cXP Bottles");
                List<String> mlist = new ArrayList<String>();
                mlist.add("§bLevel: " + p.getLevel());
                mbottle.setLore(mlist);
                bottle.setItemMeta(mbottle);
                bottle.setDurability((short)p.getLevel());
           
           
                e.getInventory().setResult(bottle);
                p.setLevel(- p.getLevel());
            }
        }
    I don't know if durability works

    Wrong place please move to plugin development D:
     
  2. Offline

    L33m4n123

    iirc the ammount of xp that is given upon bottle break is random and has nothing to do with durability​
    So. What you could do though maybe is that you write it in the Lore of the Item. and upon splashing the potion you get the Lore and then add the level accordingly.​
     
  3. Offline

    TnT

    Moved to the correct forum.
     
    Garris0n likes this.
  4. Offline

    hubeb

  5. Offline

    Twisted_Panda

  6. Offline

    Garris0n

    You can just parse it from the lore. Also use ChatColor.AQUA instead of §b.
     
Thread Status:
Not open for further replies.

Share This Page