Solved I have a problem with the ItemStack's in 1.13.2

Discussion in 'Plugin Development' started by Mr.Nice1107, Apr 3, 2019.

Thread Status:
Not open for further replies.
  1. I try to create a Inventory with some items and open it.

    I down't know there is the misstake.

    Here is my code:

    Code:
    if (player != null) {
                ArrayList<String> portList = getPortalList(player);
                if (portList != null && !portList.isEmpty()) {
                    int invSize = (portList.size() + 1) / 9;
                    Inventory inv = Bukkit.createInventory(null, invSize, "§dYour Portals : " + player.getName().toLowerCase());
    
                    if (inv != null) {
                        ItemStack item = new ItemStack(Material.GLASS,1);
                        ItemMeta meta = item.getItemMeta();
    
                        for (int i = 0; i < portList.size(); i++) {
                            meta.setDisplayName("§d" + portList.get(i));
                            item.setItemMeta(meta);
    
                            inv.setItem(i, item);
                        }
    
                        if(inv != null) {
                            player.openInventory(inv);
                        }
                    }
                }
            }
    And here's the error:

    [21:07:11] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to PortalSystem v0.1 org.bukkit.event.EventException: null at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.java:309) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:299) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PlayerInteractManager.a(PlayerInteractManager.java:457) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1237) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.a(SourceFile:10) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?] at java.util.concurrent.FutureTask.run(Unknown Source) [?:?] at net.minecraft.server.v1_13_R2.SystemUtils.a(SourceFile:199) [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:895) [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:830) [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:728) [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at java.lang.Thread.run(Unknown Source) [?:?] Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at java.util.Arrays$ArrayList.set(Unknown Source) ~[?:?] at net.minecraft.server.v1_13_R2.NonNullList.set(SourceFile:53) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventoryCustom$MinecraftInventory.setItem(CraftInventoryCustom.java:108) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory.setItem(CraftInventory.java:98) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at de.MS_Project.PortalSystem.Main.portPlayer(Main.java:417) ~[?:?] at de.MS_Project.PortalSystem.Listener.listenerPortal.onButton(listenerPortal.java:35) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?] at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.java:305) ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] ... 17 more (open)


    I think the error is in this Line:

    inv.setItem(i, item);

    but i down't know what is wrong with thet?
    or what is wrong with the Item?:
    ItemStack item = new ItemStack(Material.GLASS,1);


    Thanks in advance​
     
  2. Offline

    Dai_Kunai

    The invSize variable that you use when you do Bukkit.createInventory is not the number of rows, but the number of slots. Don't bother dividing by 9. It is an ArrayIndexOutOfBounds Exception after all.
     
  3. Offline

    Shqep

    Can you explain this line please?
    Code:Java
    1. int invSize = (portList.size() + 1) / 9;

    I don't know what you planned to do with this. But like @Eccentric_Gamer said, the size should be the number of slots, (and also divisible by 9?).

    Also, what made you think that the error is in the line
    Code:Java
    1. inv.setItem(i, item); //:( it's sad
     
  4. Offline

    Dai_Kunai

    An inventory can have sizes of 9,18,27,36,45,54(1-6 rows). My method would be to get the portlist size and add (portlist.size() % 9) to it to knock it up to the highest amount of inventory slots.
     
  5. Oh... that was the problem thank you for halp...
    Realy nice!
     
Thread Status:
Not open for further replies.

Share This Page