mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-02 15:43:23 +01:00
Fix for double chest protection.
Double chests could be viewed but not accessed even if chest access or trapped chest access was allowed. Fixes https://github.com/BentoBoxWorld/BentoBox/issues/1912
This commit is contained in:
parent
bea9f0e394
commit
046c4fff35
@ -1,11 +1,13 @@
|
|||||||
package world.bentobox.bentobox.listeners.flags.protection;
|
package world.bentobox.bentobox.listeners.flags.protection;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Barrel;
|
import org.bukkit.block.Barrel;
|
||||||
import org.bukkit.block.Beacon;
|
import org.bukkit.block.Beacon;
|
||||||
import org.bukkit.block.BrewingStand;
|
import org.bukkit.block.BrewingStand;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.Dispenser;
|
||||||
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.block.Dropper;
|
import org.bukkit.block.Dropper;
|
||||||
import org.bukkit.block.Furnace;
|
import org.bukkit.block.Furnace;
|
||||||
import org.bukkit.block.Hopper;
|
import org.bukkit.block.Hopper;
|
||||||
@ -20,6 +22,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||||
import world.bentobox.bentobox.lists.Flags;
|
import world.bentobox.bentobox.lists.Flags;
|
||||||
|
|
||||||
@ -72,25 +75,29 @@ public class InventoryListener extends FlagListener {
|
|||||||
else if (inventoryHolder instanceof ShulkerBox) {
|
else if (inventoryHolder instanceof ShulkerBox) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.SHULKER_BOX);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.SHULKER_BOX);
|
||||||
}
|
}
|
||||||
else if (inventoryHolder instanceof Chest chestInventoryHolder) {
|
else if (inventoryHolder instanceof Chest c) {
|
||||||
// To differentiate between a Chest and a Trapped Chest we need to get the Block corresponding to the inventory
|
checkInvHolder(c.getLocation(), e, player);
|
||||||
try {
|
}
|
||||||
if (chestInventoryHolder.getType() == Material.TRAPPED_CHEST) {
|
else if (inventoryHolder instanceof DoubleChest dc) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.TRAPPED_CHEST);
|
checkInvHolder(dc.getLocation(), e, player);
|
||||||
} else {
|
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException ignored) {
|
|
||||||
// Thrown if the Chest corresponds to a block that isn't placed (how did we get here?)
|
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (inventoryHolder instanceof StorageMinecart) {
|
else if (inventoryHolder instanceof StorageMinecart) {
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.CHEST);
|
||||||
}
|
}
|
||||||
else if (!(inventoryHolder instanceof Player)) {
|
else if (!(inventoryHolder instanceof Player)) {
|
||||||
|
BentoBox.getInstance().logDebug(inventoryHolder.getClass().toGenericString());
|
||||||
// All other containers
|
// All other containers
|
||||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CONTAINER);
|
checkIsland(e, player, e.getInventory().getLocation(), Flags.CONTAINER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkInvHolder(Location l, InventoryClickEvent e, Player player) {
|
||||||
|
if (l.getBlock().getType().equals(Material.TRAPPED_CHEST)) {
|
||||||
|
checkIsland(e, player, l, Flags.TRAPPED_CHEST);
|
||||||
|
} else {
|
||||||
|
checkIsland(e, player, l, Flags.CHEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user