Use sexy new (but untested) chest logging.

This commit is contained in:
md_5
2012-06-23 18:03:50 +10:00
parent 8a47e3b2ec
commit f1ea45ce83
3 changed files with 267 additions and 360 deletions

View File

@@ -1,42 +0,0 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.BukkitUtils.compareInventories;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.rawData;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.getspout.spoutapi.event.inventory.InventoryCloseEvent;
import org.getspout.spoutapi.event.inventory.InventoryOpenEvent;
import de.diddiz.LogBlock.listeners.LoggingListener;
class LBSpoutChestAccessListener extends LoggingListener
{
private final Map<Player, ItemStack[]> containers = new HashMap<Player, ItemStack[]>();
private LBSpoutChestAccessListener(LogBlock lb) {
super(lb);
}
public void onInventoryClose(InventoryCloseEvent event) {
if (!event.isCancelled() && event.getLocation() != null) {
final Player player = event.getPlayer();
final ItemStack[] before = containers.get(player);
if (before != null) {
final ItemStack[] after = compressInventory(event.getInventory().getContents());
final ItemStack[] diff = compareInventories(before, after);
final Location loc = event.getLocation();
for (final ItemStack item : diff)
consumer.queueChestAccess(player.getName(), loc, loc.getWorld().getBlockTypeIdAt(loc), (short)item.getTypeId(), (short)item.getAmount(), rawData(item));
containers.remove(player);
}
}
}
public void onInventoryOpen(InventoryOpenEvent event) {
if (!event.isCancelled() && event.getLocation() != null && event.getLocation().getBlock().getTypeId() != 58)
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
}
}

View File

