Discussion in 'Spigot Plugin Development' started by Lovis, Aug 5, 2018.

  1. So i have enchantments saved to a config with the category Enchantments the error comes when i try to put them on items:

    helm.addEnchantments((Map<Enchantment, Integer>) getConfig().get("Enchantments"));

    Help-me please
  2. What exactly is being stored in your config file? And what type of error are you getting?

    Also what do you mean by "category enchantments"
  3. plugin.getConfig().set("Enchantments.", item.getEnchantments());
  4. Mind to show us the error and the file when it’s stored?
    • Agree Agree x 2
  5. The error comes when I try to put it into items
  6. Copy and paste the error message from the console please ?
  7. [05:07:23 ERROR]: Could not pass event InventoryClickEvent to Tloja v1.0
    va:310) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(
    :1630) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31)
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9)
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$
    3) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at java.util.concurrent.Executors$ Source) [
    at Source) [?:1.8.0_51]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(
    15) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(
    74) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(
    54) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    :557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at Source) [?:1.8.0_51]
    Caused by: java.lang.IllegalArgumentException: Specified enchantment cannot be a
    pplied to this itemstack
    at org.bukkit.inventory.ItemStack.addEnchantment( ~[s
    at org.bukkit.inventory.ItemStack.addEnchantments( ~[
    at TLoja.Inventarios.Inventarios.lambda$0( ~[?:?]
    at TLoja.Inventarios.Inventarios$$Lambda$8/3046746.accept(Unknown Source
    ) ~[?:?]
    at java.lang.Iterable.forEach(Unknown Source) ~[?:1.8.0_51]
    at TLoja.Inventarios.Inventarios.AbrirMenuC( ~[?:?]
    at TLoja.Eventos.Eventos.MenuInicial( ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
    va:306) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    ... 15 more
  8. It's saying that the enchant you are trying to add cannot be applied to that item. What enchant and item are you using?
  9. Regarding this:
    Check first if the enchantment you are trying to add can be added. If I am not mistaken there is a method for checking this.
    This is simple error protection code. Always check if some things can cause error in different situations :)
  10. The enchantment was wrong, but I fixed it and it was not.
  11. Are you getting a new error message in the console?
  12. Enchantments:
    !!org.bukkit.craftbukkit.v1_8_R3.enchantments.CraftEnchantment {}: 2
    !!org.bukkit.craftbukkit.v1_8_R3.enchantments.CraftEnchantment {}: 3

    Is saving so in configuration, is right?
  13. Is that what is being shown in the config? If so you are saving the object, not the actual enchantment.
  14. Code (Text):
    Caused by: java.lang.IllegalArgumentException: Specified enchantment cannot be a
    pplied to this itemstack
    use addUnsafeEnchantment instead of addEnchantment.
    I think its line 75 of Inventarios i can barely make out what your console logs are.
    Your code should look like this no?

    Code (Text):
    ItemStack helm = new ItemStack(Material.DIAMOND_HELMET, 1);
    item.addUnsafeEnchantment(Enchantment.valueOf(getConfig().getString("anyenchant")), 2);
    Please post your class in code brackets (relevant parts) error messages (if any) and your config as well as where you set the config
    #15 FalconSeeker, Aug 5, 2018
    Last edited: Aug 5, 2018
  15. How do I get the charm of an item?