2012-02-20 20:09:44 +00:00
|
|
|
/*
|
2012-03-03 18:58:24 +00:00
|
|
|
* Copyright (C) 2011-2012 lishid. All rights reserved.
|
2012-02-20 20:09:44 +00:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2011-06-03 14:32:54 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
package com.lishid.openinv;
|
2011-06-03 14:32:54 +00:00
|
|
|
|
2012-06-28 14:53:11 +00:00
|
|
|
import java.util.HashMap;
|
2012-12-13 03:41:18 +00:00
|
|
|
import java.util.logging.Logger;
|
2012-06-28 14:53:11 +00:00
|
|
|
|
2012-01-12 19:23:53 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2013-07-06 04:58:42 +00:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2012-01-12 19:23:53 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2013-12-06 07:31:14 +00:00
|
|
|
import org.bukkit.permissions.Permissible;
|
2011-06-03 14:32:54 +00:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
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;
|
|
|
|
|
2011-06-03 14:32:54 +00:00
|
|
|
/**
|
|
|
|
* Open other player's inventory
|
2012-06-28 14:53:11 +00:00
|
|
|
*
|
2011-06-03 14:32:54 +00:00
|
|
|
* @author lishid
|
|
|
|
*/
|
2013-12-07 09:44:40 +00:00
|
|
|
public class OpenInv extends JavaPlugin {
|
2012-12-13 03:41:18 +00:00
|
|
|
public static final Logger logger = Logger.getLogger("Minecraft.OpenInv");
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
public static HashMap<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
|
|
|
|
public static HashMap<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
|
2012-06-28 14:53:11 +00:00
|
|
|
private static Metrics metrics;
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
private UpdateManager updater = new UpdateManager();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
public static OpenInv mainPlugin;
|
|
|
|
|
|
|
|
public static IPlayerDataManager playerLoader;
|
|
|
|
public static IInventoryAccess inventoryAccess;
|
|
|
|
public static IAnySilentChest anySilentChest;
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public void onEnable() {
|
2012-12-13 03:41:18 +00:00
|
|
|
// Get plugin manager
|
|
|
|
PluginManager pm = getServer().getPluginManager();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
// Version check
|
|
|
|
boolean success = InternalAccessor.Initialize(this.getServer());
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
if (!success) {
|
2012-12-13 03:41:18 +00:00
|
|
|
OpenInv.log("Your version of CraftBukkit is not supported.");
|
2012-12-23 22:41:20 +00:00
|
|
|
OpenInv.log("Please look for an updated version of OpenInv.");
|
2012-12-13 03:41:18 +00:00
|
|
|
pm.disablePlugin(this);
|
|
|
|
return;
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
playerLoader = InternalAccessor.Instance.newPlayerDataManager();
|
|
|
|
inventoryAccess = InternalAccessor.Instance.newInventoryAccess();
|
|
|
|
anySilentChest = InternalAccessor.Instance.newAnySilentChest();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin = this;
|
2013-07-06 04:58:42 +00:00
|
|
|
FileConfiguration config = getConfig();
|
|
|
|
config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
|
|
|
|
config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
|
|
|
|
config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
|
|
|
|
config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
|
|
|
|
config.addDefault("ItemOpenInvItemID", 280);
|
|
|
|
config.addDefault("CheckForUpdates", true);
|
|
|
|
config.addDefault("NotifySilentChest", true);
|
|
|
|
config.addDefault("NotifyAnyChest", true);
|
|
|
|
config.options().copyDefaults(true);
|
|
|
|
saveConfig();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-08-10 17:36:36 +00:00
|
|
|
pm.registerEvents(new OpenInvPlayerListener(), this);
|
|
|
|
pm.registerEvents(new OpenInvEntityListener(), this);
|
|
|
|
pm.registerEvents(new OpenInvInventoryListener(), this);
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2011-06-03 14:32:54 +00:00
|
|
|
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
2012-11-16 03:45:53 +00:00
|
|
|
getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
|
2012-01-12 19:23:53 +00:00
|
|
|
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
|
2011-12-16 10:30:28 +00:00
|
|
|
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
|
2012-01-12 19:23:53 +00:00
|
|
|
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
|
2012-08-10 17:36:36 +00:00
|
|
|
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
updater.Initialize(this, getFile());
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-06-28 14:53:11 +00:00
|
|
|
// Metrics
|
2013-12-07 09:44:40 +00:00
|
|
|
try {
|
2012-06-28 14:53:11 +00:00
|
|
|
metrics = new Metrics(this);
|
|
|
|
metrics.start();
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
catch (Exception e) {
|
2012-12-13 03:41:18 +00:00
|
|
|
OpenInv.log(e);
|
2012-06-28 14:53:11 +00:00
|
|
|
}
|
2012-12-13 03:41:18 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean NotifySilentChest() {
|
2013-07-06 04:58:42 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("NotifySilentChest", true);
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean NotifyAnyChest() {
|
2013-07-06 04:58:42 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true);
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean GetCheckForUpdates() {
|
2012-12-13 03:41:18 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("CheckForUpdates", true);
|
2011-06-03 14:32:54 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean GetPlayerItemOpenInvStatus(String name) {
|
2012-06-28 14:53:11 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false);
|
2011-09-19 00:44:57 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static void SetPlayerItemOpenInvStatus(String name, boolean status) {
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status);
|
|
|
|
mainPlugin.saveConfig();
|
2011-09-19 00:44:57 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean GetPlayerSilentChestStatus(String name) {
|
2012-06-28 14:53:11 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false);
|
2011-12-16 10:30:28 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static void SetPlayerSilentChestStatus(String name, boolean status) {
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status);
|
|
|
|
mainPlugin.saveConfig();
|
2011-12-16 10:30:28 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static boolean GetPlayerAnyChestStatus(String name) {
|
2012-06-28 14:53:11 +00:00
|
|
|
return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true);
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static void SetPlayerAnyChestStatus(String name, boolean status) {
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status);
|
|
|
|
mainPlugin.saveConfig();
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static int GetItemOpenInvItem() {
|
|
|
|
if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) {
|
2012-06-28 14:53:11 +00:00
|
|
|
SaveToConfig("ItemOpenInvItemID", 280);
|
|
|
|
}
|
|
|
|
return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
|
2011-09-19 00:44:57 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static Object GetFromConfig(String data, Object defaultValue) {
|
2012-06-28 14:53:11 +00:00
|
|
|
Object val = mainPlugin.getConfig().get(data);
|
2013-12-07 09:44:40 +00:00
|
|
|
if (val == null) {
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin.getConfig().set(data, defaultValue);
|
2011-09-18 23:34:06 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
else {
|
2012-06-28 14:53:11 +00:00
|
|
|
return val;
|
2011-09-18 23:34:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static void SaveToConfig(String data, Object value) {
|
2012-06-28 14:53:11 +00:00
|
|
|
mainPlugin.getConfig().set(data, value);
|
|
|
|
mainPlugin.saveConfig();
|
2011-09-18 23:34:06 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
/**
|
|
|
|
* Log an information
|
|
|
|
*/
|
2013-12-07 09:44:40 +00:00
|
|
|
public static void log(String text) {
|
2012-12-13 03:41:18 +00:00
|
|
|
logger.info("[OpenInv] " + text);
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2012-12-13 03:41:18 +00:00
|
|
|
/**
|
|
|
|
* Log an error
|
|
|
|
*/
|
2013-12-07 09:44:40 +00:00
|
|
|
public static void log(Throwable e) {
|
2012-12-13 03:41:18 +00:00
|
|
|
logger.severe("[OpenInv] " + e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
|
|
|
public static void ShowHelp(Player player) {
|
2012-06-28 14:53:11 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/openinv <Player> - Open a player's inventory");
|
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
2012-08-10 17:36:36 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/openender <Player> - Open a player's enderchest");
|
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)");
|
2012-06-28 14:53:11 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function");
|
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
|
|
|
|
player.sendMessage(ChatColor.GREEN + "/searchinv <Item> [MinAmount] - ");
|
|
|
|
player.sendMessage(ChatColor.GREEN + " 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)");
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2013-12-06 07:31:14 +00:00
|
|
|
public static boolean hasPermission(Permissible player, String permission) {
|
|
|
|
String[] parts = permission.split("\\.");
|
|
|
|
String perm = "";
|
2013-12-07 09:44:40 +00:00
|
|
|
for (int i = 0; i < parts.length; i++) {
|
|
|
|
if (player.hasPermission(perm + "*")) {
|
2013-12-06 07:31:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
perm += parts[i] + ".";
|
|
|
|
}
|
|
|
|
return player.hasPermission(permission);
|
|
|
|
}
|
2011-06-03 14:32:54 +00:00
|
|
|
}
|