Bug fix and changes #27
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <packaging>jar</packaging>
 | 
			
		||||
    <version>2.3.0</version>
 | 
			
		||||
    <version>2.3.1</version>
 | 
			
		||||
    <name>OpenInv</name>
 | 
			
		||||
    <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										160
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							@@ -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<UUID, Boolean> anyChestToggles = null;
 | 
			
		||||
        Map<UUID, Boolean> itemOpenInvToggles = null;
 | 
			
		||||
        Map<UUID, Boolean> 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<UUID, Boolean> entry : anyChestToggles.entrySet()) {
 | 
			
		||||
                config.set("toggles.any-chest." + entry.getKey(), entry.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) {
 | 
			
		||||
            for (Map.Entry<UUID, Boolean> entry : itemOpenInvToggles.entrySet()) {
 | 
			
		||||
                config.set("toggles.items.open-inv." + entry.getKey(), entry.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (silentChestToggles != null && !silentChestToggles.isEmpty()) {
 | 
			
		||||
            for (Map.Entry<UUID, Boolean> 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<UUID, Boolean> updateToggles(String sectionName) {
 | 
			
		||||
        Map<UUID, Boolean> toggles = new HashMap<UUID, Boolean>();
 | 
			
		||||
 | 
			
		||||
        ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
 | 
			
		||||
        Set<String> 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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
 | 
			
		||||
    public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
 | 
			
		||||
 | 
			
		||||
    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 <Player> - Open a player's inventory");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: oi, inv, open)");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/openender <Player> - 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 <Item> [MinAmount] - ");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/openender <player> - Open a player's ender chest.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: oe)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/searchinv <item> [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 <item> [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)");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
@@ -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<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -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<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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.*;
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
        // }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
 | 
			
		||||
                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);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,25 +1,69 @@
 | 
			
		||||
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.OfflinePlayer;
 | 
			
		||||
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<? extends Player> 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings("deprecation")
 | 
			
		||||
    public static UUID getUUIDOf(String name) {
 | 
			
		||||
        UUID uuid = null;
 | 
			
		||||
        Player player = getPlayer(name);
 | 
			
		||||
 | 
			
		||||
        UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
 | 
			
		||||
        Map<String, UUID> 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<String, UUID> response;
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                response = fetcher.call();
 | 
			
		||||
                uuid = response.get(name.toLowerCase());
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {
 | 
			
		||||
                /*
 | 
			
		||||
                Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                */
 | 
			
		||||
 | 
			
		||||
                // 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();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return uuid;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
config-version: 2
 | 
			
		||||
notify:
 | 
			
		||||
  any-chest: true
 | 
			
		||||
  silent-chest: true
 | 
			
		||||
items:
 | 
			
		||||
  open-inv: STICK
 | 
			
		||||
@@ -1,38 +1,44 @@
 | 
			
		||||
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.
 | 
			
		||||
commands:
 | 
			
		||||
  openinv:
 | 
			
		||||
    aliases: [oi, inv, open]
 | 
			
		||||
    description: Open a player's inventory
 | 
			
		||||
    description: Opens a player's inventory.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> - Open last person's inventory
 | 
			
		||||
           /<command> <Player> - Open a player's inventory
 | 
			
		||||
           /<command> - Opens last person's inventory.
 | 
			
		||||
           /<command> <player> - Opens a player's inventory.
 | 
			
		||||
  openender:
 | 
			
		||||
    aliases: [oe]
 | 
			
		||||
    description: Opens the enderchest of a player
 | 
			
		||||
    description: Opens a player's ender chest.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> <Player> - Opens a player's enderchest
 | 
			
		||||
           /<command> - Opens last person's ender chest.
 | 
			
		||||
           /<command> <player> - 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: |
 | 
			
		||||
           /<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
 | 
			
		||||
           /<command> <item> [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: |
 | 
			
		||||
           /<command> <item> [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: |
 | 
			
		||||
           /<command> [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: |
 | 
			
		||||
           /<command> [Check] - Checks whether silent chest is enabled
 | 
			
		||||
           /<command> [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: |
 | 
			
		||||
           /<command> [Check] - Checks whether anychest is enabled
 | 
			
		||||
           /<command> [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: |
 | 
			
		||||
           /<command> [check] - Checks whether silent chest is enabled.
 | 
			
		||||
		Reference in New Issue
	
	Block a user