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

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

  1. Offline


    I try to create a Inventory with some items and open it.

    I down't know there is the misstake.

    Here is my 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));
                            inv.setItem(i, item);
                        if(inv != null) {
    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 ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.SimplePluginManager.fireEvent( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.plugin.SimplePluginManager.callEvent( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PlayerInteractManager.a( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PlayerConnection.a( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.PacketPlayInUseItem.a( ~[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$ Source) [?:?] at 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( [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.DedicatedServer.b( [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at net.minecraft.server.v1_13_R2.MinecraftServer.a( [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at [spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at 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( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory.setItem( ~[spigot-1.13.2.jar:git-Spigot-518206a-a5b9c7b] at de.MS_Project.PortalSystem.Main.portPlayer( ~[?:?] at de.MS_Project.PortalSystem.Listener.listenerPortal.onButton( ~[?:?] 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 ~[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


    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


    Can you explain this line please?
    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
    1. inv.setItem(i, item); //:( it's sad
  4. Offline


    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. Offline


    Oh... that was the problem thank you for halp...
    Realy nice!

Share This Page