Fixed a bug: people were able to move banned items in /f chest by using hotbar keys.

This commit is contained in:
Stefan923 2020-05-09 17:37:06 +03:00 committed by BrowkS
parent f5f8e6aad2
commit c42949ec59

View File

@ -27,9 +27,10 @@ public class AntiChestListener implements Listener {
if (e.isCancelled()) return; if (e.isCancelled()) return;
Inventory clicked = e.getClickedInventory(); Inventory clicked = e.getClickedInventory();
Inventory clicker = e.getWhoClicked().getInventory();
if (e.getClick().isShiftClick()) { if (e.getClick().isShiftClick()) {
if (clicked == e.getWhoClicked().getInventory()) { if (clicked == clicker) {
ItemStack clickedOn = e.getCurrentItem(); ItemStack clickedOn = e.getCurrentItem();
if (clickedOn != null && FactionsPlugin.getInstance().itemList.contains(clickedOn.getType().toString())) { if (clickedOn != null && FactionsPlugin.getInstance().itemList.contains(clickedOn.getType().toString())) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, clickedOn.getType().toString()); fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, clickedOn.getType().toString());
@ -38,11 +39,17 @@ public class AntiChestListener implements Listener {
} }
} }
if (clicked != e.getWhoClicked().getInventory()) { if (clicked != clicker) {
ItemStack onCursor = e.getCursor(); ItemStack onCursor = e.getCursor();
if (onCursor != null && FactionsPlugin.getInstance().itemList.contains(onCursor.getType().toString())) { if (onCursor != null && FactionsPlugin.getInstance().itemList.contains(onCursor.getType().toString())) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, onCursor.getType().toString()); fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, onCursor.getType().toString());
e.setCancelled(true); e.setCancelled(true);
} else if (e.getClick().isKeyboardClick()) {
ItemStack item = clicker.getItem(e.getHotbarButton());
if (item != null && FactionsPlugin.getInstance().itemList.contains(item.getType().toString())) {
fPlayer.msg(TL.CHEST_ITEM_DENIED_TRANSFER, item.getType().toString());
e.setCancelled(true);
}
} }
} }
} }