Everytime i try to use my event it gives me this error : [10:07:56] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to Backpacks v1.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:227) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:194) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:692) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40] at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot_server.jar:git-Spigot-2f787bd-ea28011] at java.lang.Thread.run(Unknown Source) [?:1.8.0_40] Caused by: java.lang.NullPointerException at me.vhbob.backpacks.back.openBP(back.java:28) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_40] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_40] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot_server.jar:git-Spigot-2f787bd-ea28011] ... 18 more [/QUOTE] My code is : Code: package me.vhbob.backpacks; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class back extends JavaPlugin implements Listener { public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void openBP(PlayerInteractEvent e) { Player p = e.getPlayer(); if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (p.getItemInHand().getType().equals(Material.CHEST)) { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Small Backpack"); for (String slot : getConfig().getConfigurationSection("Backpack." + p.getName()).getKeys(false)) { ItemStack item = getConfig().getItemStack("Backpack." + p.getName() + "." + slot); inv.addItem(item); } p.openInventory(inv); } } } @EventHandler public void save(InventoryCloseEvent e){ if (e.getInventory().getTitle().equalsIgnoreCase("Small Backpack")) { Player p = (Player) e.getPlayer(); for (int i = 0; i < e.getInventory().getSize(); i++) { getConfig().set("Backpack." + p.getName() + "." + i, e.getInventory().getItem(i)); saveConfig(); } } } please help
@vhbob Your error line is: Code: for (String slot : getConfig().getConfigurationSection("Backpack." + p.getName()).getKeys(false)) and you have a NullPointerException. Is the Configuration Section null? Is player null?
Nevermind, i fixed it but the items dont load, heres the code @BrickBoy55 : Code: package me.vhbob.backpacks; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class back extends JavaPlugin implements Listener { public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void openBP(PlayerInteractEvent e) { Player p = e.getPlayer(); if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (p.getItemInHand().getType().equals(Material.CHEST)) { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Small Backpack"); if (getConfig().contains(p.getName())) { for (String slot : getConfig().getConfigurationSection( "Backpack." + p.getName()).getKeys(false)) { ItemStack item = getConfig().getItemStack( "Backpack." + p.getName() + "." + slot); inv.addItem(item); } p.openInventory(inv); } else { p.openInventory(inv); } } } } @EventHandler public void save(InventoryCloseEvent e) { if (e.getInventory().getTitle().equalsIgnoreCase("Small Backpack")) { Player p = (Player) e.getPlayer(); for (int i = 0; i < e.getInventory().getSize(); i++) { getConfig().set("Backpack." + p.getName() + "." + i, e.getInventory().getItem(i)); saveConfig(); } } } } and heres the config : Code: Backpack: vhbob: '0': ==: org.bukkit.inventory.ItemStack type: SAND '1': ==: org.bukkit.inventory.ItemStack type: GRASS '2': ==: org.bukkit.inventory.ItemStack type: STONE '3': ==: org.bukkit.inventory.ItemStack type: DIRT the item stacks dont load at all
@vhbob I don't know, but you could try a for loop starting at 0, and increasing to your inventory size, it can get the values and add it then it will keep repeating to add the items. It probably isn't that most efficient way, so you should try finding someone more experienced than me.