From 0e35e96e770091c78dd5b43d698f848becff01f3 Mon Sep 17 00:00:00 2001 From: Zerthick Date: Wed, 14 Jun 2017 16:58:53 -0400 Subject: [PATCH] Add blockstate ids to block permissions --- .../github/zerthick/protectionperms/ProtectionPerms.java | 2 +- .../listeners/block/changeBlockEvent/BreakListener.java | 8 +++++--- .../listeners/block/changeBlockEvent/PlaceListener.java | 8 +++++--- .../block/interactBlockEvent/PrimaryListener.java | 8 +++++--- .../block/interactBlockEvent/SecondaryListener.java | 8 +++++--- .../item/interactBlockEvent/PrimaryBlockListener.java | 8 +++++--- .../item/interactBlockEvent/SecondaryBlockListener.java | 8 +++++--- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/github/zerthick/protectionperms/ProtectionPerms.java b/src/main/java/io/github/zerthick/protectionperms/ProtectionPerms.java index c50004f..caf4be1 100644 --- a/src/main/java/io/github/zerthick/protectionperms/ProtectionPerms.java +++ b/src/main/java/io/github/zerthick/protectionperms/ProtectionPerms.java @@ -31,7 +31,7 @@ @Plugin(id = "protectionperms", name = "ProtectionPerms", - version = "0.8.0", + version = "1.0.0", description = "A simple player protection and control plugin.", authors = { "Zerthick" diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/BreakListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/BreakListener.java index ef9aab0..341af74 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/BreakListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/BreakListener.java @@ -38,11 +38,13 @@ public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) { List> transactions = event.getTransactions(); for (Transaction transaction : transactions) { BlockSnapshot snapshot = transaction.getOriginal(); - String blockId = snapshot.getState().getType().getId(); - if (!player.hasPermission("protectionperms.block.break." + blockId)) { + String blockTypeId = snapshot.getState().getType().getId(); + String blockStateId = snapshot.getState().getId(); + if (!player.hasPermission("protectionperms.block.break." + blockTypeId) || + !player.hasPermission("protectionperms.block.break." + blockStateId)) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to break " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to break " + blockStateId + '!')); break; } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/PlaceListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/PlaceListener.java index 272f36b..9fb6de9 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/PlaceListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/PlaceListener.java @@ -38,11 +38,13 @@ public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) { List> transactions = event.getTransactions(); for (Transaction transaction : transactions) { BlockSnapshot snapshot = transaction.getFinal(); - String blockId = snapshot.getState().getType().getId(); - if (!player.hasPermission("protectionperms.block.place." + blockId)) { + String blockTypeId = snapshot.getState().getType().getId(); + String blockStateId = snapshot.getState().getId(); + if (!player.hasPermission("protectionperms.block.place." + blockTypeId) || + !player.hasPermission("protectionperms.block.place." + blockStateId)) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to place " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to place " + blockStateId + '!')); break; } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/PrimaryListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/PrimaryListener.java index 123815c..34193b1 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/PrimaryListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/PrimaryListener.java @@ -31,11 +31,13 @@ public class PrimaryListener { @Listener public void onInteractBlockPrimary(InteractBlockEvent.Primary event, @Root Player player) { - String blockId = event.getTargetBlock().getState().getType().getId(); - if (!player.hasPermission("protectionperms.block.interact." + blockId + ".primary")) { + String blockTypeId = event.getTargetBlock().getState().getType().getId(); + String blockStateId = event.getTargetBlock().getState().getId(); + if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".primary") || + !player.hasPermission("protectionperms.block.interact." + blockStateId + ".primary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockStateId + '!')); } } } diff --git a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/SecondaryListener.java b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/SecondaryListener.java index 8587118..a53be13 100644 --- a/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/SecondaryListener.java +++ b/src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/SecondaryListener.java @@ -31,11 +31,13 @@ public class SecondaryListener { @Listener public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) { - String blockId = event.getTargetBlock().getState().getType().getId(); - if (!player.hasPermission("protectionperms.block.interact." + blockId + ".secondary")) { + String blockTypeId = event.getTargetBlock().getState().getType().getId(); + String blockStateId = event.getTargetBlock().getState().getId(); + if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".secondary") || + !player.hasPermission("protectionperms.block.interact." + blockStateId + ".secondary")) { event.setCancelled(true); player.sendMessage(ChatTypes.ACTION_BAR, - Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockStateId + '!')); } } } 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 cf8b13e..1722893 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 @@ -36,12 +36,14 @@ public class PrimaryBlockListener { public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String blockId = event.getTargetBlock().getState().getType().getId(); + String blockTypeId = event.getTargetBlock().getState().getType().getId(); + String blockStateId = event.getTargetBlock().getState().getId(); String itemId = itemStackOptional.get().getItem().getId(); - if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockId + ".primary")) { + 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 " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to primary use " + itemId + " on " + blockStateId + '!')); } } } 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 17db04c..d166d6e 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 @@ -36,12 +36,14 @@ public class SecondaryBlockListener { public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) { Optional itemStackOptional = player.getItemInHand(event.getHandType()); if(itemStackOptional.isPresent()) { - String blockId = event.getTargetBlock().getState().getType().getId(); + String blockTypeId = event.getTargetBlock().getState().getType().getId(); + String blockStateId = event.getTargetBlock().getState().getId(); String itemId = itemStackOptional.get().getItem().getId(); - if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockId + ".secondary")) { + 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 " + blockId + '!')); + Text.of(TextColors.RED, "You don't have permission to secondary use " + itemId + " on " + blockStateId + '!')); } } }