() {
+ @Override
+ public boolean run(Player value) {
+ String key = playerLoader.getPlayerDataID(value);
- private Configuration configuration;
+ // Check if inventory is stored, and if it is, remove it and eject all viewers
+ if (inventories.containsKey(key)) {
+ Inventory inv = inventories.remove(key).getBukkitInventory();
+ for (HumanEntity entity : inv.getViewers()) {
+ entity.closeInventory();
+ }
+ }
+
+ // Check if ender chest is stored, and if it is, remove it and eject all viewers
+ if (enderChests.containsKey(key)) {
+ Inventory inv = enderChests.remove(key).getBukkitInventory();
+ for (HumanEntity entity : inv.getViewers()) {
+ entity.closeInventory();
+ }
+ }
+
+ if (!OpenInv.this.disableSaving() && !value.isOnline()) {
+ value.saveData();
+ }
+ return true;
+ }
+ });
private InternalAccessor accessor;
private IPlayerDataManager playerLoader;
private IInventoryAccess inventoryAccess;
- private IAnySilentChest anySilentChest;
+ private IAnySilentContainer anySilentContainer;
@Override
public void onEnable() {
- // Save the default config.yml if it doesn't already exist
- saveDefaultConfig();
-
- // Config
- configuration = new Configuration(this);
-
+ // Get plugin manager
PluginManager pm = getServer().getPluginManager();
+ accessor = new InternalAccessor(this);
// Version check
- if (!accessor.initialize(getServer())) {
+ if (!accessor.isSupported()) {
getLogger().info("Your version of CraftBukkit (" + accessor.getVersion() + ") is not supported.");
getLogger().info("Please look for an updated version of OpenInv.");
pm.disablePlugin(this);
@@ -76,195 +116,473 @@ public class OpenInv extends JavaPlugin {
playerLoader = accessor.newPlayerDataManager();
inventoryAccess = accessor.newInventoryAccess();
- anySilentChest = accessor.newAnySilentChest();
+ anySilentContainer = accessor.newAnySilentContainer();
+
+ FileConfiguration config = getConfig();
+ boolean dirtyConfig = false;
+ if (!config.isBoolean("NotifySilentChest")) {
+ config.set("NotifySilentChest", true);
+ dirtyConfig = true;
+ }
+ if (!config.isBoolean("NotifyAnyChest")) {
+ config.set("NotifyAnyChest", true);
+ dirtyConfig = true;
+ }
+ if (!config.isBoolean("DisableSaving")) {
+ config.set("DisableSaving", false);
+ dirtyConfig = true;
+ }
+ config.addDefault("NotifySilentChest", true);
+ config.addDefault("NotifyAnyChest", true);
+ config.addDefault("DisableSaving", false);
+ config.options().copyDefaults(true);
+ if (dirtyConfig) {
+ saveConfig();
+ }
- // Register the plugin's events
pm.registerEvents(new OpenInvPlayerListener(this), this);
- pm.registerEvents(new OpenInvEntityListener(this), this);
pm.registerEvents(new OpenInvInventoryListener(this), this);
- // Register the plugin's commands
- getCommand("openinv").setExecutor(new OpenInvCommand(this));
- getCommand("openender").setExecutor(new OpenEnderCommand(this));
- getCommand("searchinv").setExecutor(new SearchInvCommand(this));
- getCommand("searchender").setExecutor(new SearchEnderCommand());
- getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand(this));
- getCommand("anychest").setExecutor(new AnyChestCommand(this));
- getCommand("silentchest").setExecutor(new SilentChestCommand(this));
+ getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
+ getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
+ getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
+ getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
+ getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
+
+ }
+
+ @Override
+ public void onDisable() {
+
+ if (this.disableSaving()) {
+ return;
+ }
+
+ this.playerCache.invalidateAll();
}
/**
- * Returns the plugin Configuration.
- *
- * @return the plugin Configuration
+ * Checks if the server version is supported by OpenInv.
+ *
+ * @return true if the server version is supported
*/
- public Configuration getConfiguration() {
- return configuration;
+ public boolean isSupportedVersion() {
+ return accessor.isSupported();
}
/**
- * Returns an instance of PlayerDataManager.
- *
- * @return an instance of PlayerDataManager
- */
- public IPlayerDataManager getPlayerLoader() {
- return playerLoader;
- }
-
- /**
- * Returns an instance of InventoryAccess.
- *
- * @return an instance of InventoryAccess
+ * Gets the active IInventoryAccess implementation. May return null if the server version is
+ * unsupported.
+ *
+ * @return the IInventoryAccess
*/
public IInventoryAccess getInventoryAccess() {
- return inventoryAccess;
+ return this.inventoryAccess;
}
/**
- * Returns an instance of AnySilentChest.
- *
- * @return an instance of AnySilentChest
+ * Gets the active ISilentContainer implementation. May return null if the server version is
+ * unsupported.
+ *
+ * @return the ISilentContainer
*/
- public IAnySilentChest getAnySilentChest() {
- return anySilentChest;
+ public IAnySilentContainer getAnySilentContainer() {
+ return this.anySilentContainer;
}
/**
- * Returns a player's SpecialPlayerInventory.
- *
- * @param player the player to get the SpecialPlayerInventory of
- * @param createIfNull whether or not to create it if it doesn't exist
- * @return the player's SpecialPlayerInventory or null
+ * Gets an ISpecialPlayerInventory for the given Player.
+ *
+ * @param player the Player
+ * @param online true if the Player is currently online
+ * @return the ISpecialPlayerInventory
*/
- public ISpecialPlayerInventory getPlayerInventory(Player player, boolean createIfNull) {
- ISpecialPlayerInventory inventory = inventories.get(player.getUniqueId());
+ public ISpecialPlayerInventory getInventory(Player player, boolean online) {
+ String id = playerLoader.getPlayerDataID(player);
+ if (inventories.containsKey(id)) {
+ return inventories.get(id);
+ }
+ ISpecialPlayerInventory inv = accessor.newSpecialPlayerInventory(player, online);
+ inventories.put(id, inv);
+ playerCache.put(id, player);
+ return inv;
+ }
- if (inventory == null && createIfNull) {
- inventory = accessor.newSpecialPlayerInventory(player, !player.isOnline());
- inventories.put(player.getUniqueId(), inventory);
+ /**
+ * Gets an ISpecialEnderChest for the given Player.
+ *
+ * @param player the Player
+ * @param online true if the Player is currently online
+ * @return the ISpecialEnderChest
+ */
+ public ISpecialEnderChest getEnderChest(Player player, boolean online) {
+ String id = playerLoader.getPlayerDataID(player);
+ if (enderChests.containsKey(id)) {
+ return enderChests.get(id);
+ }
+ ISpecialEnderChest inv = accessor.newSpecialEnderChest(player, online);
+ enderChests.put(id, inv);
+ playerCache.put(id, player);
+ return inv;
+ }
+
+ /**
+ * Forcibly unload a cached Player's data.
+ *
+ * @param player the OfflinePlayer to unload
+ */
+ public void unload(OfflinePlayer player) {
+ this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player));
+ }
+
+ /**
+ * Check the configuration value for whether or not OpenInv saves player data when unloading
+ * players. This is exclusively for users who do not allow editing of inventories, only viewing,
+ * and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
+ * save any edits made to players.
+ *
+ * @return false unless configured otherwise
+ */
+ public boolean disableSaving() {
+ return getConfig().getBoolean("DisableSaving", false);
+ }
+
+ /**
+ * Check the configuration value for whether or not OpenInv displays a notification to the user
+ * when a container is activated with SilentChest.
+ *
+ * @return true unless configured otherwise
+ */
+ public boolean notifySilentChest() {
+ return getConfig().getBoolean("NotifySilentChest", true);
+ }
+
+ /**
+ * Check the configuration value for whether or not OpenInv displays a notification to the user
+ * when a container is activated with AnyChest.
+ *
+ * @return true unless configured otherwise
+ */
+ public boolean notifyAnyChest() {
+ return getConfig().getBoolean("NotifyAnyChest", true);
+ }
+
+ /**
+ * Gets a player's SilentChest setting.
+ *
+ * @param player the OfflinePlayer
+ * @return true if SilentChest is enabled
+ */
+ public boolean getPlayerSilentChestStatus(OfflinePlayer player) {
+ return getConfig().getBoolean("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", false);
+ }
+
+ /**
+ * Sets a player's SilentChest setting.
+ *
+ * @param player the OfflinePlayer
+ * @param status the status
+ */
+ public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) {
+ getConfig().set("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
+ saveConfig();
+ }
+
+ /**
+ * Gets the provided player's AnyChest setting.
+ *
+ * @param player the OfflinePlayer
+ * @return true if AnyChest is enabled
+ */
+ public boolean getPlayerAnyChestStatus(OfflinePlayer player) {
+ return getConfig().getBoolean("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", true);
+ }
+
+ /**
+ * Sets a player's AnyChest setting.
+ *
+ * @param player the OfflinePlayer
+ * @param status the status
+ */
+ public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) {
+ getConfig().set("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
+ saveConfig();
+ }
+
+ /**
+ * Get an OfflinePlayer by name.
+ *
+ * Note: This method is potentially very heavily blocking. It should not ever be called on the
+ * main thread, and if it is, a stack trace will be displayed alerting server owners to the
+ * call.
+ *
+ * @param name the name of the Player
+ * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
+ */
+ public OfflinePlayer matchPlayer(String name) {
+
+ // Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
+ if (getServer().isPrimaryThread()) {
+ getLogger().warning("Call to OpenInv#matchPlayer made on the main thread!");
+ getLogger().warning("This can cause the server to hang, potentially severely.");
+ getLogger().warning("Trace:");
+ for (StackTraceElement element : new Throwable().fillInStackTrace().getStackTrace()) {
+ getLogger().warning(element.toString());
+ }
}
- return inventory;
- }
-
- /**
- * Returns a player's SpecialEnderChest.
- *
- * @param player the player to get the SpecialEnderChest of
- * @param createIfNull whether or not to create it if it doesn't exist
- * @return the player's SpecialEnderChest or null
- */
- public ISpecialEnderChest getPlayerEnderChest(Player player, boolean createIfNull) {
- ISpecialEnderChest enderChest = enderChests.get(player.getUniqueId());
-
- if (enderChest == null && createIfNull) {
- enderChest = accessor.newSpecialEnderChest(player, player.isOnline());
- enderChests.put(player.getUniqueId(), enderChest);
+ // Ensure name is valid if server is in online mode to avoid unnecessary searching
+ if (getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
+ return null;
}
- return enderChest;
- }
+ OfflinePlayer player = getServer().getPlayerExact(name);
- /**
- * Removes a player's loaded inventory if it exists.
- *
- * @param player the player to remove the loaded inventory of
- */
- public void removeLoadedInventory(Player player) {
- if (inventories.containsKey(player.getUniqueId())) {
- inventories.remove(player.getUniqueId());
+ if (player != null) {
+ return player;
}
- }
- /**
- * Removes a player's loaded ender chest if it exists.
- *
- * @param player the player to remove the loaded ender chest of
- */
- public void removeLoadedEnderChest(Player player) {
- if (enderChests.containsKey(player.getUniqueId())) {
- enderChests.remove(player.getUniqueId());
+ player = getServer().getOfflinePlayer(name);
+
+ /*
+ * Compatibility: Pre-UUID, getOfflinePlayer always returns an OfflinePlayer. Post-UUID,
+ * getOfflinePlayer will return null if no matching player is found. To preserve
+ * compatibility, only return the player if they have played before. Ignoring current online
+ * status is fine, they'd have been found by getPlayerExact otherwise.
+ */
+ if (player != null && player.hasPlayedBefore()) {
+ return player;
}
- }
- /**
- * Logs a message to console.
- *
- * @param text the message to log
- */
- public void log(String text) {
- getLogger().info(text);
- }
+ player = getServer().getPlayer(name);
- /**
- * Logs a Throwable to console.
- *
- * @param e the Throwable to log
- */
- public void log(Throwable e) {
- getLogger().severe(e.toString());
- e.printStackTrace();
- }
+ if (player != null) {
+ return player;
+ }
- /**
- * Sends an OpenInv message to a player.
- *
- * @param sender the CommandSender to message
- * @param message the message to send
- */
- public static void sendMessage(CommandSender sender, String message) {
- sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
- }
-
- /**
- * Outputs OpenInv help information to a CommandSender.
- *
- * @param sender the CommandSender to show help to
- */
- public static void showHelp(CommandSender sender) {
- sender.sendMessage(ChatColor.GREEN + "/openinv - Opens a player's inventory.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
-
- sender.sendMessage(ChatColor.GREEN + "/openender - Opens a player's ender chest.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: oe)");
-
- sender.sendMessage(ChatColor.GREEN + "/searchinv - [minAmount] -");
- sender.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their inventory.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: si)");
-
- sender.sendMessage(ChatColor.GREEN + "/searchender
- [minAmount] -");
- sender.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their ender chest.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: se)");
-
- sender.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggles the item openinv function.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
-
- sender.sendMessage(ChatColor.GREEN + "/anychest - Toggles the any chest function.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: ac)");
-
- sender.sendMessage(ChatColor.GREEN + "/silentchest - Toggles the silent chest function.");
- sender.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
- }
-
- /**
- * Returns whether or not a player has a permission.
- *
- * @param player the player to check
- * @param permission the permission node to check for
- * @return true if the player has the permission; false otherwise
- */
- public static boolean hasPermission(Permissible player, String permission) {
- String[] parts = permission.split("\\.");
- String perm = "";
-
- for (int i = 0; i < parts.length; i++) {
- if (player.hasPermission(perm + "*")) {
- return true;
+ int bestMatch = Integer.MAX_VALUE;
+ for (OfflinePlayer offline : getServer().getOfflinePlayers()) {
+ if (offline.getName() == null) {
+ // Loaded by UUID only, name has never been looked up.
+ continue;
}
- perm += parts[i] + ".";
+ // Compatibility: Lang3 is only bundled with 1.8+
+ int currentMatch = org.apache.commons.lang.StringUtils.getLevenshteinDistance(name, offline.getName());
+
+ if (currentMatch == 0) {
+ return offline;
+ }
+
+ if (currentMatch < bestMatch) {
+ bestMatch = currentMatch;
+ player = offline;
+ }
}
- return player.hasPermission(permission);
+ // Only null if no players have played ever, otherwise even the worst match will do.
+ return player;
}
+
+ /**
+ * Load a Player from an OfflinePlayer. May return null under some circumstances.
+ *
+ * @param offline the OfflinePlayer to load a Player for
+ * @return the Player
+ */
+ public Player loadPlayer(final OfflinePlayer offline) {
+
+ if (offline == null) {
+ return null;
+ }
+
+ String key = this.playerLoader.getPlayerDataID(offline);
+ if (this.playerCache.containsKey(key)) {
+ return this.playerCache.get(key);
+ }
+
+ Player loaded;
+
+ if (offline.isOnline()) {
+ loaded = offline.getPlayer();
+ this.playerCache.put(key, loaded);
+ return loaded;
+ }
+
+ if (Bukkit.isPrimaryThread()) {
+ return this.playerLoader.loadPlayer(offline);
+ }
+
+ Future future = Bukkit.getScheduler().callSyncMethod(this,
+ new Callable() {
+ @Override
+ public Player call() throws Exception {
+ return playerLoader.loadPlayer(offline);
+ }
+ });
+
+ int ticks = 0;
+ while (!future.isDone() && !future.isCancelled() && ticks < 10) {
+ ++ticks;
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ if (!future.isDone() || future.isCancelled()) {
+ return null;
+ }
+
+ try {
+ loaded = future.get();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ return null;
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ if (loaded != null) {
+ this.playerCache.put(key, loaded);
+ }
+
+ return loaded;
+ }
+
+ /**
+ * Method for handling a Player coming online.
+ *
+ * @param player the Player
+ */
+ public void setPlayerOnline(final Player player) {
+
+ String key = this.playerLoader.getPlayerDataID(player);
+
+ // Check if the player is cached. If not, neither of their inventories is open.
+ if (!this.playerCache.containsKey(key)) {
+ return;
+ }
+
+ this.playerCache.put(key, player);
+
+ if (this.inventories.containsKey(key)) {
+ this.inventories.get(key).setPlayerOnline(player);
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (player.isOnline()) {
+ player.updateInventory();
+ }
+ }
+ }.runTask(this);
+ }
+
+ if (this.enderChests.containsKey(key)) {
+ this.enderChests.get(key).setPlayerOnline(player);
+ }
+ }
+
+ /**
+ * Method for handling a Player going offline.
+ *
+ * @param player the Player
+ */
+ public void setPlayerOffline(final Player player) {
+
+ String key = this.playerLoader.getPlayerDataID(player);
+
+ // Check if the player is cached. If not, neither of their inventories is open.
+ if (!this.playerCache.containsKey(key)) {
+ return;
+ }
+
+ if (this.inventories.containsKey(key)) {
+ this.inventories.get(key).setPlayerOffline();
+ }
+
+ if (this.enderChests.containsKey(key)) {
+ this.enderChests.get(key).setPlayerOffline();
+ }
+ }
+
+ /**
+ * Evicts all viewers lacking cross-world permissions from a Player's inventory.
+ *
+ * @param player the Player
+ */
+ public void changeWorld(final Player player) {
+
+ String key = this.playerLoader.getPlayerDataID(player);
+
+ // Check if the player is cached. If not, neither of their inventories is open.
+ if (!this.playerCache.containsKey(key)) {
+ return;
+ }
+
+ if (this.inventories.containsKey(key)) {
+ Iterator iterator = this.inventories.get(key).getBukkitInventory().getViewers().iterator();
+ while (iterator.hasNext()) {
+ HumanEntity human = iterator.next();
+ // If player has permission or is in the same world, allow continued access
+ // Just in case, also allow null worlds.
+ if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
+ || human.getWorld().equals(player.getWorld())) {
+ continue;
+ }
+ human.closeInventory();
+ }
+ }
+
+ if (this.enderChests.containsKey(key)) {
+ Iterator iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator();
+ while (iterator.hasNext()) {
+ HumanEntity human = iterator.next();
+ if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
+ || human.getWorld().equals(player.getWorld())) {
+ continue;
+ }
+ human.closeInventory();
+ }
+ }
+ }
+
+ /**
+ * Displays all applicable help for OpenInv commands.
+ *
+ * @param player the Player to help
+ */
+ public void showHelp(Player player) {
+ // Get registered commands
+ for (String commandName : this.getDescription().getCommands().keySet()) {
+ PluginCommand command = this.getCommand(commandName);
+
+ // Ensure command is successfully registered and player can use it
+ if (command == null || !command.testPermissionSilent(player)) {
+ continue;
+ }
+
+ // Send usage
+ player.sendMessage(command.getUsage());
+
+ List aliases = command.getAliases();
+ if (aliases.isEmpty()) {
+ continue;
+ }
+
+ // Assemble alias list
+ StringBuilder aliasBuilder = new StringBuilder(" (aliases: ");
+ for (String alias : aliases) {
+ aliasBuilder.append(alias).append(", ");
+ }
+ aliasBuilder.delete(aliasBuilder.length() - 2, aliasBuilder.length()).append(')');
+
+ // Send all aliases
+ player.sendMessage(aliasBuilder.toString());
+ }
+ }
+
}
diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java b/plugin/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java
new file mode 100644
index 0000000..f9eba2c
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv;
+
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryDragEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.inventory.Inventory;
+
+public class OpenInvInventoryListener implements Listener {
+
+ private final OpenInv plugin;
+
+ public OpenInvInventoryListener(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
+ public void onInventoryClick(InventoryClickEvent event) {
+ if (cancelInteract(event.getWhoClicked(), event.getInventory())) {
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
+ public void onInventoryDrag(InventoryDragEvent event) {
+ if (cancelInteract(event.getWhoClicked(), event.getInventory())) {
+ event.setCancelled(true);
+ }
+ }
+
+ private boolean cancelInteract(HumanEntity entity, Inventory inventory) {
+ return plugin.getInventoryAccess().isSpecialPlayerInventory(inventory)
+ && !Permissions.EDITINV.hasPermission(entity)
+ || plugin.getInventoryAccess().isSpecialEnderChest(inventory)
+ && !Permissions.EDITENDER.hasPermission(entity);
+ }
+
+ @EventHandler
+ public void onWorldChange(PlayerChangedWorldEvent event) {
+ plugin.changeWorld(event.getPlayer());
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java b/plugin/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java
new file mode 100644
index 0000000..d0c65ff
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event.Result;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+
+public class OpenInvPlayerListener implements Listener {
+
+ private final OpenInv plugin;
+
+ public OpenInvPlayerListener(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerJoin(final PlayerJoinEvent event) {
+ plugin.setPlayerOnline(event.getPlayer());
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerQuit(PlayerQuitEvent event) {
+ plugin.setPlayerOffline(event.getPlayer());
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onPlayerInteract(PlayerInteractEvent event) {
+ if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
+ || event.useInteractedBlock() == Result.DENY
+ || !plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
+ return;
+ }
+
+ Player player = event.getPlayer();
+ boolean anychest = Permissions.ANYCHEST.hasPermission(player) && plugin.getPlayerAnyChestStatus(player);
+ boolean needsAnyChest = plugin.getAnySilentContainer().isAnyContainerNeeded(player, event.getClickedBlock());
+
+ if (!anychest && needsAnyChest) {
+ return;
+ }
+
+ boolean silentchest = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
+
+ // If anychest or silentchest is active
+ if ((anychest || silentchest) && plugin.getAnySilentContainer().activateContainer(player, silentchest, event.getClickedBlock())) {
+ if (silentchest && plugin.notifySilentChest() && needsAnyChest && plugin.notifyAnyChest()) {
+ player.sendMessage("You are opening a blocked container silently.");
+ } else if (silentchest && plugin.notifySilentChest()) {
+ player.sendMessage("You are opening a container silently.");
+ } else if (needsAnyChest && plugin.notifyAnyChest()) {
+ player.sendMessage("You are opening a blocked container.");
+ }
+ event.setCancelled(true);
+ }
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/Permissions.java b/plugin/src/main/java/com/lishid/openinv/Permissions.java
index 0577a51..b08fc6a 100644
--- a/plugin/src/main/java/com/lishid/openinv/Permissions.java
+++ b/plugin/src/main/java/com/lishid/openinv/Permissions.java
@@ -1,19 +1,38 @@
package com.lishid.openinv;
-public final class Permissions {
+import org.bukkit.permissions.Permissible;
- private Permissions() {}
+public enum Permissions {
+
+ OPENINV("OpenInv.openinv"),
+ OVERRIDE("OpenInv.override"),
+ EXEMPT("OpenInv.exempt"),
+ CROSSWORLD("OpenInv.crossworld"),
+ SILENT("OpenInv.silent"),
+ ANYCHEST("OpenInv.anychest"),
+ ENDERCHEST("OpenInv.openender"),
+ ENDERCHEST_ALL("OpenInv.openenderall"),
+ SEARCH("OpenInv.search"),
+ EDITINV("OpenInv.editinv"),
+ EDITENDER("OpenInv.editender"),
+ OPENSELF("OpenInv.openself");
+
+ private final String permission;
+
+ private Permissions(String permission) {
+ this.permission = permission;
+ }
+
+ public boolean hasPermission(Permissible permissible) {
+ String[] parts = permission.split("\\.");
+ String perm = "";
+ for (int i = 0; i < parts.length; i++) {
+ if (permissible.hasPermission(perm + "*")) {
+ return true;
+ }
+ perm += parts[i] + ".";
+ }
+ return permissible.hasPermission(permission);
+ }
- public static final String PERM_OPENINV = "OpenInv.openinv";
- public static final String PERM_OVERRIDE = "OpenInv.override";
- public static final String PERM_EXEMPT = "OpenInv.exempt";
- public static final String PERM_CROSSWORLD = "OpenInv.crossworld";
- public static final String PERM_SILENT = "OpenInv.silent";
- public static final String PERM_ANYCHEST = "OpenInv.anychest";
- public static final String PERM_ENDERCHEST = "OpenInv.openender";
- public static final String PERM_ENDERCHEST_ALL = "OpenInv.openenderall";
- public static final String PERM_SEARCH = "OpenInv.search";
- public static final String PERM_EDITINV = "OpenInv.editinv";
- public static final String PERM_EDITENDER = "OpenInv.editender";
- public static final String PERM_OPENSELF = "OpenInv.openself";
}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java
deleted file mode 100644
index 1cfdd85..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.Configuration;
-
-public class AnyChestCommand implements CommandExecutor {
-
- private final OpenInv plugin;
- private final Configuration configuration;
-
- public AnyChestCommand(OpenInv plugin) {
- this.plugin = plugin;
- configuration = plugin.getConfiguration();
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("anychest")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
- return true;
- }
-
- if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to use any chest.");
- return true;
- }
-
- Player player = (Player) sender;
-
- if (args.length > 0) {
- if (args[0].equalsIgnoreCase("check")) {
- String status = configuration.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + ".");
- return true;
- }
- }
-
- configuration.setPlayerAnyChestStatus(player, !configuration.getPlayerAnyChestStatus(player));
-
- String status = configuration.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + ".");
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java
new file mode 100644
index 0000000..3036f30
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv.commands;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.lishid.openinv.OpenInv;
+
+public class AnyChestPluginCommand implements CommandExecutor {
+
+ private final OpenInv plugin;
+
+ public AnyChestPluginCommand(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
+ return true;
+ }
+
+ Player player = (Player) sender;
+
+ if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
+ sender.sendMessage("AnyChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
+ return true;
+ }
+
+ plugin.setPlayerAnyChestStatus(player, !plugin.getPlayerAnyChestStatus(player));
+ sender.sendMessage("AnyChest is now " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
+
+ return true;
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java
deleted file mode 100644
index aef46ca..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.internal.ISpecialEnderChest;
-import com.lishid.openinv.utils.UUIDUtils;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-public class OpenEnderCommand implements CommandExecutor {
-
- private final OpenInv plugin;
- private final Map openEnderHistory = new ConcurrentHashMap();
-
- public OpenEnderCommand(OpenInv plugin) {
- this.plugin = plugin;
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("openender")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
- return true;
- }
-
- if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to access player ender chests.");
- return true;
- }
-
- if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
- OpenInv.showHelp(sender);
- return true;
- }
-
- final Player player = (Player) sender;
-
- // History management
- UUID history = openEnderHistory.get(player.getUniqueId());
- if (history == null) {
- history = player.getUniqueId();
- openEnderHistory.put(player.getUniqueId(), history);
- }
-
- final UUID uuid;
-
- // Read from history if target is not named
- if (args.length < 1) {
- if (history != null) {
- uuid = history;
- } else {
- sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
- return true;
- }
- }
- else {
- uuid = UUIDUtils.getPlayerUUID(args[0]);
- if (uuid == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return true;
- }
- }
-
- final UUID playerUUID = player.getUniqueId();
-
- Player target = Bukkit.getPlayer(uuid);
- if (target == null) {
- // Targeted player was not found online, start asynchronous lookup in files
- Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
- @Override
- public void run() {
- // Try loading the player's data asynchronously
- final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
- if (target == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return;
- }
-
- // Open target's inventory synchronously
- Bukkit.getScheduler().runTask(plugin, new Runnable() {
- @Override
- public void run() {
- Player player = Bukkit.getPlayer(playerUUID);
- // If sender is no longer online after loading the target, abort!
- if (player == null) {
- return;
- }
-
- openInventory(player, target);
- }
- });
- }
- });
- } else {
- openInventory(player, target);
- }
-
- return true;
- }
-
- return false;
- }
-
- private void openInventory(Player player, Player target) {
- // Null target check
- if (target == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return;
- }
-
- // Permissions checks
- if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
- player.sendMessage(ChatColor.RED + "You do not have permission to access other player's ender chests.");
- return;
- }
-
- if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
- player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s ender chest is protected!");
- return;
- }
-
- // Crossworld check
- if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
- player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
- return;
- }
-
- // Record the target
- openEnderHistory.put(player.getUniqueId(), target.getUniqueId());
-
- // Get the inventory and open it
- ISpecialEnderChest enderChest = plugin.getPlayerEnderChest(target, true);
- player.openInventory(enderChest.getBukkitInventory());
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java
new file mode 100644
index 0000000..96995e6
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv.commands;
+
+import java.util.HashMap;
+
+import com.lishid.openinv.OpenInv;
+import com.lishid.openinv.Permissions;
+import com.lishid.openinv.internal.ISpecialEnderChest;
+
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class OpenEnderPluginCommand implements CommandExecutor {
+
+ private final OpenInv plugin;
+ private final HashMap openEnderHistory = new HashMap();
+
+ public OpenEnderPluginCommand(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
+ return true;
+ }
+
+ if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
+ plugin.showHelp((Player) sender);
+ return true;
+ }
+
+ final Player player = (Player) sender;
+
+ // History management
+ String history = openEnderHistory.get(player);
+
+ if (history == null || history == "") {
+ history = player.getName();
+ openEnderHistory.put(player, history);
+ }
+
+ final String name;
+
+ // Read from history if target is not named
+ if (args.length < 1) {
+ name = history;
+ } else {
+ name = args[0];
+ }
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ final OfflinePlayer offlinePlayer = plugin.matchPlayer(name);
+
+ if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
+ player.sendMessage(ChatColor.RED + "Player not found!");
+ return;
+ }
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (!player.isOnline()) {
+ return;
+ }
+ openInventory(player, offlinePlayer);
+ }
+ }.runTask(plugin);
+
+ }
+ }.runTaskAsynchronously(plugin);
+
+ return true;
+ }
+
+ private void openInventory(Player player, OfflinePlayer target) {
+
+ Player onlineTarget;
+ boolean online = target.isOnline();
+
+ if (!online) {
+ // Try loading the player's data
+ onlineTarget = plugin.loadPlayer(target);
+
+ if (onlineTarget == null) {
+ player.sendMessage(ChatColor.RED + "Player not found!");
+ return;
+ }
+ } else {
+ onlineTarget = target.getPlayer();
+ }
+
+
+ if (!onlineTarget.equals(player) && !Permissions.ENDERCHEST_ALL.hasPermission(player)) {
+ player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest");
+ return;
+ }
+
+ // Record the target
+ openEnderHistory.put(player, onlineTarget.getName());
+
+ // Create the inventory
+ ISpecialEnderChest chest = plugin.getEnderChest(onlineTarget, online);
+
+ // Open the inventory
+ player.openInventory(chest.getBukkitInventory());
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java
deleted file mode 100644
index 0b2e37a..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.internal.ISpecialPlayerInventory;
-import com.lishid.openinv.utils.UUIDUtils;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-public class OpenInvCommand implements CommandExecutor {
-
- private final OpenInv plugin;
- private final Map openInvHistory = new ConcurrentHashMap();
-
- public OpenInvCommand(OpenInv plugin) {
- this.plugin = plugin;
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("openinv")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
- return true;
- }
-
- if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories.");
- return true;
- }
-
- if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
- OpenInv.showHelp(sender);
- return true;
- }
-
- final Player player = (Player) sender;
-
- // History management
- UUID history = openInvHistory.get(player.getUniqueId());
- if (history == null) {
- history = player.getUniqueId();
- openInvHistory.put(player.getUniqueId(), history);
- }
-
- final UUID uuid;
-
- // Read from history if target is not named
- if (args.length < 1) {
- uuid = history;
- } else {
- uuid = UUIDUtils.getPlayerUUID(args[0]);
- if (uuid == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return true;
- }
- }
-
- final UUID playerUUID = player.getUniqueId();
-
- Player target = Bukkit.getPlayer(uuid);
- if (target == null) {
- // Targeted player was not found online, start asynchronous lookup in files
- Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
- @Override
- public void run() {
- // Try loading the player's data asynchronously
- final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
- if (target == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return;
- }
-
- // Open target's inventory synchronously
- Bukkit.getScheduler().runTask(plugin, new Runnable() {
- @Override
- public void run() {
- Player player = Bukkit.getPlayer(playerUUID);
- // If sender is no longer online after loading the target, abort!
- if (player == null) {
- return;
- }
-
- openInventory(player, target);
- }
- });
- }
- });
- } else {
- openInventory(player, target);
- }
-
- return true;
- }
-
- return false;
- }
-
- private void openInventory(Player player, Player target) {
- // Null target check
- if (target == null) {
- player.sendMessage(ChatColor.RED + "Player not found!");
- return;
- }
-
- // Permissions checks
- if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
- player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
- return;
- }
-
- // Crossworld check
- if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
- player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
- return;
- }
-
- // Self-open check
- if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) {
- player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
- return;
- }
-
- // Record the target
- openInvHistory.put(player.getUniqueId(), target.getUniqueId());
-
- // Get the inventory and open it
- ISpecialPlayerInventory inventory = plugin.getPlayerInventory(target, true);
- player.openInventory(inventory.getBukkitInventory());
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java
new file mode 100644
index 0000000..4ac56f8
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv.commands;
+
+import java.util.HashMap;
+
+import com.lishid.openinv.OpenInv;
+import com.lishid.openinv.Permissions;
+import com.lishid.openinv.internal.ISpecialPlayerInventory;
+
+import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class OpenInvPluginCommand implements CommandExecutor {
+
+ private final OpenInv plugin;
+ private final HashMap openInvHistory = new HashMap();
+
+ public OpenInvPluginCommand(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
+ return true;
+ }
+
+ if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
+ plugin.showHelp((Player) sender);
+ return true;
+ }
+
+ final Player player = (Player) sender;
+
+ // History management
+ String history = openInvHistory.get(player);
+
+ if (history == null || history == "") {
+ history = player.getName();
+ openInvHistory.put(player, history);
+ }
+
+ final String name;
+
+ // Read from history if target is not named
+ if (args.length < 1) {
+ name = history;
+ } else {
+ name = args[0];
+ }
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ final OfflinePlayer offlinePlayer = plugin.matchPlayer(name);
+
+ if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
+ player.sendMessage(ChatColor.RED + "Player not found!");
+ return;
+ }
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (!player.isOnline()) {
+ return;
+ }
+ openInventory(player, offlinePlayer);
+ }
+ }.runTask(plugin);
+
+ }
+ }.runTaskAsynchronously(plugin);
+
+ return true;
+ }
+
+ private void openInventory(Player player, OfflinePlayer target) {
+
+
+ Player onlineTarget;
+ boolean online = target.isOnline();
+
+ if (!online) {
+ // Try loading the player's data
+ onlineTarget = plugin.loadPlayer(target);
+
+ if (onlineTarget == null) {
+ player.sendMessage(ChatColor.RED + "Player not found!");
+ return;
+ }
+ } else {
+ onlineTarget = target.getPlayer();
+ }
+
+ // Permissions checks
+ if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) {
+ player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
+ return;
+ }
+
+ // Crosswork check
+ if ((!Permissions.CROSSWORLD.hasPermission(player) && !Permissions.OVERRIDE.hasPermission(player)) && onlineTarget.getWorld() != player.getWorld()) {
+ player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
+ return;
+ }
+
+ // Self-open check
+ if (!Permissions.OPENSELF.hasPermission(player) && onlineTarget.equals(player)) {
+ player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
+ return;
+ }
+
+ // Record the target
+ openInvHistory.put(player, onlineTarget.getName());
+
+ // Create the inventory
+ ISpecialPlayerInventory inv = plugin.getInventory(onlineTarget, online);
+
+ // Open the inventory
+ player.openInventory(inv.getBukkitInventory());
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java
deleted file mode 100644
index aa30025..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.lishid.openinv.commands;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-
-public class SearchEnderCommand implements CommandExecutor {
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("searchender")) {
- if (sender instanceof Player) {
- if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to search player ender chests.");
- return true;
- }
- }
-
- Material material = null;
- int count = 1;
-
- if (args.length >= 1) {
- String[] gData;
- gData = args[0].split(":");
- material = Material.matchMaterial(gData[0]);
- }
-
- if (args.length >= 2) {
- try {
- count = Integer.parseInt(args[1]);
- } catch (NumberFormatException e) {
- sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
- return false;
- }
- }
-
- if (material == null) {
- sender.sendMessage(ChatColor.RED + "Unknown item.");
- return false;
- }
-
- StringBuilder sb = new StringBuilder();
-
- for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
- if (onlinePlayer.getEnderChest().contains(material, count)) {
- sb.append(onlinePlayer.getName());
- sb.append(" ");
- }
- }
-
- String playerList = sb.toString();
- sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their ender chest: " + playerList);
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java
deleted file mode 100644
index 481b635..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-
-public class SearchInvCommand implements CommandExecutor {
-
- private final OpenInv plugin;
-
- public SearchInvCommand(OpenInv plugin) {
- this.plugin = plugin;
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("searchinv")) {
- if (sender instanceof Player) {
- if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to search player inventories.");
- return true;
- }
- }
-
- Material material = null;
- int count = 1;
-
- if (args.length >= 1) {
- String[] gData;
- gData = args[0].split(":");
- material = Material.matchMaterial(gData[0]);
- }
-
- if (args.length >= 2) {
- try {
- count = Integer.parseInt(args[1]);
- } catch (NumberFormatException e) {
- sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
- return false;
- }
- }
-
- if (material == null) {
- sender.sendMessage(ChatColor.RED + "Unknown item.");
- return false;
- }
-
- StringBuilder sb = new StringBuilder();
-
- for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
- if (onlinePlayer.getInventory().contains(material, count)) {
- sb.append(onlinePlayer.getName());
- sb.append(" ");
- }
- }
-
- String playerList = sb.toString();
- sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their inventory: " + playerList);
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java
new file mode 100644
index 0000000..917d883
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SearchInvPluginCommand implements CommandExecutor {
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+
+ Material material = null;
+ int count = 1;
+
+ if (args.length >= 1) {
+ String[] gData = null;
+ gData = args[0].split(":");
+ material = Material.matchMaterial(gData[0]);
+ }
+
+ if (args.length >= 2) {
+ try {
+ count = Integer.parseInt(args[1]);
+ } catch (NumberFormatException ex) {
+ sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
+ return false;
+ }
+ }
+
+ if (material == null) {
+ sender.sendMessage(ChatColor.RED + "Unknown item");
+ return false;
+ }
+
+ StringBuilder players = new StringBuilder();
+ for (Player player : Bukkit.getServer().getOnlinePlayers()) {
+ if (player.getInventory().contains(material, count)) {
+ players.append(player.getName()).append(", ");
+ }
+ }
+
+ // Matches found, delete trailing comma and space
+ if (players.length() > 0) {
+ players.delete(players.length() - 2, players.length());
+ } else {
+ sender.sendMessage("No players found with " + material.toString());
+ }
+
+ sender.sendMessage("Players with the item " + material.toString() + ": " + players.toString());
+ return true;
+ }
+
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java
deleted file mode 100644
index 6b14379..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.Configuration;
-
-public class SilentChestCommand implements CommandExecutor {
-
- private final OpenInv plugin;
- private final Configuration configuration;
-
- public SilentChestCommand(OpenInv plugin) {
- this.plugin = plugin;
- configuration = plugin.getConfiguration();
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("silentchest")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
- return true;
- }
-
- if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
- return true;
- }
-
- Player player = (Player) sender;
-
- if (args.length > 0) {
- if (args[0].equalsIgnoreCase("check")) {
- String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
- return true;
- }
- }
-
- configuration.setPlayerSilentChestStatus(player, !configuration.getPlayerSilentChestStatus(player));
-
- String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java
new file mode 100644
index 0000000..3710f6e
--- /dev/null
+++ b/plugin/src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2011-2014 lishid. All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.lishid.openinv.commands;
+
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.lishid.openinv.OpenInv;
+
+public class SilentChestPluginCommand implements CommandExecutor {
+
+ private final OpenInv plugin;
+
+ public SilentChestPluginCommand(OpenInv plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
+ return true;
+ }
+
+ Player player = (Player) sender;
+
+ if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
+ sender.sendMessage("SilentChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
+ return true;
+ }
+
+ plugin.setPlayerSilentChestStatus(player, !plugin.getPlayerSilentChestStatus(player));
+ sender.sendMessage("SilentChest is now " + (plugin.getPlayerSilentChestStatus(player) ? "ON" : "OFF") + ".");
+
+ return true;
+ }
+}
diff --git a/plugin/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java b/plugin/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java
deleted file mode 100644
index dcda462..0000000
--- a/plugin/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.commands;
-
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.Configuration;
-
-public class ToggleOpenInvCommand implements CommandExecutor {
-
- private final OpenInv plugin;
- private final Configuration configuration;
-
- public ToggleOpenInvCommand(OpenInv plugin) {
- this.plugin = plugin;
- configuration = plugin.getConfiguration();
- }
-
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("toggleopeninv")) {
- if (!(sender instanceof Player)) {
- sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
- return true;
- }
-
- if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
- sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories.");
- return true;
- }
-
- Player player = (Player) sender;
-
- if (args.length > 0) {
- if (args[0].equalsIgnoreCase("check")) {
- String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
- return true;
- }
- }
-
- configuration.setPlayerItemOpenInvStatus(player, !configuration.getPlayerItemOpenInvStatus(player));
-
- String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
- OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
-
- return true;
- }
-
- return false;
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java b/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java
deleted file mode 100644
index b01a9f4..0000000
--- a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.listeners;
-
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Player;
-import org.bukkit.event.entity.EntityDamageByEntityEvent;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.Configuration;
-
-public class OpenInvEntityListener implements Listener {
-
- private final OpenInv plugin;
- private final Configuration configuration;
-
- public OpenInvEntityListener(OpenInv plugin) {
- this.plugin = plugin;
- configuration = plugin.getConfiguration();
- }
-
- @EventHandler(priority = EventPriority.LOWEST)
- public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
- Entity attacker = event.getDamager();
- Entity defender = event.getEntity();
-
- if (!(attacker instanceof Player) || !(defender instanceof Player)) {
- return;
- }
-
- Player player = (Player) attacker;
-
- if (player.getInventory().getItemInMainHand().getType() == configuration.getOpenInvItem()) {
- if (!configuration.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
- return;
- }
-
- Player target = (Player) defender;
-
- event.setDamage(0);
- event.setCancelled(true);
-
- player.performCommand("openinv " + target.getName());
- }
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java b/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java
deleted file mode 100644
index efe92fe..0000000
--- a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.listeners;
-
-import org.bukkit.entity.HumanEntity;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.inventory.Inventory;
-
-import com.lishid.openinv.OpenInv;
-
-public class OpenInvInventoryListener implements Listener {
-
- private final OpenInv plugin;
-
- public OpenInvInventoryListener(OpenInv plugin) {
- this.plugin = plugin;
- }
-
- @EventHandler
- public void onInventoryClick(InventoryClickEvent event) {
- Inventory inventory = event.getInventory();
- HumanEntity player = event.getWhoClicked();
-
- if (!plugin.getInventoryAccess().check(inventory, player)) {
- event.setCancelled(true);
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java b/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java
deleted file mode 100644
index 22495fa..0000000
--- a/plugin/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2011-2016 lishid. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package com.lishid.openinv.listeners;
-
-import com.lishid.openinv.Configuration;
-import com.lishid.openinv.OpenInv;
-import com.lishid.openinv.Permissions;
-import com.lishid.openinv.internal.ISpecialEnderChest;
-import com.lishid.openinv.internal.ISpecialPlayerInventory;
-
-import org.bukkit.ChatColor;
-import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.block.Chest;
-import org.bukkit.block.Sign;
-import org.bukkit.entity.Player;
-import org.bukkit.event.Event.Result;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.scheduler.BukkitRunnable;
-
-public class OpenInvPlayerListener implements Listener {
-
- private final OpenInv plugin;
- private final Configuration configuration;
-
- public OpenInvPlayerListener(OpenInv plugin) {
- this.plugin = plugin;
- configuration = plugin.getConfiguration();
- }
-
- @SuppressWarnings("deprecation")
- @EventHandler(priority = EventPriority.MONITOR)
- public void onPlayerJoin(PlayerJoinEvent event) {
- final Player player = event.getPlayer();
-
- new BukkitRunnable() {
- @Override
- public void run() {
- if (!player.isOnline()) {
- return;
- }
-
- ISpecialPlayerInventory inventory = plugin.getPlayerInventory(player, false);
- if (inventory != null) {
- inventory.playerOnline(player);
- player.updateInventory();
- }
-
- ISpecialEnderChest enderChest = plugin.getPlayerEnderChest(player, false);
- if (enderChest != null) {
- enderChest.playerOnline(player);
- }
- }
- }.runTask(plugin);
- }
-
- @EventHandler
- public void onPlayerQuit(PlayerQuitEvent event) {
- Player player = event.getPlayer();
-
- ISpecialPlayerInventory inventory = plugin.getPlayerInventory(player, false);
- if (inventory != null) {
- inventory.playerOffline();
- if (inventory.isInUse()) {
- plugin.removeLoadedInventory(event.getPlayer());
- }
- }
-
- ISpecialEnderChest enderChest = plugin.getPlayerEnderChest(player, false);
- if (enderChest != null) {
- enderChest.playerOffline();
- if (!enderChest.isInUse()) {
- plugin.removeLoadedEnderChest(event.getPlayer());
- }
- }
- }
-
- @EventHandler
- public void onPlayerInteract(PlayerInteractEvent event) {
- Player player = event.getPlayer();
-
- if (player.isSneaking()) {
- return;
- }
-
- Action action = event.getAction();
- Block block = event.getClickedBlock();
-
- switch (action) {
- case RIGHT_CLICK_BLOCK:
- if (event.useInteractedBlock() == Result.DENY) {
- return;
- }
-
- // Ender Chests
- if (block.getType() == Material.ENDER_CHEST) {
- if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && configuration.getPlayerSilentChestStatus(player)) {
- event.setCancelled(true);
- player.openInventory(player.getEnderChest());
- return;
- }
- }
-
- // Chests
- if (block.getState() instanceof Chest) {
- boolean silentChest = false;
- boolean anyChest = false;
- int x = block.getX();
- int y = block.getY();
- int z = block.getZ();
-
- if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && configuration.getPlayerSilentChestStatus(player)) {
- silentChest = true;
- }
-
- if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && configuration.getPlayerAnyChestStatus(player)) {
- try {
- anyChest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
- } catch (Exception e) {
- player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
- e.printStackTrace();
- }
- }
-
- // If the anyChest or silentChest is active
- if (anyChest || silentChest) {
- if (!plugin.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
- event.setCancelled(true);
- }
- }
-
- return;
- }
-
- // Signs
- if (block.getState() instanceof Sign) {
- try {
- Sign sign = (Sign) block.getState();
-
- if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
- String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
- player.performCommand("openinv " + text);
- }
- } catch (Exception e) {
- player.sendMessage(ChatColor.RED + "An internal error occured.");
- e.printStackTrace();
- }
-
- return;
- }
- case RIGHT_CLICK_AIR:
- // OpenInv item
- if (player.getInventory().getItemInMainHand().getType() == configuration.getOpenInvItem() && configuration.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
- player.performCommand("openinv");
- }
- }
- }
-}
diff --git a/plugin/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java b/plugin/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java
deleted file mode 100644
index cc0499a..0000000
--- a/plugin/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.lishid.openinv.utils;
-
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.util.*;
-import java.util.concurrent.Callable;
-
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-
-import com.google.common.collect.ImmutableList;
-
-public class UUIDFetcher implements Callable