Console Error

Discussion in 'Spigot Plugin Development' started by darkshadow22mc, Jun 1, 2016.

  1. Hi!
    I have a code that allows me to create items and put them in an inventory quickly, with help of MenuAPI.
    I get this error:
    Code (Text):
    [07:57:34 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cc'
    in plugin OdiNServer v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:646) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 15
            at perks.ChatColorMethods.setMenuItem(ChatColorMethods.java:64) ~[?:?]
            at perks.ChatColorCommand.onCommand(ChatColorCommand.java:31) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            ... 14 more
    Here's the line 64 of ChatColorMethods and the line 31 of ChatColorCommand:
    Code (Text):
    items_name[items_name.length+1] = name;
    Code (Text):
    ccm.setMenuItem(p, Material.WOOL, (byte) 0, "§f§lWhite", 5, 2);
    And here my full code for ChatColorMethods:
    Code (Text):

    package perks;

    import java.util.Arrays;
    import java.util.List;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.inventory.Inventory;

    import com.colonelhedgehog.menuapi.components.ActionListener;
    import com.colonelhedgehog.menuapi.components.Coordinates;
    import com.colonelhedgehog.menuapi.components.Menu;
    import com.colonelhedgehog.menuapi.components.MenuObject;

    import core.Nexus;

    public class ChatColorMethods {
       
        Nexus nexus;
       
        public Menu menu;
        public Inventory inventory;
        public String[] permissions = new String[14];
        public MenuObject[] items = new MenuObject[14];
        public String[] items_name = new String[14];
        public Coordinates[] items_coordinates = new Coordinates[14];
       
        public void createInventory(Player p){

            inventory = Bukkit.createInventory(p, 54, "§3§lChatColor Selector");
            menu = new Menu(inventory);
           
        }
       
        public boolean getPermission(Player p, int colorcode){
            permissions[1] = "odin.cc.dark_blue";
            permissions[2] = "odin.cc.dark_green";
            permissions[3] = "odin.cc.dark_aqua";
            permissions[4] = "odin.cc.dark_red";
            permissions[5] = "odin.cc.dark_purple";
            permissions[6] = "odin.cc.gold";
            permissions[7] = "odin.cc.blue";
            permissions[8] = "odin.cc.green";
            permissions[9] = "odin.cc.aqua";
            permissions[10] = "odin.cc.red";
            permissions[11] = "odin.cc.purple";
            permissions[12] = "odin.cc.yellow";
            permissions[13] = "odin.cc.white";
            permissions[14] = "odin.cc.reset";
           
            if(p.hasPermission(permissions[colorcode]) || p.isOp()){
                return true;
            }else{
                return false;
            }
        }
        public void setMenuItem(Player p, Material icon, byte data ,String name, int x, int y){
            int idItem = items.length+1;
            int idCoord = items_coordinates.length+1;
            items_name[items_name.length+1] = name;
            List<String> lore = null;
            if(getPermission(p, idItem)){
                lore = Arrays.asList("§8Left click to change your Chat Color.");
            }else{
                lore = Arrays.asList("§cYou don't have permission to this Chat Color.");
            }
            items[idItem] = new MenuObject(icon, data, name, lore);
            items_coordinates[items_coordinates.length+1] = new Coordinates(menu, x, y);
            menu.setMenuObjectAt(items_coordinates[idCoord], items[idItem]);
        }
        public void resetData(Player p){
            nexus.getData().getStringList("colors.dark_blue").remove(p.getName());
            nexus.getData().getStringList("colors.dark_green").remove(p.getName());
            nexus.getData().getStringList("colors.dark_aqua").remove(p.getName());
            nexus.getData().getStringList("colors.dark_red").remove(p.getName());
            nexus.getData().getStringList("colors.dark_purple").remove(p.getName());
            nexus.getData().getStringList("colors.gold").remove(p.getName());
            nexus.getData().getStringList("colors.blue").remove(p.getName());
            nexus.getData().getStringList("colors.green").remove(p.getName());
            nexus.getData().getStringList("colors.aqua").remove(p.getName());
            nexus.getData().getStringList("colors.red").remove(p.getName());
            nexus.getData().getStringList("colors.purple").remove(p.getName());
            nexus.getData().getStringList("colors.yellow").remove(p.getName());
            nexus.getData().getStringList("colors.white").remove(p.getName());
            nexus.saveData();
        }
        public void executeChange(Player p){
           
            menu.openForPlayer(p);
           
            for(int i = 1; i <= permissions.length; i++){
                items[i].setActionListener(new ActionListener() {
                   
                    @Override
                    public void onClick(ClickType click, MenuObject menuobject, Player p) {
                       
                        if(click == ClickType.LEFT){
                            int a = 1;
                            if(menuobject.toItemStack().getItemMeta().getDisplayName().equalsIgnoreCase(items_name[a])){
                                if(getPermission(p, a)){
                                    resetData(p);
                                    if(permissions[a] == permissions[1]){
                                        nexus.getData().getStringList("colors.dark_blue").add(p.getName());
                                    }else if(permissions[a] == permissions[2]){
                                        nexus.getData().getStringList("colors.dark_green").add(p.getName());
                                    }else if(permissions[a] == permissions[3]){
                                        nexus.getData().getStringList("colors.dark_aqua").add(p.getName());
                                    }else if(permissions[a] == permissions[4]){
                                        nexus.getData().getStringList("colors.dark_red").add(p.getName());
                                    }else if(permissions[a] == permissions[5]){
                                        nexus.getData().getStringList("colors.dark_purple").add(p.getName());
                                    }else if(permissions[a] == permissions[6]){
                                        nexus.getData().getStringList("colors.gold").add(p.getName());
                                    }else if(permissions[a] == permissions[7]){
                                        nexus.getData().getStringList("colors.blue").add(p.getName());
                                    }else if(permissions[a] == permissions[8]){
                                        nexus.getData().getStringList("colors.green").add(p.getName());
                                    }else if(permissions[a] == permissions[9]){
                                        nexus.getData().getStringList("colors.aqua").add(p.getName());
                                    }else if(permissions[a] == permissions[10]){
                                        nexus.getData().getStringList("colors.red").add(p.getName());
                                    }else if(permissions[a] == permissions[11]){
                                        nexus.getData().getStringList("colors.purple").add(p.getName());
                                    }else if(permissions[a] == permissions[12]){
                                        nexus.getData().getStringList("colors.yellow").add(p.getName());
                                    }else if(permissions[a] == permissions[13]){
                                        nexus.getData().getStringList("colors.white").add(p.getName());
                                    }
                                }else{
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou don't have permissions. Buy it at&6 http://odinserver.enjin.com/shop/"));
                                }
                            }
                            a++;
                           
                        }
                       
                    }
                });
               
            }
           
        }
       
    }

    [CENTER]
    I hope you can help me! :D[/CENTER]
     
  2. 4chan

    Supporter

    items_name.length+1
    might be your problem
    7:40 AM
    tired
    no sleep yet
    leave me alone
     
    • Agree Agree x 2
  3. You're right,I solved that problem. Now I have another one with this code:

    Code (Text):
    package perks;

    import java.util.Arrays;
    import java.util.List;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.inventory.ClickType;
    import org.bukkit.inventory.Inventory;

    import com.colonelhedgehog.menuapi.components.ActionListener;
    import com.colonelhedgehog.menuapi.components.Coordinates;
    import com.colonelhedgehog.menuapi.components.Menu;
    import com.colonelhedgehog.menuapi.components.MenuObject;

    import core.Nexus;

    public class ChatColorMethods {
       
        Nexus nexus;
       
        public Menu menu;
        public Inventory inventory;
        public String[] permissions = new String[15];
        public MenuObject[] items = new MenuObject[15];
        public String[] items_name = new String[15];
        public Coordinates[] items_coordinates = new Coordinates[15];
       
        public void createInventory(Player p){

            inventory = Bukkit.createInventory(p, 54, "§3§lChatColor Selector");
            menu = new Menu(inventory);
           
        }
       
        public boolean getPermission(Player p, int colorcode){
            permissions[1] = "odin.cc.dark_blue";
            permissions[2] = "odin.cc.dark_green";
            permissions[3] = "odin.cc.dark_aqua";
            permissions[4] = "odin.cc.dark_red";
            permissions[5] = "odin.cc.dark_purple";
            permissions[6] = "odin.cc.gold";
            permissions[7] = "odin.cc.blue";
            permissions[8] = "odin.cc.green";
            permissions[9] = "odin.cc.aqua";
            permissions[10] = "odin.cc.red";
            permissions[11] = "odin.cc.purple";
            permissions[12] = "odin.cc.yellow";
            permissions[13] = "odin.cc.white";
            permissions[14] = "odin.cc.reset";
           
            if(p.hasPermission(permissions[colorcode]) || p.isOp()){
                return true;
            }else{
                return false;
            }
        }
        public void setMenuItem(Player p, Material icon, byte data ,String name, int x, int y){
            int idItem = 0;
            int idCoord = 0;
            int idName = 0;
            for(int i = 1; i >= 14; i++){
                if(items_name[i] != null){
                    idName = i;
                    break;
                }
            }
            for(int i = 1; i >= 14; i++){
                if(items[i] != null){
                    idItem = i;
                }
            }
            for(int i = 1; i >= 14; i++){
                if(items_coordinates[i] != null){
                    idCoord = i;
                    break;
                }
            }
            items_name[idName] = name;
            List<String> lore = null;
            if(getPermission(p, idItem)){
                lore = Arrays.asList("§8Left click to change your Chat Color.");
            }else{
                lore = Arrays.asList("§cYou don't have permission to this Chat Color.");
            }
            items[idItem] = new MenuObject(icon, data, name, lore);
            items_coordinates[items_coordinates.length+1] = new Coordinates(menu, x, y);
            menu.setMenuObjectAt(items_coordinates[idCoord], items[idItem]);
        }
        public void resetData(Player p){
            nexus.getData().getStringList("colors.dark_blue").remove(p.getName());
            nexus.getData().getStringList("colors.dark_green").remove(p.getName());
            nexus.getData().getStringList("colors.dark_aqua").remove(p.getName());
            nexus.getData().getStringList("colors.dark_red").remove(p.getName());
            nexus.getData().getStringList("colors.dark_purple").remove(p.getName());
            nexus.getData().getStringList("colors.gold").remove(p.getName());
            nexus.getData().getStringList("colors.blue").remove(p.getName());
            nexus.getData().getStringList("colors.green").remove(p.getName());
            nexus.getData().getStringList("colors.aqua").remove(p.getName());
            nexus.getData().getStringList("colors.red").remove(p.getName());
            nexus.getData().getStringList("colors.purple").remove(p.getName());
            nexus.getData().getStringList("colors.yellow").remove(p.getName());
            nexus.getData().getStringList("colors.white").remove(p.getName());
            nexus.saveData();
        }
        public void executeChange(Player p){
           
            menu.openForPlayer(p);
           
            for(int i = 1; i <= permissions.length; i++){
                items[i].setActionListener(new ActionListener() {
                   
                    @Override
                    public void onClick(ClickType click, MenuObject menuobject, Player p) {
                       
                        if(click == ClickType.LEFT){
                            int a = 1;
                            if(menuobject.toItemStack().getItemMeta().getDisplayName().equalsIgnoreCase(items_name[a])){
                                if(getPermission(p, a)){
                                    resetData(p);
                                    if(permissions[a] == permissions[1]){
                                        nexus.getData().getStringList("colors.dark_blue").add(p.getName());
                                    }else if(permissions[a] == permissions[2]){
                                        nexus.getData().getStringList("colors.dark_green").add(p.getName());
                                    }else if(permissions[a] == permissions[3]){
                                        nexus.getData().getStringList("colors.dark_aqua").add(p.getName());
                                    }else if(permissions[a] == permissions[4]){
                                        nexus.getData().getStringList("colors.dark_red").add(p.getName());
                                    }else if(permissions[a] == permissions[5]){
                                        nexus.getData().getStringList("colors.dark_purple").add(p.getName());
                                    }else if(permissions[a] == permissions[6]){
                                        nexus.getData().getStringList("colors.gold").add(p.getName());
                                    }else if(permissions[a] == permissions[7]){
                                        nexus.getData().getStringList("colors.blue").add(p.getName());
                                    }else if(permissions[a] == permissions[8]){
                                        nexus.getData().getStringList("colors.green").add(p.getName());
                                    }else if(permissions[a] == permissions[9]){
                                        nexus.getData().getStringList("colors.aqua").add(p.getName());
                                    }else if(permissions[a] == permissions[10]){
                                        nexus.getData().getStringList("colors.red").add(p.getName());
                                    }else if(permissions[a] == permissions[11]){
                                        nexus.getData().getStringList("colors.purple").add(p.getName());
                                    }else if(permissions[a] == permissions[12]){
                                        nexus.getData().getStringList("colors.yellow").add(p.getName());
                                    }else if(permissions[a] == permissions[13]){
                                        nexus.getData().getStringList("colors.white").add(p.getName());
                                    }
                                }else{
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cYou don't have permissions. Buy it at&6 http://odinserver.enjin.com/shop/"));
                                }
                            }
                            a++;
                           
                        }
                       
                    }
                });
               
            }
           
        }
       
    }
     
    The stacktrace
    Code (Text):
    [08:53:51 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'cc'
    in plugin OdiNServer v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:646) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.IllegalArgumentException: Permission name cannot be null
            at org.bukkit.permissions.PermissibleBase.isPermissionSet(PermissibleBas
    e.java:50) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at ru.tehkode.permissions.bukkit.regexperms.PermissiblePEX.hasPermission
    (PermissiblePEX.java:135) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity.hasPermission(
    CraftHumanEntity.java:102) ~[spigot-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            at perks.ChatColorMethods.getPermission(ChatColorMethods.java:55) ~[?:?]

            at perks.ChatColorMethods.setMenuItem(ChatColorMethods.java:88) ~[?:?]
            at perks.ChatColorCommand.onCommand(ChatColorCommand.java:31) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got-1.8.3.jar:git-Spigot-15fa8e1-17a3db7]
            ... 14 more
    [08:53:54 ERROR]: [PermissionsEx] Error occurred with PermissionsEx! Please post
    it to http://git.io/<html><body>You are being <a href="https://git.io/create">r
    edirected</a>.</body></html>. Full error:
    java.lang.IllegalArgumentException: Permissions being checked must not be null!
            at org.apache.commons.lang.Validate.notNull(Validate.java:192)
            at ru.tehkode.permissions.bukkit.regexperms.PermissiblePEX.permissionVal
    ue(PermissiblePEX.java:227)
            at ru.tehkode.permissions.bukkit.regexperms.PermissiblePEX.hasPermission
    (PermissiblePEX.java:127)
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity.hasPermission(
    CraftHumanEntity.java:102)
            at perks.ChatColorMethods.getPermission(ChatColorMethods.java:55)
            at perks.ChatColorMethods.setMenuItem(ChatColorMethods.java:88)
            at perks.ChatColorCommand.onCommand(ChatColorCommand.java:31)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1)
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:646)
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115)
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950)
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26)
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53)
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13)
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
            at java.util.concurrent.FutureTask.run(Unknown Source)
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96)
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16)
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34)
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537)
            at java.lang.Thread.run(Unknown Source)
     
    :
     
  4. PermissionsEx is causing a problem somehow.
     
  5. Code (Text):
    java.lang.IllegalArgumentException: Permissions being checked must not be null![CODE]permissions[1] = "odin.cc.dark_blue";
            permissions[2] = "odin.cc.dark_green";
            permissions[3] = "odin.cc.dark_aqua";
            permissions[4] = "odin.cc.dark_red";
            permissions[5] = "odin.cc.dark_purple";
            permissions[6] = "odin.cc.gold";
            permissions[7] = "odin.cc.blue";
            permissions[8] = "odin.cc.green";
            permissions[9] = "odin.cc.aqua";
            permissions[10] = "odin.cc.red";
            permissions[11] = "odin.cc.purple";
            permissions[12] = "odin.cc.yellow";
            permissions[13] = "odin.cc.white";
            permissions[14] = "odin.cc.reset";
    Where is permissions[0]??
     
  6. Oh God,my bad... now the problem is
    Code (Text):
    items[i].setActionListener(new ActionListener() {
     
  7. Please show the error.
     
  8. Missing a ).
     
  9. Nope, that is not the problem. It probably lies in the indexing of items.
     
  10. If you remove the "new ActionListener()" part, it's an unclosed parantheses.

    But yeah, you're right. Probably that too
     
  11. No, because he creates a new ActionListener instance as the parameter for setActionListener like this;

    Code (Text):
    items[i].setActionListener(new ActionListener() {
        //code here
    });
     
  12. Ohh. Thanks.. never worked with an ActionListener before.
     
  13. I solved the problem before your answers but I forgot to edit the message. The problem was that I was doing a for(int i = 1; i >= items.length; i++) instead of i = 0