I'm trying to create a method allows me add items easier & create inventories alot easier. Here's my code. Here's the problem whenever I right click my glowstone dust it throws out a eventexception error and i'm not sure why. Here's what it's suppose to do whenever someone right clicks the glowstone dust it should open up a inventory named "Gadgets" in green. With one item in the inventory thats named "HidePlayers"
Error
[01:25:55 ERROR]: Could not pass event PlayerInteractEvent to KnoxHub v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:310) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:502) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:487) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:227) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:194) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInte
ractEvent(CraftEventFactory.java:190) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git
-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
:694) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:52) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91ae
d8]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlo
ckPlace.java:1) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed
8]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
3) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
?:1.8.0_51]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spig
ot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
18) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a
multiple of 9!
at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot-1
.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.createInventory(CraftServe
r.java:1525) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.Bukkit.createInventory(Bukkit.java:937) ~[spigot-1.8.7-R0.
1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at crypted.knoxhub.Gadgets.GadgetCore.KInventoryCreate(GadgetCore.java:3
5) ~[?:?]
at crypted.knoxhub.Gadgets.GadgetCore.AddGadget(GadgetCore.java:42) ~[?:
?]
at crypted.knoxhub.Gadgets.GadgetCore.Interact(GadgetCore.java:66) ~[?:?
]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
.8.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:306) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
... 18 more
>
GadgetCore.Java
private Core Plugin;
public GadgetCore(Core p){ this.Plugin = p; }
//Inventories
public Inventory GadgetMenu;
// Simple Inventory Creation
public Inventory KInventoryCreate( int slots, String invname ) throws IOException {
return Bukkit.createInventory(null, slots, invname);
}
// Simple Gadget Creation
public void AddGadget(Player player,int position ,String permission, ItemStack item, String GadgetItemName, String lore) throws IOException {
GadgetMenu = KInventoryCreate(10, ChatColor.GREEN + "Gadgets");
if ( !player.hasPermission(permission) ) {
player.sendMessage( ChatColor.RED + GadgetItemName.toUpperCase() + ChatColor.YELLOW + " can only be used by specific Ranks");
return;
}
GadgetMenu.setItem(position, Plugin.applyLore(item, GadgetItemName, lore));
}
@EventHandler
public void Interact(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.GLOWSTONE_DUST)) {
e.setCancelled(true);
AddGadget(p, 3, "gadget.hide", new ItemStack(Material.GLOWSTONE_DUST), "HidePlayers", ChatColor.GRAY + "d");
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
@EventHandler
public void Debug(PlayerInteractEvent e) throws IOException{
Player p = e.getPlayer();
ItemStack item = p.getItemInHand();
if ( e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK) ) {
if ( item.getType().equals(Material.REDSTONE) ) {
e.setCancelled(true);
p.openInventory(GadgetMenu);
p.sendMessage("Debug");
}
}
}
Core.Java
public class Core extends JavaPlugin implements Listener {
public Core plugin;
public GadgetCore gc;
public ItemStack applyLore(ItemStack stack, String name, String lore1){
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(name);
ArrayList<String> lore = new ArrayList<String>();
lore.add(lore1);
meta.setLore(lore);
stack.setItemMeta(meta);
return stack;
}
public void onEnable(){
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[KnoxHub] created by 2hash");
// Bukkit.getPluginManager().registerEvents(new );
getServer().getPluginManager().registerEvents(new GadgetCore(this), this);
}
}