2012-02-20 20:09:44 +00:00
|
|
|
/*
|
2016-03-02 09:11:45 +00:00
|
|
|
* Copyright (C) 2011-2016 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;
|
2014-12-31 03:28:52 +00:00
|
|
|
import java.util.Map;
|
2015-06-22 02:03:03 +00:00
|
|
|
import java.util.UUID;
|
2012-06-28 14:53:11 +00:00
|
|
|
|
2012-01-12 19:23:53 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2015-06-23 03:31:26 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
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;
|
|
|
|
|
2015-06-23 03:31:26 +00:00
|
|
|
import com.lishid.openinv.commands.AnyChestCommand;
|
|
|
|
import com.lishid.openinv.commands.OpenEnderCommand;
|
|
|
|
import com.lishid.openinv.commands.OpenInvCommand;
|
2015-06-24 09:19:45 +00:00
|
|
|
import com.lishid.openinv.commands.SearchEnderCommand;
|
2015-06-23 03:31:26 +00:00
|
|
|
import com.lishid.openinv.commands.SearchInvCommand;
|
|
|
|
import com.lishid.openinv.commands.SilentChestCommand;
|
|
|
|
import com.lishid.openinv.commands.ToggleOpenInvCommand;
|
2015-06-22 02:03:03 +00:00
|
|
|
import com.lishid.openinv.internal.AnySilentChest;
|
|
|
|
import com.lishid.openinv.internal.InventoryAccess;
|
|
|
|
import com.lishid.openinv.internal.PlayerDataManager;
|
|
|
|
import com.lishid.openinv.internal.SpecialEnderChest;
|
|
|
|
import com.lishid.openinv.internal.SpecialPlayerInventory;
|
|
|
|
import com.lishid.openinv.listeners.OpenInvEntityListener;
|
|
|
|
import com.lishid.openinv.listeners.OpenInvInventoryListener;
|
|
|
|
import com.lishid.openinv.listeners.OpenInvPlayerListener;
|
2012-12-13 03:41:18 +00:00
|
|
|
|
2013-12-07 09:44:40 +00:00
|
|
|
public class OpenInv extends JavaPlugin {
|
2016-03-04 02:45:54 +00:00
|
|
|
|
2015-06-22 02:03:03 +00:00
|
|
|
public static final Map<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
|
|
|
|
public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
private PlayerDataManager playerLoader;
|
|
|
|
private InventoryAccess inventoryAccess;
|
|
|
|
private AnySilentChest anySilentChest;
|
2012-12-13 03:41:18 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
private Configuration configuration;
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2015-06-22 02:03:03 +00:00
|
|
|
@Override
|
2013-12-07 09:44:40 +00:00
|
|
|
public void onEnable() {
|
2016-03-10 02:47:17 +00:00
|
|
|
// Save the default config.yml if it doesn't already exist
|
|
|
|
saveDefaultConfig();
|
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
// Config
|
|
|
|
configuration = new Configuration(this);
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2015-06-23 03:31:26 +00:00
|
|
|
// Initialize
|
2016-03-10 02:37:28 +00:00
|
|
|
playerLoader = new PlayerDataManager(this);
|
|
|
|
inventoryAccess = new InventoryAccess(this);
|
|
|
|
anySilentChest = new AnySilentChest(this);
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
// Register the plugin's events
|
2015-06-23 03:31:26 +00:00
|
|
|
PluginManager pm = getServer().getPluginManager();
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
pm.registerEvents(new OpenInvPlayerListener(this), this);
|
|
|
|
pm.registerEvents(new OpenInvEntityListener(this), this);
|
|
|
|
pm.registerEvents(new OpenInvInventoryListener(this), this);
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
// Register the plugin's commands
|
2015-06-23 03:31:26 +00:00
|
|
|
getCommand("openinv").setExecutor(new OpenInvCommand(this));
|
2015-06-24 09:19:45 +00:00
|
|
|
getCommand("openender").setExecutor(new OpenEnderCommand(this));
|
2016-03-10 02:37:28 +00:00
|
|
|
getCommand("searchinv").setExecutor(new SearchInvCommand(this));
|
2016-03-10 03:01:56 +00:00
|
|
|
getCommand("searchender").setExecutor(new SearchEnderCommand());
|
2016-03-10 02:37:28 +00:00
|
|
|
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand(this));
|
|
|
|
getCommand("anychest").setExecutor(new AnyChestCommand(this));
|
|
|
|
getCommand("silentchest").setExecutor(new SilentChestCommand(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the plugin Configuration.
|
|
|
|
*
|
|
|
|
* @return the plugin Configuration
|
|
|
|
*/
|
|
|
|
public Configuration getConfiguration() {
|
|
|
|
return configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an instance of PlayerDataManager.
|
|
|
|
*
|
|
|
|
* @return an instance of PlayerDataManager
|
|
|
|
*/
|
|
|
|
public PlayerDataManager getPlayerLoader() {
|
2015-06-23 03:31:26 +00:00
|
|
|
return playerLoader;
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Returns an instance of InventoryAccess.
|
|
|
|
*
|
|
|
|
* @return an instance of InventoryAccess
|
|
|
|
*/
|
|
|
|
public InventoryAccess getInventoryAccess() {
|
2015-06-23 03:31:26 +00:00
|
|
|
return inventoryAccess;
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Returns an instance of AnySilentChest.
|
|
|
|
*
|
|
|
|
* @return an instance of AnySilentChest
|
|
|
|
*/
|
|
|
|
public AnySilentChest getAnySilentChest() {
|
2015-06-23 03:31:26 +00:00
|
|
|
return anySilentChest;
|
2011-09-19 00:44:57 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Logs a message to console.
|
|
|
|
*
|
|
|
|
* @param text the message to log
|
|
|
|
*/
|
|
|
|
public void log(String text) {
|
|
|
|
getLogger().info(text);
|
2012-12-13 03:41:18 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Logs a Throwable to console.
|
|
|
|
*
|
|
|
|
* @param e the Throwable to log
|
|
|
|
*/
|
|
|
|
public void log(Throwable e) {
|
|
|
|
getLogger().severe(e.toString());
|
2012-12-13 03:41:18 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Sends an OpenInv message to a player.
|
|
|
|
*
|
|
|
|
* @param sender the CommandSender to message
|
|
|
|
* @param message the message to send
|
|
|
|
*/
|
2015-06-23 03:31:26 +00:00
|
|
|
public static void sendMessage(CommandSender sender, String message) {
|
|
|
|
sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
|
|
|
|
}
|
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Outputs OpenInv help information to a player.
|
|
|
|
*
|
|
|
|
* @param player the player to show help to
|
|
|
|
*/
|
2015-06-22 10:15:28 +00:00
|
|
|
public static void showHelp(Player player) {
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Opens a player's inventory.");
|
2012-06-28 14:53:11 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
2015-06-24 09:19:45 +00:00
|
|
|
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/openender <player> - Opens a player's ender chest.");
|
2015-06-24 09:19:45 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: oe)");
|
|
|
|
|
|
|
|
player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] -");
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their inventory.");
|
2015-06-24 09:19:45 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: si)");
|
|
|
|
|
|
|
|
player.sendMessage(ChatColor.GREEN + "/searchender <item> [minAmount] -");
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their ender chest.");
|
2015-06-24 09:19:45 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: se)");
|
|
|
|
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggles the item openinv function.");
|
2015-06-24 09:19:45 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
|
|
|
|
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/anychest - Toggles the any chest function.");
|
2012-06-28 14:53:11 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
|
2015-06-24 09:19:45 +00:00
|
|
|
|
2016-03-10 02:47:17 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggles the silent chest function.");
|
2012-06-28 14:53:11 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
|
2012-01-12 19:23:53 +00:00
|
|
|
}
|
2013-12-07 09:44:40 +00:00
|
|
|
|
2016-03-10 02:37:28 +00:00
|
|
|
/**
|
|
|
|
* Returns whether or not a player has a permission.
|
|
|
|
*
|
|
|
|
* @param player the player to check
|
|
|
|
* @param permission the permission node to check for
|
|
|
|
* @return true if the player has the permission; false otherwise
|
|
|
|
*/
|
2013-12-06 07:31:14 +00:00
|
|
|
public static boolean hasPermission(Permissible player, String permission) {
|
|
|
|
String[] parts = permission.split("\\.");
|
|
|
|
String perm = "";
|
2016-03-04 02:45:54 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2016-03-04 02:45:54 +00:00
|
|
|
|
2013-12-06 07:31:14 +00:00
|
|
|
perm += parts[i] + ".";
|
|
|
|
}
|
2016-03-04 02:45:54 +00:00
|
|
|
|
2013-12-06 07:31:14 +00:00
|
|
|
return player.hasPermission(permission);
|
|
|
|
}
|
2015-06-22 02:03:03 +00:00
|
|
|
}
|