@@ -56,260 +56,255 @@ import de.diddiz.util.MySQLConnectionPool;
public class LogBlock extends JavaPlugin
{
private static LogBlock logblock = null;
private MySQLConnectionPool pool;
private Consumer consumer = null;
private CommandsHandler commandsHandler;
private Updater updater = null;
private Timer timer = null;
private boolean errorAtLoading = false, noDb = false, connected = true;
private static LogBlock logblock = null;
private MySQLConnectionPool pool;
private Consumer consumer = null;
private CommandsHandler commandsHandler;
private Updater updater = null;
private Timer timer = null;
private boolean errorAtLoading = false, noDb = false, connected = true;
public static LogBlock getInstance() {
return logblock;
}
public static LogBlock getInstance() {
return logblock;
}
public Consumer getConsumer() {
return consumer;
}
public Consumer getConsumer() {
return consumer;
}
public CommandsHandler getCommandsHandler() {
return commandsHandler;
}
public CommandsHandler getCommandsHandler() {
return commandsHandler;
}
Updater getUpdater() {
return updater;
}
Updater getUpdater() {
return updater;
}
@Override
public void onLoad() {
logblock = this;
try {
updater = new Updater(this);
Config.load(this);
if (checkVersion)
getLogger().info("[LogBlock] Version check: " + updater.checkVersion());
getLogger().info("[LogBlock] Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
final Connection conn = getConnection();
if (conn == null) {
noDb = true;
return;
}
conn.close();
if (updater.update())
load(this);
updater.checkTables();
} catch (final NullPointerException ex) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
} catch (final Exception ex) {
getLogger().severe("[LogBlock] Error while loading: " + ex.getMessage());
errorAtLoading = true;
return;
}
consumer = new Consumer(this);
}
@Override
public void onLoad() {
logblock = this;
try {
updater = new Updater(this);
Config.load(this);
if (checkVersion)
getLogger().info("[LogBlock] Version check: " + updater.checkVersion());
getLogger().info("[LogBlock] Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
final Connection conn = getConnection();
if (conn == null) {
noDb = true;
return;
}
conn.close();
if (updater.update())
load(this);
updater.checkTables();
} catch (final NullPointerException ex) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while loading: ", ex);
} catch (final Exception ex) {
getLogger().severe("[LogBlock] Error while loading: " + ex.getMessage());
errorAtLoading = true;
return;
}
consumer = new Consumer(this);
}
@Override
public void onEnable() {
final PluginManager pm = getPluginManager();
if (errorAtLoading) {
pm.disablePlugin(this);
return;
}
if (noDb)
return;
if (pm.getPlugin("WorldEdit") == null && !new File("lib/WorldEdit.jar").exists() && !new File("WorldEdit.jar").exists())
try {
download(getLogger(), new URL("http://diddiz.insane-architects.net/download/WorldEdit.jar"), new File("lib/WorldEdit.jar"));
getLogger().info("[LogBlock] You've to restart/reload your server now.");
pm.disablePlugin(this);
return;
} catch (final Exception ex) {
getLogger().warning("[LogBlock] Failed to download WorldEdit. You may have to download it manually. You don't have to install it, just place the jar in the lib folder.");
}
commandsHandler = new CommandsHandler(this);
@Override
public void onEnable() {
final PluginManager pm = getPluginManager();
if (errorAtLoading) {
pm.disablePlugin(this);
return;
}
if (noDb)
return;
if (pm.getPlugin("WorldEdit") == null && !new File("lib/WorldEdit.jar").exists() && !new File("WorldEdit.jar").exists())
try {
download(getLogger(), new URL("http://diddiz.insane-architects.net/download/WorldEdit.jar"), new File("lib/WorldEdit.jar"));
getLogger().info("[LogBlock] You've to restart/reload your server now.");
pm.disablePlugin(this);
return;
} catch (final Exception ex) {
getLogger().warning("[LogBlock] Failed to download WorldEdit. You may have to download it manually. You don't have to install it, just place the jar in the lib folder.");
}
commandsHandler = new CommandsHandler(this);
getCommand("lb").setExecutor(commandsHandler);
getLogger().info("[LogBlock] Permissions plugin not found. Using Bukkit Permissions.");
if (enableAutoClearLog && autoClearLogDelay > 0)
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
getServer().getScheduler().scheduleAsyncDelayedTask(this, new DumpedLogImporter(this));
registerEvents();
if (useBukkitScheduler) {
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, delayBetweenRuns * 20, delayBetweenRuns * 20) > 0)
getLogger().info("[LogBlock] Scheduled consumer with bukkit scheduler.");
else {
getLogger().warning("[LogBlock] Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
timer = new Timer();
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
}
} else {
timer = new Timer();
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
getLogger().info("[LogBlock] Scheduled consumer with timer.");
}
for (final Tool tool : toolsByType.values())
if (pm.getPermission("logblock.tools." + tool.name) == null) {
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
pm.addPermission(perm);
}
// perm.addParent("logblock.*", true);
getLogger().info("LogBlock v" + getDescription().getVersion() + " by DiddiZ enabled.");
}
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
getServer().getScheduler().scheduleAsyncDelayedTask(this, new DumpedLogImporter(this));
registerEvents();
if (useBukkitScheduler) {
if (getServer().getScheduler().scheduleAsyncRepeatingTask(this, consumer, delayBetweenRuns * 20, delayBetweenRuns * 20) > 0)
getLogger().info("[LogBlock] Scheduled consumer with bukkit scheduler.");
else {
getLogger().warning("[LogBlock] Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
timer = new Timer();
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
}
} else {
timer = new Timer();
timer.scheduleAtFixedRate(consumer, delayBetweenRuns * 1000, delayBetweenRuns * 1000);
getLogger().info("[LogBlock] Scheduled consumer with timer.");
}
for (final Tool tool : toolsByType.values())
if (pm.getPermission("logblock.tools." + tool.name) == null) {
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
pm.addPermission(perm);
}
// perm.addParent("logblock.*", true);
getLogger().info("LogBlock v" + getDescription().getVersion() + " by DiddiZ enabled.");
}
public void reload() {
// TODO
}
public void reload() {
// TODO
}
private void registerEvents() {
final PluginManager pm = getPluginManager();
pm.registerEvents(new ToolListener(this), this);
if (askRollbackAfterBan)
pm.registerEvents(new BanListener(this), this);
if (isLogging(Logging.BLOCKPLACE))
pm.registerEvents(new BlockPlaceLogging(this), this);
if (isLogging(Logging.BLOCKPLACE) || isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW))
pm.registerEvents(new FluidFlowLogging(this), this);
if (isLogging(Logging.BLOCKBREAK))
pm.registerEvents(new BlockBreakLogging(this), this);
if (isLogging(Logging.SIGNTEXT))
pm.registerEvents(new SignChangeLogging(this), this);
if (isLogging(Logging.FIRE))
pm.registerEvents(new BlockBurnLogging(this), this);
if (isLogging(Logging.SNOWFORM))
pm.registerEvents(new SnowFormLogging(this), this);
if (isLogging(Logging.SNOWFADE))
pm.registerEvents(new SnowFadeLogging(this), this);
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION))
pm.registerEvents(new ExplosionLogging(this), this);
if (isLogging(Logging.LEAVESDECAY))
pm.registerEvents(new LeavesDecayLogging(this), this);
if (isLogging(Logging.CHESTACCESS)) {
// if (pm.isPluginEnabled("Spout")) { //TODO
// pm.registerEvents(Type.CUSTOM_EVENT, new LBSpoutChestAccessListener(this), Priority.Monitor, this);
// getLogger().info("[LogBlock] Using Spout as chest access API");
// } else {
pm.registerEvents(new ChestAccessLogging(this), this);
getLogger().info("[LogBlock] Using own chest access API");
}
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT))
pm.registerEvents(new InteractLogging(this), this);
if (isLogging(Logging.KILL))
pm.registerEvents(new KillLogging(this), this);
if (isLogging(Logging.CHAT))
pm.registerEvents(new ChatLogging(this), this);
if (isLogging(Logging.ENDERMEN))
pm.registerEvents(new EndermenLogging(this), this);
if (isLogging(Logging.NATURALSTRUCTUREGROW) || isLogging(Logging.BONEMEALSTRUCTUREGROW))
pm.registerEvents(new StructureGrowLogging(this), this);
if (logPlayerInfo)
pm.registerEvents(new PlayerInfoLogging(this), this);
}
private void registerEvents() {
final PluginManager pm = getPluginManager();
pm.registerEvents(new ToolListener(this), this);
if (askRollbackAfterBan)
pm.registerEvents(new BanListener(this), this);
if (isLogging(Logging.BLOCKPLACE))
pm.registerEvents(new BlockPlaceLogging(this), this);
if (isLogging(Logging.BLOCKPLACE) || isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW))
pm.registerEvents(new FluidFlowLogging(this), this);
if (isLogging(Logging.BLOCKBREAK))
pm.registerEvents(new BlockBreakLogging(this), this);
if (isLogging(Logging.SIGNTEXT))
pm.registerEvents(new SignChangeLogging(this), this);
if (isLogging(Logging.FIRE))
pm.registerEvents(new BlockBurnLogging(this), this);
if (isLogging(Logging.SNOWFORM))
pm.registerEvents(new SnowFormLogging(this), this);
if (isLogging(Logging.SNOWFADE))
pm.registerEvents(new SnowFadeLogging(this), this);
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION))
pm.registerEvents(new ExplosionLogging(this), this);
if (isLogging(Logging.LEAVESDECAY))
pm.registerEvents(new LeavesDecayLogging(this), this);
if (isLogging(Logging.CHESTACCESS)) {
pm.registerEvents(new ChestAccessLogging(this), this);
}
if (isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT))
pm.registerEvents(new InteractLogging(this), this);
if (isLogging(Logging.KILL))
pm.registerEvents(new KillLogging(this), this);
if (isLogging(Logging.CHAT))
pm.registerEvents(new ChatLogging(this), this);
if (isLogging(Logging.ENDERMEN))
pm.registerEvents(new EndermenLogging(this), this);
if (isLogging(Logging.NATURALSTRUCTUREGROW) || isLogging(Logging.BONEMEALSTRUCTUREGROW))
pm.registerEvents(new StructureGrowLogging(this), this);
if (logPlayerInfo)
pm.registerEvents(new PlayerInfoLogging(this), this);
}
@Override
public void onDisable() {
if (timer != null)
timer.cancel();
getServer().getScheduler().cancelTasks(this);
if (consumer != null) {
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
for (final Player player : getServer().getOnlinePlayers())
consumer.queueLeave(player);
if (consumer.getQueueSize() > 0) {
getLogger().info("[LogBlock] Waiting for consumer ...");
int tries = 10;
while (consumer.getQueueSize() > 0) {
getLogger().info("[LogBlock] Remaining queue size: " + consumer.getQueueSize());
if (tries > 0)
getLogger().info("[LogBlock] Remaining tries: " + tries);
else {
getLogger().info("Unable to save queue to database. Trying to write to a local file.");
try {
consumer.writeToFile();
getLogger().info("Successfully dumped queue.");
} catch (final FileNotFoundException ex) {
getLogger().info("Failed to write. Given up.");
break;
}
}
consumer.run();
tries--;
}
}
}
if (pool != null)
pool.close();
getLogger().info("LogBlock disabled.");
}
@Override
public void onDisable() {
if (timer != null)
timer.cancel();
getServer().getScheduler().cancelTasks(this);
if (consumer != null) {
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
for (final Player player : getServer().getOnlinePlayers())
consumer.queueLeave(player);
if (consumer.getQueueSize() > 0) {
getLogger().info("[LogBlock] Waiting for consumer ...");
int tries = 10;
while (consumer.getQueueSize() > 0) {
getLogger().info("[LogBlock] Remaining queue size: " + consumer.getQueueSize());
if (tries > 0)
getLogger().info("[LogBlock] Remaining tries: " + tries);
else {
getLogger().info("Unable to save queue to database. Trying to write to a local file.");
try {
consumer.writeToFile();
getLogger().info("Successfully dumped queue.");
} catch (final FileNotFoundException ex) {
getLogger().info("Failed to write. Given up.");
break;
}
}
consumer.run();
tries--;
}
}
}
if (pool != null)
pool.close();
getLogger().info("LogBlock disabled.");
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (noDb)
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
return true;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (noDb)
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
return true;
}
public boolean hasPermission(CommandSender sender, String permission) {
return sender.hasPermission(permission);
}
public boolean hasPermission(CommandSender sender, String permission) {
return sender.hasPermission(permission);
}
public Connection getConnection() {
try {
final Connection conn = pool.getConnection();
if (!connected) {
getLogger().info("[LogBlock] MySQL connection rebuild");
connected = true;
}
return conn;
} catch (final Exception ex) {
if (connected) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection: ", ex);
connected = false;
} else
getLogger().severe("[LogBlock] MySQL connection lost");
return null;
}
}
public Connection getConnection() {
try {
final Connection conn = pool.getConnection();
if (!connected) {
getLogger().info("[LogBlock] MySQL connection rebuild");
connected = true;
}
return conn;
} catch (final Exception ex) {
if (connected) {
getLogger().log(Level.SEVERE, "[LogBlock] Error while fetching connection: ", ex);
connected = false;
} else
getLogger().severe("[LogBlock] MySQL connection lost");
return null;
}
}
/**
* @param params
* QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
*/
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
final Connection conn = getConnection();
Statement state = null;
if (conn == null)
throw new SQLException("No connection");
try {
state = conn.createStatement();
final ResultSet rs = state.executeQuery(params.getQuery());
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
while (rs.next())
blockchanges.add(new BlockChange(rs, params));
return blockchanges;
} finally {
if (state != null)
state.close();
conn.close();
}
}
/**
* @param params
* QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
*/
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
final Connection conn = getConnection();
Statement state = null;
if (conn == null)
throw new SQLException("No connection");
try {
state = conn.createStatement();
final ResultSet rs = state.executeQuery(params.getQuery());
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
while (rs.next())
blockchanges.add(new BlockChange(rs, params));
return blockchanges;
} finally {
if (state != null)
state.close();
conn.close();
}
}
public int getCount(QueryParams params) throws SQLException {
final Connection conn = getConnection();
Statement state = null;
if (conn == null)
throw new SQLException("No connection");
try {
state = conn.createStatement();
final QueryParams p = params.clone();
p.needCount = true;
final ResultSet rs = state.executeQuery(p.getQuery());
if (!rs.next())
return 0;
return rs.getInt(1);
} finally {
if (state != null)
state.close();
conn.close();
}
}
public int getCount(QueryParams params) throws SQLException {
final Connection conn = getConnection();
Statement state = null;
if (conn == null)
throw new SQLException("No connection");
try {
state = conn.createStatement();
final QueryParams p = params.clone();
p.needCount = true;
final ResultSet rs = state.executeQuery(p.getQuery());
if (!rs.next())
return 0;
return rs.getInt(1);
} finally {
if (state != null)
state.close();
conn.close();
}
}
}

