diff --git a/src/main/java/net/simplyvanilla/noillegals/NoIllegalsPlugin.java b/src/main/java/net/simplyvanilla/noillegals/NoIllegalsPlugin.java index ced172f..8412ad4 100644 --- a/src/main/java/net/simplyvanilla/noillegals/NoIllegalsPlugin.java +++ b/src/main/java/net/simplyvanilla/noillegals/NoIllegalsPlugin.java @@ -223,7 +223,7 @@ public void logPlayerItemSent(Player player, ItemStack itemStack, } } - public void logInventoryCreation(Player player, InventoryType inventoryType, + public void logInventoryCreation(Player player, String inventoryType, Location location) { if (!inventoryCreationLogText.isEmpty()) { this.getLogger() @@ -231,7 +231,7 @@ public void logInventoryCreation(Player player, InventoryType inventoryType, Level.INFO, () -> inventoryCreationLogText - .replace("[inventory_type]", inventoryType.name()) + .replace("[inventory_type]", inventoryType) .replace(PLAYER_NAME_PLACEHOLDER, player.getName()) .replace("[x]", String.valueOf(location.getBlockX())) .replace("[y]", String.valueOf(location.getBlockY())) diff --git a/src/main/java/net/simplyvanilla/noillegals/check/InventoryCreationCheck.java b/src/main/java/net/simplyvanilla/noillegals/check/InventoryCreationCheck.java index 95970ba..f7d28cc 100644 --- a/src/main/java/net/simplyvanilla/noillegals/check/InventoryCreationCheck.java +++ b/src/main/java/net/simplyvanilla/noillegals/check/InventoryCreationCheck.java @@ -1,7 +1,10 @@ package net.simplyvanilla.noillegals.check; import net.simplyvanilla.noillegals.NoIllegalsPlugin; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.block.Container; +import org.bukkit.block.EnderChest; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; @@ -16,7 +19,7 @@ public InventoryCreationCheck(NoIllegalsPlugin plugin) { @EventHandler(ignoreCancelled = true) public void handleInventoryCreation(BlockPlaceEvent event) { // block isn't a container, so we don't care - if (!(event.getBlock().getState() instanceof Container container)) { + if (!this.isContainer(event.getBlock())) { return; } @@ -25,7 +28,30 @@ public void handleInventoryCreation(BlockPlaceEvent event) { return; } - this.plugin.logInventoryCreation(event.getPlayer(), container.getInventory().getType(), + String containerType = this.getContainerType(event.getBlock()); + + this.plugin.logInventoryCreation(event.getPlayer(), containerType, event.getBlock().getLocation()); } + + private String getContainerType(Block block) { + if (block.getState() instanceof EnderChest) { + return "ENDER_CHEST"; + } + + if (block.getState() instanceof Container container) { + return container.getInventory().getType().name(); + } + + // should not happen + return "unknown"; + } + + private boolean isContainer(Block block) { + if (block.getState() instanceof Container) { + return true; + } + + return block.getType().equals(Material.ENDER_CHEST); + } } diff --git a/src/main/java/net/simplyvanilla/noillegals/check/InventoryItemCheck.java b/src/main/java/net/simplyvanilla/noillegals/check/InventoryItemCheck.java index 291f81f..3533291 100644 --- a/src/main/java/net/simplyvanilla/noillegals/check/InventoryItemCheck.java +++ b/src/main/java/net/simplyvanilla/noillegals/check/InventoryItemCheck.java @@ -56,8 +56,7 @@ private void handleItemManipulation(InventoryClickEvent event, Player player) { this.plugin.logPlayerItemReceive(player, item); } else { this.plugin.logPlayerItemSent(player, item, - event.getClickedInventory() - .getType()); + event.getView().getTopInventory().getType()); } } if ((event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD) @@ -82,7 +81,7 @@ private void handleItemPickups(Player player, InventoryClickEvent event) { item.setAmount(0); return; } - + if (event.getView().getTopInventory().getType().equals(InventoryType.CRAFTING)) { return; }