mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-22 16:05:03 +00:00
General refactoring
This commit is contained in:
parent
8feca3fb21
commit
f9ac6804b2
20 changed files with 381 additions and 158 deletions
146
src/main/java/com/lishid/openinv/Configuration.java
Normal file
146
src/main/java/com/lishid/openinv/Configuration.java
Normal file
|
@ -0,0 +1,146 @@
|
|||
package com.lishid.openinv;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
private Material openInvItem;
|
||||
private boolean notifySilentChest;
|
||||
private boolean notifyAnyChest;
|
||||
|
||||
public Configuration(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
// Check for config updates
|
||||
ConfigUpdater configUpdater = new ConfigUpdater(plugin);
|
||||
configUpdater.checkForUpdates();
|
||||
|
||||
// Load the config settings
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads OpenInv's config settings.
|
||||
*/
|
||||
public void load() {
|
||||
// OpenInv Item
|
||||
if (!plugin.getConfig().isSet("items.open-inv")) {
|
||||
saveToConfig("items.open-inv", "STICK");
|
||||
}
|
||||
|
||||
String itemName = plugin.getConfig().getString("items.open-inv", "STICK");
|
||||
Material material = Material.getMaterial(itemName);
|
||||
|
||||
if (material == null) {
|
||||
plugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick.");
|
||||
material = Material.STICK;
|
||||
}
|
||||
|
||||
openInvItem = material;
|
||||
|
||||
// Other Values
|
||||
notifySilentChest = plugin.getConfig().getBoolean("notify.silent-chest", true);
|
||||
notifyAnyChest = plugin.getConfig().getBoolean("notify.any-chest", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a value to the plugin config at the specified path.
|
||||
*
|
||||
* @param path the path to set the value to
|
||||
* @param value the value to set to the path
|
||||
*/
|
||||
public void saveToConfig(String path, Object value) {
|
||||
plugin.getConfig().set(path, value);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the OpenInv item Material.
|
||||
*
|
||||
* @return the OpenInv item Material
|
||||
*/
|
||||
public Material getOpenInvItem() {
|
||||
return openInvItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not notify silent chest is enabled.
|
||||
*
|
||||
* @return true if notify silent chest is enabled; false otherwise
|
||||
*/
|
||||
public boolean notifySilentChest() {
|
||||
return notifySilentChest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not notify any chest is enabled.
|
||||
*
|
||||
* @return true if notify any chest is enabled; false otherwise
|
||||
*/
|
||||
public boolean notifyAnyChest() {
|
||||
return notifyAnyChest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a player's item OpenInv status.
|
||||
*
|
||||
* @param player the player to get the item OpenInv status of
|
||||
* @return the player's item OpenInv status
|
||||
*/
|
||||
public boolean getPlayerItemOpenInvStatus(Player player) {
|
||||
return plugin.getConfig().getBoolean("toggles.items.open-inv." + player.getUniqueId(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a player's any chest status.
|
||||
*
|
||||
* @param player the player to get the any chest status of
|
||||
* @return the player's any chest status
|
||||
*/
|
||||
public boolean getPlayerAnyChestStatus(Player player) {
|
||||
return plugin.getConfig().getBoolean("toggles.any-chest." + player.getUniqueId(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a player's any chest status.
|
||||
*
|
||||
* @param player the player to set the any chest status of
|
||||
* @param status the status to set with
|
||||
*/
|
||||
public void setPlayerAnyChestStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.any-chest." + player.getUniqueId(), status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a player's item OpenInv status.
|
||||
*
|
||||
* @param player the player to set the item OpenInv status of
|
||||
* @param status the status to set with
|
||||
*/
|
||||
public void setPlayerItemOpenInvStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.items.open-inv." + player.getUniqueId(), status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a player's silent chest status.
|
||||
*
|
||||
* @param player the player to get the silent chest status of
|
||||
* @return the player's silent chest status
|
||||
*/
|
||||
public boolean getPlayerSilentChestStatus(Player player) {
|
||||
return plugin.getConfig().getBoolean("toggles.silent-chest." + player.getUniqueId(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a player's silent chest status.
|
||||
*
|
||||
* @param player the player to set the silent chest status of
|
||||
* @param status the status to set with
|
||||
*/
|
||||
public void setPlayerSilentChestStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.silent-chest." + player.getUniqueId(), status);
|
||||
}
|
||||
}
|
|
@ -20,9 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
@ -50,140 +48,112 @@ public class OpenInv extends JavaPlugin {
|
|||
public static final Map<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
|
||||
public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
|
||||
|
||||
public static OpenInv mainPlugin;
|
||||
private PlayerDataManager playerLoader;
|
||||
private InventoryAccess inventoryAccess;
|
||||
private AnySilentChest anySilentChest;
|
||||
|
||||
private static PlayerDataManager playerLoader;
|
||||
private static InventoryAccess inventoryAccess;
|
||||
private static AnySilentChest anySilentChest;
|
||||
private Configuration configuration;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin
|
||||
mainPlugin = this;
|
||||
|
||||
// Config Updater
|
||||
ConfigUpdater configUpdater = new ConfigUpdater(this);
|
||||
configUpdater.checkForUpdates();
|
||||
// Config
|
||||
configuration = new Configuration(this);
|
||||
|
||||
// Initialize
|
||||
playerLoader = new PlayerDataManager();
|
||||
inventoryAccess = new InventoryAccess();
|
||||
anySilentChest = new AnySilentChest();
|
||||
playerLoader = new PlayerDataManager(this);
|
||||
inventoryAccess = new InventoryAccess(this);
|
||||
anySilentChest = new AnySilentChest(this);
|
||||
|
||||
// Save the default config.yml if it doesn't already exist
|
||||
saveDefaultConfig();
|
||||
|
||||
// Register the plugin's events & commands
|
||||
registerEvents();
|
||||
registerCommands();
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
// Register the plugin's events
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
pm.registerEvents(new OpenInvPlayerListener(), this);
|
||||
pm.registerEvents(new OpenInvEntityListener(), this);
|
||||
pm.registerEvents(new OpenInvInventoryListener(), this);
|
||||
}
|
||||
pm.registerEvents(new OpenInvPlayerListener(this), this);
|
||||
pm.registerEvents(new OpenInvEntityListener(this), this);
|
||||
pm.registerEvents(new OpenInvInventoryListener(this), this);
|
||||
|
||||
private void registerCommands() {
|
||||
// Register the plugin's commands
|
||||
getCommand("openinv").setExecutor(new OpenInvCommand(this));
|
||||
getCommand("openender").setExecutor(new OpenEnderCommand(this));
|
||||
getCommand("searchinv").setExecutor(new SearchInvCommand());
|
||||
getCommand("searchender").setExecutor(new SearchEnderCommand());
|
||||
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
|
||||
getCommand("anychest").setExecutor(new AnyChestCommand());
|
||||
getCommand("silentchest").setExecutor(new SilentChestCommand());
|
||||
getCommand("searchinv").setExecutor(new SearchInvCommand(this));
|
||||
getCommand("searchender").setExecutor(new SearchEnderCommand(this));
|
||||
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand(this));
|
||||
getCommand("anychest").setExecutor(new AnyChestCommand(this));
|
||||
getCommand("silentchest").setExecutor(new SilentChestCommand(this));
|
||||
}
|
||||
|
||||
public static PlayerDataManager getPlayerLoader() {
|
||||
/**
|
||||
* 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() {
|
||||
return playerLoader;
|
||||
}
|
||||
|
||||
public static InventoryAccess getInventoryAccess() {
|
||||
/**
|
||||
* Returns an instance of InventoryAccess.
|
||||
*
|
||||
* @return an instance of InventoryAccess
|
||||
*/
|
||||
public InventoryAccess getInventoryAccess() {
|
||||
return inventoryAccess;
|
||||
}
|
||||
|
||||
public static AnySilentChest getAnySilentChest() {
|
||||
/**
|
||||
* Returns an instance of AnySilentChest.
|
||||
*
|
||||
* @return an instance of AnySilentChest
|
||||
*/
|
||||
public AnySilentChest getAnySilentChest() {
|
||||
return anySilentChest;
|
||||
}
|
||||
|
||||
public static Object getFromConfig(String path, Object defaultValue) {
|
||||
Object val = mainPlugin.getConfig().get(path);
|
||||
|
||||
if (val == null) {
|
||||
mainPlugin.getConfig().set(path, defaultValue);
|
||||
return defaultValue;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
/**
|
||||
* Logs a message to console.
|
||||
*
|
||||
* @param text the message to log
|
||||
*/
|
||||
public void log(String text) {
|
||||
getLogger().info(text);
|
||||
}
|
||||
|
||||
public static void saveToConfig(String path, Object value) {
|
||||
mainPlugin.getConfig().set(path, value);
|
||||
mainPlugin.saveConfig();
|
||||
}
|
||||
|
||||
public static Material getOpenInvItem() {
|
||||
if (!mainPlugin.getConfig().isSet("items.open-inv")) {
|
||||
saveToConfig("items.open-inv", "STICK");
|
||||
}
|
||||
|
||||
String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK");
|
||||
Material material = Material.getMaterial(itemName);
|
||||
if (material == null) {
|
||||
mainPlugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick.");
|
||||
material = Material.STICK;
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
public static boolean notifySilentChest() {
|
||||
return mainPlugin.getConfig().getBoolean("notify.silent-chest", true);
|
||||
}
|
||||
|
||||
public static boolean notifyAnyChest() {
|
||||
return mainPlugin.getConfig().getBoolean("notify.any-chest", true);
|
||||
}
|
||||
|
||||
public static boolean getPlayerAnyChestStatus(Player player) {
|
||||
return mainPlugin.getConfig().getBoolean("toggles.any-chest." + player.getUniqueId(), true);
|
||||
}
|
||||
|
||||
public static void setPlayerAnyChestStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.any-chest." + player.getUniqueId(), status);
|
||||
}
|
||||
|
||||
public static boolean getPlayerItemOpenInvStatus(Player player) {
|
||||
return mainPlugin.getConfig().getBoolean("toggles.items.open-inv." + player.getUniqueId(), false);
|
||||
}
|
||||
|
||||
public static void setPlayerItemOpenInvStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.items.open-inv." + player.getUniqueId(), status);
|
||||
}
|
||||
|
||||
public static boolean getPlayerSilentChestStatus(Player player) {
|
||||
return mainPlugin.getConfig().getBoolean("toggles.silent-chest." + player.getUniqueId(), false);
|
||||
}
|
||||
|
||||
public static void setPlayerSilentChestStatus(Player player, boolean status) {
|
||||
saveToConfig("toggles.silent-chest." + player.getUniqueId(), status);
|
||||
}
|
||||
|
||||
public static void log(String text) {
|
||||
mainPlugin.getLogger().info("[OpenInv] " + text);
|
||||
}
|
||||
|
||||
public static void log(Throwable e) {
|
||||
mainPlugin.getLogger().severe("[OpenInv] " + e.toString());
|
||||
/**
|
||||
* Logs a Throwable to console.
|
||||
*
|
||||
* @param e the Throwable to log
|
||||
*/
|
||||
public void log(Throwable e) {
|
||||
getLogger().severe(e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an OpenInv message to a player.
|
||||
*
|
||||
* @param sender the CommandSender to message
|
||||
* @param message the message to send
|
||||
*/
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs OpenInv help information to a player.
|
||||
*
|
||||
* @param player the player to show help to
|
||||
*/
|
||||
public static void showHelp(Player player) {
|
||||
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory.");
|
||||
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
||||
|
@ -209,6 +179,13 @@ public class OpenInv extends JavaPlugin {
|
|||
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static boolean hasPermission(Permissible player, String permission) {
|
||||
String[] parts = permission.split("\\.");
|
||||
String perm = "";
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.lishid.openinv;
|
||||
|
||||
public class Permissions {
|
||||
public final class Permissions {
|
||||
|
||||
private Permissions() {}
|
||||
|
||||
public static final String PERM_OPENINV = "OpenInv.openinv";
|
||||
public static final String PERM_OVERRIDE = "OpenInv.override";
|
||||
public static final String PERM_EXEMPT = "OpenInv.exempt";
|
||||
|
|
|
@ -24,9 +24,18 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.Configuration;
|
||||
|
||||
public class AnyChestCommand implements CommandExecutor {
|
||||
|
||||
private final OpenInv plugin;
|
||||
private final Configuration configuration;
|
||||
|
||||
public AnyChestCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
configuration = plugin.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("anychest")) {
|
||||
|
@ -44,15 +53,15 @@ public class AnyChestCommand implements CommandExecutor {
|
|||
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("check")) {
|
||||
String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
String status = configuration.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OpenInv.setPlayerAnyChestStatus(player, !OpenInv.getPlayerAnyChestStatus(player));
|
||||
configuration.setPlayerAnyChestStatus(player, !configuration.getPlayerAnyChestStatus(player));
|
||||
|
||||
String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
String status = configuration.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + ".");
|
||||
|
||||
return true;
|
||||
|
|
|
@ -96,7 +96,7 @@ public class OpenEnderCommand implements CommandExecutor {
|
|||
@Override
|
||||
public void run() {
|
||||
// Try loading the player's data asynchronously
|
||||
final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
|
||||
final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
|
||||
if (target == null) {
|
||||
player.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return;
|
||||
|
|
|
@ -48,6 +48,7 @@ public class OpenInvCommand implements CommandExecutor {
|
|||
sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories.");
|
||||
return true;
|
||||
|
@ -90,7 +91,7 @@ public class OpenInvCommand implements CommandExecutor {
|
|||
@Override
|
||||
public void run() {
|
||||
// Try loading the player's data asynchronously
|
||||
final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
|
||||
final Player target = plugin.getPlayerLoader().loadPlayer(uuid);
|
||||
if (target == null) {
|
||||
player.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return;
|
||||
|
@ -148,14 +149,10 @@ public class OpenInvCommand implements CommandExecutor {
|
|||
openInvHistory.put(player.getUniqueId(), target.getUniqueId());
|
||||
|
||||
// Create the inventory
|
||||
/*
|
||||
SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
|
||||
if (inv == null) {
|
||||
inv = new SpecialPlayerInventory(target, target.isOnline());
|
||||
}
|
||||
*/
|
||||
|
||||
SpecialPlayerInventory inv = new SpecialPlayerInventory(target, target.isOnline());
|
||||
|
||||
// Open the inventory
|
||||
player.openInventory(inv.getBukkitInventory());
|
||||
|
|
|
@ -13,6 +13,12 @@ import com.lishid.openinv.Permissions;
|
|||
|
||||
public class SearchEnderCommand implements CommandExecutor {
|
||||
|
||||
private OpenInv plugin;
|
||||
|
||||
public SearchEnderCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("searchender")) {
|
||||
|
|
|
@ -29,6 +29,12 @@ import com.lishid.openinv.Permissions;
|
|||
|
||||
public class SearchInvCommand implements CommandExecutor {
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
public SearchInvCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("searchinv")) {
|
||||
|
|
|
@ -24,9 +24,18 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.Configuration;
|
||||
|
||||
public class SilentChestCommand implements CommandExecutor {
|
||||
|
||||
private final OpenInv plugin;
|
||||
private final Configuration configuration;
|
||||
|
||||
public SilentChestCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
configuration = plugin.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("silentchest")) {
|
||||
|
@ -44,16 +53,16 @@ public class SilentChestCommand implements CommandExecutor {
|
|||
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("check")) {
|
||||
String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
|
||||
String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
plugin.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OpenInv.setPlayerSilentChestStatus(player, !OpenInv.getPlayerSilentChestStatus(player));
|
||||
configuration.setPlayerSilentChestStatus(player, !configuration.getPlayerSilentChestStatus(player));
|
||||
|
||||
String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
|
||||
String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
plugin.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,9 +24,18 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.Configuration;
|
||||
|
||||
public class ToggleOpenInvCommand implements CommandExecutor {
|
||||
|
||||
private final OpenInv plugin;
|
||||
private final Configuration configuration;
|
||||
|
||||
public ToggleOpenInvCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
configuration = plugin.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("toggleopeninv")) {
|
||||
|
@ -44,16 +53,16 @@ public class ToggleOpenInvCommand implements CommandExecutor {
|
|||
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("check")) {
|
||||
String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
|
||||
String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
plugin.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OpenInv.setPlayerItemOpenInvStatus(player, !OpenInv.getPlayerItemOpenInvStatus(player));
|
||||
configuration.setPlayerItemOpenInvStatus(player, !configuration.getPlayerItemOpenInvStatus(player));
|
||||
|
||||
String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
|
||||
String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||
plugin.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,18 +18,34 @@ package com.lishid.openinv.internal;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_9_R1.Block;
|
||||
import net.minecraft.server.v1_9_R1.BlockChest;
|
||||
import net.minecraft.server.v1_9_R1.BlockChest.Type;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.*;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.Entity;
|
||||
import net.minecraft.server.v1_9_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_9_R1.EnumDirection;
|
||||
import net.minecraft.server.v1_9_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_9_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_9_R1.TileEntity;
|
||||
import net.minecraft.server.v1_9_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_9_R1.World;
|
||||
|
||||
public class AnySilentChest {
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
public AnySilentChest(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
BlockPosition position = new BlockPosition(x, y, z);
|
||||
|
@ -135,8 +151,8 @@ public class AnySilentChest {
|
|||
if (silentChest) {
|
||||
tileInventory = new SilentInventory(tileInventory);
|
||||
|
||||
if (OpenInv.notifySilentChest()) {
|
||||
OpenInv.sendMessage(p, "You are opening a chest silently.");
|
||||
if (plugin.getConfiguration().notifySilentChest()) {
|
||||
plugin.sendMessage(p, "You are opening a chest silently.");
|
||||
}
|
||||
|
||||
returnValue = false;
|
||||
|
@ -144,8 +160,8 @@ public class AnySilentChest {
|
|||
|
||||
player.openContainer(tileInventory);
|
||||
|
||||
if (anyChest && OpenInv.notifyAnyChest()) {
|
||||
OpenInv.sendMessage(p, "You are opening a blocked chest.");
|
||||
if (anyChest && plugin.getConfiguration().notifyAnyChest()) {
|
||||
plugin.sendMessage(p, "You are opening a blocked chest.");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
|
|
@ -18,19 +18,23 @@ package com.lishid.openinv.internal;
|
|||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.*;
|
||||
import net.minecraft.server.v1_9_R1.IInventory;
|
||||
|
||||
public class InventoryAccess {
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
public InventoryAccess(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = grabInventory(inventory);
|
||||
|
||||
|
@ -64,7 +68,7 @@ public class InventoryAccess {
|
|||
try {
|
||||
result = (IInventory) f.get(inventory);
|
||||
} catch (Exception e) {
|
||||
OpenInv.log(e);
|
||||
plugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,24 @@ import java.util.UUID;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.*;
|
||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_9_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_9_R1.PlayerInteractManager;
|
||||
|
||||
public class PlayerDataManager {
|
||||
|
||||
private OpenInv plugin;
|
||||
|
||||
public PlayerDataManager(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Player loadPlayer(UUID uuid) {
|
||||
try {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
|
@ -55,7 +61,7 @@ public class PlayerDataManager {
|
|||
return target;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
OpenInv.log(e);
|
||||
plugin.log(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import net.minecraft.server.v1_9_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_9_R1.IInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
|
|
|
@ -7,8 +7,14 @@ import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
|
|||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
import net.minecraft.server.v1_9_R1.ChestLock;
|
||||
import net.minecraft.server.v1_9_R1.Container;
|
||||
import net.minecraft.server.v1_9_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_9_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_9_R1.ItemStack;
|
||||
import net.minecraft.server.v1_9_R1.PlayerInventory;
|
||||
|
||||
public class SilentInventory implements ITileInventory {
|
||||
|
||||
|
|
|
@ -16,17 +16,17 @@
|
|||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
|
||||
// Volatile
|
||||
import net.minecraft.server.v1_9_R1.*;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.*;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.*;
|
||||
import net.minecraft.server.v1_9_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_9_R1.InventorySubcontainer;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer {
|
||||
|
||||
|
|
|
@ -25,8 +25,18 @@ import org.bukkit.event.Listener;
|
|||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.Configuration;
|
||||
|
||||
public class OpenInvEntityListener implements Listener {
|
||||
|
||||
private final OpenInv plugin;
|
||||
private final Configuration configuration;
|
||||
|
||||
public OpenInvEntityListener(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
configuration = plugin.getConfiguration();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
|
@ -38,8 +48,8 @@ public class OpenInvEntityListener implements Listener {
|
|||
|
||||
Player player = (Player) attacker;
|
||||
|
||||
if (player.getInventory().getItemInMainHand().getType() == OpenInv.getOpenInvItem()) {
|
||||
if (!OpenInv.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == configuration.getOpenInvItem()) {
|
||||
if (!configuration.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,19 @@ import org.bukkit.inventory.Inventory;
|
|||
import com.lishid.openinv.OpenInv;
|
||||
|
||||
public class OpenInvInventoryListener implements Listener {
|
||||
|
||||
private final OpenInv plugin;
|
||||
|
||||
public OpenInvInventoryListener(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
HumanEntity player = event.getWhoClicked();
|
||||
|
||||
if (!OpenInv.getInventoryAccess().check(inventory, player)) {
|
||||
if (!plugin.getInventoryAccess().check(inventory, player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,20 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||
|
||||
import com.lishid.openinv.OpenInv;
|
||||
import com.lishid.openinv.Permissions;
|
||||
import com.lishid.openinv.Configuration;
|
||||
import com.lishid.openinv.internal.SpecialEnderChest;
|
||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
|
||||
|
||||
public class OpenInvPlayerListener implements Listener {
|
||||
|
||||
private final OpenInv plugin;
|
||||
private final Configuration configuration;
|
||||
|
||||
public OpenInvPlayerListener(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
configuration = plugin.getConfiguration();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -86,7 +96,7 @@ public class OpenInvPlayerListener implements Listener {
|
|||
|
||||
// Ender Chests
|
||||
if (block.getType() == Material.ENDER_CHEST) {
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && configuration.getPlayerSilentChestStatus(player)) {
|
||||
event.setCancelled(true);
|
||||
player.openInventory(player.getEnderChest());
|
||||
return;
|
||||
|
@ -101,13 +111,13 @@ public class OpenInvPlayerListener implements Listener {
|
|||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && configuration.getPlayerSilentChestStatus(player)) {
|
||||
silentChest = true;
|
||||
}
|
||||
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && configuration.getPlayerAnyChestStatus(player)) {
|
||||
try {
|
||||
anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
|
||||
anyChest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
|
||||
}
|
||||
catch (Exception e) {
|
||||
player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
|
||||
|
@ -117,7 +127,7 @@ public class OpenInvPlayerListener implements Listener {
|
|||
|
||||
// If the anyChest or silentChest is active
|
||||
if (anyChest || silentChest) {
|
||||
if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
|
||||
if (!plugin.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +138,7 @@ public class OpenInvPlayerListener implements Listener {
|
|||
// Signs
|
||||
if (block.getState() instanceof Sign) {
|
||||
try {
|
||||
Sign sign = ((Sign) block.getState());
|
||||
Sign sign = (Sign) block.getState();
|
||||
if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
|
||||
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
|
||||
player.performCommand("openinv " + text);
|
||||
|
@ -143,7 +153,7 @@ public class OpenInvPlayerListener implements Listener {
|
|||
}
|
||||
case RIGHT_CLICK_AIR:
|
||||
// OpenInv item
|
||||
if (player.getInventory().getItemInMainHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
||||
if (player.getInventory().getItemInMainHand().getType() == configuration.getOpenInvItem() && configuration.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
||||
player.performCommand("openinv");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ name: OpenInv
|
|||
main: com.lishid.openinv.OpenInv
|
||||
version: 2.3.6
|
||||
author: lishid
|
||||
authors: [ShadowRanger]
|
||||
description: >
|
||||
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
||||
commands:
|
||||
|
|
Loading…
Reference in a new issue