View File

@@ -1,98 +1,52 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import de.diddiz.LogBlock.LogBlock;
import static de.diddiz.util.BukkitUtils.compareInventories;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.rawData;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.entity.Player;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
public class ChestAccessLogging extends LoggingListener
{
private final Map<Player, ContainerState> containers = new HashMap<Player, ContainerState>();
private final Map<HumanEntity, ItemStack[]> containers = new HashMap<HumanEntity, ItemStack[]>();
public ChestAccessLogging(LogBlock lb) {
super(lb);
}
public ChestAccessLogging(LogBlock lb) {
super(lb);
}
public void checkInventoryClose(Player player) {
final ContainerState cont = containers.get(player);
if (cont != null) {
final ItemStack[] before = cont.items;
final BlockState state = cont.loc.getBlock().getState();
if (!(state instanceof InventoryHolder))
return;
final ItemStack[] after = compressInventory(((InventoryHolder)state).getInventory().getContents());
final ItemStack[] diff = compareInventories(before, after);
for (final ItemStack item : diff)
consumer.queueChestAccess(player.getName(), cont.loc, state.getTypeId(), (short)item.getTypeId(), (short)item.getAmount(), rawData(item));
containers.remove(player);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent event) {
if (event.getInventory().getHolder() instanceof BlockState) {
final HumanEntity player = event.getPlayer();
final ItemStack[] before = containers.get(player);
if (before != null) {
final ItemStack[] after = compressInventory(event.getInventory().getContents());
final ItemStack[] diff = compareInventories(before, after);
final Location loc = ((BlockState) event.getInventory().getHolder()).getLocation();
for (final ItemStack item : diff) {
consumer.queueChestAccess(player.getName(), loc, loc.getWorld().getBlockTypeIdAt(loc), (short) item.getTypeId(), (short) item.getAmount(), rawData(item));
}
containers.remove(player);
}
}
}
public void checkInventoryOpen(Player player, Block block) {
final BlockState state = block.getState();
if (!(state instanceof InventoryHolder))
return;
containers.put(player, new ContainerState(block.getLocation(), compressInventory(((InventoryHolder)state).getInventory().getContents())));
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(PlayerChatEvent event) {
checkInventoryClose(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
checkInventoryClose(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
checkInventoryClose(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
checkInventoryClose(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();
checkInventoryClose(player);
if (!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && isLogging(player.getWorld(), Logging.CHESTACCESS)) {
final Block block = event.getClickedBlock();
final int type = block.getTypeId();
if (type == 23 || type == 54 || type == 61 || type == 62)
checkInventoryOpen(player, block);
}
}
private static class ContainerState
{
public final ItemStack[] items;
public final Location loc;
private ContainerState(Location loc, ItemStack[] items) {
this.items = items;
this.loc = loc;
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getInventory().getHolder() instanceof BlockState) {
BlockState block = (BlockState) event.getInventory().getHolder();
if (block.getTypeId() != 58) {
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
}
}
}
}