diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/CraftItemListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/CraftItemListener.java index d9d210f..61f20b3 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/CraftItemListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/CraftItemListener.java @@ -3,11 +3,13 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.filter.Getter; -import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.event.filter.cause.First; import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.Inventory; import org.spongepowered.api.item.inventory.InventoryArchetypes; import org.spongepowered.api.item.inventory.crafting.CraftingOutput; +import org.spongepowered.api.item.inventory.query.QueryOperationTypes; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.format.TextColors; @@ -16,17 +18,19 @@ public class CraftItemListener { @Listener - public void onItemCraft(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { + public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) { if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) { - Inventory craftingOutputs = inventory.query(CraftingOutput.class); + Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class)); craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> { - String itemId = itemStack.getItem().getType().getId(); + + ItemType itemType = itemStack.getType(); + String itemId = itemType.getId(); if (!player.hasPermission("protectionperms.item.craft." + itemId)) { event.setCancelled(true); - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemId + '!')); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!')); } })); } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDeathListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDeathListener.java index c9dae48..9bad04d 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDeathListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDeathListener.java @@ -4,17 +4,14 @@ import org.spongepowered.api.entity.Item; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause; import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.item.inventory.DropItemEvent; public class DropItemDeathListener { @Listener - public void onItemDropDeath(DropItemEvent.Destruct event, @Root EntitySpawnCause spawnCause) { + public void onItemDropDeath(DropItemEvent.Destruct event, @Root Player player) { - if (spawnCause.getEntity() instanceof Player) { - Player player = (Player) spawnCause.getEntity(); event.filterEntities(entity -> { if (entity.getType().equals(EntityTypes.ITEM)) { Item item = (Item) entity; @@ -23,6 +20,5 @@ public void onItemDropDeath(DropItemEvent.Destruct event, @Root EntitySpawnCause } return true; }); - } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDispenseListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDispenseListener.java index f544675..f0c2827 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDispenseListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/DropItemDispenseListener.java @@ -23,9 +23,9 @@ import org.spongepowered.api.entity.Item; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause; import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.item.inventory.DropItemEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.format.TextColors; @@ -33,21 +33,19 @@ public class DropItemDispenseListener { @Listener - public void onItemDrop(DropItemEvent.Dispense event, @Root EntitySpawnCause spawnCause) { + public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) { - if (spawnCause.getEntity() instanceof Player) { - Player player = (Player) spawnCause.getEntity(); - event.filterEntities(entity -> { - if (entity.getType().equals(EntityTypes.ITEM)) { - Item item = (Item) entity; - String itemId = item.getItemType().getId(); - if (!player.hasPermission("protectionperms.item.drop." + itemId + ".dispense")) { - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemId + '!')); - return false; - } + event.filterEntities(entity -> { + if (entity.getType().equals(EntityTypes.ITEM)) { + Item item = (Item) entity; + ItemType itemType = item.getItemType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.drop." + itemId + ".dispense")) { + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!')); + return false; } - return true; - }); - } + } + return true; + }); } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EnchantItemListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EnchantItemListener.java index 68c53a6..33cd063 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EnchantItemListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EnchantItemListener.java @@ -1,24 +1,18 @@ package io.github.zerthick.protectionperms.events.listeners.item; -import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.filter.Getter; import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; import org.spongepowered.api.item.inventory.Inventory; -import org.spongepowered.api.item.inventory.InventoryArchetypes; -import org.spongepowered.api.item.inventory.slot.InputSlot; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.text.chat.ChatTypes; -import org.spongepowered.api.text.format.TextColors; public class EnchantItemListener { @Listener public void onItemEnchant(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { - if (inventory.getArchetype() == InventoryArchetypes.ENCHANTING_TABLE) { + /*if (inventory.getArchetype() == InventoryArchetypes.ENCHANTING_TABLE) { Inventory enchantingInputs = inventory.query(InputSlot.class); @@ -33,7 +27,7 @@ public void onItemEnchant(ClickInventoryEvent event, @Root Player player, @Gette } })); })); - } + }*/ } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EquipItemListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EquipItemListener.java index 6f1a91c..9bac153 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EquipItemListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/EquipItemListener.java @@ -3,10 +3,12 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.filter.Getter; -import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.event.filter.cause.First; import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.Inventory; import org.spongepowered.api.item.inventory.InventoryArchetypes; +import org.spongepowered.api.item.inventory.query.QueryOperationTypes; import org.spongepowered.api.item.inventory.slot.EquipmentSlot; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; @@ -15,17 +17,20 @@ public class EquipItemListener { @Listener - public void onItemEquip(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { + public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) { if (inventory.getArchetype() == InventoryArchetypes.PLAYER) { - Inventory equipmentSlots = inventory.query(EquipmentSlot.class); + Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class)); equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> { - String itemId = itemStack.getItem().getType().getId(); + + ItemType itemType = itemStack.getType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.equip." + itemId + ".on.self")) { event.setCancelled(true); - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemId + '!')); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!')); } })); } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/ItemListenerManager.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/ItemListenerManager.java index 1aa9fc9..4e9f060 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/ItemListenerManager.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/ItemListenerManager.java @@ -20,10 +20,6 @@ package io.github.zerthick.protectionperms.events.listeners.item; import io.github.zerthick.protectionperms.events.listeners.ListenerManager; -import io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent.PrimaryBlockListener; -import io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent.SecondaryBlockListener; -import io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent.PrimaryEntityListener; -import io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent.SecondaryEntityListener; import java.util.LinkedList; import java.util.List; @@ -34,18 +30,18 @@ public class ItemListenerManager implements ListenerManager{ public ItemListenerManager() { listeners = new LinkedList<>(); - listeners.add(new PrimaryBlockListener()); - listeners.add(new SecondaryBlockListener()); - listeners.add(new PrimaryEntityListener()); - listeners.add(new SecondaryEntityListener()); - listeners.add(new UseItemListener()); - listeners.add(new DropItemDispenseListener()); - listeners.add(new DropItemDeathListener()); - listeners.add(new CraftItemListener()); - //listeners.add(new EnchantItemListener()); - listeners.add(new SmeltItemListener()); - //listeners.add(new ForgeItemListener()); - //listeners.add(new BrewItemListener()); + //listeners.add(new PrimaryBlockListener()); + //listeners.add(new SecondaryBlockListener()); + //listeners.add(new PrimaryEntityListener()); + //listeners.add(new SecondaryEntityListener()); + //listeners.add(new UseItemListener()); + //listeners.add(new DropItemDispenseListener()); + //listeners.add(new DropItemDeathListener()); + //listeners.add(new CraftItemListener()); + //*listeners.add(new EnchantItemListener()); + //listeners.add(new SmeltItemListener()); + //*listeners.add(new ForgeItemListener()); + //*listeners.add(new BrewItemListener()); listeners.add(new EquipItemListener()); } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/SmeltItemListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/SmeltItemListener.java index de509b0..d4181cd 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/SmeltItemListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/SmeltItemListener.java @@ -3,10 +3,12 @@ import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.filter.Getter; -import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.event.filter.cause.First; import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.Inventory; import org.spongepowered.api.item.inventory.InventoryArchetypes; +import org.spongepowered.api.item.inventory.query.QueryOperationTypes; import org.spongepowered.api.item.inventory.slot.FuelSlot; import org.spongepowered.api.item.inventory.slot.InputSlot; import org.spongepowered.api.text.Text; @@ -16,24 +18,26 @@ public class SmeltItemListener { @Listener - public void onItemSmelt(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) { + public void onItemSmelt(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) { if (inventory.getArchetype() == InventoryArchetypes.FURNACE) { - Inventory smeltingInputs = inventory.query(InputSlot.class); + Inventory smeltingInputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(InputSlot.class)); smeltingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> { - String itemId = itemStack.getItem().getType().getId(); + + ItemType itemType = itemStack.getType(); + String itemId = itemType.getId(); if (slot instanceof FuelSlot) { if (!player.hasPermission("protectionperms.item.fuel." + itemId)) { event.setCancelled(true); - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemId + " as fuel!")); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + " as fuel!")); } } else { if (!player.hasPermission("protectionperms.item.smelt." + itemId)) { event.setCancelled(true); - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to smelt " + itemId + '!')); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to smelt " + itemType.getName() + '!')); } } })); diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/UseItemListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/UseItemListener.java index 8636cdd..4843114 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/UseItemListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/UseItemListener.java @@ -23,6 +23,7 @@ import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.filter.cause.Root; import org.spongepowered.api.event.item.inventory.UseItemStackEvent; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.format.TextColors; @@ -31,10 +32,12 @@ public class UseItemListener { @Listener public void onItemUse(UseItemStackEvent.Start event, @Root Player player) { - String itemId = event.getItemStackInUse().getType().getId(); + + ItemType itemType = event.getItemStackInUse().getType(); + String itemId = itemType.getId(); if (!player.hasPermission("protectionperms.item.use." + itemId + ".on.self")) { event.setCancelled(true); - player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemId + '!')); + player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + '!')); } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java index 6bc6ab0..eb72b8e 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java @@ -19,10 +19,12 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent; +import org.spongepowered.api.block.BlockState; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.block.InteractBlockEvent; import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; @@ -36,14 +38,19 @@ public class PrimaryBlockListener { public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String blockTypeId = event.getTargetBlock().getState().getType().getId(); - String blockStateId = event.getTargetBlock().getState().getId(); - String itemId = itemStackOptional.get().getItem().getId(); + + BlockState blockState = event.getTargetBlock().getState(); + String blockTypeId = blockState.getType().getId(); + String blockStateId = blockState.getId(); + + ItemType itemType = itemStackOptional.get().getType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary") && !player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to primary use " + itemId + " on " + blockStateId + '!')); + Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + blockState.getName() + '!')); } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java index 7e599dd..2e6a402 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java @@ -19,10 +19,12 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactBlockEvent; +import org.spongepowered.api.block.BlockState; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.block.InteractBlockEvent; import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; @@ -36,14 +38,19 @@ public class SecondaryBlockListener { public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String blockTypeId = event.getTargetBlock().getState().getType().getId(); - String blockStateId = event.getTargetBlock().getState().getId(); - String itemId = itemStackOptional.get().getItem().getId(); + + BlockState blockState = event.getTargetBlock().getState(); + String blockTypeId = blockState.getType().getId(); + String blockStateId = blockState.getId(); + + ItemType itemType = itemStackOptional.get().getType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary") && !player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to secondary use " + itemId + " on " + blockStateId + '!')); + Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + blockState.getName() + '!')); } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java index 80500bb..02eeebc 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/PrimaryEntityListener.java @@ -19,10 +19,12 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent; +import org.spongepowered.api.entity.EntityType; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.entity.InteractEntityEvent; import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; @@ -36,12 +38,17 @@ public class PrimaryEntityListener { public void onInteractEntityPrimaryMain(InteractEntityEvent.Primary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String entityId = event.getTargetEntity().getType().getId(); - String itemId = itemStackOptional.get().getItem().getId(); + + EntityType entityType = event.getTargetEntity().getType(); + String entityId = entityType.getId(); + + ItemType itemType = itemStackOptional.get().getType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to primary use " + itemId + " on " + entityId + '!')); + Text.of(TextColors.RED, "You don't have permission to primary use " + itemType.getName() + " on " + entityType.getName() + "s!")); } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java index c40d1ef..4abd6e0 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactEntityEvent/SecondaryEntityListener.java @@ -19,10 +19,12 @@ package io.github.zerthick.protectionperms.events.listeners.item.interactEntityEvent; +import org.spongepowered.api.entity.EntityType; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.entity.InteractEntityEvent; import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.text.Text; import org.spongepowered.api.text.chat.ChatTypes; @@ -36,12 +38,17 @@ public class SecondaryEntityListener { public void onInteractEntitySecondaryMain(InteractEntityEvent.Secondary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String entityId = event.getTargetEntity().getType().getId(); - String itemId = itemStackOptional.get().getItem().getId(); + + EntityType entityType = event.getTargetEntity().getType(); + String entityId = entityType.getId(); + + ItemType itemType = itemStackOptional.get().getType(); + String itemId = itemType.getId(); + if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + entityId + ".primary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to secondary use " + itemId + " on " + entityId + '!')); + Text.of(TextColors.RED, "You don't have permission to secondary use " + itemType.getName() + " on " + entityType.getName() + "s!")); } } }