mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 02:25:25 +01:00
Only close our own inventories on teleport (Fixes #312)
This commit is contained in:
parent
7f32a7a722
commit
e22a50e1cf
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user