Bug fix and changes #27
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -4,7 +4,7 @@
 | 
				
			|||||||
    <groupId>com.lishid</groupId>
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
    <artifactId>openinv</artifactId>
 | 
					    <artifactId>openinv</artifactId>
 | 
				
			||||||
    <packaging>jar</packaging>
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
    <version>2.3.0</version>
 | 
					    <version>2.3.1</version>
 | 
				
			||||||
    <name>OpenInv</name>
 | 
					    <name>OpenInv</name>
 | 
				
			||||||
    <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
					    <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										161
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										161
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,161 @@
 | 
				
			|||||||
 | 
					package com.lishid.openinv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Material;
 | 
				
			||||||
 | 
					import org.bukkit.configuration.ConfigurationSection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.utils.UUIDUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class ConfigUpdater {
 | 
				
			||||||
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final int LATEST_CONFIG_VERSION = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ConfigUpdater(OpenInv plugin) {
 | 
				
			||||||
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int getConfigVersion() {
 | 
				
			||||||
 | 
					        return plugin.getConfig().getInt("config-version", 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean isConfigOutdated() {
 | 
				
			||||||
 | 
					        return getConfigVersion() < LATEST_CONFIG_VERSION;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void checkForUpdates() {
 | 
				
			||||||
 | 
					        if (isConfigOutdated()) {
 | 
				
			||||||
 | 
					            plugin.getLogger().info("[Config] Update found! Performing update...");
 | 
				
			||||||
 | 
					            updateConfig();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            plugin.getLogger().info("[Config] Update not found. Config is already up-to-date.");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private void updateConfig() {
 | 
				
			||||||
 | 
					        // Get the old config settings
 | 
				
			||||||
 | 
					        int itemOpenInvItemId = plugin.getConfig().getInt("ItemOpenInvItemID", 280);
 | 
				
			||||||
 | 
					        boolean checkForUpdates = plugin.getConfig().getBoolean("CheckForUpdates", true);
 | 
				
			||||||
 | 
					        boolean notifySilentChest = plugin.getConfig().getBoolean("NotifySilentChest", true);
 | 
				
			||||||
 | 
					        boolean notifyAnyChest = plugin.getConfig().getBoolean("NotifyAnyChest", true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> anyChestToggles = null;
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> itemOpenInvToggles = null;
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> silentChestToggles = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (plugin.getConfig().isSet("AnyChest")) {
 | 
				
			||||||
 | 
					            anyChestToggles = updateAnyChestToggles();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (plugin.getConfig().isSet("ItemOpenInv")) {
 | 
				
			||||||
 | 
					            itemOpenInvToggles = updateItemOpenInvToggles();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (plugin.getConfig().isSet("SilentChest")) {
 | 
				
			||||||
 | 
					            silentChestToggles = updateSilentChestToggles();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Clear the old config
 | 
				
			||||||
 | 
					        for (String key : plugin.getConfig().getKeys(false)) {
 | 
				
			||||||
 | 
					            plugin.getConfig().set(key, null);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Set the new config options
 | 
				
			||||||
 | 
					        plugin.getConfig().set("config-version", LATEST_CONFIG_VERSION);
 | 
				
			||||||
 | 
					        plugin.getConfig().set("check-for-updates", checkForUpdates);
 | 
				
			||||||
 | 
					        plugin.getConfig().set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
 | 
				
			||||||
 | 
					        plugin.getConfig().set("notify.any-chest", notifyAnyChest);
 | 
				
			||||||
 | 
					        plugin.getConfig().set("notify.silent-chest", notifySilentChest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (anyChestToggles != null && !anyChestToggles.isEmpty()) {
 | 
				
			||||||
 | 
					            for (Map.Entry<UUID, Boolean> entry : anyChestToggles.entrySet()) {
 | 
				
			||||||
 | 
					                plugin.getConfig().set("toggles.any-chest." + entry.getKey(), entry.getValue());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) {
 | 
				
			||||||
 | 
					            for (Map.Entry<UUID, Boolean> entry : itemOpenInvToggles.entrySet()) {
 | 
				
			||||||
 | 
					                plugin.getConfig().set("toggles.items.open-inv." + entry.getKey(), entry.getValue());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (silentChestToggles != null && !silentChestToggles.isEmpty()) {
 | 
				
			||||||
 | 
					            for (Map.Entry<UUID, Boolean> entry : silentChestToggles.entrySet()) {
 | 
				
			||||||
 | 
					                plugin.getConfig().set("toggles.silent-chest." + entry.getKey(), entry.getValue());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Save the new config
 | 
				
			||||||
 | 
					        plugin.saveConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        plugin.getLogger().info("[Config] Update complete.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Map<UUID, Boolean> updateAnyChestToggles() {
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> toggles = new HashMap<UUID, Boolean>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("AnyChest");
 | 
				
			||||||
 | 
					        Set<String> keys = anyChestSection.getKeys(false);
 | 
				
			||||||
 | 
					        if (keys == null || keys.isEmpty()) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (String playerName : keys) {
 | 
				
			||||||
 | 
					            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
				
			||||||
 | 
					            if (uuid != null) {
 | 
				
			||||||
 | 
					                boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false);
 | 
				
			||||||
 | 
					                toggles.put(uuid, toggled);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return toggles;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Map<UUID, Boolean> updateItemOpenInvToggles() {
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> toggles = new HashMap<UUID, Boolean>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ConfigurationSection anyChestSection = plugin.getConfig().getConfigurationSection("ItemOpenInv");
 | 
				
			||||||
 | 
					        Set<String> keys = anyChestSection.getKeys(false);
 | 
				
			||||||
 | 
					        if (keys == null || keys.isEmpty()) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (String playerName : keys) {
 | 
				
			||||||
 | 
					            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
				
			||||||
 | 
					            if (uuid != null) {
 | 
				
			||||||
 | 
					                boolean toggled = anyChestSection.getBoolean(playerName + ".toggle", false);
 | 
				
			||||||
 | 
					                toggles.put(uuid, toggled);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return toggles;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Map<UUID, Boolean> updateSilentChestToggles() {
 | 
				
			||||||
 | 
					        Map<UUID, Boolean> toggles = new HashMap<UUID, Boolean>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ConfigurationSection silentChestSection = plugin.getConfig().getConfigurationSection("SilentChest");
 | 
				
			||||||
 | 
					        Set<String> keys = silentChestSection.getKeys(false);
 | 
				
			||||||
 | 
					        if (keys == null || keys.isEmpty()) return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (String playerName : keys) {
 | 
				
			||||||
 | 
					            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
				
			||||||
 | 
					            if (uuid != null) {
 | 
				
			||||||
 | 
					                boolean toggled = silentChestSection.getBoolean(playerName + ".toggle", false);
 | 
				
			||||||
 | 
					                toggles.put(uuid, toggled);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return toggles;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @SuppressWarnings("deprecation")
 | 
				
			||||||
 | 
					    private Material getMaterialById(int id) {
 | 
				
			||||||
 | 
					        Material material = Material.getMaterial(id);
 | 
				
			||||||
 | 
					        if (material == null) {
 | 
				
			||||||
 | 
					            material = Material.STICK;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return material;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -19,16 +19,21 @@ package com.lishid.openinv;
 | 
				
			|||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.logging.Logger;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					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.entity.Player;
 | 
				
			||||||
import org.bukkit.permissions.Permissible;
 | 
					import org.bukkit.permissions.Permissible;
 | 
				
			||||||
import org.bukkit.plugin.PluginManager;
 | 
					import org.bukkit.plugin.PluginManager;
 | 
				
			||||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
					import org.bukkit.plugin.java.JavaPlugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.commands.*;
 | 
					import com.lishid.openinv.commands.AnyChestCommand;
 | 
				
			||||||
 | 
					import com.lishid.openinv.commands.OpenEnderCommand;
 | 
				
			||||||
 | 
					import com.lishid.openinv.commands.OpenInvCommand;
 | 
				
			||||||
 | 
					import com.lishid.openinv.commands.SearchInvCommand;
 | 
				
			||||||
 | 
					import com.lishid.openinv.commands.SilentChestCommand;
 | 
				
			||||||
 | 
					import com.lishid.openinv.commands.ToggleOpenInvCommand;
 | 
				
			||||||
import com.lishid.openinv.internal.AnySilentChest;
 | 
					import com.lishid.openinv.internal.AnySilentChest;
 | 
				
			||||||
import com.lishid.openinv.internal.InventoryAccess;
 | 
					import com.lishid.openinv.internal.InventoryAccess;
 | 
				
			||||||
import com.lishid.openinv.internal.PlayerDataManager;
 | 
					import com.lishid.openinv.internal.PlayerDataManager;
 | 
				
			||||||
@@ -44,93 +49,67 @@ import com.lishid.openinv.listeners.OpenInvPlayerListener;
 | 
				
			|||||||
 * @author lishid
 | 
					 * @author lishid
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class OpenInv extends JavaPlugin {
 | 
					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, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
 | 
				
			||||||
    public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
 | 
					    public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static OpenInv mainPlugin;
 | 
					    public static OpenInv mainPlugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static PlayerDataManager playerLoader;
 | 
					    private static PlayerDataManager playerLoader;
 | 
				
			||||||
    public static InventoryAccess inventoryAccess;
 | 
					    private static InventoryAccess inventoryAccess;
 | 
				
			||||||
    public static AnySilentChest anySilentChest;
 | 
					    private static AnySilentChest anySilentChest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onEnable() {
 | 
					    public void onEnable() {
 | 
				
			||||||
        // Get plugin manager
 | 
					        // Plugin
 | 
				
			||||||
        PluginManager pm = getServer().getPluginManager();
 | 
					        mainPlugin = this;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Config
 | 
				
			||||||
 | 
					        ConfigUpdater configUpdater = new ConfigUpdater(this);
 | 
				
			||||||
 | 
					        configUpdater.checkForUpdates();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Initialize
 | 
				
			||||||
        playerLoader = new PlayerDataManager();
 | 
					        playerLoader = new PlayerDataManager();
 | 
				
			||||||
        inventoryAccess = new InventoryAccess();
 | 
					        inventoryAccess = new InventoryAccess();
 | 
				
			||||||
        anySilentChest = new AnySilentChest();
 | 
					        anySilentChest = new AnySilentChest();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mainPlugin = this;
 | 
					        // Save the default config.yml if it doesn't already exist
 | 
				
			||||||
        FileConfiguration config = getConfig();
 | 
					        saveDefaultConfig();
 | 
				
			||||||
        config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
 | 
					
 | 
				
			||||||
        config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
 | 
					        // Register the plugin's events & commands
 | 
				
			||||||
        config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
 | 
					        registerEvents();
 | 
				
			||||||
        config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
 | 
					        registerCommands();
 | 
				
			||||||
        config.addDefault("ItemOpenInvItemID", 280);
 | 
					    }
 | 
				
			||||||
        config.addDefault("CheckForUpdates", true);
 | 
					
 | 
				
			||||||
        config.addDefault("NotifySilentChest", true);
 | 
					    private void registerEvents() {
 | 
				
			||||||
        config.addDefault("NotifyAnyChest", true);
 | 
					        PluginManager pm = getServer().getPluginManager();
 | 
				
			||||||
        config.options().copyDefaults(true);
 | 
					 | 
				
			||||||
        saveConfig();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pm.registerEvents(new OpenInvPlayerListener(), this);
 | 
					        pm.registerEvents(new OpenInvPlayerListener(), this);
 | 
				
			||||||
        pm.registerEvents(new OpenInvEntityListener(), this);
 | 
					        pm.registerEvents(new OpenInvEntityListener(), this);
 | 
				
			||||||
        pm.registerEvents(new OpenInvInventoryListener(), 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() {
 | 
					    private void registerCommands() {
 | 
				
			||||||
        return mainPlugin.getConfig().getBoolean("NotifySilentChest", true);
 | 
					        getCommand("openinv").setExecutor(new OpenInvCommand(this));
 | 
				
			||||||
 | 
					        getCommand("searchinv").setExecutor(new SearchInvCommand());
 | 
				
			||||||
 | 
					        getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
 | 
				
			||||||
 | 
					        getCommand("silentchest").setExecutor(new SilentChestCommand());
 | 
				
			||||||
 | 
					        getCommand("anychest").setExecutor(new AnyChestCommand());
 | 
				
			||||||
 | 
					        getCommand("openender").setExecutor(new OpenEnderCommand(this));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static boolean notifyAnyChest() {
 | 
					    public static PlayerDataManager getPlayerLoader() {
 | 
				
			||||||
        return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true);
 | 
					        return playerLoader;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static boolean getPlayerItemOpenInvStatus(String name) {
 | 
					    public static InventoryAccess getInventoryAccess() {
 | 
				
			||||||
        return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false);
 | 
					        return inventoryAccess;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void setPlayerItemOpenInvStatus(String name, boolean status) {
 | 
					    public static AnySilentChest getAnySilentChest() {
 | 
				
			||||||
        mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status);
 | 
					        return anySilentChest;
 | 
				
			||||||
        mainPlugin.saveConfig();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static boolean getPlayerSilentChestStatus(String name) {
 | 
					 | 
				
			||||||
        return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static void setPlayerSilentChestStatus(String name, boolean status) {
 | 
					 | 
				
			||||||
        mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status);
 | 
					 | 
				
			||||||
        mainPlugin.saveConfig();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static boolean getPlayerAnyChestStatus(String name) {
 | 
					 | 
				
			||||||
        return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static void setPlayerAnyChestStatus(String name, boolean status) {
 | 
					 | 
				
			||||||
        mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status);
 | 
					 | 
				
			||||||
        mainPlugin.saveConfig();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static int getItemOpenInvItem() {
 | 
					 | 
				
			||||||
        if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) {
 | 
					 | 
				
			||||||
            saveToConfig("ItemOpenInvItemID", 280);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
    public static Object getFromConfig(String data, Object defaultValue) {
 | 
					    public static Object getFromConfig(String data, Object defaultValue) {
 | 
				
			||||||
        Object val = mainPlugin.getConfig().get(data);
 | 
					        Object val = mainPlugin.getConfig().get(data);
 | 
				
			||||||
        if (val == null) {
 | 
					        if (val == null) {
 | 
				
			||||||
@@ -141,27 +120,83 @@ public class OpenInv extends JavaPlugin {
 | 
				
			|||||||
            return val;
 | 
					            return val;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void saveToConfig(String data, Object value) {
 | 
					    public static void saveToConfig(String data, Object value) {
 | 
				
			||||||
        mainPlugin.getConfig().set(data, value);
 | 
					        mainPlugin.getConfig().set(data, value);
 | 
				
			||||||
        mainPlugin.saveConfig();
 | 
					        mainPlugin.saveConfig();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    public static Material getOpenInvItem() {
 | 
				
			||||||
     * Log an information
 | 
					        if (!mainPlugin.getConfig().isSet("items.open-inv")) {
 | 
				
			||||||
     */
 | 
					            saveToConfig("items.open-inv", "STICK");
 | 
				
			||||||
    public static void log(String text) {
 | 
					        }
 | 
				
			||||||
        logger.info("[OpenInv] " + text);
 | 
					
 | 
				
			||||||
 | 
					        String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK");
 | 
				
			||||||
 | 
					        return Material.getMaterial(itemName);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean notifySilentChest() {
 | 
				
			||||||
 | 
					        return mainPlugin.getConfig().getBoolean("notify.silent-chest", true);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean notifyAnyChest() {
 | 
				
			||||||
 | 
					        return mainPlugin.getConfig().getBoolean("notify.any-chest", true);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean getPlayerAnyChestStatus(Player player) {
 | 
				
			||||||
 | 
					        return mainPlugin.getConfig().getBoolean("toggles.any-chest." + player.getUniqueId(), false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void setPlayerAnyChestStatus(Player player, boolean status) {
 | 
				
			||||||
 | 
					        saveToConfig("toggles.any-chest." + player.getUniqueId(), status);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean getPlayerItemOpenInvStatus(Player player) {
 | 
				
			||||||
 | 
					        return mainPlugin.getConfig().getBoolean("toggles.items.open-inv" + player.getUniqueId(), false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void setPlayerItemOpenInvStatus(Player player, boolean status) {
 | 
				
			||||||
 | 
					        saveToConfig("toggles.items.open-inv." + player.getUniqueId(), status);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static boolean getPlayerSilentChestStatus(Player player) {
 | 
				
			||||||
 | 
					        return mainPlugin.getConfig().getBoolean("toggles.silent-chest." + player.getUniqueId(), false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void setPlayerSilentChestStatus(Player player, boolean status) {
 | 
				
			||||||
 | 
					        saveToConfig("toggles.silent-chest." + player.getUniqueId(), status);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Log an error
 | 
					     * Logs a given message to console.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param text the text to log
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void log(String text) {
 | 
				
			||||||
 | 
					        mainPlugin.getLogger().info("[OpenInv] " + text);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Logs an error to console.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param e the throwable error to log
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static void log(Throwable e) {
 | 
					    public static void log(Throwable e) {
 | 
				
			||||||
        logger.severe("[OpenInv] " + e.toString());
 | 
					        mainPlugin.getLogger().severe("[OpenInv] " + e.toString());
 | 
				
			||||||
        e.printStackTrace();
 | 
					        e.printStackTrace();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Sends a specified message to a given CommandSender with the OpenInv prefix.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param sender the CommandSender to message
 | 
				
			||||||
 | 
					     * @param message the message to send to the player
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void sendMessage(CommandSender sender, String message) {
 | 
				
			||||||
 | 
					        sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void showHelp(Player player) {
 | 
					    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 + "   (aliases: oi, inv, open)");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,30 +25,34 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AnyChestPluginCommand implements CommandExecutor {
 | 
					public class AnyChestCommand implements CommandExecutor {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("anychest")) {
 | 
					        if (command.getName().equalsIgnoreCase("anychest")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (args.length > 0) {
 | 
					            if (args.length > 0) {
 | 
				
			||||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
					                if (args[0].equalsIgnoreCase("check")) {
 | 
				
			||||||
                    if (OpenInv.getPlayerAnyChestStatus(sender.getName()))
 | 
					                    String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
                        sender.sendMessage("AnyChest is ON.");
 | 
					                    OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + ".");
 | 
				
			||||||
                    else
 | 
					                    return true;
 | 
				
			||||||
                        sender.sendMessage("AnyChest is OFF.");
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            OpenInv.setPlayerAnyChestStatus(sender.getName(), !OpenInv.getPlayerAnyChestStatus(sender.getName()));
 | 
					            OpenInv.setPlayerAnyChestStatus(player, !OpenInv.getPlayerAnyChestStatus(player));
 | 
				
			||||||
            sender.sendMessage("AnyChest is now " + (OpenInv.getPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
 | 
					
 | 
				
			||||||
 | 
					            String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
 | 
					            OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + ".");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -32,11 +32,11 @@ import com.lishid.openinv.Permissions;
 | 
				
			|||||||
import com.lishid.openinv.internal.SpecialEnderChest;
 | 
					import com.lishid.openinv.internal.SpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.utils.UUIDUtil;
 | 
					import com.lishid.openinv.utils.UUIDUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenEnderPluginCommand implements CommandExecutor {
 | 
					public class OpenEnderCommand implements CommandExecutor {
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
    private final Map<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
					    private final Map<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public OpenEnderPluginCommand(OpenInv plugin) {
 | 
					    public OpenEnderCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -44,7 +44,7 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("openender")) {
 | 
					        if (command.getName().equalsIgnoreCase("openender")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -82,6 +82,11 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
					                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (uuid == null) {
 | 
				
			||||||
 | 
					                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final UUID playerUUID = player.getUniqueId();
 | 
					            final UUID playerUUID = player.getUniqueId();
 | 
				
			||||||
@@ -93,11 +98,12 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
                    public void run() {
 | 
					                    public void run() {
 | 
				
			||||||
                        // Try loading the player's data asynchronously
 | 
					                        // Try loading the player's data asynchronously
 | 
				
			||||||
                        final Player target = OpenInv.playerLoader.loadPlayer(uuid);
 | 
					                        final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
 | 
				
			||||||
                        if (target == null) {
 | 
					                        if (target == null) {
 | 
				
			||||||
                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
					                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // Open target's inventory synchronously
 | 
					                        // Open target's inventory synchronously
 | 
				
			||||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
					                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
				
			||||||
                            @Override
 | 
					                            @Override
 | 
				
			||||||
@@ -129,7 +135,7 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
 | 
					        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;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,11 +32,11 @@ import com.lishid.openinv.Permissions;
 | 
				
			|||||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
				
			||||||
import com.lishid.openinv.utils.UUIDUtil;
 | 
					import com.lishid.openinv.utils.UUIDUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenInvPluginCommand implements CommandExecutor {
 | 
					public class OpenInvCommand implements CommandExecutor {
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
    private final Map<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
					    private final Map<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public OpenInvPluginCommand(OpenInv plugin) {
 | 
					    public OpenInvCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -44,7 +44,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("openinv")) {
 | 
					        if (command.getName().equalsIgnoreCase("openinv")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
 | 
					            if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
 | 
				
			||||||
@@ -75,6 +75,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
					                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (uuid == null) {
 | 
				
			||||||
 | 
					                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final UUID playerUUID = player.getUniqueId();
 | 
					            final UUID playerUUID = player.getUniqueId();
 | 
				
			||||||
@@ -86,11 +91,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
                    public void run() {
 | 
					                    public void run() {
 | 
				
			||||||
                        // Try loading the player's data asynchronously
 | 
					                        // Try loading the player's data asynchronously
 | 
				
			||||||
                        final Player target = OpenInv.playerLoader.loadPlayer(uuid);
 | 
					                        final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
 | 
				
			||||||
                        if (target == null) {
 | 
					                        if (target == null) {
 | 
				
			||||||
                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
					                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
                            return;
 | 
					                            return;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        // Open target's inventory synchronously
 | 
					                        // Open target's inventory synchronously
 | 
				
			||||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
					                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
				
			||||||
                            @Override
 | 
					                            @Override
 | 
				
			||||||
@@ -0,0 +1,67 @@
 | 
				
			|||||||
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					import org.bukkit.Material;
 | 
				
			||||||
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SearchEnderCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					    // TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("searchinv")) {
 | 
				
			||||||
 | 
					            if (sender instanceof Player) {
 | 
				
			||||||
 | 
					                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
				
			||||||
 | 
					                    sender.sendMessage(ChatColor.RED + "You do not have permission to search player ender chests.");
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Material material = null;
 | 
				
			||||||
 | 
					            int count = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (args.length >= 1) {
 | 
				
			||||||
 | 
					                String[] gData = null;
 | 
				
			||||||
 | 
					                gData = args[0].split(":");
 | 
				
			||||||
 | 
					                material = Material.matchMaterial(gData[0]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (args.length >= 2) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    count = Integer.parseInt(args[1]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                catch (NumberFormatException ex) {
 | 
				
			||||||
 | 
					                    sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (material == null) {
 | 
				
			||||||
 | 
					                sender.sendMessage(ChatColor.RED + "Unknown item");
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            StringBuilder sb = new StringBuilder();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
				
			||||||
 | 
					                if (onlinePlayer.getInventory().contains(material, count)) {
 | 
				
			||||||
 | 
					                    sb.append(onlinePlayer.getName());
 | 
				
			||||||
 | 
					                    sb.append("  ");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            String playerList = sb.toString();
 | 
				
			||||||
 | 
					            sender.sendMessage("Players with the item " + material.toString() + ":  " + playerList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -27,19 +27,17 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SearchInvPluginCommand implements CommandExecutor {
 | 
					public class SearchInvCommand implements CommandExecutor {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("searchinv")) {
 | 
					        if (command.getName().equalsIgnoreCase("searchinv")) {
 | 
				
			||||||
            if (sender instanceof Player) {
 | 
					            if (sender instanceof Player) {
 | 
				
			||||||
                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
					                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;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            String playerList = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Material material = null;
 | 
					            Material material = null;
 | 
				
			||||||
            int count = 1;
 | 
					            int count = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -63,12 +61,16 @@ public class SearchInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
					            StringBuilder sb = new StringBuilder();
 | 
				
			||||||
                if (templayer.getInventory().contains(material, count)) {
 | 
					
 | 
				
			||||||
                    playerList += templayer.getName() + "  ";
 | 
					            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
				
			||||||
 | 
					                if (onlinePlayer.getInventory().contains(material, count)) {
 | 
				
			||||||
 | 
					                    sb.append(onlinePlayer.getName());
 | 
				
			||||||
 | 
					                    sb.append("  ");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            String playerList = sb.toString();
 | 
				
			||||||
            sender.sendMessage("Players with the item " + material.toString() + ":  " + playerList);
 | 
					            sender.sendMessage("Players with the item " + material.toString() + ":  " + playerList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
@@ -25,30 +25,34 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SilentChestPluginCommand implements CommandExecutor {
 | 
					public class SilentChestCommand implements CommandExecutor {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("silentchest")) {
 | 
					        if (command.getName().equalsIgnoreCase("silentchest")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
 | 
					            if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
 | 
					                sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (args.length > 0) {
 | 
					            if (args.length > 0) {
 | 
				
			||||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
					                if (args[0].equalsIgnoreCase("check")) {
 | 
				
			||||||
                    if (OpenInv.getPlayerSilentChestStatus(sender.getName()))
 | 
					                    String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
                        sender.sendMessage("SilentChest is ON.");
 | 
					                    OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
 | 
				
			||||||
                    else
 | 
					                    return true;
 | 
				
			||||||
                        sender.sendMessage("SilentChest is OFF.");
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            OpenInv.setPlayerSilentChestStatus(sender.getName(), !OpenInv.getPlayerSilentChestStatus(sender.getName()));
 | 
					            OpenInv.setPlayerSilentChestStatus(player, !OpenInv.getPlayerSilentChestStatus(player));
 | 
				
			||||||
            sender.sendMessage("SilentChest is now " + (OpenInv.getPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + ".");
 | 
					
 | 
				
			||||||
 | 
					            String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
 | 
					            OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -17,7 +17,6 @@
 | 
				
			|||||||
package com.lishid.openinv.commands;
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					 | 
				
			||||||
import org.bukkit.command.Command;
 | 
					import org.bukkit.command.Command;
 | 
				
			||||||
import org.bukkit.command.CommandExecutor;
 | 
					import org.bukkit.command.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
@@ -26,37 +25,35 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SuppressWarnings("deprecation")
 | 
					public class ToggleOpenInvCommand implements CommandExecutor {
 | 
				
			||||||
public class ToggleOpenInvPluginCommand implements CommandExecutor {
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
        if (command.getName().equalsIgnoreCase("toggleopeninv")) {
 | 
					        if (command.getName().equalsIgnoreCase("toggleopeninv")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
 | 
					            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;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Player player = (Player) sender;
 | 
					            Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (args.length > 0) {
 | 
					            if (args.length > 0) {
 | 
				
			||||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
					                if (args[0].equalsIgnoreCase("check")) {
 | 
				
			||||||
                    if (OpenInv.getPlayerItemOpenInvStatus(player.getName()))
 | 
					                    String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
                        player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON.");
 | 
					                    OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
 | 
				
			||||||
                    else
 | 
					                    return true;
 | 
				
			||||||
                        player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF.");
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (OpenInv.getPlayerItemOpenInvStatus(player.getName())) {
 | 
					
 | 
				
			||||||
                OpenInv.setPlayerItemOpenInvStatus(player.getName(), false);
 | 
					            OpenInv.setPlayerItemOpenInvStatus(player, !OpenInv.getPlayerItemOpenInvStatus(player));
 | 
				
			||||||
                player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF.");
 | 
					
 | 
				
			||||||
            }
 | 
					            String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
				
			||||||
            else {
 | 
					            OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
 | 
				
			||||||
                OpenInv.setPlayerItemOpenInvStatus(player.getName(), true);
 | 
					
 | 
				
			||||||
                player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON.");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -28,7 +28,7 @@ import net.minecraft.server.v1_8_R3.*;
 | 
				
			|||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AnySilentChest {
 | 
					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
 | 
					        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
				
			||||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
					        BlockPosition position = new BlockPosition(x, y, z);
 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
				
			||||||
@@ -81,7 +81,7 @@ public class AnySilentChest {
 | 
				
			|||||||
        return true;
 | 
					        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);
 | 
					        BlockPosition position = new BlockPosition(x, y, z);
 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
				
			||||||
        World world = player.world;
 | 
					        World world = player.world;
 | 
				
			||||||
@@ -98,7 +98,7 @@ public class AnySilentChest {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ITileInventory tileInventory = (ITileInventory) tileEntity;
 | 
					        ITileInventory tileInventory = (ITileInventory) tileEntity;
 | 
				
			||||||
        if (!anychest && this.topBlocking(world, position)) {
 | 
					        if (!anyChest && this.topBlocking(world, position)) {
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -106,7 +106,7 @@ public class AnySilentChest {
 | 
				
			|||||||
            BlockPosition side = position.shift(direction);
 | 
					            BlockPosition side = position.shift(direction);
 | 
				
			||||||
            Block block = world.getType(side).getBlock();
 | 
					            Block block = world.getType(side).getBlock();
 | 
				
			||||||
            if (block == chest) {
 | 
					            if (block == chest) {
 | 
				
			||||||
                if (!anychest && this.topBlocking(world, side)) {
 | 
					                if (!anyChest && this.topBlocking(world, side)) {
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -122,7 +122,7 @@ public class AnySilentChest {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        boolean returnValue = true;
 | 
					        boolean returnValue = true;
 | 
				
			||||||
        if (silentchest) {
 | 
					        if (silentChest) {
 | 
				
			||||||
            tileInventory = new SilentInventory(tileInventory);
 | 
					            tileInventory = new SilentInventory(tileInventory);
 | 
				
			||||||
            if (OpenInv.notifySilentChest()) {
 | 
					            if (OpenInv.notifySilentChest()) {
 | 
				
			||||||
                p.sendMessage("You are opening a chest silently.");
 | 
					                p.sendMessage("You are opening a chest silently.");
 | 
				
			||||||
@@ -132,7 +132,7 @@ public class AnySilentChest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        player.openContainer(tileInventory);
 | 
					        player.openContainer(tileInventory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (anychest && OpenInv.notifyAnyChest()) {
 | 
					        if (anyChest && OpenInv.notifyAnyChest()) {
 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					            p.sendMessage("You are opening a blocked chest.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -180,7 +180,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					    public void setItem(int i, ItemStack itemStack) {
 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					        ItemStack[] is = this.items;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (i >= is.length) {
 | 
					        if (i >= is.length) {
 | 
				
			||||||
@@ -199,11 +199,11 @@ public class SpecialPlayerInventory extends PlayerInventory {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Effects
 | 
					        // Effects
 | 
				
			||||||
        if (is == this.extra) {
 | 
					        if (is == this.extra) {
 | 
				
			||||||
            owner.getHandle().drop(itemstack, true);
 | 
					            owner.getHandle().drop(itemStack, true);
 | 
				
			||||||
            itemstack = null;
 | 
					            itemStack = null;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        is[i] = itemstack;
 | 
					        is[i] = itemStack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					        owner.getHandle().defaultContainer.b();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,21 +19,18 @@ package com.lishid.openinv.listeners;
 | 
				
			|||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
					import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageEvent;
 | 
					 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
import org.bukkit.event.EventPriority;
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
import org.bukkit.event.Listener;
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SuppressWarnings("deprecation")
 | 
					 | 
				
			||||||
public class OpenInvEntityListener implements Listener {
 | 
					public class OpenInvEntityListener implements Listener {
 | 
				
			||||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
					    @EventHandler(priority = EventPriority.LOWEST)
 | 
				
			||||||
    public void onEntityDamage(EntityDamageEvent event) {
 | 
					    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
 | 
				
			||||||
        if (event instanceof EntityDamageByEntityEvent) {
 | 
					        Entity attacker = event.getDamager();
 | 
				
			||||||
            EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event;
 | 
					        Entity defender = event.getEntity();
 | 
				
			||||||
            Entity attacker = evt.getDamager();
 | 
					 | 
				
			||||||
            Entity defender = evt.getEntity();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!(attacker instanceof Player) || !(defender instanceof Player)) {
 | 
					        if (!(attacker instanceof Player) || !(defender instanceof Player)) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@@ -41,15 +38,17 @@ public class OpenInvEntityListener implements Listener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        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;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Player target = (Player) defender;
 | 
					            Player target = (Player) defender;
 | 
				
			||||||
            player.performCommand("openinv " + target.getName());
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            evt.setDamage(0);
 | 
					            event.setDamage(0);
 | 
				
			||||||
            evt.setCancelled(true);
 | 
					            event.setCancelled(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            player.performCommand("openinv " + target.getName());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,22 +16,22 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.listeners;
 | 
					package com.lishid.openinv.listeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
import org.bukkit.event.EventPriority;
 | 
					 | 
				
			||||||
import org.bukkit.event.Listener;
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
import org.bukkit.event.inventory.InventoryClickEvent;
 | 
					import org.bukkit.event.inventory.InventoryClickEvent;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenInvInventoryListener implements Listener {
 | 
					public class OpenInvInventoryListener implements Listener {
 | 
				
			||||||
    @EventHandler(priority = EventPriority.NORMAL)
 | 
					    @EventHandler
 | 
				
			||||||
    public void onInventoryClick(InventoryClickEvent event) {
 | 
					    public void onInventoryClick(InventoryClickEvent event) {
 | 
				
			||||||
        // If this is the top inventory
 | 
					        Inventory inventory = event.getInventory();
 | 
				
			||||||
        // if (event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot())
 | 
					        HumanEntity player = event.getWhoClicked();
 | 
				
			||||||
        // {
 | 
					
 | 
				
			||||||
        if (!OpenInv.inventoryAccess.check(event.getInventory(), event.getWhoClicked())) {
 | 
					        if (!OpenInv.getInventoryAccess().check(inventory, player)) {
 | 
				
			||||||
            event.setCancelled(true);
 | 
					            event.setCancelled(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -17,6 +17,8 @@
 | 
				
			|||||||
package com.lishid.openinv.listeners;
 | 
					package com.lishid.openinv.listeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					import org.bukkit.Material;
 | 
				
			||||||
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.block.Chest;
 | 
					import org.bukkit.block.Chest;
 | 
				
			||||||
import org.bukkit.block.Sign;
 | 
					import org.bukkit.block.Sign;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					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.SpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SuppressWarnings("deprecation")
 | 
					 | 
				
			||||||
public class OpenInvPlayerListener implements Listener {
 | 
					public class OpenInvPlayerListener implements Listener {
 | 
				
			||||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
					    @EventHandler(priority = EventPriority.LOWEST)
 | 
				
			||||||
    public void onPlayerJoin(PlayerJoinEvent event) {
 | 
					    public void onPlayerJoin(PlayerJoinEvent event) {
 | 
				
			||||||
@@ -70,35 +71,40 @@ public class OpenInvPlayerListener implements Listener {
 | 
				
			|||||||
    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
					    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
				
			||||||
        Player player = event.getPlayer();
 | 
					        Player player = event.getPlayer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getPlayer().isSneaking()) {
 | 
					        if (player.isSneaking()) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) {
 | 
					        Action action = event.getAction();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (action == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
 | 
					        Block block = event.getClickedBlock();
 | 
				
			||||||
            if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) {
 | 
					
 | 
				
			||||||
 | 
					        if (action == Action.RIGHT_CLICK_BLOCK && block.getType() == Material.ENDER_CHEST) {
 | 
				
			||||||
 | 
					            if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
 | 
				
			||||||
                event.setCancelled(true);
 | 
					                event.setCancelled(true);
 | 
				
			||||||
                player.openInventory(player.getEnderChest());
 | 
					                player.openInventory(player.getEnderChest());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) {
 | 
					        if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Chest) {
 | 
				
			||||||
            boolean silentchest = false;
 | 
					            boolean silentChest = false;
 | 
				
			||||||
            boolean anychest = 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())) {
 | 
					            int x = block.getX();
 | 
				
			||||||
                silentchest = true;
 | 
					            int y = block.getY();
 | 
				
			||||||
 | 
					            int z = block.getZ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
 | 
				
			||||||
 | 
					                silentChest = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player.getName())) {
 | 
					            if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
 | 
				
			||||||
                try {
 | 
					                try {
 | 
				
			||||||
                    anychest = OpenInv.anySilentChest.IsAnyChestNeeded(player, x, y, z);
 | 
					                    anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (Exception e) {
 | 
					                catch (Exception e) {
 | 
				
			||||||
                    player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
 | 
					                    player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
 | 
				
			||||||
@@ -107,16 +113,16 @@ public class OpenInvPlayerListener implements Listener {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // If the anychest or silentchest is active
 | 
					            // If the anychest or silentchest is active
 | 
				
			||||||
            if (anychest || silentchest) {
 | 
					            if (anyChest || silentChest) {
 | 
				
			||||||
                if (!OpenInv.anySilentChest.ActivateChest(player, anychest, silentchest, x, y, z)) {
 | 
					                if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
 | 
				
			||||||
                    event.setCancelled(true);
 | 
					                    event.setCancelled(true);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign) {
 | 
					        if (action == Action.RIGHT_CLICK_BLOCK && block.getState() instanceof Sign) {
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                Sign sign = ((Sign) event.getClickedBlock().getState());
 | 
					                Sign sign = ((Sign) block.getState());
 | 
				
			||||||
                if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
 | 
					                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();
 | 
					                    String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
 | 
				
			||||||
                    player.performCommand("openinv " + text);
 | 
					                    player.performCommand("openinv " + text);
 | 
				
			||||||
@@ -128,8 +134,8 @@ public class OpenInvPlayerListener implements Listener {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
 | 
					        if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) {
 | 
				
			||||||
            if (!(player.getItemInHand().getType().getId() == OpenInv.getItemOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
 | 
					            if (!(player.getItemInHand().getType() == OpenInv.getOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player)) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,47 @@
 | 
				
			|||||||
package com.lishid.openinv.utils;
 | 
					package com.lishid.openinv.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Arrays;
 | 
					import java.util.Arrays;
 | 
				
			||||||
 | 
					import java.util.Collection;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.commons.lang.Validate;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class UUIDUtil {
 | 
					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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static UUID getUUIDOf(String name) {
 | 
					    public static UUID getUUIDOf(String name) {
 | 
				
			||||||
        UUID uuid = null;
 | 
					        UUID uuid = null;
 | 
				
			||||||
 | 
					        Player player = getPlayer(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (player != null) {
 | 
				
			||||||
 | 
					            // Player was found online
 | 
				
			||||||
 | 
					            uuid = player.getUniqueId();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            // Player was not found online. Fetch their UUID instead
 | 
				
			||||||
            UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
 | 
					            UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
 | 
				
			||||||
            Map<String, UUID> response;
 | 
					            Map<String, UUID> response;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,6 +53,7 @@ public class UUIDUtil {
 | 
				
			|||||||
                Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
 | 
					                Bukkit.getServer().getLogger().warning("Exception while running UUIDFetcher");
 | 
				
			||||||
                e.printStackTrace();
 | 
					                e.printStackTrace();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return uuid;
 | 
					        return uuid;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					config-version: 2
 | 
				
			||||||
 | 
					check-for-updates: true
 | 
				
			||||||
 | 
					notify:
 | 
				
			||||||
 | 
					  any-chest: true
 | 
				
			||||||
 | 
					  silent-chest: true
 | 
				
			||||||
 | 
					items:
 | 
				
			||||||
 | 
					  open-inv: STICK
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
name: OpenInv
 | 
					name: OpenInv
 | 
				
			||||||
main: com.lishid.openinv.OpenInv
 | 
					main: com.lishid.openinv.OpenInv
 | 
				
			||||||
version: 2.3.0
 | 
					version: 2.3.1
 | 
				
			||||||
author: lishid
 | 
					author: lishid
 | 
				
			||||||
description: >
 | 
					description: >
 | 
				
			||||||
             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
					             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user