From 902def1dd7c43ac3db191ed75761f5d1592a23ab Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 13:31:26 +1000 Subject: [PATCH 01/10] Bug fix and changes --- gpl.txt => LICENSE.txt | 0 pom.xml | 2 +- .../com/lishid/openinv/ConfigUpdater.java | 161 ++++++++++++++++ src/main/java/com/lishid/openinv/OpenInv.java | 175 +++++++++++------- ...luginCommand.java => AnyChestCommand.java} | 22 ++- ...uginCommand.java => OpenEnderCommand.java} | 16 +- ...PluginCommand.java => OpenInvCommand.java} | 14 +- .../openinv/commands/SearchEnderCommand.java | 67 +++++++ ...uginCommand.java => SearchInvCommand.java} | 16 +- ...inCommand.java => SilentChestCommand.java} | 20 +- ...Command.java => ToggleOpenInvCommand.java} | 31 ++-- .../openinv/internal/AnySilentChest.java | 12 +- .../internal/SpecialPlayerInventory.java | 8 +- .../listeners/OpenInvEntityListener.java | 29 ++- .../listeners/OpenInvInventoryListener.java | 14 +- .../listeners/OpenInvPlayerListener.java | 50 ++--- .../com/lishid/openinv/utils/UUIDUtil.java | 51 ++++- src/main/resources/config.yml | 7 + src/main/resources/plugin.yml | 2 +- 19 files changed, 512 insertions(+), 185 deletions(-) rename gpl.txt => LICENSE.txt (100%) create mode 100644 src/main/java/com/lishid/openinv/ConfigUpdater.java rename src/main/java/com/lishid/openinv/commands/{AnyChestPluginCommand.java => AnyChestCommand.java} (68%) rename src/main/java/com/lishid/openinv/commands/{OpenEnderPluginCommand.java => OpenEnderCommand.java} (92%) rename src/main/java/com/lishid/openinv/commands/{OpenInvPluginCommand.java => OpenInvCommand.java} (93%) create mode 100644 src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java rename src/main/java/com/lishid/openinv/commands/{SearchInvPluginCommand.java => SearchInvCommand.java} (83%) rename src/main/java/com/lishid/openinv/commands/{SilentChestPluginCommand.java => SilentChestCommand.java} (69%) rename src/main/java/com/lishid/openinv/commands/{ToggleOpenInvPluginCommand.java => ToggleOpenInvCommand.java} (60%) create mode 100644 src/main/resources/config.yml diff --git a/gpl.txt b/LICENSE.txt similarity index 100% rename from gpl.txt rename to LICENSE.txt diff --git a/pom.xml b/pom.xml index ef32711..63f5b9e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.lishid openinv jar - 2.3.0 + 2.3.1 OpenInv http://dev.bukkit.org/bukkit-plugins/openinv/ diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java new file mode 100644 index 0000000..5d4f42e --- /dev/null +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -0,0 +1,161 @@ +package com.lishid.openinv; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; + +import com.lishid.openinv.utils.UUIDUtil; + +public class ConfigUpdater { + private final OpenInv plugin; + + private static final int LATEST_CONFIG_VERSION = 2; + + public ConfigUpdater(OpenInv plugin) { + this.plugin = plugin; + } + + private int getConfigVersion() { + return plugin.getConfig().getInt("config-version", 1); + } + + private boolean isConfigOutdated() { + return getConfigVersion() < LATEST_CONFIG_VERSION; + } + + public void checkForUpdates() { + if (isConfigOutdated()) { + plugin.getLogger().info("[Config] Update found! Performing update..."); + updateConfig(); + } else { + plugin.getLogger().info("[Config] Update not found. Config is already up-to-date."); + } + } + + private void updateConfig() { + // Get the old config settings + int itemOpenInvItemId = plugin.getConfig().getInt("ItemOpenInvItemID", 280); + boolean checkForUpdates = plugin.getConfig().getBoolean("CheckForUpdates", true); + boolean notifySilentChest = plugin.getConfig().getBoolean("NotifySilentChest", true); + boolean notifyAnyChest = plugin.getConfig().getBoolean("NotifyAnyChest", true); + + Map anyChestToggles = null; + Map itemOpenInvToggles = null; + Map silentChestToggles = null; + + if (plugin.getConfig().isSet("AnyChest")) { + anyChestToggles = updateAnyChestToggles(); + } + + if (plugin.getConfig().isSet("ItemOpenInv")) { + itemOpenInvToggles = updateItemOpenInvToggles(); + } + + if (plugin.getConfig().isSet("SilentChest")) { + silentChestToggles = updateSilentChestToggles(); + } + + // Clear the old config + for (String key : plugin.getConfig().getKeys(false)) { + plugin.getConfig().set(key, null); + } + + // Set the new config options + plugin.getConfig().set("config-version", LATEST_CONFIG_VERSION); + plugin.getConfig().set("check-for-updates", checkForUpdates); + plugin.getConfig().set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); + plugin.getConfig().set("notify.any-chest", notifyAnyChest); + plugin.getConfig().set("notify.silent-chest", notifySilentChest); + + if (anyChestToggles != null && !anyChestToggles.isEmpty()) { + for (Map.Entry entry : anyChestToggles.entrySet()) { + plugin.getConfig().set("toggles.any-chest." + entry.getKey(), entry.getValue()); + } + } + + if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) { + for (Map.Entry entry : itemOpenInvToggles.entrySet()) { + plugin.getConfig().set("toggles.items.open-inv." + entry.getKey(), entry.getValue()); + } + } + + if (silentChestToggles != null && !silentChestToggles.isEmpty()) { + for (Map.Entry entry : silentChestToggles.entrySet()) { + plugin.getConfig().set("toggles.silent-chest." + entry.getKey(), entry.getValue()); + } + } + + // Save the new config + plugin.saveConfig(); + + plugin.getLogger().info("[Config] Update complete."); + + } + + private Map updateAnyChestToggles() { + Map toggles = new HashMap(); + + ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("AnyChest"); + Set keys = anyChestSection.getKeys(false); + if (keys == null || keys.isEmpty()) return null; + + for (String playerName : keys) { + UUID uuid = UUIDUtil.getUUIDOf(playerName); + if (uuid != null) { + boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false); + toggles.put(uuid, toggled); + } + } + + return toggles; + } + + private Map updateItemOpenInvToggles() { + Map toggles = new HashMap(); + + ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("ItemOpenInv"); + Set keys = anyChestSection.getKeys(false); + if (keys == null || keys.isEmpty()) return null; + + for (String playerName : keys) { + UUID uuid = UUIDUtil.getUUIDOf(playerName); + if (uuid != null) { + boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false); + toggles.put(uuid, toggled); + } + } + + return toggles; + } + + private Map updateSilentChestToggles() { + Map toggles = new HashMap(); + + ConfigurationSection silentChestSection = plugin.getConfig().getConfigurationSection("SilentChest"); + Set keys = silentChestSection.getKeys(false); + if (keys == null || keys.isEmpty()) return null; + + for (String playerName : keys) { + UUID uuid = UUIDUtil.getUUIDOf(playerName); + if (uuid != null) { + boolean toggled = silentChestSection.getBoolean(playerName + ".toggle", false); + toggles.put(uuid, toggled); + } + } + + return toggles; + } + + @SuppressWarnings("deprecation") + private Material getMaterialById(int id) { + Material material = Material.getMaterial(id); + if (material == null) { + material = Material.STICK; + } + return material; + } +} diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index d67bf99..e300fc0 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -19,16 +19,21 @@ package com.lishid.openinv; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.logging.Logger; import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permissible; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import com.lishid.openinv.commands.*; +import com.lishid.openinv.commands.AnyChestCommand; +import com.lishid.openinv.commands.OpenEnderCommand; +import com.lishid.openinv.commands.OpenInvCommand; +import com.lishid.openinv.commands.SearchInvCommand; +import com.lishid.openinv.commands.SilentChestCommand; +import com.lishid.openinv.commands.ToggleOpenInvCommand; import com.lishid.openinv.internal.AnySilentChest; import com.lishid.openinv.internal.InventoryAccess; import com.lishid.openinv.internal.PlayerDataManager; @@ -44,93 +49,67 @@ import com.lishid.openinv.listeners.OpenInvPlayerListener; * @author lishid */ public class OpenInv extends JavaPlugin { - public static final Logger logger = Logger.getLogger("Minecraft.OpenInv"); - public static final Map inventories = new HashMap(); public static final Map enderChests = new HashMap(); public static OpenInv mainPlugin; - public static PlayerDataManager playerLoader; - public static InventoryAccess inventoryAccess; - public static AnySilentChest anySilentChest; + private static PlayerDataManager playerLoader; + private static InventoryAccess inventoryAccess; + private static AnySilentChest anySilentChest; @Override public void onEnable() { - // Get plugin manager - PluginManager pm = getServer().getPluginManager(); + // Plugin + mainPlugin = this; + // Config + ConfigUpdater configUpdater = new ConfigUpdater(this); + configUpdater.checkForUpdates(); + + // Initialize playerLoader = new PlayerDataManager(); inventoryAccess = new InventoryAccess(); anySilentChest = new AnySilentChest(); - mainPlugin = this; - FileConfiguration config = getConfig(); - config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true)); - config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true)); - config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true)); - config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280)); - config.addDefault("ItemOpenInvItemID", 280); - config.addDefault("CheckForUpdates", true); - config.addDefault("NotifySilentChest", true); - config.addDefault("NotifyAnyChest", true); - config.options().copyDefaults(true); - saveConfig(); + // Save the default config.yml if it doesn't already exist + saveDefaultConfig(); + + // Register the plugin's events & commands + registerEvents(); + registerCommands(); + } + + private void registerEvents() { + PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new OpenInvPlayerListener(), this); pm.registerEvents(new OpenInvEntityListener(), this); pm.registerEvents(new OpenInvInventoryListener(), this); - - getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); - getCommand("searchinv").setExecutor(new SearchInvPluginCommand()); - getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand()); - getCommand("silentchest").setExecutor(new SilentChestPluginCommand()); - getCommand("anychest").setExecutor(new AnyChestPluginCommand()); - getCommand("openender").setExecutor(new OpenEnderPluginCommand(this)); } - public static boolean notifySilentChest() { - return mainPlugin.getConfig().getBoolean("NotifySilentChest", true); + private void registerCommands() { + getCommand("openinv").setExecutor(new OpenInvCommand(this)); + getCommand("searchinv").setExecutor(new SearchInvCommand()); + getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand()); + getCommand("silentchest").setExecutor(new SilentChestCommand()); + getCommand("anychest").setExecutor(new AnyChestCommand()); + getCommand("openender").setExecutor(new OpenEnderCommand(this)); } - public static boolean notifyAnyChest() { - return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true); + public static PlayerDataManager getPlayerLoader() { + return playerLoader; } - public static boolean getPlayerItemOpenInvStatus(String name) { - return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false); + public static InventoryAccess getInventoryAccess() { + return inventoryAccess; } - public static void setPlayerItemOpenInvStatus(String name, boolean status) { - mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status); - mainPlugin.saveConfig(); - } - - public static boolean getPlayerSilentChestStatus(String name) { - return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false); - } - - public static void setPlayerSilentChestStatus(String name, boolean status) { - mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status); - mainPlugin.saveConfig(); - } - - public static boolean getPlayerAnyChestStatus(String name) { - return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true); - } - - public static void setPlayerAnyChestStatus(String name, boolean status) { - mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status); - mainPlugin.saveConfig(); - } - - public static int getItemOpenInvItem() { - if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) { - saveToConfig("ItemOpenInvItemID", 280); - } - return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280); + public static AnySilentChest getAnySilentChest() { + return anySilentChest; } + /* public static Object getFromConfig(String data, Object defaultValue) { Object val = mainPlugin.getConfig().get(data); if (val == null) { @@ -141,27 +120,83 @@ public class OpenInv extends JavaPlugin { return val; } } + */ public static void saveToConfig(String data, Object value) { mainPlugin.getConfig().set(data, value); mainPlugin.saveConfig(); } - /** - * Log an information - */ - public static void log(String text) { - logger.info("[OpenInv] " + text); + public static Material getOpenInvItem() { + if (!mainPlugin.getConfig().isSet("items.open-inv")) { + saveToConfig("items.open-inv", "STICK"); + } + + String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK"); + return Material.getMaterial(itemName); + } + + public static boolean notifySilentChest() { + return mainPlugin.getConfig().getBoolean("notify.silent-chest", true); + } + + public static boolean notifyAnyChest() { + return mainPlugin.getConfig().getBoolean("notify.any-chest", true); + } + + public static boolean getPlayerAnyChestStatus(Player player) { + return mainPlugin.getConfig().getBoolean("toggles.any-chest." + player.getUniqueId(), false); + } + + public static void setPlayerAnyChestStatus(Player player, boolean status) { + saveToConfig("toggles.any-chest." + player.getUniqueId(), status); + } + + public static boolean getPlayerItemOpenInvStatus(Player player) { + return mainPlugin.getConfig().getBoolean("toggles.items.open-inv" + player.getUniqueId(), false); + } + + public static void setPlayerItemOpenInvStatus(Player player, boolean status) { + saveToConfig("toggles.items.open-inv." + player.getUniqueId(), status); + } + + public static boolean getPlayerSilentChestStatus(Player player) { + return mainPlugin.getConfig().getBoolean("toggles.silent-chest." + player.getUniqueId(), false); + } + + public static void setPlayerSilentChestStatus(Player player, boolean status) { + saveToConfig("toggles.silent-chest." + player.getUniqueId(), status); } /** - * Log an error + * Logs a given message to console. + * + * @param text the text to log + */ + public static void log(String text) { + mainPlugin.getLogger().info("[OpenInv] " + text); + } + + /** + * Logs an error to console. + * + * @param e the throwable error to log */ public static void log(Throwable e) { - logger.severe("[OpenInv] " + e.toString()); + mainPlugin.getLogger().severe("[OpenInv] " + e.toString()); e.printStackTrace(); } + /** + * Sends a specified message to a given CommandSender with the OpenInv prefix. + * + * @param sender the CommandSender to message + * @param message the message to send to the player + */ + public static void sendMessage(CommandSender sender, String message) { + sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message); + } + public static void showHelp(Player player) { player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); diff --git a/src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java similarity index 68% rename from src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/AnyChestCommand.java index 21423fe..3bcde82 100644 --- a/src/main/java/com/lishid/openinv/commands/AnyChestPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java @@ -25,30 +25,34 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -public class AnyChestPluginCommand implements CommandExecutor { +public class AnyChestCommand implements CommandExecutor { @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 from the console."); + 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 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")) { - if (OpenInv.getPlayerAnyChestStatus(sender.getName())) - sender.sendMessage("AnyChest is ON."); - else - sender.sendMessage("AnyChest is OFF."); + String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + "."); + return true; } } - OpenInv.setPlayerAnyChestStatus(sender.getName(), !OpenInv.getPlayerAnyChestStatus(sender.getName())); - sender.sendMessage("AnyChest is now " + (OpenInv.getPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + "."); + OpenInv.setPlayerAnyChestStatus(player, !OpenInv.getPlayerAnyChestStatus(player)); + + String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + "."); return true; } diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java similarity index 92% rename from src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index 8c934a9..4fbaa0c 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -32,11 +32,11 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.SpecialEnderChest; import com.lishid.openinv.utils.UUIDUtil; -public class OpenEnderPluginCommand implements CommandExecutor { +public class OpenEnderCommand implements CommandExecutor { private final OpenInv plugin; private final Map openEnderHistory = new ConcurrentHashMap(); - public OpenEnderPluginCommand(OpenInv plugin) { + public OpenEnderCommand(OpenInv plugin) { this.plugin = plugin; } @@ -44,7 +44,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { 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 from the console."); + sender.sendMessage(ChatColor.RED + "You can't use this command from the console."); return true; } @@ -82,6 +82,11 @@ public class OpenEnderPluginCommand implements CommandExecutor { } else { uuid = UUIDUtil.getUUIDOf(args[0]); + + if (uuid == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } } final UUID playerUUID = player.getUniqueId(); @@ -93,11 +98,12 @@ public class OpenEnderPluginCommand implements CommandExecutor { @Override public void run() { // Try loading the player's data asynchronously - final Player target = OpenInv.playerLoader.loadPlayer(uuid); + final Player target = OpenInv.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 @@ -129,7 +135,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { } 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"); + player.sendMessage(ChatColor.RED + "You do not have permission to access other player's ender chests."); return; } diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java similarity index 93% rename from src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index a3e8629..2bfbb8c 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -32,11 +32,11 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.SpecialPlayerInventory; import com.lishid.openinv.utils.UUIDUtil; -public class OpenInvPluginCommand implements CommandExecutor { +public class OpenInvCommand implements CommandExecutor { private final OpenInv plugin; private final Map openInvHistory = new ConcurrentHashMap(); - public OpenInvPluginCommand(OpenInv plugin) { + public OpenInvCommand(OpenInv plugin) { this.plugin = plugin; } @@ -44,7 +44,7 @@ public class OpenInvPluginCommand implements CommandExecutor { 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 from the console."); + sender.sendMessage(ChatColor.RED + "You can't use this command from the console."); return true; } if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) { @@ -75,6 +75,11 @@ public class OpenInvPluginCommand implements CommandExecutor { } else { uuid = UUIDUtil.getUUIDOf(args[0]); + + if (uuid == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } } final UUID playerUUID = player.getUniqueId(); @@ -86,11 +91,12 @@ public class OpenInvPluginCommand implements CommandExecutor { @Override public void run() { // Try loading the player's data asynchronously - final Player target = OpenInv.playerLoader.loadPlayer(uuid); + final Player target = OpenInv.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 diff --git a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java new file mode 100644 index 0000000..658fa94 --- /dev/null +++ b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java @@ -0,0 +1,67 @@ +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 { + // TODO + + @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 ender chests."); + return true; + } + } + + 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 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 " + material.toString() + ": " + playerList); + + return true; + } + + return false; + } +} diff --git a/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java similarity index 83% rename from src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/SearchInvCommand.java index 968e1ab..98d1527 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java @@ -27,19 +27,17 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -public class SearchInvPluginCommand implements CommandExecutor { +public class SearchInvCommand implements CommandExecutor { @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 access player inventories"); + sender.sendMessage(ChatColor.RED + "You do not have permission to search player inventories."); return true; } } - String playerList = ""; - Material material = null; int count = 1; @@ -63,12 +61,16 @@ public class SearchInvPluginCommand implements CommandExecutor { return false; } - for (Player templayer : Bukkit.getServer().getOnlinePlayers()) { - if (templayer.getInventory().contains(material, count)) { - playerList += templayer.getName() + " "; + 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 " + material.toString() + ": " + playerList); return true; diff --git a/src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java similarity index 69% rename from src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/SilentChestCommand.java index 90bd3fc..ce94e88 100644 --- a/src/main/java/com/lishid/openinv/commands/SilentChestPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java @@ -25,30 +25,34 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -public class SilentChestPluginCommand implements CommandExecutor { +public class SilentChestCommand implements CommandExecutor { @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 from the console."); + 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")) { - if (OpenInv.getPlayerSilentChestStatus(sender.getName())) - sender.sendMessage("SilentChest is ON."); - else - sender.sendMessage("SilentChest is OFF."); + String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + "."); + return true; } } - OpenInv.setPlayerSilentChestStatus(sender.getName(), !OpenInv.getPlayerSilentChestStatus(sender.getName())); - sender.sendMessage("SilentChest is now " + (OpenInv.getPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + "."); + OpenInv.setPlayerSilentChestStatus(player, !OpenInv.getPlayerSilentChestStatus(player)); + + String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + "."); return true; } diff --git a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java similarity index 60% rename from src/main/java/com/lishid/openinv/commands/ToggleOpenInvPluginCommand.java rename to src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java index b59f841..a024c24 100644 --- a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java @@ -17,7 +17,6 @@ package com.lishid.openinv.commands; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -26,37 +25,35 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -@SuppressWarnings("deprecation") -public class ToggleOpenInvPluginCommand implements CommandExecutor { +public class ToggleOpenInvCommand implements CommandExecutor { @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 from the console."); + 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"); + 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")) { - if (OpenInv.getPlayerItemOpenInvStatus(player.getName())) - player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON."); - else - player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF."); + String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + "."); + return true; } } - if (OpenInv.getPlayerItemOpenInvStatus(player.getName())) { - OpenInv.setPlayerItemOpenInvStatus(player.getName(), false); - player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF."); - } - else { - OpenInv.setPlayerItemOpenInvStatus(player.getName(), true); - player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON."); - } + + OpenInv.setPlayerItemOpenInvStatus(player, !OpenInv.getPlayerItemOpenInvStatus(player)); + + String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF"; + OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + "."); + return true; } diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index d668c82..213422e 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -28,7 +28,7 @@ import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.entity.*; public class AnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { + public boolean isAnyChestNeeded(Player p, int x, int y, int z) { // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest BlockPosition position = new BlockPosition(x, y, z); EntityPlayer player = ((CraftPlayer) p).getHandle(); @@ -81,7 +81,7 @@ public class AnySilentChest { return true; } - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { + public boolean activateChest(Player p, boolean anyChest, boolean silentChest, int x, int y, int z) { BlockPosition position = new BlockPosition(x, y, z); EntityPlayer player = ((CraftPlayer) p).getHandle(); World world = player.world; @@ -98,7 +98,7 @@ public class AnySilentChest { } ITileInventory tileInventory = (ITileInventory) tileEntity; - if (!anychest && this.topBlocking(world, position)) { + if (!anyChest && this.topBlocking(world, position)) { return true; } @@ -106,7 +106,7 @@ public class AnySilentChest { BlockPosition side = position.shift(direction); Block block = world.getType(side).getBlock(); if (block == chest) { - if (!anychest && this.topBlocking(world, side)) { + if (!anyChest && this.topBlocking(world, side)) { return true; } @@ -122,7 +122,7 @@ public class AnySilentChest { } boolean returnValue = true; - if (silentchest) { + if (silentChest) { tileInventory = new SilentInventory(tileInventory); if (OpenInv.notifySilentChest()) { p.sendMessage("You are opening a chest silently."); @@ -132,7 +132,7 @@ public class AnySilentChest { player.openContainer(tileInventory); - if (anychest && OpenInv.notifyAnyChest()) { + if (anyChest && OpenInv.notifyAnyChest()) { p.sendMessage("You are opening a blocked chest."); } diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index f167e28..c9e39e3 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -180,7 +180,7 @@ public class SpecialPlayerInventory extends PlayerInventory { } @Override - public void setItem(int i, ItemStack itemstack) { + public void setItem(int i, ItemStack itemStack) { ItemStack[] is = this.items; if (i >= is.length) { @@ -199,11 +199,11 @@ public class SpecialPlayerInventory extends PlayerInventory { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); - itemstack = null; + owner.getHandle().drop(itemStack, true); + itemStack = null; } - is[i] = itemstack; + is[i] = itemStack; owner.getHandle().defaultContainer.b(); } diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java index 5697cfb..3508af5 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java @@ -19,37 +19,36 @@ 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.entity.EntityDamageEvent; 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; -@SuppressWarnings("deprecation") public class OpenInvEntityListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) - public void onEntityDamage(EntityDamageEvent event) { - if (event instanceof EntityDamageByEntityEvent) { - EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event; - Entity attacker = evt.getDamager(); - Entity defender = evt.getEntity(); + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity attacker = event.getDamager(); + Entity defender = event.getEntity(); - if (!(attacker instanceof Player) || !(defender instanceof Player)) { - return; - } + if (!(attacker instanceof Player) || !(defender instanceof Player)) { + return; + } - Player player = (Player) attacker; + Player player = (Player) attacker; - if (!(player.getItemInHand().getType().getId() == OpenInv.getItemOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, "OpenInv.openinv")) { + if (player.getItemInHand().getType() == OpenInv.getOpenInvItem()) { + if (!OpenInv.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { return; } Player target = (Player) defender; - player.performCommand("openinv " + target.getName()); - evt.setDamage(0); - evt.setCancelled(true); + event.setDamage(0); + event.setCancelled(true); + + player.performCommand("openinv " + target.getName()); } } } diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java index bd100c6..6d3250e 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java @@ -16,22 +16,22 @@ package com.lishid.openinv.listeners; +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.inventory.Inventory; import com.lishid.openinv.OpenInv; public class OpenInvInventoryListener implements Listener { - @EventHandler(priority = EventPriority.NORMAL) + @EventHandler public void onInventoryClick(InventoryClickEvent event) { - // If this is the top inventory - // if (event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot()) - // { - if (!OpenInv.inventoryAccess.check(event.getInventory(), event.getWhoClicked())) { + Inventory inventory = event.getInventory(); + HumanEntity player = event.getWhoClicked(); + + if (!OpenInv.getInventoryAccess().check(inventory, player)) { event.setCancelled(true); } - // } } } \ No newline at end of file diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java index b78e606..07f8fc9 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java @@ -17,6 +17,8 @@ package com.lishid.openinv.listeners; 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; @@ -34,7 +36,6 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.SpecialEnderChest; import com.lishid.openinv.internal.SpecialPlayerInventory; -@SuppressWarnings("deprecation") public class OpenInvPlayerListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { @@ -70,35 +71,40 @@ public class OpenInvPlayerListener implements Listener { public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if (event.getPlayer().isSneaking()) { + if (player.isSneaking()) { return; } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) { + Action action = event.getAction(); + + if (action == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) { return; } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) { - if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) { + Block block = event.getClickedBlock(); + + if (action == Action.RIGHT_CLICK_BLOCK && block.getType() == Material.ENDER_CHEST) { + if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) { event.setCancelled(true); player.openInventory(player.getEnderChest()); } } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) { - boolean silentchest = false; - boolean anychest = false; - int x = event.getClickedBlock().getX(); - int y = event.getClickedBlock().getY(); - int z = event.getClickedBlock().getZ(); + if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Chest) { + boolean silentChest = false; + boolean anyChest = false; - if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) { - silentchest = true; + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + + if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) { + silentChest = true; } - if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player.getName())) { + if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) { try { - anychest = OpenInv.anySilentChest.IsAnyChestNeeded(player, x, y, z); + anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z); } catch (Exception e) { player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit."); @@ -107,16 +113,16 @@ public class OpenInvPlayerListener implements Listener { } // If the anychest or silentchest is active - if (anychest || silentchest) { - if (!OpenInv.anySilentChest.ActivateChest(player, anychest, silentchest, x, y, z)) { + if (anyChest || silentChest) { + if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) { event.setCancelled(true); } } } - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign) { + if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Sign) { try { - Sign sign = ((Sign) event.getClickedBlock().getState()); + 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); @@ -128,12 +134,12 @@ public class OpenInvPlayerListener implements Listener { } } - if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - if (!(player.getItemInHand().getType().getId() == OpenInv.getItemOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { + if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { + if (!(player.getItemInHand().getType() == OpenInv.getOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player)) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { return; } player.performCommand("openinv"); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java index 76ebb38..22e3928 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java @@ -1,25 +1,58 @@ package com.lishid.openinv.utils; import java.util.Arrays; +import java.util.Collection; import java.util.Map; import java.util.UUID; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; public class UUIDUtil { + private static Player getPlayer(String name) { + Validate.notNull(name, "Name cannot be null"); + + Player found = null; + String lowerName = name.toLowerCase(); + int delta = Integer.MAX_VALUE; + + Collection players = Bukkit.getOnlinePlayers(); + for (Player player : players) { + if (player.getName().toLowerCase().startsWith(lowerName)) { + int curDelta = player.getName().length() - lowerName.length(); + if (curDelta < delta) { + found = player; + delta = curDelta; + } + if (curDelta == 0) break; + } + } + + return found; + } + public static UUID getUUIDOf(String name) { UUID uuid = null; + Player player = getPlayer(name); - UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); - Map response; - - try { - response = fetcher.call(); - uuid = response.get(name); + if (player != null) { + // Player was found online + uuid = player.getUniqueId(); } - catch (Exception e) { - Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); - e.printStackTrace(); + else { + // Player was not found online. Fetch their UUID instead + UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name)); + Map response; + + try { + response = fetcher.call(); + uuid = response.get(name); + } + catch (Exception e) { + Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); + e.printStackTrace(); + } } return uuid; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..eb76f52 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,7 @@ +config-version: 2 +check-for-updates: true +notify: + any-chest: true + silent-chest: true +items: + open-inv: STICK \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4cd5127..73a1bf2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 2.3.0 +version: 2.3.1 author: lishid description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time. From 3c7d1696ff469fb9b05eb53a5360c315ed1747e0 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 13:35:25 +1000 Subject: [PATCH 02/10] Bug fix and changes --- src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java | 1 - src/main/java/com/lishid/openinv/commands/OpenInvCommand.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index 4fbaa0c..28a3ed5 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -82,7 +82,6 @@ public class OpenEnderCommand implements CommandExecutor { } else { uuid = UUIDUtil.getUUIDOf(args[0]); - if (uuid == null) { player.sendMessage(ChatColor.RED + "Player not found!"); return true; diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index 2bfbb8c..3d2cdd7 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -75,7 +75,6 @@ public class OpenInvCommand implements CommandExecutor { } else { uuid = UUIDUtil.getUUIDOf(args[0]); - if (uuid == null) { player.sendMessage(ChatColor.RED + "Player not found!"); return true; From f8e4e69e53ada5227a6bed4dc2e63917592aa93e Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 15:11:35 +1000 Subject: [PATCH 03/10] Bug fix and changes --- src/main/java/com/lishid/openinv/ConfigUpdater.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index 5d4f42e..6265210 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -13,7 +13,7 @@ import com.lishid.openinv.utils.UUIDUtil; public class ConfigUpdater { private final OpenInv plugin; - private static final int LATEST_CONFIG_VERSION = 2; + private static final int CONFIG_VERSION = 2; public ConfigUpdater(OpenInv plugin) { this.plugin = plugin; @@ -24,7 +24,7 @@ public class ConfigUpdater { } private boolean isConfigOutdated() { - return getConfigVersion() < LATEST_CONFIG_VERSION; + return getConfigVersion() < CONFIG_VERSION; } public void checkForUpdates() { @@ -65,7 +65,7 @@ public class ConfigUpdater { } // Set the new config options - plugin.getConfig().set("config-version", LATEST_CONFIG_VERSION); + plugin.getConfig().set("config-version", CONFIG_VERSION); plugin.getConfig().set("check-for-updates", checkForUpdates); plugin.getConfig().set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); plugin.getConfig().set("notify.any-chest", notifyAnyChest); From 55deabe56ba8730cb3ab560b4a49ed701dacb990 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 16:17:51 +1000 Subject: [PATCH 04/10] Small fixes --- .../com/lishid/openinv/ConfigUpdater.java | 100 +++++++----------- src/main/java/com/lishid/openinv/OpenInv.java | 10 +- 2 files changed, 42 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index 6265210..eff633e 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import com.lishid.openinv.utils.UUIDUtil; @@ -30,119 +31,92 @@ public class ConfigUpdater { public void checkForUpdates() { if (isConfigOutdated()) { plugin.getLogger().info("[Config] Update found! Performing update..."); - updateConfig(); + performUpdate(); } else { plugin.getLogger().info("[Config] Update not found. Config is already up-to-date."); } } - private void updateConfig() { + private void performUpdate() { + // Update according to the right version + switch (getConfigVersion()) { + case 1: + updateConfig1To2(); + break; + } + } + + private void updateConfig1To2() { // Get the old config settings - int itemOpenInvItemId = plugin.getConfig().getInt("ItemOpenInvItemID", 280); - boolean checkForUpdates = plugin.getConfig().getBoolean("CheckForUpdates", true); - boolean notifySilentChest = plugin.getConfig().getBoolean("NotifySilentChest", true); - boolean notifyAnyChest = plugin.getConfig().getBoolean("NotifyAnyChest", true); + FileConfiguration config = plugin.getConfig(); + + int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280); + boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); + boolean notifySilentChest = config.getBoolean("NotifySilentChest", true); + boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true); Map anyChestToggles = null; Map itemOpenInvToggles = null; Map silentChestToggles = null; - if (plugin.getConfig().isSet("AnyChest")) { - anyChestToggles = updateAnyChestToggles(); + if (config.isSet("AnyChest")) { + anyChestToggles = updateToggles("AnyChest"); } - if (plugin.getConfig().isSet("ItemOpenInv")) { - itemOpenInvToggles = updateItemOpenInvToggles(); + if (config.isSet("ItemOpenInv")) { + itemOpenInvToggles = updateToggles("ItemOpenInv"); } - if (plugin.getConfig().isSet("SilentChest")) { - silentChestToggles = updateSilentChestToggles(); + if (config.isSet("SilentChest")) { + silentChestToggles = updateToggles("SilentChest"); } // Clear the old config - for (String key : plugin.getConfig().getKeys(false)) { + for (String key : config.getKeys(false)) { plugin.getConfig().set(key, null); } // Set the new config options - plugin.getConfig().set("config-version", CONFIG_VERSION); - plugin.getConfig().set("check-for-updates", checkForUpdates); - plugin.getConfig().set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); - plugin.getConfig().set("notify.any-chest", notifyAnyChest); - plugin.getConfig().set("notify.silent-chest", notifySilentChest); + config.set("config-version", "2"); + config.set("check-for-updates", checkForUpdates); + config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); + config.set("notify.any-chest", notifyAnyChest); + config.set("notify.silent-chest", notifySilentChest); if (anyChestToggles != null && !anyChestToggles.isEmpty()) { for (Map.Entry entry : anyChestToggles.entrySet()) { - plugin.getConfig().set("toggles.any-chest." + entry.getKey(), entry.getValue()); + config.set("toggles.any-chest." + entry.getKey(), entry.getValue()); } } if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) { for (Map.Entry entry : itemOpenInvToggles.entrySet()) { - plugin.getConfig().set("toggles.items.open-inv." + entry.getKey(), entry.getValue()); + config.set("toggles.items.open-inv." + entry.getKey(), entry.getValue()); } } if (silentChestToggles != null && !silentChestToggles.isEmpty()) { for (Map.Entry entry : silentChestToggles.entrySet()) { - plugin.getConfig().set("toggles.silent-chest." + entry.getKey(), entry.getValue()); + config.set("toggles.silent-chest." + entry.getKey(), entry.getValue()); } } // Save the new config plugin.saveConfig(); - plugin.getLogger().info("[Config] Update complete."); - } - private Map updateAnyChestToggles() { + private Map updateToggles(String sectionName) { Map toggles = new HashMap(); - ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("AnyChest"); - Set keys = anyChestSection.getKeys(false); + ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName); + Set keys = section.getKeys(false); if (keys == null || keys.isEmpty()) return null; for (String playerName : keys) { UUID uuid = UUIDUtil.getUUIDOf(playerName); if (uuid != null) { - boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false); - toggles.put(uuid, toggled); - } - } - - return toggles; - } - - private Map updateItemOpenInvToggles() { - Map toggles = new HashMap(); - - ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("ItemOpenInv"); - Set keys = anyChestSection.getKeys(false); - if (keys == null || keys.isEmpty()) return null; - - for (String playerName : keys) { - UUID uuid = UUIDUtil.getUUIDOf(playerName); - if (uuid != null) { - boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false); - toggles.put(uuid, toggled); - } - } - - return toggles; - } - - private Map updateSilentChestToggles() { - Map toggles = new HashMap(); - - ConfigurationSection silentChestSection = plugin.getConfig().getConfigurationSection("SilentChest"); - Set keys = silentChestSection.getKeys(false); - if (keys == null || keys.isEmpty()) return null; - - for (String playerName : keys) { - UUID uuid = UUIDUtil.getUUIDOf(playerName); - if (uuid != null) { - boolean toggled = silentChestSection.getBoolean(playerName + ".toggle", false); + boolean toggled = section.getBoolean(playerName + ".toggle", false); toggles.put(uuid, toggled); } } diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index e300fc0..ae96043 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -131,9 +131,9 @@ public class OpenInv extends JavaPlugin { if (!mainPlugin.getConfig().isSet("items.open-inv")) { saveToConfig("items.open-inv", "STICK"); } - String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK"); - return Material.getMaterial(itemName); + Material material = Material.getMaterial(itemName); + return material != null ? material : Material.STICK; } public static boolean notifySilentChest() { @@ -198,13 +198,13 @@ public class OpenInv extends JavaPlugin { } public static void showHelp(Player player) { - player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); + player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); - player.sendMessage(ChatColor.GREEN + "/openender - Open a player's enderchest"); + player.sendMessage(ChatColor.GREEN + "/openender - Open a player's ender chest"); player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)"); player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function"); player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); - player.sendMessage(ChatColor.GREEN + "/searchinv [MinAmount] - "); + player.sendMessage(ChatColor.GREEN + "/searchinv [minAmount] - "); player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item."); player.sendMessage(ChatColor.GREEN + " (aliases: si, search)"); player.sendMessage(ChatColor.GREEN + "/anychest - Toggle anychest function"); From 802e405c4e36128e452584936568c621c7ff520e Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 16:28:58 +1000 Subject: [PATCH 05/10] Small change to update not required message --- src/main/java/com/lishid/openinv/ConfigUpdater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index eff633e..b061298 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -33,7 +33,7 @@ public class ConfigUpdater { plugin.getLogger().info("[Config] Update found! Performing update..."); performUpdate(); } else { - plugin.getLogger().info("[Config] Update not found. Config is already up-to-date."); + plugin.getLogger().info("[Config] Update not required."); } } From f7029e5ee2de5a3e897b8a19d03e44736836cec5 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 16:46:14 +1000 Subject: [PATCH 06/10] Another small change --- src/main/java/com/lishid/openinv/OpenInv.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index ae96043..22a5c77 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -131,9 +131,15 @@ public class OpenInv extends JavaPlugin { if (!mainPlugin.getConfig().isSet("items.open-inv")) { saveToConfig("items.open-inv", "STICK"); } + String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK"); Material material = Material.getMaterial(itemName); - return material != null ? material : Material.STICK; + if (material == null) { + mainPlugin.getLogger().info("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick."); + material = Material.STICK; + } + + return material; } public static boolean notifySilentChest() { From a03c73f8d608a6db064c788f1e138c01af3617ba Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 19:05:26 +1000 Subject: [PATCH 07/10] More fixes and improvements --- .../com/lishid/openinv/ConfigUpdater.java | 30 ++++++++++++++++--- src/main/java/com/lishid/openinv/OpenInv.java | 2 +- .../com/lishid/openinv/utils/UUIDFetcher.java | 2 +- .../com/lishid/openinv/utils/UUIDUtil.java | 14 ++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index b061298..e8af988 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -1,5 +1,6 @@ package com.lishid.openinv; +import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -32,7 +33,8 @@ public class ConfigUpdater { if (isConfigOutdated()) { plugin.getLogger().info("[Config] Update found! Performing update..."); performUpdate(); - } else { + } + else { plugin.getLogger().info("[Config] Update not required."); } } @@ -47,9 +49,19 @@ public class ConfigUpdater { } private void updateConfig1To2() { - // Get the old config settings FileConfiguration config = plugin.getConfig(); + // Backup the old config file + File configFile = new File(plugin.getDataFolder(), "config.yml"); + File oldConfigFile = new File(plugin.getDataFolder(), "config_old.yml"); + + configFile.renameTo(oldConfigFile); + + if (configFile.exists()) { + configFile.delete(); + } + + // Get the old config settings int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280); boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); boolean notifySilentChest = config.getBoolean("NotifySilentChest", true); @@ -73,10 +85,15 @@ public class ConfigUpdater { // Clear the old config for (String key : config.getKeys(false)) { - plugin.getConfig().set(key, null); + config.set(key, null); } // Set the new config options + plugin.saveDefaultConfig(); + plugin.reloadConfig(); + + config = plugin.getConfig(); // Refresh the referenced config + config.set("config-version", "2"); config.set("check-for-updates", checkForUpdates); config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); @@ -111,7 +128,9 @@ public class ConfigUpdater { ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName); Set keys = section.getKeys(false); - if (keys == null || keys.isEmpty()) return null; + if (keys == null || keys.isEmpty()) { + return null; + } for (String playerName : keys) { UUID uuid = UUIDUtil.getUUIDOf(playerName); @@ -119,6 +138,9 @@ public class ConfigUpdater { boolean toggled = section.getBoolean(playerName + ".toggle", false); toggles.put(uuid, toggled); } + else { + plugin.getLogger().warning("Failed to retrieve UUID of player: " + playerName); + } } return toggles; diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 22a5c77..26adac5 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -135,7 +135,7 @@ public class OpenInv extends JavaPlugin { String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK"); Material material = Material.getMaterial(itemName); if (material == null) { - mainPlugin.getLogger().info("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick."); + mainPlugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick."); material = Material.STICK; } diff --git a/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java b/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java index 11776a3..2784fb4 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDFetcher.java @@ -44,7 +44,7 @@ public class UUIDFetcher implements Callable> { String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); - uuidMap.put(name, uuid); + uuidMap.put(name.toLowerCase(), uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); diff --git a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java index 22e3928..ce736aa 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java @@ -7,6 +7,7 @@ import java.util.UUID; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; public class UUIDUtil { @@ -32,6 +33,7 @@ public class UUIDUtil { return found; } + @SuppressWarnings("deprecation") public static UUID getUUIDOf(String name) { UUID uuid = null; Player player = getPlayer(name); @@ -47,11 +49,21 @@ public class UUIDUtil { try { response = fetcher.call(); - uuid = response.get(name); + uuid = response.get(name.toLowerCase()); } catch (Exception e) { + /* Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); e.printStackTrace(); + */ + Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); + // Failed to retrieve with UUIDFetcher, server might be offline? + // Fallback on searching for the player via their name + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); + + if (offlinePlayer != null) { + uuid = offlinePlayer.getUniqueId(); + } } } From 2f1fd8743587975d52cf509061c425ec57def456 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Tue, 23 Jun 2015 19:07:19 +1000 Subject: [PATCH 08/10] More fixes and improvements --- src/main/java/com/lishid/openinv/utils/UUIDUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java index ce736aa..1489ad5 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDUtil.java @@ -56,11 +56,10 @@ public class UUIDUtil { Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); e.printStackTrace(); */ - Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher"); + // Failed to retrieve with UUIDFetcher, server might be offline? // Fallback on searching for the player via their name OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); - if (offlinePlayer != null) { uuid = offlinePlayer.getUniqueId(); } From 471b63183800f416a6b2261f2cbc14993af99d13 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 24 Jun 2015 19:19:45 +1000 Subject: [PATCH 09/10] More fixes and improvements - continued --- .../com/lishid/openinv/ConfigUpdater.java | 19 ++- src/main/java/com/lishid/openinv/OpenInv.java | 67 +++++----- .../openinv/commands/OpenEnderCommand.java | 1 - .../openinv/commands/OpenInvCommand.java | 1 - .../openinv/commands/SearchEnderCommand.java | 8 +- .../openinv/commands/SearchInvCommand.java | 4 +- .../openinv/internal/AnySilentChest.java | 6 +- .../openinv/internal/InventoryAccess.java | 4 +- .../openinv/internal/PlayerDataManager.java | 2 +- .../internal/SilentContainerChest.java | 4 +- .../openinv/internal/SilentInventory.java | 8 +- .../openinv/internal/SpecialEnderChest.java | 15 ++- .../internal/SpecialPlayerInventory.java | 5 +- .../listeners/OpenInvPlayerListener.java | 120 +++++++++--------- src/main/resources/plugin.yml | 38 +++--- 15 files changed, 156 insertions(+), 146 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index e8af988..e94ae1b 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -61,9 +61,11 @@ public class ConfigUpdater { configFile.delete(); } + plugin.getLogger().info("[Config] Backup of old config.yml file created."); + // Get the old config settings int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280); - boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); + // boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); boolean notifySilentChest = config.getBoolean("NotifySilentChest", true); boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true); @@ -92,10 +94,10 @@ public class ConfigUpdater { plugin.saveDefaultConfig(); plugin.reloadConfig(); - config = plugin.getConfig(); // Refresh the referenced config + config = plugin.getConfig(); // Refresh the referenced plugin config - config.set("config-version", "2"); - config.set("check-for-updates", checkForUpdates); + config.set("config-version", 2); + // config.set("check-for-updates", checkForUpdates); config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); config.set("notify.any-chest", notifyAnyChest); config.set("notify.silent-chest", notifySilentChest); @@ -132,17 +134,20 @@ public class ConfigUpdater { return null; } + int total = keys.size(); + int converted = 0; + for (String playerName : keys) { UUID uuid = UUIDUtil.getUUIDOf(playerName); if (uuid != null) { boolean toggled = section.getBoolean(playerName + ".toggle", false); toggles.put(uuid, toggled); - } - else { - plugin.getLogger().warning("Failed to retrieve UUID of player: " + playerName); + converted++; } } + plugin.getLogger().info("[Config] Converted (" + converted + "/" + total + ") " + sectionName + " toggle player usernames to UUIDs."); + return toggles; } diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 26adac5..71773f1 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -31,6 +31,7 @@ import org.bukkit.plugin.java.JavaPlugin; import com.lishid.openinv.commands.AnyChestCommand; import com.lishid.openinv.commands.OpenEnderCommand; import com.lishid.openinv.commands.OpenInvCommand; +import com.lishid.openinv.commands.SearchEnderCommand; import com.lishid.openinv.commands.SearchInvCommand; import com.lishid.openinv.commands.SilentChestCommand; import com.lishid.openinv.commands.ToggleOpenInvCommand; @@ -63,7 +64,7 @@ public class OpenInv extends JavaPlugin { // Plugin mainPlugin = this; - // Config + // Config Updater ConfigUpdater configUpdater = new ConfigUpdater(this); configUpdater.checkForUpdates(); @@ -90,11 +91,12 @@ public class OpenInv extends JavaPlugin { private void registerCommands() { getCommand("openinv").setExecutor(new OpenInvCommand(this)); - getCommand("searchinv").setExecutor(new SearchInvCommand()); - getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand()); - getCommand("silentchest").setExecutor(new SilentChestCommand()); - getCommand("anychest").setExecutor(new AnyChestCommand()); getCommand("openender").setExecutor(new OpenEnderCommand(this)); + getCommand("searchinv").setExecutor(new SearchInvCommand()); + getCommand("searchender").setExecutor(new SearchEnderCommand()); + getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand()); + getCommand("anychest").setExecutor(new AnyChestCommand()); + getCommand("silentchest").setExecutor(new SilentChestCommand()); } public static PlayerDataManager getPlayerLoader() { @@ -109,21 +111,19 @@ public class OpenInv extends JavaPlugin { return anySilentChest; } - /* - public static Object getFromConfig(String data, Object defaultValue) { - Object val = mainPlugin.getConfig().get(data); + public static Object getFromConfig(String path, Object defaultValue) { + Object val = mainPlugin.getConfig().get(path); if (val == null) { - mainPlugin.getConfig().set(data, defaultValue); + mainPlugin.getConfig().set(path, defaultValue); return defaultValue; } else { return val; } } - */ - public static void saveToConfig(String data, Object value) { - mainPlugin.getConfig().set(data, value); + public static void saveToConfig(String path, Object value) { + mainPlugin.getConfig().set(path, value); mainPlugin.saveConfig(); } @@ -174,48 +174,41 @@ public class OpenInv extends JavaPlugin { saveToConfig("toggles.silent-chest." + player.getUniqueId(), status); } - /** - * Logs a given message to console. - * - * @param text the text to log - */ public static void log(String text) { mainPlugin.getLogger().info("[OpenInv] " + text); } - /** - * Logs an error to console. - * - * @param e the throwable error to log - */ public static void log(Throwable e) { mainPlugin.getLogger().severe("[OpenInv] " + e.toString()); e.printStackTrace(); } - /** - * Sends a specified message to a given CommandSender with the OpenInv prefix. - * - * @param sender the CommandSender to message - * @param message the message to send to the player - */ public static void sendMessage(CommandSender sender, String message) { sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message); } public static void showHelp(Player player) { - player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); + player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory."); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); - player.sendMessage(ChatColor.GREEN + "/openender - Open a player's ender chest"); - player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)"); - player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function"); - player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); - player.sendMessage(ChatColor.GREEN + "/searchinv [minAmount] - "); + + player.sendMessage(ChatColor.GREEN + "/openender - Open a player's ender chest."); + player.sendMessage(ChatColor.GREEN + " (aliases: oe)"); + + player.sendMessage(ChatColor.GREEN + "/searchinv [minAmount] -"); player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item."); - player.sendMessage(ChatColor.GREEN + " (aliases: si, search)"); - player.sendMessage(ChatColor.GREEN + "/anychest - Toggle anychest function"); + player.sendMessage(ChatColor.GREEN + " (aliases: si)"); + + player.sendMessage(ChatColor.GREEN + "/searchender [minAmount] -"); + player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item."); + player.sendMessage(ChatColor.GREEN + " (aliases: se)"); + + player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle the item openinv function."); + player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); + + player.sendMessage(ChatColor.GREEN + "/anychest - Toggle the any chest function."); player.sendMessage(ChatColor.GREEN + " (aliases: ac)"); - player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle silent chest function"); + + player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle the silent chest function."); player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)"); } diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index 28a3ed5..f39fce8 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -62,7 +62,6 @@ public class OpenEnderCommand implements CommandExecutor { // History management UUID history = openEnderHistory.get(player.getUniqueId()); - if (history == null) { history = player.getUniqueId(); openEnderHistory.put(player.getUniqueId(), history); diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index 3d2cdd7..4368ac7 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -61,7 +61,6 @@ public class OpenInvCommand implements CommandExecutor { // History management UUID history = openInvHistory.get(player.getUniqueId()); - if (history == null) { history = player.getUniqueId(); openInvHistory.put(player.getUniqueId(), history); diff --git a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java index 658fa94..65fd961 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java @@ -16,7 +16,7 @@ public class SearchEnderCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (command.getName().equalsIgnoreCase("searchinv")) { + 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."); @@ -28,7 +28,7 @@ public class SearchEnderCommand implements CommandExecutor { int count = 1; if (args.length >= 1) { - String[] gData = null; + String[] gData; gData = args[0].split(":"); material = Material.matchMaterial(gData[0]); } @@ -50,14 +50,14 @@ public class SearchEnderCommand implements CommandExecutor { StringBuilder sb = new StringBuilder(); for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) { - if (onlinePlayer.getInventory().contains(material, count)) { + if (onlinePlayer.getEnderChest().contains(material, count)) { sb.append(onlinePlayer.getName()); sb.append(" "); } } String playerList = sb.toString(); - sender.sendMessage("Players with the item " + material.toString() + ": " + playerList); + sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their ender chest: " + playerList); return true; } diff --git a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java index 98d1527..babe370 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java @@ -42,7 +42,7 @@ public class SearchInvCommand implements CommandExecutor { int count = 1; if (args.length >= 1) { - String[] gData = null; + String[] gData; gData = args[0].split(":"); material = Material.matchMaterial(gData[0]); } @@ -71,7 +71,7 @@ public class SearchInvCommand implements CommandExecutor { } String playerList = sb.toString(); - sender.sendMessage("Players with the item " + material.toString() + ": " + playerList); + sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their inventory: " + playerList); return true; } diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index 213422e..6c88ad6 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.entity.*; @@ -125,7 +125,7 @@ public class AnySilentChest { if (silentChest) { tileInventory = new SilentInventory(tileInventory); if (OpenInv.notifySilentChest()) { - p.sendMessage("You are opening a chest silently."); + OpenInv.sendMessage(p, "You are opening a chest silently."); } returnValue = false; } @@ -133,7 +133,7 @@ public class AnySilentChest { player.openContainer(tileInventory); if (anyChest && OpenInv.notifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); + OpenInv.sendMessage(p, "You are opening a blocked chest."); } return returnValue; diff --git a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java index 97931f4..9d6940b 100644 --- a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java @@ -24,7 +24,7 @@ import org.bukkit.inventory.Inventory; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.inventory.*; @@ -53,7 +53,7 @@ public class InventoryAccess { return ((CraftInventory) inventory).getInventory(); } - //Use reflection to find the inventory + // Use reflection to find the inventory Class clazz = inventory.getClass(); IInventory result = null; for(Field f : clazz.getDeclaredFields()) { diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index 2bbc264..d6fa177 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -25,7 +25,7 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.mojang.authlib.GameProfile; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; import org.bukkit.craftbukkit.v1_8_R3.*; diff --git a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java index bc923e0..b9bc4be 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java +++ b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java @@ -16,7 +16,7 @@ package com.lishid.openinv.internal; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; public class SilentContainerChest extends ContainerChest { @@ -25,7 +25,7 @@ public class SilentContainerChest extends ContainerChest { public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman human) { super(i1, i2, human); inv = i2; - // close signal + // Close signal inv.closeContainer(human); } diff --git a/src/main/java/com/lishid/openinv/internal/SilentInventory.java b/src/main/java/com/lishid/openinv/internal/SilentInventory.java index dcea079..a2f50a6 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SilentInventory.java @@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; public class SilentInventory implements ITileInventory { @@ -73,12 +73,12 @@ public class SilentInventory implements ITileInventory { @Override public void startOpen(EntityHuman entityHuman) { - //Don't do anything + // Don't do anything } @Override public void closeContainer(EntityHuman entityHuman) { - //Don't do anything + // Don't do anything } @Override @@ -153,7 +153,7 @@ public class SilentInventory implements ITileInventory { @Override public Container createContainer(PlayerInventory playerInventory, EntityHuman entityHuman) { - //Don't let the chest itself create the container. + // Don't let the chest itself create the container. return new ContainerChest(playerInventory, this, entityHuman); } diff --git a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java index ed43765..91f7b94 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java @@ -22,8 +22,9 @@ import org.bukkit.inventory.InventoryHolder; import com.lishid.openinv.OpenInv; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; + import org.bukkit.craftbukkit.v1_8_R3.entity.*; import org.bukkit.craftbukkit.v1_8_R3.inventory.*; @@ -31,17 +32,17 @@ public class SpecialEnderChest extends InventorySubcontainer { private final CraftInventory inventory = new CraftInventory(this); private final InventoryEnderChest enderChest; private final CraftPlayer owner; - private boolean playerOnline = false; + private boolean playerOnline; - public SpecialEnderChest(Player p, Boolean online) { + public SpecialEnderChest(Player p, boolean online) { this(p, ((CraftPlayer) p).getHandle().getEnderChest(), online); } - public SpecialEnderChest(Player p, InventoryEnderChest enderchest, boolean online) { - super(enderchest.getName(), enderchest.hasCustomName(), enderchest.getSize()); + public SpecialEnderChest(Player p, InventoryEnderChest enderChest, boolean online) { + super(enderChest.getName(), enderChest.hasCustomName(), enderChest.getSize()); this.owner = (CraftPlayer) p; - this.enderChest = enderchest; - this.items = enderChest.getContents(); + this.enderChest = enderChest; + this.items = this.enderChest.getContents(); this.playerOnline = online; OpenInv.enderChests.put(owner.getUniqueId(), this); } diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index c9e39e3..a53110d 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -21,8 +21,9 @@ import org.bukkit.inventory.Inventory; import com.lishid.openinv.OpenInv; -//Volatile +// Volatile import net.minecraft.server.v1_8_R3.*; + import org.bukkit.craftbukkit.v1_8_R3.entity.*; import org.bukkit.craftbukkit.v1_8_R3.inventory.*; @@ -30,7 +31,7 @@ public class SpecialPlayerInventory extends PlayerInventory { private final CraftInventory inventory = new CraftInventory(this); private final ItemStack[] extra = new ItemStack[5]; private final CraftPlayer owner; - private boolean playerOnline = false; + private boolean playerOnline; public SpecialPlayerInventory(Player p, boolean online) { super(((CraftPlayer) p).getHandle()); diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java index 07f8fc9..2c479f0 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java @@ -67,7 +67,7 @@ public class OpenInvPlayerListener implements Listener { } } - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); @@ -76,70 +76,76 @@ public class OpenInvPlayerListener implements Listener { } Action action = event.getAction(); - - if (action == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) { - return; - } - Block block = event.getClickedBlock(); - if (action == Action.RIGHT_CLICK_BLOCK && block.getType() == Material.ENDER_CHEST) { - if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) { - event.setCancelled(true); - player.openInventory(player.getEnderChest()); - } - } - - if (action == Action.RIGHT_CLICK_BLOCK && 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) && OpenInv.getPlayerSilentChestStatus(player)) { - silentChest = true; - } - - if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) { - try { - anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z); + switch (action) { + case RIGHT_CLICK_BLOCK: + if (event.useInteractedBlock() == Result.DENY) { + return; } - catch (Exception e) { - player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit."); - e.printStackTrace(); + + // Ender Chests + if (block.getType() == Material.ENDER_CHEST) { + if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) { + event.setCancelled(true); + player.openInventory(player.getEnderChest()); + return; + } } - } - // If the anychest or silentchest is active - if (anyChest || silentChest) { - if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) { - event.setCancelled(true); + // 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) && OpenInv.getPlayerSilentChestStatus(player)) { + silentChest = true; + } + + if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) { + try { + anyChest = OpenInv.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 (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) { + event.setCancelled(true); + } + } + + return; } - } - } - if (action == Action.RIGHT_CLICK_BLOCK && 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); + // 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("Internal Error."); + e.printStackTrace(); + } + + return; + } + case RIGHT_CLICK_AIR: + // OpenInv item + if (player.getItemInHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { + player.performCommand("openinv"); } - } - catch (Exception ex) { - player.sendMessage("Internal Error."); - ex.printStackTrace(); - } - } - - if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { - if (!(player.getItemInHand().getType() == OpenInv.getOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player)) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { - return; - } - - player.performCommand("openinv"); } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 73a1bf2..2058558 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,32 +7,38 @@ description: > commands: openinv: aliases: [oi, inv, open] - description: Open a player's inventory + description: Open a player's inventory. usage: | - / - Open last person's inventory - / - Open a player's inventory + / - Opens last person's inventory. + / - Opens a player's inventory. openender: aliases: [oe] - description: Opens the enderchest of a player + description: Opens a player's ender chest. usage: | - / - Opens a player's enderchest + / - Opens last person's ender chest. + / - Opens a player's ender chest. searchinv: aliases: [si] - description: Search and list players having a specific item + description: Searches and lists players that have a specific item in their inventory. usage: | - / [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. + / [minAmount] - Item can be the Item ID or the CraftBukkit Item Name, minAmount is the minimum amount to be considered. + searchender: + aliases: [se] + description: Searches and lists players that have a specific item in their ender chest. + usage: | + / [minAmount] - Item can be the Item ID or the CraftBukkit Item Name, minAmount is the minimum amount to be considered. toggleopeninv: aliases: [toi, toggleoi, toggleinv] - description: Toggle item openinv function + description: Toggles the item openinv function. usage: | - / [Check] - Checks whether item openinv is enabled - silentchest: - aliases: [sc, silent] - description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound. - usage: | - / [Check] - Checks whether silent chest is enabled + / [check] - Checks whether item openinv is enabled. anychest: aliases: [ac] - description: Toggle anychest function, which allows opening of blocked chests. + description: Toggles the any chest function, which allows opening of blocked chests. usage: | - / [Check] - Checks whether anychest is enabled + / [check] - Checks whether any chest is enabled. + silentchest: + aliases: [sc, silent] + description: Toggles the silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound. + usage: | + / [check] - Checks whether silent chest is enabled. \ No newline at end of file From d1d60e55d50fea966bbebaa92339f83c0965f298 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 24 Jun 2015 19:37:09 +1000 Subject: [PATCH 10/10] More fixes and improvements - continued --- src/main/java/com/lishid/openinv/ConfigUpdater.java | 2 -- .../java/com/lishid/openinv/commands/SearchEnderCommand.java | 2 -- src/main/resources/config.yml | 1 - src/main/resources/plugin.yml | 2 +- 4 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index e94ae1b..f3fa1bb 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -65,7 +65,6 @@ public class ConfigUpdater { // Get the old config settings int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280); - // boolean checkForUpdates = config.getBoolean("CheckForUpdates", true); boolean notifySilentChest = config.getBoolean("NotifySilentChest", true); boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true); @@ -97,7 +96,6 @@ public class ConfigUpdater { config = plugin.getConfig(); // Refresh the referenced plugin config config.set("config-version", 2); - // config.set("check-for-updates", checkForUpdates); config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString()); config.set("notify.any-chest", notifyAnyChest); config.set("notify.silent-chest", notifySilentChest); diff --git a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java index 65fd961..71c4557 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java @@ -12,8 +12,6 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class SearchEnderCommand implements CommandExecutor { - // TODO - @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("searchender")) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index eb76f52..50320d5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,4 @@ config-version: 2 -check-for-updates: true notify: any-chest: true silent-chest: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2058558..163b3a0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,7 +7,7 @@ description: > commands: openinv: aliases: [oi, inv, open] - description: Open a player's inventory. + description: Opens a player's inventory. usage: | / - Opens last person's inventory. / - Opens a player's inventory.