Solved Item List help

Discussion in 'Spigot Plugin Development' started by xMaikiYT, Oct 18, 2020 at 6:08 PM.

  1. Hello,

    I need to make a custom item plugin, i want to make the config file like this:

    Code (Text):
    Items:
        item_name:
             name:
             click-on-item: "sothing"
        item_name2:
             name:
             click-on-item: "sothing"
     
    but i want to be able to add more itmes for the config! Give me an idea!
     
  2. ConfigurationSection#getKeys(boolean) might help
     
    • Like Like x 1
  3. Thanks For Helping me! I am waiting for more replys
     
  4. I am trying to use your help but i dont know how!
     
  5. Strahan

    Benefactor

    I don't get what your problem is. You can make as many items as you want, just add them to the config. You just need a unique identifier for the keys.
     
    • Like Like x 1
  6. You can give me a guide?
     
  7. Hello! i have this bit of code... but its not working its returning me an error:

    code:
    Code (Java):
    for (String string : plugin.getConfig().getConfigurationSection("blocked-words").getKeys(false)) {              
                            player.sendMessage("items: " + string);
    }
     
  8. Strahan

    Benefactor

    Yea, giving us the error would make it a tad easier to diagnose your problem, lol.

    I'd guess that the "blocked-words" path doesn't exist in your config. You should never hang methods off another method that may return a null. Always null check it first.
     
  9. It is in my config!

    Error:
    Code (Text):
    [08:52:50] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'waterdamage' in plugin SimpleFood v0.1
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchCommand(CraftServer.java:756) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.PlayerConnection.handleCommand(PlayerConnection.java:1697) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.PlayerConnection.a(PlayerConnection.java:1540) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.TickTask.run(SourceFile:18) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.MinecraftServer.ba(MinecraftServer.java:941) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.MinecraftServer.executeNext(MinecraftServer.java:934) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.MinecraftServer.sleepForTick(MinecraftServer.java:918) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:850) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_261]
    Caused by: java.lang.NullPointerException
            at me.maiky.simplefood.cJobWaterDamage.onCommand(cJobWaterDamage.java:25) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:git-Spigot-379750e-43c7ff9]
            ... 18 more
     
  10. NickCloud

    NickCloud Previously TheNickSkater

    Code (Text):
    at me.maiky.simplefood.cJobWaterDamage.onCommand(cJobWaterDamage.java:25) ~[?:?]
    What code is exactly in line 25? Or was at the time of the error.
     
  11. On line 25:
    Code (Java):
    for (String string : plugin.getConfig().getConfigurationSection("blocked-words").getKeys(false)) {
     
  12. NickCloud

    NickCloud Previously TheNickSkater

    Well then something there is definitely null.. Are you sure "plugin" is correctly initialized? Also does "blocked-words" really exist in the config? Can you show us the config?
     
    • Like Like x 1
  13. Here is the config:
    Code (Text):
    # | Simple Food By Maiky
    # | Version: 0.1
    # | Discord: M4iky#0001

    blocked-words:
      - item1: "NAME: test test"
      - item2: "NAME: test test"
     
  14. NickCloud

    NickCloud Previously TheNickSkater

    Well there is the problem I'd say. You are making a "list" out of it.

    Code (Text):
    blocked-words:
      item1:
        NAME: "test"
      item2:
        NAME: "test2"
    This format would be correct.
     
  15. YESSSS THANKSSS