mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-22 18:16:05 +01:00
Fix issues with LWC Single/Double Chest protections (Fixes #359)
This commit is contained in:
parent
9dd56385eb
commit
a14aaa7235
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user