Fix issues with LWC Single/Double Chest protections (Fixes #359)

This commit is contained in:
Phoenix616 2020-09-24 16:54:36 +01:00
parent 9dd56385eb
commit a14aaa7235
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 23 additions and 9 deletions

View File

@ -13,6 +13,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryHolder;
import java.util.ArrayList;
import java.util.List;
/**
* @author Acrobot
*/
@ -28,24 +31,32 @@ public class PlayerInventory implements Listener {
}
InventoryHolder holder = event.getInventory().getHolder();
if (!(holder instanceof BlockState)) {
if (!(holder instanceof BlockState) && !(holder instanceof DoubleChest)) {
return;
}
Player player = (Player) event.getPlayer();
Block container;
List<Block> containers = new ArrayList<>();
if (holder instanceof DoubleChest) {
container = ((DoubleChest) holder).getLocation().getBlock();
containers.add(((BlockState) ((DoubleChest) holder).getLeftSide()).getBlock());
containers.add(((BlockState) ((DoubleChest) holder).getRightSide()).getBlock());
} else {
container = ((BlockState) holder).getBlock();
containers.add(((BlockState) holder).getBlock());
}
if (!ChestShopSign.isShopBlock(container)) {
return;
boolean canAccess = false;
for (Block container : containers) {
if (ChestShopSign.isShopBlock(container)) {
if (Security.canAccess(player, container)) {
canAccess = true;
}
} else {
canAccess = true;
}
}
if (!Security.canAccess(player, container)) {
if (!canAccess) {
Messages.ACCESS_DENIED.sendWithPrefix(player);
event.setCancelled(true);
}

View File

@ -23,6 +23,7 @@ import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.OTHER_BREAK;
@ -104,9 +105,9 @@ public class LightweightChestProtection implements Listener {
}
}
@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void onProtectionCheck(ProtectionCheckEvent event) {
if (event.getResult() == Event.Result.DENY) {
if (event.getResult() == Event.Result.DENY && !Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
return;
}
@ -121,6 +122,8 @@ public class LightweightChestProtection implements Listener {
if (!lwc.canAccessProtection(player, protection) || protection.getType() == Protection.Type.DONATION) {
event.setResult(Event.Result.DENY);
} else if (Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
event.setResult(Event.Result.ALLOW);
}
}