Differentiate between shop accessing and administrating

This fixes LWC donation and display protections not working correctly
This commit is contained in:
Phoenix616 2021-05-16 00:31:33 +01:00
parent 5b214e09f5
commit 2be9207faa
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
5 changed files with 24 additions and 3 deletions

View File

@ -13,6 +13,7 @@ public class ProtectionCheckEvent extends Event {
private Result result = Result.DEFAULT;
private boolean ignoreBuiltInProtection = false;
private boolean checkManagement = true;
private Block block;
private Player player;
@ -27,10 +28,21 @@ public class ProtectionCheckEvent extends Event {
this.ignoreBuiltInProtection = ignoreBuiltInProtection;
}
public ProtectionCheckEvent(Block block, Player player, boolean ignoreBuiltInProtection, boolean checkManagement) {
this.block = block;
this.player = player;
this.ignoreBuiltInProtection = ignoreBuiltInProtection;
this.checkManagement = checkManagement;
}
public boolean isBuiltInProtectionIgnored() {
return ignoreBuiltInProtection;
}
public boolean checkCanManage() {
return checkManagement;
}
public Result getResult() {
return result;
}

View File

@ -67,7 +67,7 @@ public class PlayerInteract implements Listener {
Sign sign = uBlock.getConnectedSign(block);
if (sign != null) {
if (!Security.canAccess(player, block, Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY)) {
if (!Security.canView(player, block, Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY)) {
if (Permission.has(player, Permission.SHOPINFO)) {
ChestShop.callEvent(new ShopInfoEvent(player, sign));
event.setCancelled(true);

View File

@ -55,7 +55,7 @@ public class PlayerInventory implements Listener {
boolean canAccess = false;
for (Block container : containers) {
if (ChestShopSign.isShopBlock(container)) {
if (Security.canAccess(player, container)) {
if (Security.canView(player, container, false)) {
canAccess = true;
}
} else {

View File

@ -120,7 +120,9 @@ public class LightweightChestProtection implements Listener {
return;
}
if (!lwc.canAccessProtection(player, protection) && !protection.getType().name().equals("DONATION") && !protection.getType().name().equals("DISPLAY")) {
if (event.checkCanManage()
? !lwc.canAdminProtection(player, protection)
: !lwc.canAccessProtection(player, protection)) {
event.setResult(Event.Result.DENY);
} else if (Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
event.setResult(Event.Result.ALLOW);

View File

@ -52,6 +52,13 @@ public class Security {
return event.getResult() != Event.Result.DENY;
}
public static boolean canView(Player player, Block block, boolean ignoreDefaultProtection) {
ProtectionCheckEvent event = new ProtectionCheckEvent(block, player, ignoreDefaultProtection, false);
ChestShop.callEvent(event);
return event.getResult() != Event.Result.DENY;
}
public static boolean canPlaceSign(Player player, Sign sign) {
Block baseBlock = BlockUtil.getAttachedBlock(sign);