Skip to content

Commit

Permalink
Add blockstate ids to block permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthick committed Jun 14, 2017
1 parent 3db6320 commit 0e35e96
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '!'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '!'));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public class PrimaryBlockListener {
public void onInteractBlockPrimaryMain(InteractBlockEvent.Primary event, @Root Player player) {
Optional<ItemStack> 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 + '!'));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public class SecondaryBlockListener {
public void onInteractBlockSecondaryMain(InteractBlockEvent.Secondary event, @Root Player player) {
Optional<ItemStack> 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 + '!'));
}
}
}
Expand Down

0 comments on commit 0e35e96

Please sign in to comment.