• Our Minecraft servers are offline but we will keep this forum online for any community communication. Site permissions for posting could change at a later date but will remain online.

Having a coding issue.

ImagineFrags

Spectator
Joined
May 10, 2014
Messages
24
Reaction score
6
Before I continue, please do not comment(post) on this thread if you do not have a basic understanding of bukkit programming. Thank you.

So I am coding a Kit PvP plugin and I want it to where, when a player executes the command /shop it will open an inventory with, well, a shop. I didn't have a problem with it until I wanted to make sub menus. So the player clicks on, say, a block in the first menu. It will then send you to a new menu. That's where I had a problem and need your help.

Here's where I create the new inventory and add items:

Code:
public static Inventory shop;
    {
        shop = Bukkit.createInventory(null, 9, "§aShop");

        shop.setItem(0, createItem(Material.REDSTONE_BLOCK, 1, (short) 0, "§3Kits:", "§cList of all the kits."));
        shop.setItem(1, createItem(Material.LAPIS_BLOCK, 1, (short) 0, "§3Items:", "§cMake quick purchases."));
    }
    public static Inventory kits;
    {
        kits = Bukkit.createInventory(null, 9, "§aShop §0§l> §bKits");

        kits.setItem(1, createItem(Material.DIAMOND_SWORD, 1, (short) 0, "§3PVP", "§cPrice: §4FREE"));
    }
    public static Inventory items;
    {
        items = Bukkit.createInventory(null, 9, "§aShop §0§l> §bItems");

        items.setItem(10, createItem(Material.ARROW, 1, (short) 0, "§3Arrow", "§cPrice: §45 Coins"));
        items.setItem(11, createItem(Material.ENDER_PEARL, 1, (short) 0, "§3Ender Pearl", "§cPrice: §4250 Coins"));
        items.setItem(12, createItem(Material.GOLDEN_APPLE, 1, (short) 0, "§3Golden Apple", "§cPrice: §450 Coins"));
    }
Shop Command:


Code:
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Player player = (Player) sender;
        if (cmd.getName().equalsIgnoreCase("shop")) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "You must be a player to use this command!");
            }
            player.openInventory(shop);
        }
        return false;
    }

Here's the PlayerClickEvent:

Code:
if (event.getCurrentItem().getItemMeta().getDisplayName().equals("§3Kits:")) {
                p.openInventory(kits);
            }
            if (event.getCurrentItem().getItemMeta().getDisplayName().equals("§3Items:")) {
                p.openInventory(items);
            }
Finally, the error I get in the console(ArrayIndexOutOfBoundsException):

Code:
[07:43:51 ERROR]: Could not load 'plugins\Nebula.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.ArrayIndexOutOfBoundsExcepti
on: 10
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
ava:131) ~[CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
java:328) ~[CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
.java:251) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugins(CraftServer.ja
va:350) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.reload(CraftServer.java:78
4) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.Bukkit.reload(Bukkit.java:288) [CraftBukkit.jar:git-Bukkit
-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
23) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
0) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchCommand(CraftServe
r.java:696) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchServerCommand(Craf
tServer.java:683) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.ax(DedicatedServer.java:
286) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:2
51) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:5
48) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java
:459) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:6
18) [CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 10
        at org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventoryCustom$Minecra
ftInventory.setItem(CraftInventoryCustom.java:94) ~[CraftBukkit.jar:git-Bukkit-1
.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory.setItem(Craft
Inventory.java:82) ~[CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks
]
        at me.imaginefrags.nebula.Nebula.<init>(Nebula.java:93) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
~[?:1.8.0]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
~[?:1.8.0]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce) ~[?:1.8.0]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
a:52) ~[CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
ava:127) ~[CraftBukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        ... 14 more
 

WeiBeX

Platinum
Joined
Feb 13, 2013
Messages
1,185
Reaction score
1,613
Thread moved to off topic discussions. :)
 

Members online

No members online now.

Forum statistics

Threads
242,192
Messages
2,449,550
Members
523,971
Latest member
Atasci