mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-09 00:27:34 +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.Messages;
|
||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
import com.Acrobot.ChestShop.Security;
|
import com.Acrobot.ChestShop.Security;
|
||||||
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Chest;
|
|
||||||
import org.bukkit.block.DoubleChest;
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
@ -20,30 +19,33 @@ import org.bukkit.event.inventory.InventoryType;
|
|||||||
public class PlayerInventory implements Listener {
|
public class PlayerInventory implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public static void onInventoryOpen(InventoryOpenEvent event) {
|
public static void onInventoryOpen(InventoryOpenEvent event) {
|
||||||
if (event.getInventory().getType() != InventoryType.CHEST) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
|
if (!Properties.TURN_OFF_DEFAULT_PROTECTION_WHEN_PROTECTED_EXTERNALLY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HumanEntity entity = event.getPlayer();
|
if (!(event.getPlayer() instanceof Player)) {
|
||||||
|
|
||||||
if (!(entity instanceof Player) || (!(event.getInventory().getHolder() instanceof Chest) && !(event.getInventory().getHolder() instanceof DoubleChest))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) entity;
|
InventoryHolder holder = event.getInventory().getHolder();
|
||||||
Block chest;
|
if (!(holder instanceof BlockState)) {
|
||||||
|
return;
|
||||||
if (event.getInventory().getHolder() instanceof Chest) {
|
|
||||||
chest = ((BlockState) event.getInventory().getHolder()).getBlock();
|
|
||||||
} else {
|
|
||||||
chest = ((DoubleChest) event.getInventory().getHolder()).getLocation().getBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
player.sendMessage(Messages.prefix(Messages.ACCESS_DENIED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user