Solved I trying to add an enchant...

Discussion in 'Plugin Development' started by Dekay972, Oct 24, 2015.

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

    Dekay972

    So Im trying ot make a command that gives leather boots with an enchantment on it but I keep getting an error
    Code:
    package me.aerotm.firstplugin;
    
    import java.util.Arrays;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.enchantments.*;
    
    import net.minecraft.server.v1_8_R3.Enchantment;
    
    
    public class Itemz extends JavaPlugin implements Listener {
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("xitem") && sender instanceof Player) {
                ItemStack newItem = setMeta(new ItemStack(Material.LEATHER_BOOTS), ChatColor.AQUA + "Atlantean Boots", Arrays.asList(ChatColor.RED + "ONLY THE ATLANTEAN CLASS", "CAN WEAR THESE"));
                newItem.addUnsafeEnchantment(Enchantment.DEPTH_STRIDER, 10);
                ((Player)sender).getInventory().addItem(newItem);
               
               
                return true;
            }
           
            return false;
        }
       
        public ItemStack setMeta(ItemStack material, String name, List<String> lore) {
            if(((material == null) || material.getType() == Material.AIR)
                    || ((name == null) && lore == null))
                return null;
           
            ItemMeta im = material.getItemMeta();
            if (name != null)
                im.setDisplayName(name);
            if (lore != null)
                im.setLore(lore);
               
                material.setItemMeta(im);
                return material;
            }
           
        }
       
    
    The error is on the line newItem.addUnsafeEnchantment(Enchantment.DEPTH_STRIDER, 10);
    It says "The method addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int) in the type ItemStack is not applicable for the arguments (net.minecraft.server.v1_8_R3.Enchantment, int)"
    Thank you for help.
     
  2. Offline

    rbrick

    @Dekay972 Use `org.bukkit.enchantments.Enchantment`
    EDIT: I guess I should clarify, just in case. You imported the wrong Enchantment class (the net.mineraft.server).
     
  3. Offline

    Dekay972

    But I have
    import org.bukkit.enchantments.*;

    Doesnt that cover "org.bukkit.enchantments.Enchantment"?

    Oh never mind that worked, Thank you.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
Thread Status:
Not open for further replies.

Share This Page