How to add itemstack of StringList to inventory

Discussion in 'Spigot Plugin Development' started by xEmiMLG, Oct 13, 2017.

  1. Yeah, I explained how you'd do that earlier. Have a key and a value for the stuff that is relevant to the item. Now get it using this for example:
    Code (Text):

    String displayName = config.getString("Items.Item.DisplayName");
     
    Now do this for all of the keys. You can now using these values apply them to the item, example:
    Code (Text):

    ItemStack item = new ItemStack(Material.GRASS);
    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(displayName);
    item.setItemMeta(meta);
     
    Do this for all of the values, and then add it to the inventory.
     
  2. I understand, but dont are explain the i want. I want register the coords. If i add spawn, on inventory add item with the coords
     
  3. How to plugin of skywar.. when i create a map, the map added to a inventory
     
  4. So you DO want an item that has a lore WITH the coordinates you specify in the configuration?
     
  5. YEEEEEEEEEEEEEEEEEEEEEEAH!!
     
  6. Alright, now. Get the string list with the coordinates. After you've done that, loop through them all and deserialize them to a location. Save all deserialized locations to a list, to later on format it so that it looks good. Add them all to the lore in the formatted way.

    - Take list
    - Loop trough and deserialize
    - Make yet another list for the lore, add the locations in the format you want
    - Apply the lore to the item
     
  7. Okok, Its okay?
    Code (Text):
    List<Location> coords = Main.getInstance().listStrToLocs(Main.getInstance().getConfig().getStringList("arena."+arenaname+".spawns"));
           
            ArrayList lore = new ArrayList();
            lore.add(coords);
           
            ItemStack spawns = new ItemStack(Material.GRASS);
            ItemMeta spawnm = spawns.getItemMeta();
            spawnm.setDisplayName("Spawn");
            spawnm.setLore(lore);
            spawns.setItemMeta(spawnm);
           
            Inventory inv = Bukkit.createInventory(null, 18, "&aLocationGui of &e"+arenaname);
            inv.addItem(spawns);
     
  8. I'm not quite sure what "listStrToLocs" do, but I assume it deserializes all the strings to locations and add them as locations. Though, for the lore you might want to loop through every location and add a new line for the coordinates
    Code (Text):

    List<String> lore = new ArrayList<>();
    for (Location location : coords) {
    lore.add("X: + location.getX()"); //AND SO O[
    }
     
  9. upload_2017-10-13_11-2-6.png
     
  10. Code (Text):
      public static void onGui(Player p, String arenaname){

            Arena arena = Main.getInstance().getArenaManager().getArenaByName(arenaname);


            List<Location> coords = Main.getInstance().listStrToLocs(Main.getInstance().getConfig().getStringList("arena."+arenaname+".spawns"));

            ArrayList lore = new ArrayList();
            lore.add(coords);

            ItemStack spawns = new ItemStack(Material.GRASS);
            ItemMeta spawnm = spawns.getItemMeta();
            spawnm.setDisplayName("Spawn");
            spawnm.setLore(lore);
            spawns.setItemMeta(spawnm);

            Inventory inv = Bukkit.createInventory(null, 18, "&aLocationGui of &e"+arenaname);
            inv.addItem(spawns);

            p.openInventory(inv);
        }
     
  11. Wtf this error?
    Code (Text):
    [11:12:53 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'swh' in plugin SkywarsHardcore v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
            at java.base/java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
            at java.base/java.lang.Thread.run(Unknown Source) [?:?]
    Caused by: java.lang.StackOverflowError
            at java.base/java.lang.StringBuilder.<init>(Unknown Source) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:139) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
            at me.emi.swh.commands.SwhCommand.getHelpMessage(SwhCommand.java:151) ~[?:?]
     
  12. Well, that's why you're not adding the locations as strings to the lore. You're setting the lore to an empty list.
     
  13. Aah ok
     

Share This Page