diff --git a/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java b/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java index 32f8dc6..73e471b 100644 --- a/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java +++ b/src/main/java/ru/tehkode/modifyworld/ModifyworldListener.java @@ -24,6 +24,7 @@ import org.bukkit.block.BlockState; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.*; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -60,7 +61,7 @@ public abstract class ModifyworldListener implements Listener { return getEntityName(((ComplexEntityPart) entity).getParent()); } - String entityName = entity.getType().toString().toLowerCase().replace("_", ""); + String entityName = formatEnumString(entity.getType().toString()); if (entity instanceof Item) { entityName = getItemPermission(((Item) entity).getItemStack()); @@ -83,10 +84,14 @@ public abstract class ModifyworldListener implements Listener { return category.getNameDot() + entityName; } + + private String getInventoryTypePermission(InventoryType type) { + return formatEnumString(type.name()); + } // Functional programming fuck yeah private String getMaterialPermission(Material type) { - return this.useMaterialNames ? type.name().toLowerCase().replace("_", "") : Integer.toString(type.getId()); + return this.useMaterialNames ? formatEnumString(type.name()) : Integer.toString(type.getId()); } private String getMaterialPermission(Material type, byte metadata) { @@ -162,6 +167,8 @@ public abstract class ModifyworldListener implements Listener { return (getMaterialPermission((Material) obj)); } else if (obj instanceof Block) { return (getBlockPermission((Block) obj)); + } else if (obj instanceof InventoryType) { + return getInventoryTypePermission((InventoryType)obj); } return (obj.toString()); @@ -170,4 +177,8 @@ public abstract class ModifyworldListener implements Listener { private void registerEvents(Plugin plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } + + private String formatEnumString(String enumName) { + return enumName.toLowerCase().replace("_", ""); + } } diff --git a/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java b/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java index 85a3f4b..327abc8 100644 --- a/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java +++ b/src/main/java/ru/tehkode/modifyworld/handlers/PlayerListener.java @@ -182,14 +182,14 @@ public class PlayerListener extends ModifyworldListener { if (holder instanceof Player || // do not track inter-inventory stuff event.getRawSlot() >= event.getView().getTopInventory().getSize() || // top inventory only - event.getSlotType() == InventoryType.SlotType.OUTSIDE) { // do not track drop + event.getSlotType() == InventoryType.SlotType.OUTSIDE || // do not track drop + event.getSlot() == -999) { // temporary fix for bukkit bug (BUKKIT-2768) return; } - ItemStack take = holder.getInventory().getItem(event.getSlot()); + ItemStack take = event.getInventory().getItem(event.getSlot()); String action; - String op; ItemStack item; if (take == null) { @@ -202,7 +202,7 @@ public class PlayerListener extends ModifyworldListener { Player player = (Player) event.getWhoClicked(); - if (permissionDenied(player, "modifyworld.items", action, item, "of", holder)) { + if (permissionDenied(player, "modifyworld.items", action, item, "of", event.getInventory().getType())) { event.setCancelled(true); } }