mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-18 02:51:19 +01:00
Differentiate between shop accessing and administrating
This fixes LWC donation and display protections not working correctly
This commit is contained in:
parent
5b214e09f5
commit
2be9207faa
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user