I want to make plugin, that will store all player items into chest, and places chest in players location ON DISCONNECT, so my plugin spawns chest on the disconnected players location, but doesnt clear players inventory, and doesnt store items into spawned chest, any ideas why? My code: Code: @EventHandler public void onDc(PlayerQuitEvent e){ Player p = e.getPlayer(); ItemStack[] inv = p.getInventory().getContents(); p.getLocation().getBlock().setTypeId(54); Block b = p.getLocation().getBlock(); if(b.getTypeId()==54){ Chest chest = ((Chest) b.getState()); chest.getBlockInventory().addItem(inv); } p.getInventory().clear(); p.updateInventory(); } CONSOLE ERROR:
@Wingas If @Jay3105's method does not work you're doing something wrong, as that does not check for null values. Please post your code.
Code: if(!inv.equals(null)&&chest.equals(null)){ } hm? Code: @EventHandler public void onDc(PlayerQuitEvent e){ Player p = e.getPlayer(); ItemStack[] inv = p.getInventory().getContents(); p.getLocation().getBlock().setTypeId(54); Block b = p.getLocation().getBlock(); Chest chest = ((Chest) b.getState()); chest.getBlockInventory().setContents(inv); p.getInventory().clear(); p.updateInventory(); } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@Wingas Building on what @timtower said, use a double chest instead of a single. Or listen for a right click on the chest and open a virtual inv Sent from my iPhone using Tapatalk