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..f3fa1bb
--- /dev/null
+++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java
@@ -0,0 +1,160 @@
+package com.lishid.openinv;
+
+import java.io.File;
+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 org.bukkit.configuration.file.FileConfiguration;
+
+import com.lishid.openinv.utils.UUIDUtil;
+
+public class ConfigUpdater {
+ private final OpenInv plugin;
+
+ private static final int 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() < CONFIG_VERSION;
+ }
+
+ public void checkForUpdates() {
+ if (isConfigOutdated()) {
+ plugin.getLogger().info("[Config] Update found! Performing update...");
+ performUpdate();
+ }
+ else {
+ plugin.getLogger().info("[Config] Update not required.");
+ }
+ }
+
+ private void performUpdate() {
+ // Update according to the right version
+ switch (getConfigVersion()) {
+ case 1:
+ updateConfig1To2();
+ break;
+ }
+ }
+
+ private void updateConfig1To2() {
+ 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();
+ }
+
+ plugin.getLogger().info("[Config] Backup of old config.yml file created.");
+
+ // Get the old config settings
+ int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280);
+ boolean notifySilentChest = config.getBoolean("NotifySilentChest", true);
+ boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true);
+
+ Map anyChestToggles = null;
+ Map itemOpenInvToggles = null;
+ Map silentChestToggles = null;
+
+ if (config.isSet("AnyChest")) {
+ anyChestToggles = updateToggles("AnyChest");
+ }
+
+ if (config.isSet("ItemOpenInv")) {
+ itemOpenInvToggles = updateToggles("ItemOpenInv");
+ }
+
+ if (config.isSet("SilentChest")) {
+ silentChestToggles = updateToggles("SilentChest");
+ }
+
+ // Clear the old config
+ for (String key : config.getKeys(false)) {
+ config.set(key, null);
+ }
+
+ // Set the new config options
+ plugin.saveDefaultConfig();
+ plugin.reloadConfig();
+
+ config = plugin.getConfig(); // Refresh the referenced plugin config
+
+ config.set("config-version", 2);
+ 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()) {
+ config.set("toggles.any-chest." + entry.getKey(), entry.getValue());
+ }
+ }
+
+ if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) {
+ for (Map.Entry entry : itemOpenInvToggles.entrySet()) {
+ config.set("toggles.items.open-inv." + entry.getKey(), entry.getValue());
+ }
+ }
+
+ if (silentChestToggles != null && !silentChestToggles.isEmpty()) {
+ for (Map.Entry entry : silentChestToggles.entrySet()) {
+ config.set("toggles.silent-chest." + entry.getKey(), entry.getValue());
+ }
+ }
+
+ // Save the new config
+ plugin.saveConfig();
+ plugin.getLogger().info("[Config] Update complete.");
+ }
+
+ private Map updateToggles(String sectionName) {
+ Map toggles = new HashMap();
+
+ ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
+ Set keys = section.getKeys(false);
+ if (keys == null || keys.isEmpty()) {
+ 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);
+ converted++;
+ }
+ }
+
+ plugin.getLogger().info("[Config] Converted (" + converted + "/" + total + ") " + sectionName + " toggle player usernames to UUIDs.");
+
+ 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..71773f1 100644
--- a/src/main/java/com/lishid/openinv/OpenInv.java
+++ b/src/main/java/com/lishid/openinv/OpenInv.java
@@ -19,16 +19,22 @@ 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.SearchEnderCommand;
+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,97 +50,71 @@ 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 Updater
+ 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("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 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 AnySilentChest getAnySilentChest() {
+ return anySilentChest;
}
- 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 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 {
@@ -142,39 +122,93 @@ public class OpenInv extends JavaPlugin {
}
}
- 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();
}
- /**
- * 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");
+ Material material = Material.getMaterial(itemName);
+ if (material == null) {
+ mainPlugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick.");
+ material = Material.STICK;
+ }
+
+ return material;
+ }
+
+ 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);
+ }
+
+ public static void log(String text) {
+ mainPlugin.getLogger().info("[OpenInv] " + text);
}
- /**
- * Log an error
- */
public static void log(Throwable e) {
- logger.severe("[OpenInv] " + e.toString());
+ mainPlugin.getLogger().severe("[OpenInv] " + e.toString());
e.printStackTrace();
}
+ 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 enderchest");
- 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/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..f39fce8 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;
}
@@ -62,7 +62,6 @@ public class OpenEnderPluginCommand implements CommandExecutor {
// History management
UUID history = openEnderHistory.get(player.getUniqueId());
-
if (history == null) {
history = player.getUniqueId();
openEnderHistory.put(player.getUniqueId(), history);
@@ -82,6 +81,10 @@ 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 +96,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 +133,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..4368ac7 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)) {
@@ -61,7 +61,6 @@ public class OpenInvPluginCommand implements CommandExecutor {
// History management
UUID history = openInvHistory.get(player.getUniqueId());
-
if (history == null) {
history = player.getUniqueId();
openInvHistory.put(player.getUniqueId(), history);
@@ -75,6 +74,10 @@ 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 +89,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..71c4557
--- /dev/null
+++ b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java
@@ -0,0 +1,65 @@
+package com.lishid.openinv.commands;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import com.lishid.openinv.OpenInv;
+import com.lishid.openinv.Permissions;
+
+public class SearchEnderCommand implements CommandExecutor {
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (command.getName().equalsIgnoreCase("searchender")) {
+ if (sender instanceof Player) {
+ if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
+ sender.sendMessage(ChatColor.RED + "You do not have permission to search player ender chests.");
+ return true;
+ }
+ }
+
+ Material material = null;
+ int count = 1;
+
+ if (args.length >= 1) {
+ String[] gData;
+ gData = args[0].split(":");
+ material = Material.matchMaterial(gData[0]);
+ }
+ if (args.length >= 2) {
+ try {
+ count = Integer.parseInt(args[1]);
+ }
+ catch (NumberFormatException 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.getEnderChest().contains(material, count)) {
+ sb.append(onlinePlayer.getName());
+ sb.append(" ");
+ }
+ }
+
+ String playerList = sb.toString();
+ sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their ender chest: " + playerList);
+
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java
similarity index 77%
rename from src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java
rename to src/main/java/com/lishid/openinv/commands/SearchInvCommand.java
index 968e1ab..babe370 100644
--- a/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java
+++ b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java
@@ -27,24 +27,22 @@ 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;
if (args.length >= 1) {
- String[] gData = null;
+ String[] gData;
gData = args[0].split(":");
material = Material.matchMaterial(gData[0]);
}
@@ -63,13 +61,17 @@ 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(" ");
}
}
- sender.sendMessage("Players with the item " + material.toString() + ": " + playerList);
+ String playerList = sb.toString();
+ 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/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..6c88ad6 100644
--- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java
+++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java
@@ -22,13 +22,13 @@ 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.*;
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,18 +122,18 @@ 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.");
+ OpenInv.sendMessage(p, "You are opening a chest silently.");
}
returnValue = false;
}
player.openContainer(tileInventory);
- if (anychest && OpenInv.notifyAnyChest()) {
- p.sendMessage("You are opening a blocked chest.");
+ if (anyChest && OpenInv.notifyAnyChest()) {
+ 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 extends Inventory> 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 f167e28..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());
@@ -180,7 +181,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 +200,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..2c479f0 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) {
@@ -66,74 +67,85 @@ public class OpenInvPlayerListener implements Listener {
}
}
- @EventHandler(priority = EventPriority.MONITOR)
+ @EventHandler
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) {
- return;
- }
+ Action action = event.getAction();
+ Block block = event.getClickedBlock();
- 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())) {
- 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 (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) {
- silentchest = true;
- }
-
- if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player.getName())) {
- try {
- anychest = OpenInv.anySilentChest.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.anySilentChest.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 (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign) {
- try {
- Sign sign = ((Sign) event.getClickedBlock().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 (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)) {
- return;
- }
-
- player.performCommand("openinv");
}
}
-}
\ No newline at end of file
+}
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