Enchant help!

Discussion in 'Plugin Development' started by Vipevsiki1337, Jun 4, 2019.

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

    Vipevsiki1337

    Hello i have plugin for a kits, he give items but with no enchants!

    code:

    Code:
    package pl.vipevski.kit.commands;
    
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.enchantments.Enchantment;
    
    import pl.vipevski.kit.utils.ChatUtil;
    import pl.vipevski.kit.utils.ItemBuilder;
    import pl.vipevski.kit.utils.StartUtil;
    
    public class KitCommand implements CommandExecutor
    {
        public boolean onCommand(final CommandSender sender, final Command cmd, final String arg2, final String[] args) {
            if (cmd.getName().equalsIgnoreCase("kit")) {
                final Player p = (Player)sender;
                final Inventory inv = (Inventory)p.getInventory();
                if (!(sender instanceof Player)) {
                    sender.sendMessage("Nie dla konsoli!");
                    return false;
                }
                if (!sender.hasPermission("xmegapvp.kits")) {
                    sender.sendMessage(ChatUtil.fixColor("&c» Nie posiadasz permisji do tej komendy! (xmegapvp.kits)"));
                }
                if (args.length < 1) {
                    sender.sendMessage(ChatUtil.fixColor("&c>> Dostepne kity: /kit start/vip/enderchest/miesko"));
                    return false;
                }
                if (args[0].equalsIgnoreCase("start")) {
                    if (StartUtil.checkCooldown(p.getPlayer())) {
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_SWORD).addEnchantment(Enchantment.DAMAGE_ALL, 5).addEnchantment(Enchantment.DURABILITY, 3).addEnchantment(Enchantment.FIRE_ASPECT, 2).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_SWORD).addEnchantment(Enchantment.KNOCKBACK, 2).build() });
                        inv.addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE, 2, (short)1) });
                        inv.addItem(new ItemStack[] { new ItemStack(Material.GOLDEN_APPLE, 5) });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_HELMET).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).addEnchantment(Enchantment.DURABILITY, 3).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_CHESTPLATE).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).addEnchantment(Enchantment.DURABILITY, 3).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_LEGGINGS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).addEnchantment(Enchantment.DURABILITY, 3).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_BOOTS).addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 4).addEnchantment(Enchantment.DURABILITY, 3).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.DIAMOND_PICKAXE).addEnchantment(Enchantment.DIG_SPEED, 5).addEnchantment(Enchantment.DURABILITY, 3).addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 3).build() });
                        inv.addItem(new ItemStack[] { new ItemBuilder(Material.BOW).addEnchantment(Enchantment.ARROW_DAMAGE, 5).addEnchantment(Enchantment.DURABILITY, 3).addEnchantment(Enchantment.ARROW_INFINITE, 1).addEnchantment(Enchantment.ARROW_KNOCKBACK, 2).build() });
                        inv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 2) });
                        inv.addItem(new ItemStack[] { new ItemStack(Material.ARROW, 4) });
                        sender.sendMessage(ChatUtil.fixColor("&8>> &cOdebrales zestaw: &7START"));
                        StartUtil.setCooldown(p.getPlayer(), 10);
                    }
                    else {
                        sender.sendMessage(ChatUtil.fixColor("&c>> Ten zestaw mozesz odebrac za: &6" + StartUtil.getCooldown(p.getPlayer()) + " &csekund!"));
                    }
                }
                if (args[0].equalsIgnoreCase("vip")) {
                    if (StartUtil.checkCooldown(p.getPlayer())) {
                        inv.addItem(new ItemStack[] { new ItemStack(Material.STONE_PICKAXE) });
                        addEnchantment(Enchantment.KNOCKBACK, 1);
                        inv.addItem(new ItemStack[] { new ItemStack(Material.COOKED_BEEF, 32) });
                        inv.addItem(new ItemStack[] { new ItemStack(Material.ENDER_CHEST, 1) });
                        sender.sendMessage(ChatUtil.fixColor("&8>> &cOdebrales zestaw: &7Vip"));
                        StartUtil.setCooldown(p.getPlayer(), 10);
                    }
                    else {
                        sender.sendMessage(ChatUtil.fixColor("&c>> Ten zestaw mozesz odebrac za: &6" + StartUtil.getCooldown(p.getPlayer()) + " &csekund!"));
        }
            }
            }
            return false;
        }
    
        private void addEnchantment(Enchantment knockback, int i) {
            // TODO Auto-generated method stub
          
        }
    }
     
    Last edited by a moderator: Jun 4, 2019
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Minesuchtiiii

    Are you adding the enchantment to the ItemMeta of the Item?
     
  4. @Vipevsiki1337 Unrelated: you don't return if there's no permission

    There's also just a addItem(ItemStack) but since you already initialise an array here why not just add them all to the array ans make 1 call rather than like 12

    You also cast to player BEFORE the check, this will always throw an exception.
    I also have no idea what the getPlayer function is but why call it on a player...
     
  5. Offline

    KarimAKL

    If i remember correctly that's a method inherited from OfflinePlayer that gets the Player.
     
  6. Offline

    Kars

    Code:
    ItemStack myItem = new ItemStack(Material.STONE_SWORD);  //new item of item code
    myItem.addEnchantment(Enchantment.DAMAGE_ALL, 1);  //enchant the item
    Create the item and enchant them like this. Do not use ItemBuilder.
     
Thread Status:
Not open for further replies.

Share This Page