[Solved] Enchantment.getByName("UNBREAKING") return a nullpointerexception

Discussion in 'Spigot Plugin Development' started by Waterman2707, Jun 23, 2015.

  1. Hey spigot
    I'm trtying to make a very simple thing but it won't work, so i was wodering if i doing somethign wrong :S
    It's to put a enchant on a item, but it always give me a nullpointerexception...
    Error:
    Code (Text):
    [17:43:42 ERROR]: Could not pass event BlockBreakEvent to ItemLevels v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:295) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:501) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.breakBlock(PlayerI
    nteractManager.java:285) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PlayerInteractManager.a(PlayerInteractMa
    nager.java:121) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :578) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockDig.a(SourceFile:40) [c
    raftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PacketPlayInBlockDig.a(SourceFile:10) [c
    raftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [cra
    ftbukkit.jar:git-Bukkit-"24557bc"]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_20]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_20]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    45) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:2
    84) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    00) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :508) [craftbukkit.jar:git-Bukkit-"24557bc"]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_20]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaItem.applyEnchantme
    nts(CraftMetaItem.java:398) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaItem.applyToItem(Cr
    aftMetaItem.java:364) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.setItemMeta(C
    raftItemStack.java:376) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack.setItemMeta(C
    raftItemStack.java:358) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            at me.waterman2707.il.Events.onBlockBreak(Events.java:81) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _20]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _20]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_20]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_20]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:293) ~[craftbukkit.jar:git-Bukkit-"24557bc"]
            ... 16 more
     
    Code:
    Code (Text):
    ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE, 1);
    ItemMeta im = item.getItemMeta();
    im.addEnchant(Enchantment.getByName("UNBREAKING"), 1, true);
    item.setItemMeta(im); // this is where the error comes
    Actually am i doing the "unbreaking" thing from a config, but it doesen't work, so i tried this, and it also not worked :S
     
  2. Im pretty sure its actually called DURABILITY. Its not the name that appears on the item but the name it is defined as in the enum.
     
  3. Yeah it's named that, but i will need to do it with the name "UNBREAKING" because i will put the enchantment on the item with a config ;)
     
  4. "UNBREAKING" is not part of the Enchantment enum, it is
    "DURABILITY You will need to use that. I don't see why you need to use "UNBREAKING".
     
  5. Then you need to make the switch yourself. Its up to you to make the interface nicer for the end user. :)
     
  6. Okay, then i will need some more work :p
    but thanks, inow i know this ;)