Skip to content

Commit 0e35e96

Browse files
committed
Add blockstate ids to block permissions
1 parent 3db6320 commit 0e35e96

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

src/main/java/io/github/zerthick/protectionperms/ProtectionPerms.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
@Plugin(id = "protectionperms",
3333
name = "ProtectionPerms",
34-
version = "0.8.0",
34+
version = "1.0.0",
3535
description = "A simple player protection and control plugin.",
3636
authors = {
3737
"Zerthick"

src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/BreakListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
3838
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
3939
for (Transaction<BlockSnapshot> transaction : transactions) {
4040
BlockSnapshot snapshot = transaction.getOriginal();
41-
String blockId = snapshot.getState().getType().getId();
42-
if (!player.hasPermission("protectionperms.block.break." + blockId)) {
41+
String blockTypeId = snapshot.getState().getType().getId();
42+
String blockStateId = snapshot.getState().getId();
43+
if (!player.hasPermission("protectionperms.block.break." + blockTypeId) ||
44+
!player.hasPermission("protectionperms.block.break." + blockStateId)) {
4345
event.setCancelled(true);
4446
player.sendMessage(ChatTypes.ACTION_BAR,
45-
Text.of(TextColors.RED, "You don't have permission to break " + blockId + '!'));
47+
Text.of(TextColors.RED, "You don't have permission to break " + blockStateId + '!'));
4648
break;
4749
}
4850
}

src/main/java/io/github/zerthick/protectionperms/events/listeners/block/changeBlockEvent/PlaceListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
3838
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
3939
for (Transaction<BlockSnapshot> transaction : transactions) {
4040
BlockSnapshot snapshot = transaction.getFinal();
41-
String blockId = snapshot.getState().getType().getId();
42-
if (!player.hasPermission("protectionperms.block.place." + blockId)) {
41+
String blockTypeId = snapshot.getState().getType().getId();
42+
String blockStateId = snapshot.getState().getId();
43+
if (!player.hasPermission("protectionperms.block.place." + blockTypeId) ||
44+
!player.hasPermission("protectionperms.block.place." + blockStateId)) {
4345
event.setCancelled(true);
4446
player.sendMessage(ChatTypes.ACTION_BAR,
45-
Text.of(TextColors.RED, "You don't have permission to place " + blockId + '!'));
47+
Text.of(TextColors.RED, "You don't have permission to place " + blockStateId + '!'));
4648
break;
4749
}
4850
}

src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/PrimaryListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public class PrimaryListener {
3131

3232
@Listener
3333
public void onInteractBlockPrimary(InteractBlockEvent.Primary event, @Root Player player) {
34-
String blockId = event.getTargetBlock().getState().getType().getId();
35-
if (!player.hasPermission("protectionperms.block.interact." + blockId + ".primary")) {
34+
String blockTypeId = event.getTargetBlock().getState().getType().getId();
35+
String blockStateId = event.getTargetBlock().getState().getId();
36+
if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".primary") ||
37+
!player.hasPermission("protectionperms.block.interact." + blockStateId + ".primary")) {
3638
event.setCancelled(true);
3739
player.sendMessage(ChatTypes.ACTION_BAR,
38-
Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockId + '!'));
40+
Text.of(TextColors.RED, "You don't have permission to primary interact with " + blockStateId + '!'));
3941
}
4042
}
4143
}

src/main/java/io/github/zerthick/protectionperms/events/listeners/block/interactBlockEvent/SecondaryListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public class SecondaryListener {
3131

3232
@Listener
3333
public void onInteractBlockSecondary(InteractBlockEvent.Secondary event, @Root Player player) {
34-
String blockId = event.getTargetBlock().getState().getType().getId();
35-
if (!player.hasPermission("protectionperms.block.interact." + blockId + ".secondary")) {
34+
String blockTypeId = event.getTargetBlock().getState().getType().getId();
35+
String blockStateId = event.getTargetBlock().getState().getId();
36+
if (!player.hasPermission("protectionperms.block.interact." + blockTypeId + ".secondary") ||
37+
!player.hasPermission("protectionperms.block.interact." + blockStateId + ".secondary")) {
3638
event.setCancelled(true);
3739
player.sendMessage(ChatTypes.ACTION_BAR,
38-
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockId + '!'));
40+
Text.of(TextColors.RED, "You don't have permission to secondary interact with " + blockStateId + '!'));
3941
}
4042
}
4143
}

src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/PrimaryBlockListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public class PrimaryBlockListener {
3636
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
3737
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
3838
if(itemStackOptional.isPresent()) {
39-
String blockId = event.getTargetBlock().getState().getType().getId();
39+
String blockTypeId = event.getTargetBlock().getState().getType().getId();
40+
String blockStateId = event.getTargetBlock().getState().getId();
4041
String itemId = itemStackOptional.get().getItem().getId();
41-
if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockId + ".primary")) {
42+
if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockTypeId + ".primary") ||
43+
!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockStateId + ".primary")) {
4244
event.setCancelled(true);
4345
player.sendMessage(ChatTypes.ACTION_BAR,
44-
Text.of(TextColors.RED, "You don't have permission to primary use " + itemId + " on " + blockId + '!'));
46+
Text.of(TextColors.RED, "You don't have permission to primary use " + itemId + " on " + blockStateId + '!'));
4547
}
4648
}
4749
}

src/main/java/io/github/zerthick/protectionperms/events/listeners/item/interactBlockEvent/SecondaryBlockListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ public class SecondaryBlockListener {
3636
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
3737
Optional<ItemStack> itemStackOptional = player.getItemInHand(event.getHandType());
3838
if(itemStackOptional.isPresent()) {
39-
String blockId = event.getTargetBlock().getState().getType().getId();
39+
String blockTypeId = event.getTargetBlock().getState().getType().getId();
40+
String blockStateId = event.getTargetBlock().getState().getId();
4041
String itemId = itemStackOptional.get().getItem().getId();
41-
if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockId + ".secondary")) {
42+
if (!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockTypeId + ".secondary") ||
43+
!player.hasPermission("protectionperms.item.use." + itemId + ".on." + blockStateId + ".secondary")) {
4244
event.setCancelled(true);
4345
player.sendMessage(ChatTypes.ACTION_BAR,
44-
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemId + " on " + blockId + '!'));
46+
Text.of(TextColors.RED, "You don't have permission to secondary use " + itemId + " on " + blockStateId + '!'));
4547
}
4648
}
4749
}

0 commit comments

Comments
 (0)