Solved ArrayList<ItemStack> add error.

Discussion in 'Plugin Development' started by dominikremes, Mar 21, 2017.

Thread Status:
Not open for further replies.
  1. Hello. I`ve got an error with part teams.add(getColor(j,k));. When I debugged the null is add(. Here is the code and the error:
    Code:
       public class BedwarsPlayerTeamInventory {
        public Inventory bwInv;
        private ArrayList<ItemStack> teams;
       
        private BedwarsSetupManager manager = new BedwarsSetupManager();
       
        public BedwarsPlayerTeamInventory(int i) {
            int j = manager.getReadyArenaInt(i);
            String name = manager.getReadyArena(j);
            if (name == null) {
                name = "";
            }
           
            bwInv = Bukkit.getServer().createInventory(null, 9, name);
           
            for (int k = 1; k < getStackLength(i) + 1; k++) {
     Here is the error -->           teams.add(getColor(j, k));
                bwInv.setItem(k - 1, teams.get(k - 1));
            }
           
        }
       
        @SuppressWarnings("deprecation")
        private ItemStack createMat(DyeColor color, String name, List<String> meta) {
            ItemStack i = new ItemStack(Material.WOOL, 1, color.getData());
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            im.setLore(meta);
            i.setItemMeta(im);
            return i;
        }
       
        private ItemStack getColor(int i, int j) {
                String s = manager.getReadyArenaTeam(i, j);
                return createMat(DyeColor.GREEN, s, null);
            }
       
        private int getStackLength(int i) {
            int j = Main.getInstance().settings.getBedwarsConfig().getInt("readyArenas.teams." + i + ".int");
            return j;
        }
    }
    Code:
    This part is needed from InventoryListener:
    else if (e.getClickedInventory().getName().contains(new BedwarsPlayerInventory().bwInv.getName())) {
                    if (e.getCurrentItem() == null) return;
                    if (e.getCurrentItem().getItemMeta() == null) return;
                    e.setCancelled(true);
                    p.closeInventory();
                    int i = Main.getInstance().settings.getBedwarsConfig().getInt("Arenanames." + e.getCurrentItem().getItemMeta().getDisplayName());
                    p.openInventory(new BedwarsPlayerTeamInventory(i).bwInv);
                }
    I don`t want to post the full BedwarsSetupManager class so here is everything what it configures. Everything there is is doing just this. This is the bedwars.yml with 1 "fully" configured arena.
    Code:
    ArenaAmount: 1
    Arenas:
      '1':
        name: test
        playersInTeams: 2
        teams:
          blue:
            bool: true
            bed:
              loc:
                ==: org.bukkit.Location
                world: Annihilation
                x: 272.16021556845203
                y: 4.5625
                z: -1435.3503073716356
                pitch: 0.0
                yaw: 0.0
              bool: true
            spawn:
              loc:
                ==: org.bukkit.Location
                world: Annihilation
                x: 272.16021556845203
                y: 4.5625
                z: -1435.3503073716356
                pitch: 0.0
                yaw: 0.0
              bool: true
          green:
            bool: false
          red:
            bool: true
            bed:
              loc:
                ==: org.bukkit.Location
                world: Annihilation
                x: 272.0625482888564
                y: 4.5625
                z: -1434.2824886199792
                pitch: 0.0
                yaw: 0.0
              bool: true
            spawn:
              loc:
                ==: org.bukkit.Location
                world: Annihilation
                x: 272.0625482888564
                y: 4.5625
                z: -1434.2824886199792
                pitch: 0.0
                yaw: 0.0
              bool: true
          yellow:
            bool: false
          orange:
            bool: false
          gray:
            bool: false
          cyan:
            bool: false
          purple:
            bool: false
          amount: 2
        bedamount: 2
        spawnamount: 2
        errors:
          setteams: false
          setbeds: false
          setspawns: false
          setPlayersPerTeams: false
    Arenanames:
      test: 1
    arenalist:
    - test
    readyArenas:
      int: 1
      names:
      - test
      name:
        '1': test
      arenaInt:
        '1': 1
      teams:
        '1':
          list:
          - Blue
          - Red
          int: 2
    
    And now here the error:
    Code:
    [21:17:06 ERROR]: Could not pass event InventoryClickEvent to MC_Craft_Menu v10.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-c3e4052-1953f52]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-c3e4052-1953f52]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1853) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:733) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:672) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:571) [spigot.jar:git-Spigot-c3e4052-1953f52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
            at server.mccraft.Inventorys.bedwars.BedwarsPlayerTeamInventory.<init>(BedwarsPlayerTeamInventory.java:34) ~[?:?]
            at server.mccraft.listeners.InventoryListeners.onInventoryClick(InventoryListeners.java:225) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_121]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_121]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-c3e4052-1953f52]
            ... 15 more
    This is when I click on the item named same as the arena and in the correct inventory.
    Thanks for help.
     
  2. Offline

    Zombie_Striker

    @dominikremes
    You never initialize teams. Make sure team is equal to something before you use it.
     
  3. Offline

    ITGuy12

    U are missing a very important part.. a { at the item stack!!


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page