From b5e559ff66b5500e92d48c43429f92a8964e0faf Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 1 Jan 2013 19:34:32 +0000 Subject: More cleanup --- .../essentials/EssentialsPlayerListener.java | 38 +++++++++++++++++++--- .../essentials/commands/Commandinvsee.java | 6 ++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 9a309ea6c..f8e530548 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -544,6 +544,7 @@ public class EssentialsPlayerListener implements Listener || !invOwner.isOnline())) { event.setCancelled(true); + user.updateInventory(); } } } @@ -565,10 +566,28 @@ public class EssentialsPlayerListener implements Listener } else if (type == InventoryType.CHEST && top.getSize() == 9) { - User user = ess.getUser(event.getWhoClicked()); - if (user.isInvSee()) + final User user = ess.getUser(event.getWhoClicked()); + final InventoryHolder invHolder = top.getHolder(); + if (invHolder != null && invHolder instanceof HumanEntity) { - event.setCancelled(true); + final User invOwner = ess.getUser((HumanEntity)invHolder); + + if (user.isInvSee() && (!user.isAuthorized("essentials.invsee.modify") + || invOwner.isAuthorized("essentials.invsee.preventmodify") + || !invOwner.isOnline() + || (event.getSlot() > 3 && event.getSlot() < 9))) + { + event.setCancelled(true); + user.updateInventory(); + } + else + { + final ItemStack[] contents = + { + top.getItem(0), top.getItem(1), top.getItem(2), top.getItem(3) + }; + invOwner.getInventory().setArmorContents(contents); + } } } } @@ -599,8 +618,17 @@ public class EssentialsPlayerListener implements Listener } else if (type == InventoryType.CHEST && top.getSize() == 9) { - final User user = ess.getUser(event.getPlayer()); - user.setInvSee(false); + final InventoryHolder invHolder = top.getHolder(); + if (invHolder != null && invHolder instanceof HumanEntity) + { + final User user = ess.getUser(event.getPlayer()); + final ItemStack[] contents = + { + top.getItem(0), top.getItem(1), top.getItem(2), top.getItem(3), + }; + ((HumanEntity)invHolder).getInventory().setArmorContents(contents); + user.setInvSee(false); + } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java index 29f69c22a..1f9083351 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java @@ -12,7 +12,7 @@ public class Commandinvsee extends EssentialsCommand super("invsee"); } - //This method has a hidden param, which if given will display the armour slots. #easteregg + //This method has a hidden param, which if given will display the equip slots. #easteregg @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception @@ -25,9 +25,9 @@ public class Commandinvsee extends EssentialsCommand final User invUser = getPlayer(server, args, 0); Inventory inv; - if (args.length > 1) + if (args.length > 1 && user.isAuthorized("essentials.invsee.equip")) { - inv = server.createInventory(user, 9, "Equipped"); + inv = server.createInventory(invUser, 9, "Equipped"); inv.setContents(invUser.getInventory().getArmorContents()); } else -- cgit v1.2.3