/* * Copyright (C) 2011-2012 lishid. All rights reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.lishid.openinv; import java.util.HashMap; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.lishid.openinv.commands.*; import com.lishid.openinv.internal.IAnySilentChest; import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IPlayerDataManager; import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.InternalAccessor; import com.lishid.openinv.utils.Metrics; import com.lishid.openinv.utils.UpdateManager; /** * Open other player's inventory * * @author lishid */ public class OpenInv extends JavaPlugin { public static final Logger logger = Logger.getLogger("Minecraft.OpenInv"); public static HashMap inventories = new HashMap(); public static HashMap enderChests = new HashMap(); private static Metrics metrics; private UpdateManager updater = new UpdateManager(); public static OpenInv mainPlugin; public static IPlayerDataManager playerLoader; public static IInventoryAccess inventoryAccess; public static IAnySilentChest anySilentChest; public void onEnable() { // Get plugin manager PluginManager pm = getServer().getPluginManager(); // Version check boolean success = InternalAccessor.Initialize(this.getServer()); if(!success) { OpenInv.log("Your version of CraftBukkit is not supported."); OpenInv.log("Please look for an updated version of OpenInv."); pm.disablePlugin(this); return; } playerLoader = InternalAccessor.Instance.newPlayerDataManager(); inventoryAccess = InternalAccessor.Instance.newInventoryAccess(); anySilentChest = InternalAccessor.Instance.newAnySilentChest(); mainPlugin = this; mainPlugin.getConfig().addDefault("ItemOpenInvItemID", 280); mainPlugin.getConfig().addDefault("CheckForUpdates", true); mainPlugin.getConfig().options().copyDefaults(true); mainPlugin.saveConfig(); 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(this)); getCommand("anychest").setExecutor(new AnyChestPluginCommand(this)); getCommand("openender").setExecutor(new OpenEnderPluginCommand(this)); updater.Initialize(this, getFile()); // Metrics try { metrics = new Metrics(this); metrics.start(); } catch (Exception e) { OpenInv.log(e); } } public static boolean GetCheckForUpdates() { return mainPlugin.getConfig().getBoolean("CheckForUpdates", true); } public static boolean GetPlayerItemOpenInvStatus(String name) { return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false); } public static void SetPlayerItemOpenInvStatus(String name, boolean status) { mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status); mainPlugin.saveConfig(); } public static boolean GetPlayerSilentChestStatus(String name) { return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false); } public static void SetPlayerSilentChestStatus(String name, boolean status) { mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status); mainPlugin.saveConfig(); } public static boolean GetPlayerAnyChestStatus(String name) { return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true); } public static void SetPlayerAnyChestStatus(String name, boolean status) { mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status); mainPlugin.saveConfig(); } public static int GetItemOpenInvItem() { if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) { SaveToConfig("ItemOpenInvItemID", 280); } return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280); } public static Object GetFromConfig(String data, Object defaultValue) { Object val = mainPlugin.getConfig().get(data); if (val == null) { mainPlugin.getConfig().set(data, defaultValue); return defaultValue; } else { return val; } } public static void SaveToConfig(String data, Object value) { mainPlugin.getConfig().set(data, value); mainPlugin.saveConfig(); } /** * Log an information */ public static void log(String text) { logger.info("[OpenInv] " + text); } /** * Log an error */ public static void log(Throwable e) { logger.severe("[OpenInv] " + e.toString()); e.printStackTrace(); } public static void ShowHelp(Player player) { player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); player.sendMessage(ChatColor.GREEN + "/openender - Open a player's enderchest"); player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)"); player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function"); player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); player.sendMessage(ChatColor.GREEN + "/searchinv [MinAmount] - "); player.sendMessage(ChatColor.GREEN + " 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: ac)"); player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle silent chest function"); player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)"); } }