mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-08 08:08:05 +01:00
Fix InventoryOpenEvent listener not applying to non chest containers
This commit is contained in:
parent
009febb5c2
commit
7f32a7a722
@ -3,16 +3,15 @@ package com.Acrobot.ChestShop.Listeners.Player;
|
||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Security;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -20,30 +19,33 @@ import org.bukkit.event.inventory.InventoryType;
|
||||
public class PlayerInventory implements Listener {
|
||||
@EventHandler
|
||||
public static void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (event.getInventory().getType() != InventoryType.CHEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
|
||||
return;
|
||||
}
|
||||
|
||||
HumanEntity entity = event.getPlayer();
|
||||
|
||||
if (!(entity instanceof Player) || (!(event.getInventory().getHolder() instanceof Chest) && !(event.getInventory().getHolder() instanceof DoubleChest))) {
|
||||
if (!(event.getPlayer() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
Block chest;
|
||||
|
||||
if (event.getInventory().getHolder() instanceof Chest) {
|
||||
chest = ((BlockState) event.getInventory().getHolder()).getBlock();
|
||||
} else {
|
||||
chest = ((DoubleChest) event.getInventory().getHolder()).getLocation().getBlock();
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (!(holder instanceof BlockState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Security.canAccess(player, chest)) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Block container;
|
||||
|
||||
if (holder instanceof DoubleChest) {
|
||||
container = ((DoubleChest) holder).getLocation().getBlock();
|
||||
} else {
|
||||
container = ((BlockState) holder).getBlock();
|
||||
}
|
||||
|
||||
if (!ChestShopSign.isShopBlock(container)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Security.canAccess(player, container)) {
|
||||
player.sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user