mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
commit
27de16cba9
24 changed files with 454 additions and 197 deletions
6
pom.xml
6
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.6</version>
|
<version>2.3.7</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>
|
||||||
|
|
||||||
|
@ -23,14 +23,14 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.9-R0.1-SNAPSHOT</version>
|
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>1.9-R0.1-SNAPSHOT</version>
|
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
153
src/main/java/com/lishid/openinv/Configuration.java
Normal file
153
src/main/java/com/lishid/openinv/Configuration.java
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads OpenInv's config settings.
|
||||||
|
*/
|
||||||
|
public void reload() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
private 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.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.CommandSender;
|
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;
|
||||||
|
@ -50,165 +48,144 @@ public class OpenInv extends JavaPlugin {
|
||||||
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;
|
private Configuration configuration;
|
||||||
|
|
||||||
private static PlayerDataManager playerLoader;
|
private PlayerDataManager playerLoader;
|
||||||
private static InventoryAccess inventoryAccess;
|
private InventoryAccess inventoryAccess;
|
||||||
private static AnySilentChest anySilentChest;
|
private AnySilentChest anySilentChest;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin
|
|
||||||
mainPlugin = this;
|
|
||||||
|
|
||||||
// Config Updater
|
|
||||||
ConfigUpdater configUpdater = new ConfigUpdater(this);
|
|
||||||
configUpdater.checkForUpdates();
|
|
||||||
|
|
||||||
// Initialize
|
|
||||||
playerLoader = new PlayerDataManager();
|
|
||||||
inventoryAccess = new InventoryAccess();
|
|
||||||
anySilentChest = new AnySilentChest();
|
|
||||||
|
|
||||||
// Save the default config.yml if it doesn't already exist
|
// Save the default config.yml if it doesn't already exist
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
// Register the plugin's events & commands
|
// Config
|
||||||
registerEvents();
|
configuration = new Configuration(this);
|
||||||
registerCommands();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerEvents() {
|
// Initialize
|
||||||
|
playerLoader = new PlayerDataManager(this);
|
||||||
|
inventoryAccess = new InventoryAccess(this);
|
||||||
|
anySilentChest = new AnySilentChest(this);
|
||||||
|
|
||||||
|
// Register the plugin's events
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvents(new OpenInvPlayerListener(), this);
|
pm.registerEvents(new OpenInvPlayerListener(this), this);
|
||||||
pm.registerEvents(new OpenInvEntityListener(), this);
|
pm.registerEvents(new OpenInvEntityListener(this), this);
|
||||||
pm.registerEvents(new OpenInvInventoryListener(), this);
|
pm.registerEvents(new OpenInvInventoryListener(this), this);
|
||||||
}
|
|
||||||
|
|
||||||
private void registerCommands() {
|
// Register the plugin's commands
|
||||||
getCommand("openinv").setExecutor(new OpenInvCommand(this));
|
getCommand("openinv").setExecutor(new OpenInvCommand(this));
|
||||||
getCommand("openender").setExecutor(new OpenEnderCommand(this));
|
getCommand("openender").setExecutor(new OpenEnderCommand(this));
|
||||||
getCommand("searchinv").setExecutor(new SearchInvCommand());
|
getCommand("searchinv").setExecutor(new SearchInvCommand(this));
|
||||||
getCommand("searchender").setExecutor(new SearchEnderCommand());
|
getCommand("searchender").setExecutor(new SearchEnderCommand());
|
||||||
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
|
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand(this));
|
||||||
getCommand("anychest").setExecutor(new AnyChestCommand());
|
getCommand("anychest").setExecutor(new AnyChestCommand(this));
|
||||||
getCommand("silentchest").setExecutor(new SilentChestCommand());
|
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;
|
return playerLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InventoryAccess getInventoryAccess() {
|
/**
|
||||||
|
* Returns an instance of InventoryAccess.
|
||||||
|
*
|
||||||
|
* @return an instance of InventoryAccess
|
||||||
|
*/
|
||||||
|
public InventoryAccess getInventoryAccess() {
|
||||||
return inventoryAccess;
|
return inventoryAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnySilentChest getAnySilentChest() {
|
/**
|
||||||
|
* Returns an instance of AnySilentChest.
|
||||||
|
*
|
||||||
|
* @return an instance of AnySilentChest
|
||||||
|
*/
|
||||||
|
public AnySilentChest getAnySilentChest() {
|
||||||
return anySilentChest;
|
return anySilentChest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getFromConfig(String path, Object defaultValue) {
|
/**
|
||||||
Object val = mainPlugin.getConfig().get(path);
|
* Logs a message to console.
|
||||||
|
*
|
||||||
if (val == null) {
|
* @param text the message to log
|
||||||
mainPlugin.getConfig().set(path, defaultValue);
|
*/
|
||||||
return defaultValue;
|
public void log(String text) {
|
||||||
} else {
|
getLogger().info(text);
|
||||||
return val;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveToConfig(String path, Object value) {
|
/**
|
||||||
mainPlugin.getConfig().set(path, value);
|
* Logs a Throwable to console.
|
||||||
mainPlugin.saveConfig();
|
*
|
||||||
}
|
* @param e the Throwable to log
|
||||||
|
*/
|
||||||
public static Material getOpenInvItem() {
|
public void log(Throwable e) {
|
||||||
if (!mainPlugin.getConfig().isSet("items.open-inv")) {
|
getLogger().severe(e.toString());
|
||||||
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());
|
|
||||||
e.printStackTrace();
|
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) {
|
public static void sendMessage(CommandSender sender, String message) {
|
||||||
sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + 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) {
|
public static void showHelp(Player player) {
|
||||||
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory.");
|
player.sendMessage(ChatColor.GREEN + "/openinv <player> - Opens a player's inventory.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/openender <player> - Open a player's ender chest.");
|
player.sendMessage(ChatColor.GREEN + "/openender <player> - Opens a player's ender chest.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: oe)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: oe)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] -");
|
player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] -");
|
||||||
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
|
player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their inventory.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: si)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: si)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/searchender <item> [minAmount] -");
|
player.sendMessage(ChatColor.GREEN + "/searchender <item> [minAmount] -");
|
||||||
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
|
player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their ender chest.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: se)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: se)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle the item openinv function.");
|
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggles the item openinv function.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/anychest - Toggle the any chest function.");
|
player.sendMessage(ChatColor.GREEN + "/anychest - Toggles the any chest function.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
|
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
|
||||||
|
|
||||||
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle the silent chest function.");
|
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggles the silent chest function.");
|
||||||
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
|
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) {
|
public static boolean hasPermission(Permissible player, String permission) {
|
||||||
String[] parts = permission.split("\\.");
|
String[] parts = permission.split("\\.");
|
||||||
String perm = "";
|
String perm = "";
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package com.lishid.openinv;
|
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_OPENINV = "OpenInv.openinv";
|
||||||
public static final String PERM_OVERRIDE = "OpenInv.override";
|
public static final String PERM_OVERRIDE = "OpenInv.override";
|
||||||
public static final String PERM_EXEMPT = "OpenInv.exempt";
|
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.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
|
import com.lishid.openinv.Configuration;
|
||||||
|
|
||||||
public class AnyChestCommand implements CommandExecutor {
|
public class AnyChestCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
private final Configuration configuration;
|
||||||
|
|
||||||
|
public AnyChestCommand(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
configuration = plugin.getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
@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")) {
|
||||||
|
@ -44,15 +53,15 @@ public class AnyChestCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("check")) {
|
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 + ".");
|
OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + ".");
|
||||||
return true;
|
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 + ".");
|
OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class OpenEnderCommand 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.getPlayerLoader().loadPlayer(uuid);
|
final Player target = plugin.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;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
sender.sendMessage(ChatColor.RED + "You can't use this command 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;
|
||||||
|
@ -90,7 +91,7 @@ public class OpenInvCommand 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.getPlayerLoader().loadPlayer(uuid);
|
final Player target = plugin.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;
|
||||||
|
@ -105,6 +106,7 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
openInventory(player, target);
|
openInventory(player, target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -148,14 +150,10 @@ public class OpenInvCommand implements CommandExecutor {
|
||||||
openInvHistory.put(player.getUniqueId(), target.getUniqueId());
|
openInvHistory.put(player.getUniqueId(), target.getUniqueId());
|
||||||
|
|
||||||
// Create the inventory
|
// Create the inventory
|
||||||
/*
|
|
||||||
SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
|
SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
|
||||||
if (inv == null) {
|
if (inv == null) {
|
||||||
inv = new SpecialPlayerInventory(target, target.isOnline());
|
inv = new SpecialPlayerInventory(target, target.isOnline());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
SpecialPlayerInventory inv = new SpecialPlayerInventory(target, target.isOnline());
|
|
||||||
|
|
||||||
// Open the inventory
|
// Open the inventory
|
||||||
player.openInventory(inv.getBukkitInventory());
|
player.openInventory(inv.getBukkitInventory());
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SearchEnderCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
sender.sendMessage(ChatColor.RED + "Unknown item");
|
sender.sendMessage(ChatColor.RED + "Unknown item.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,12 @@ import com.lishid.openinv.Permissions;
|
||||||
|
|
||||||
public class SearchInvCommand implements CommandExecutor {
|
public class SearchInvCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
public SearchInvCommand(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@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")) {
|
||||||
|
@ -58,7 +64,7 @@ public class SearchInvCommand implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
sender.sendMessage(ChatColor.RED + "Unknown item");
|
sender.sendMessage(ChatColor.RED + "Unknown item.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,18 @@ 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;
|
||||||
|
import com.lishid.openinv.Configuration;
|
||||||
|
|
||||||
public class SilentChestCommand implements CommandExecutor {
|
public class SilentChestCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
private final Configuration configuration;
|
||||||
|
|
||||||
|
public SilentChestCommand(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
configuration = plugin.getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
@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")) {
|
||||||
|
@ -44,15 +53,15 @@ public class SilentChestCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("check")) {
|
if (args[0].equalsIgnoreCase("check")) {
|
||||||
String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||||
OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
|
OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
|
||||||
return true;
|
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";
|
String status = configuration.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||||
OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
|
OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -24,9 +24,18 @@ 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;
|
||||||
|
import com.lishid.openinv.Configuration;
|
||||||
|
|
||||||
public class ToggleOpenInvCommand implements CommandExecutor {
|
public class ToggleOpenInvCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
private final Configuration configuration;
|
||||||
|
|
||||||
|
public ToggleOpenInvCommand(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
configuration = plugin.getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
@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")) {
|
||||||
|
@ -44,16 +53,16 @@ public class ToggleOpenInvCommand implements CommandExecutor {
|
||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("check")) {
|
if (args[0].equalsIgnoreCase("check")) {
|
||||||
String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||||
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
|
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
|
||||||
return true;
|
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";
|
String status = configuration.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
|
||||||
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
|
OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + configuration.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,34 @@ package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
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 net.minecraft.server.v1_9_R1.BlockChest.Type;
|
||||||
|
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.*;
|
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 {
|
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) {
|
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);
|
||||||
|
@ -135,7 +151,7 @@ public class AnySilentChest {
|
||||||
if (silentChest) {
|
if (silentChest) {
|
||||||
tileInventory = new SilentInventory(tileInventory);
|
tileInventory = new SilentInventory(tileInventory);
|
||||||
|
|
||||||
if (OpenInv.notifySilentChest()) {
|
if (plugin.getConfiguration().notifySilentChest()) {
|
||||||
OpenInv.sendMessage(p, "You are opening a chest silently.");
|
OpenInv.sendMessage(p, "You are opening a chest silently.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +160,7 @@ public class AnySilentChest {
|
||||||
|
|
||||||
player.openContainer(tileInventory);
|
player.openContainer(tileInventory);
|
||||||
|
|
||||||
if (anyChest && OpenInv.notifyAnyChest()) {
|
if (anyChest && plugin.getConfiguration().notifyAnyChest()) {
|
||||||
OpenInv.sendMessage(p, "You are opening a blocked chest.");
|
OpenInv.sendMessage(p, "You are opening a blocked chest.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,19 +18,23 @@ package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.IInventory;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.*;
|
|
||||||
|
|
||||||
public class InventoryAccess {
|
public class InventoryAccess {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
public InventoryAccess(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
public boolean check(Inventory inventory, HumanEntity player) {
|
||||||
IInventory inv = grabInventory(inventory);
|
IInventory inv = grabInventory(inventory);
|
||||||
|
|
||||||
|
@ -64,7 +68,7 @@ public class InventoryAccess {
|
||||||
try {
|
try {
|
||||||
result = (IInventory) f.get(inventory);
|
result = (IInventory) f.get(inventory);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
OpenInv.log(e);
|
plugin.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,18 +20,24 @@ import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.craftbukkit.v1_9_R1.CraftServer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
import net.minecraft.server.v1_9_R1.MinecraftServer;
|
||||||
|
import net.minecraft.server.v1_9_R1.PlayerInteractManager;
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.*;
|
|
||||||
|
|
||||||
public class PlayerDataManager {
|
public class PlayerDataManager {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
public PlayerDataManager(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
public Player loadPlayer(UUID uuid) {
|
public Player loadPlayer(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||||
|
@ -55,7 +61,7 @@ public class PlayerDataManager {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
OpenInv.log(e);
|
plugin.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.ContainerChest;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_9_R1.IInventory;
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
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.entity.HumanEntity;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.ChestLock;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
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 {
|
public class SilentInventory implements ITileInventory {
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,17 @@
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
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.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
|
|
||||||
// Volatile
|
import net.minecraft.server.v1_9_R1.InventoryEnderChest;
|
||||||
import net.minecraft.server.v1_9_R1.*;
|
import net.minecraft.server.v1_9_R1.InventorySubcontainer;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.*;
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.*;
|
|
||||||
|
|
||||||
public class SpecialEnderChest extends InventorySubcontainer {
|
public class SpecialEnderChest extends InventorySubcontainer {
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ public class SpecialEnderChest extends InventorySubcontainer {
|
||||||
private void saveOnExit() {
|
private void saveOnExit() {
|
||||||
if (transaction.isEmpty() && !playerOnline) {
|
if (transaction.isEmpty() && !playerOnline) {
|
||||||
owner.saveData();
|
owner.saveData();
|
||||||
OpenInv.enderChests.remove(owner.getUniqueId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +81,7 @@ public class SpecialEnderChest extends InventorySubcontainer {
|
||||||
public void onClose(CraftHumanEntity who) {
|
public void onClose(CraftHumanEntity who) {
|
||||||
super.onClose(who);
|
super.onClose(who);
|
||||||
saveOnExit();
|
saveOnExit();
|
||||||
|
OpenInv.enderChests.remove(owner.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,30 +18,31 @@ package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
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.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
// 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 com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_9_R1.ContainerUtil;
|
||||||
|
import net.minecraft.server.v1_9_R1.EntityHuman;
|
||||||
|
import net.minecraft.server.v1_9_R1.ItemStack;
|
||||||
|
import net.minecraft.server.v1_9_R1.PlayerInventory;
|
||||||
|
|
||||||
public class SpecialPlayerInventory extends PlayerInventory {
|
public class SpecialPlayerInventory extends PlayerInventory {
|
||||||
|
|
||||||
private final CraftInventory inventory = new CraftInventory(this);
|
private final CraftInventory inventory = new CraftInventory(this);
|
||||||
private final ItemStack[] extra = new ItemStack[4];
|
private final ItemStack[] extra = new ItemStack[4];
|
||||||
private final ItemStack[][] arrays;
|
|
||||||
private final CraftPlayer owner;
|
private final CraftPlayer owner;
|
||||||
|
private ItemStack[][] arrays;
|
||||||
private boolean playerOnline;
|
private boolean playerOnline;
|
||||||
|
|
||||||
public SpecialPlayerInventory(Player p, boolean online) {
|
public SpecialPlayerInventory(Player p, boolean online) {
|
||||||
super(((CraftPlayer) p).getHandle());
|
super(((CraftPlayer) p).getHandle());
|
||||||
this.owner = (CraftPlayer) p;
|
this.owner = (CraftPlayer) p;
|
||||||
reflectContents(getClass().getSuperclass(), player.inventory, this);
|
reflectContents(getClass().getSuperclass(), player.inventory, this);
|
||||||
this.arrays = new ItemStack[][] { this.items, this.armor, this.extraSlots, this.extra };
|
|
||||||
this.playerOnline = online;
|
this.playerOnline = online;
|
||||||
OpenInv.inventories.put(owner.getUniqueId(), this);
|
OpenInv.inventories.put(owner.getUniqueId(), this);
|
||||||
}
|
}
|
||||||
|
@ -68,6 +69,8 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arrays = new ItemStack[][] { this.items, this.armor, this.extraSlots, this.extra };
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory getBukkitInventory() {
|
public Inventory getBukkitInventory() {
|
||||||
|
@ -77,7 +80,6 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
||||||
private void saveOnExit() {
|
private void saveOnExit() {
|
||||||
if (transaction.isEmpty() && !playerOnline) {
|
if (transaction.isEmpty() && !playerOnline) {
|
||||||
owner.saveData();
|
owner.saveData();
|
||||||
OpenInv.inventories.remove(owner.getUniqueId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +107,7 @@ public class SpecialPlayerInventory extends PlayerInventory {
|
||||||
public void onClose(CraftHumanEntity who) {
|
public void onClose(CraftHumanEntity who) {
|
||||||
super.onClose(who);
|
super.onClose(who);
|
||||||
this.saveOnExit();
|
this.saveOnExit();
|
||||||
|
OpenInv.inventories.remove(owner.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,8 +25,18 @@ import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
|
import com.lishid.openinv.Configuration;
|
||||||
|
|
||||||
public class OpenInvEntityListener implements Listener {
|
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)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
Entity attacker = event.getDamager();
|
Entity attacker = event.getDamager();
|
||||||
|
@ -38,8 +48,8 @@ public class OpenInvEntityListener implements Listener {
|
||||||
|
|
||||||
Player player = (Player) attacker;
|
Player player = (Player) attacker;
|
||||||
|
|
||||||
if (player.getInventory().getItemInMainHand().getType() == OpenInv.getOpenInvItem()) {
|
if (player.getInventory().getItemInMainHand().getType() == configuration.getOpenInvItem()) {
|
||||||
if (!OpenInv.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
if (!configuration.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,19 @@ 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 {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
public OpenInvInventoryListener(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
HumanEntity player = event.getWhoClicked();
|
HumanEntity player = event.getWhoClicked();
|
||||||
|
|
||||||
if (!OpenInv.getInventoryAccess().check(inventory, player)) {
|
if (!plugin.getInventoryAccess().check(inventory, player)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,24 @@ import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
|
import com.lishid.openinv.Configuration;
|
||||||
import com.lishid.openinv.internal.SpecialEnderChest;
|
import com.lishid.openinv.internal.SpecialEnderChest;
|
||||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
|
import com.lishid.openinv.internal.SpecialPlayerInventory;
|
||||||
|
|
||||||
public class OpenInvPlayerListener implements Listener {
|
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)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
@ -46,24 +57,34 @@ public class OpenInvPlayerListener implements Listener {
|
||||||
inventory.playerOnline(event.getPlayer());
|
inventory.playerOnline(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
|
SpecialEnderChest enderChest = OpenInv.enderChests.get(player.getUniqueId());
|
||||||
if (chest != null) {
|
if (enderChest != null) {
|
||||||
chest.playerOnline(event.getPlayer());
|
enderChest.playerOnline(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
final SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
|
||||||
if (inventory != null) {
|
if (inventory != null) {
|
||||||
inventory.playerOffline();
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
inventory.playerOffline();
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
|
final SpecialEnderChest enderChest = OpenInv.enderChests.get(player.getUniqueId());
|
||||||
if (chest != null) {
|
if (enderChest != null) {
|
||||||
chest.playerOffline();
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
enderChest.playerOffline();
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +107,7 @@ public class OpenInvPlayerListener implements Listener {
|
||||||
|
|
||||||
// Ender Chests
|
// Ender Chests
|
||||||
if (block.getType() == Material.ENDER_CHEST) {
|
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);
|
event.setCancelled(true);
|
||||||
player.openInventory(player.getEnderChest());
|
player.openInventory(player.getEnderChest());
|
||||||
return;
|
return;
|
||||||
|
@ -101,15 +122,14 @@ public class OpenInvPlayerListener implements Listener {
|
||||||
int y = block.getY();
|
int y = block.getY();
|
||||||
int z = block.getZ();
|
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;
|
silentChest = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
|
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && configuration.getPlayerAnyChestStatus(player)) {
|
||||||
try {
|
try {
|
||||||
anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
|
anyChest = plugin.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.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -117,7 +137,7 @@ 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.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
|
if (!plugin.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,14 +148,14 @@ public class OpenInvPlayerListener implements Listener {
|
||||||
// Signs
|
// Signs
|
||||||
if (block.getState() instanceof Sign) {
|
if (block.getState() instanceof Sign) {
|
||||||
try {
|
try {
|
||||||
Sign sign = ((Sign) block.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);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
player.sendMessage(ChatColor.RED + "An internal error occured.");
|
||||||
player.sendMessage("Internal Error.");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +163,7 @@ public class OpenInvPlayerListener implements Listener {
|
||||||
}
|
}
|
||||||
case RIGHT_CLICK_AIR:
|
case RIGHT_CLICK_AIR:
|
||||||
// OpenInv item
|
// 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");
|
player.performCommand("openinv");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.json.simple.parser.JSONParser;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
|
|
||||||
private static final double PROFILES_PER_REQUEST = 100;
|
private static final double PROFILES_PER_REQUEST = 100;
|
||||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
private final JSONParser jsonParser = new JSONParser();
|
||||||
|
@ -34,11 +35,13 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
public Map<String, UUID> call() throws Exception {
|
public Map<String, UUID> call() throws Exception {
|
||||||
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
|
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
|
||||||
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
|
||||||
|
|
||||||
for (int i = 0; i < requests; i++) {
|
for (int i = 0; i < requests; i++) {
|
||||||
HttpURLConnection connection = createConnection();
|
HttpURLConnection connection = createConnection();
|
||||||
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
||||||
writeBody(connection, body);
|
writeBody(connection, body);
|
||||||
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
for (Object profile : array) {
|
for (Object profile : array) {
|
||||||
JSONObject jsonProfile = (JSONObject) profile;
|
JSONObject jsonProfile = (JSONObject) profile;
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = (String) jsonProfile.get("id");
|
||||||
|
@ -46,10 +49,12 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
UUID uuid = UUIDFetcher.getUUID(id);
|
UUID uuid = UUIDFetcher.getUUID(id);
|
||||||
uuidMap.put(name.toLowerCase(), uuid);
|
uuidMap.put(name.toLowerCase(), uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rateLimiting && i != requests - 1) {
|
if (rateLimiting && i != requests - 1) {
|
||||||
Thread.sleep(100L);
|
Thread.sleep(100L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return uuidMap;
|
return uuidMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +67,14 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
|
|
||||||
private static HttpURLConnection createConnection() throws Exception {
|
private static HttpURLConnection createConnection() throws Exception {
|
||||||
URL url = new URL(PROFILE_URL);
|
URL url = new URL(PROFILE_URL);
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +86,7 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||||
byteBuffer.putLong(uuid.getMostSignificantBits());
|
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||||
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||||
|
|
||||||
return byteBuffer.array();
|
return byteBuffer.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +94,11 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||||
if (array.length != 16) {
|
if (array.length != 16) {
|
||||||
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
|
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
|
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
|
||||||
long mostSignificant = byteBuffer.getLong();
|
long mostSignificant = byteBuffer.getLong();
|
||||||
long leastSignificant = byteBuffer.getLong();
|
long leastSignificant = byteBuffer.getLong();
|
||||||
|
|
||||||
return new UUID(mostSignificant, leastSignificant);
|
return new UUID(mostSignificant, leastSignificant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,10 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class UUIDUtil {
|
public final class UUIDUtil {
|
||||||
|
|
||||||
|
private UUIDUtil() {}
|
||||||
|
|
||||||
private static Player getPlayer(String name) {
|
private static Player getPlayer(String name) {
|
||||||
Validate.notNull(name, "Name cannot be null");
|
Validate.notNull(name, "Name cannot be null");
|
||||||
|
|
||||||
|
@ -22,10 +25,12 @@ public class UUIDUtil {
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
if (player.getName().toLowerCase().startsWith(lowerName)) {
|
if (player.getName().toLowerCase().startsWith(lowerName)) {
|
||||||
int curDelta = player.getName().length() - lowerName.length();
|
int curDelta = player.getName().length() - lowerName.length();
|
||||||
|
|
||||||
if (curDelta < delta) {
|
if (curDelta < delta) {
|
||||||
found = player;
|
found = player;
|
||||||
delta = curDelta;
|
delta = curDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curDelta == 0) break;
|
if (curDelta == 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,14 +44,19 @@ public class UUIDUtil {
|
||||||
return offlinePlayer.hasPlayedBefore() ? offlinePlayer.getUniqueId() : null;
|
return offlinePlayer.hasPlayedBefore() ? offlinePlayer.getUniqueId() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the UUID of a player by their name.
|
||||||
|
*
|
||||||
|
* @param name the name of the player to get the UUID of
|
||||||
|
* @return the player's UUID or null
|
||||||
|
*/
|
||||||
public static UUID getUUIDOf(String name) {
|
public static UUID getUUIDOf(String name) {
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
Player player = getPlayer(name);
|
Player player = getPlayer(name);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (Bukkit.getServer().getOnlineMode()) {
|
if (Bukkit.getServer().getOnlineMode()) {
|
||||||
if (!Bukkit.getServer().isPrimaryThread()) {
|
if (!Bukkit.getServer().isPrimaryThread()) {
|
||||||
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
|
UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
|
||||||
|
@ -55,8 +65,7 @@ public class UUIDUtil {
|
||||||
try {
|
try {
|
||||||
response = fetcher.call();
|
response = fetcher.call();
|
||||||
uuid = response.get(name.toLowerCase());
|
uuid = response.get(name.toLowerCase());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
uuid = getUUIDLocally(name);
|
uuid = getUUIDLocally(name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
name: OpenInv
|
name: OpenInv
|
||||||
main: com.lishid.openinv.OpenInv
|
main: com.lishid.openinv.OpenInv
|
||||||
version: 2.3.6
|
version: 2.3.7
|
||||||
author: lishid
|
author: lishid
|
||||||
|
authors: [ShadowRanger]
|
||||||
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.
|
||||||
commands:
|
commands:
|
||||||
|
|
Loading…
Reference in a new issue