Only close our own inventories on teleport (Fixes #312)

This commit is contained in:
Phoenix616 2020-05-16 22:33:40 +01:00
parent 7f32a7a722
commit e22a50e1cf

View File

@ -1,9 +1,13 @@
package com.Acrobot.ChestShop.Listeners.Player;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.InventoryHolder;
/**
* A fix for a CraftBukkit bug.
@ -14,11 +18,19 @@ public class PlayerTeleport implements Listener {
@EventHandler
public static void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getPlayer() == null || event.getPlayer().getOpenInventory() == null) {
InventoryHolder holder = event.getPlayer().getOpenInventory().getTopInventory().getHolder();
if (!(holder instanceof BlockState)) {
return;
}
if (event.getPlayer().getOpenInventory().getType() != InventoryType.CRAFTING) {
Block container;
if (holder instanceof DoubleChest) {
container = ((DoubleChest) holder).getLocation().getBlock();
} else {
container = ((BlockState) holder).getBlock();
}
if (ChestShopSign.isShopBlock(container)) {
event.getPlayer().closeInventory();
}
}