Merge pull request #26 from ShadowRanger/master

General refactoring + minor changes
This commit is contained in:
ShadowRanger 2015-06-22 20:30:14 +10:00
commit f260ed1175
16 changed files with 50 additions and 49 deletions

1
.gitignore vendored
View file

@ -7,4 +7,3 @@
/bin /bin
/lib /lib
/out /out
*.iml

View file

@ -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.2.9</version> <version>2.3.0</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>

View file

@ -89,49 +89,49 @@ public class OpenInv extends JavaPlugin {
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this)); getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
} }
public static boolean NotifySilentChest() { public static boolean notifySilentChest() {
return mainPlugin.getConfig().getBoolean("NotifySilentChest", true); return mainPlugin.getConfig().getBoolean("NotifySilentChest", true);
} }
public static boolean NotifyAnyChest() { public static boolean notifyAnyChest() {
return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true); return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true);
} }
public static boolean GetPlayerItemOpenInvStatus(String name) { public static boolean getPlayerItemOpenInvStatus(String name) {
return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false); return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false);
} }
public static void SetPlayerItemOpenInvStatus(String name, boolean status) { public static void setPlayerItemOpenInvStatus(String name, boolean status) {
mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status); mainPlugin.getConfig().set("ItemOpenInv." + name.toLowerCase() + ".toggle", status);
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
public static boolean GetPlayerSilentChestStatus(String name) { public static boolean getPlayerSilentChestStatus(String name) {
return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false); return mainPlugin.getConfig().getBoolean("SilentChest." + name.toLowerCase() + ".toggle", false);
} }
public static void SetPlayerSilentChestStatus(String name, boolean status) { public static void setPlayerSilentChestStatus(String name, boolean status) {
mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status); mainPlugin.getConfig().set("SilentChest." + name.toLowerCase() + ".toggle", status);
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
public static boolean GetPlayerAnyChestStatus(String name) { public static boolean getPlayerAnyChestStatus(String name) {
return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true); return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true);
} }
public static void SetPlayerAnyChestStatus(String name, boolean status) { public static void setPlayerAnyChestStatus(String name, boolean status) {
mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status); mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status);
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
public static int GetItemOpenInvItem() { public static int getItemOpenInvItem() {
if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) { if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) {
SaveToConfig("ItemOpenInvItemID", 280); saveToConfig("ItemOpenInvItemID", 280);
} }
return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280); return mainPlugin.getConfig().getInt("ItemOpenInvItemID", 280);
} }
public static Object GetFromConfig(String data, Object defaultValue) { public static Object getFromConfig(String data, Object defaultValue) {
Object val = mainPlugin.getConfig().get(data); Object val = mainPlugin.getConfig().get(data);
if (val == null) { if (val == null) {
mainPlugin.getConfig().set(data, defaultValue); mainPlugin.getConfig().set(data, defaultValue);
@ -142,7 +142,7 @@ public class OpenInv extends JavaPlugin {
} }
} }
public static void SaveToConfig(String data, Object value) { public static void saveToConfig(String data, Object value) {
mainPlugin.getConfig().set(data, value); mainPlugin.getConfig().set(data, value);
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
@ -162,7 +162,7 @@ public class OpenInv extends JavaPlugin {
e.printStackTrace(); e.printStackTrace();
} }
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> - Open 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 enderchest"); player.sendMessage(ChatColor.GREEN + "/openender <Player> - Open a player's enderchest");

View file

@ -40,15 +40,15 @@ public class AnyChestPluginCommand implements CommandExecutor {
if (args.length > 0) { if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) { if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerAnyChestStatus(sender.getName())) if (OpenInv.getPlayerAnyChestStatus(sender.getName()))
sender.sendMessage("AnyChest is ON."); sender.sendMessage("AnyChest is ON.");
else else
sender.sendMessage("AnyChest is OFF."); sender.sendMessage("AnyChest is OFF.");
} }
} }
OpenInv.SetPlayerAnyChestStatus(sender.getName(), !OpenInv.GetPlayerAnyChestStatus(sender.getName())); OpenInv.setPlayerAnyChestStatus(sender.getName(), !OpenInv.getPlayerAnyChestStatus(sender.getName()));
sender.sendMessage("AnyChest is now " + (OpenInv.GetPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + "."); sender.sendMessage("AnyChest is now " + (OpenInv.getPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true; return true;
} }

View file

@ -49,12 +49,12 @@ public class OpenEnderPluginCommand implements CommandExecutor {
} }
if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) { if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchests."); sender.sendMessage(ChatColor.RED + "You do not have permission to access player ender chests.");
return true; return true;
} }
if (args.length > 0 && args[0].equalsIgnoreCase("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender); OpenInv.showHelp((Player) sender);
return true; return true;
} }
@ -129,13 +129,13 @@ public class OpenEnderPluginCommand implements CommandExecutor {
} }
if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) { if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest"); player.sendMessage(ChatColor.RED + "You do not have permission to access other player's ender chests");
return; return;
} }
// Permissions checks // Permissions checks
if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) { if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s enderchest is protected!"); player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s ender chest is protected!");
return; return;
} }

View file

@ -53,7 +53,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
} }
if (args.length > 0 && args[0].equalsIgnoreCase("?")) { if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
OpenInv.ShowHelp((Player) sender); OpenInv.showHelp((Player) sender);
return true; return true;
} }

View file

@ -40,15 +40,15 @@ public class SilentChestPluginCommand implements CommandExecutor {
if (args.length > 0) { if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) { if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerSilentChestStatus(sender.getName())) if (OpenInv.getPlayerSilentChestStatus(sender.getName()))
sender.sendMessage("SilentChest is ON."); sender.sendMessage("SilentChest is ON.");
else else
sender.sendMessage("SilentChest is OFF."); sender.sendMessage("SilentChest is OFF.");
} }
} }
OpenInv.SetPlayerSilentChestStatus(sender.getName(), !OpenInv.GetPlayerSilentChestStatus(sender.getName())); OpenInv.setPlayerSilentChestStatus(sender.getName(), !OpenInv.getPlayerSilentChestStatus(sender.getName()));
sender.sendMessage("SilentChest is now " + (OpenInv.GetPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + "."); sender.sendMessage("SilentChest is now " + (OpenInv.getPlayerSilentChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true; return true;
} }

View file

@ -43,19 +43,19 @@ public class ToggleOpenInvPluginCommand implements CommandExecutor {
Player player = (Player) sender; Player player = (Player) sender;
if (args.length > 0) { if (args.length > 0) {
if (args[0].equalsIgnoreCase("check")) { if (args[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName())) if (OpenInv.getPlayerItemOpenInvStatus(player.getName()))
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON."); player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON.");
else else
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF."); player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF.");
} }
} }
if (OpenInv.GetPlayerItemOpenInvStatus(player.getName())) { if (OpenInv.getPlayerItemOpenInvStatus(player.getName())) {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false); OpenInv.setPlayerItemOpenInvStatus(player.getName(), false);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF."); player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is OFF.");
} }
else { else {
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true); OpenInv.setPlayerItemOpenInvStatus(player.getName(), true);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON."); player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.getItemOpenInvItem()).toString() + " is ON.");
} }
return true; return true;
} }

View file

@ -124,7 +124,7 @@ public class AnySilentChest {
boolean returnValue = true; boolean returnValue = true;
if (silentchest) { if (silentchest) {
tileInventory = new SilentInventory(tileInventory); tileInventory = new SilentInventory(tileInventory);
if (OpenInv.NotifySilentChest()) { if (OpenInv.notifySilentChest()) {
p.sendMessage("You are opening a chest silently."); p.sendMessage("You are opening a chest silently.");
} }
returnValue = false; returnValue = false;
@ -132,7 +132,7 @@ public class AnySilentChest {
player.openContainer(tileInventory); player.openContainer(tileInventory);
if (anychest && OpenInv.NotifyAnyChest()) { if (anychest && OpenInv.notifyAnyChest()) {
p.sendMessage("You are opening a blocked chest."); p.sendMessage("You are opening a blocked chest.");
} }

View file

@ -11,7 +11,7 @@ public enum EnumDirectionList implements Iterable<EnumDirection> {
HORIZONTAL(EnumDirectionLimit.HORIZONTAL), HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
VERTICAL(EnumDirectionLimit.VERTICAL); VERTICAL(EnumDirectionLimit.VERTICAL);
private EnumDirectionLimit list; private final EnumDirectionLimit list;
private EnumDirectionList(EnumDirectionLimit list) { private EnumDirectionList(EnumDirectionLimit list) {
this.list = list; this.list = list;

View file

@ -111,10 +111,12 @@ public class SilentInventory implements ITileInventory {
return inv.getContents(); return inv.getContents();
} }
@Override
public void onOpen(CraftHumanEntity craftHumanEntity) { public void onOpen(CraftHumanEntity craftHumanEntity) {
inv.onOpen(craftHumanEntity); inv.onOpen(craftHumanEntity);
} }
@Override
public void onClose(CraftHumanEntity craftHumanEntity) { public void onClose(CraftHumanEntity craftHumanEntity) {
inv.onClose(craftHumanEntity); inv.onClose(craftHumanEntity);
} }

View file

@ -28,9 +28,9 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*; import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
public class SpecialEnderChest extends InventorySubcontainer { public class SpecialEnderChest extends InventorySubcontainer {
private CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private CraftPlayer owner; private final CraftPlayer owner;
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player p, Boolean online) {

View file

@ -27,9 +27,9 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.*;
import org.bukkit.craftbukkit.v1_8_R3.inventory.*; import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
public class SpecialPlayerInventory extends PlayerInventory { public class SpecialPlayerInventory extends PlayerInventory {
private CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private CraftPlayer owner; private final CraftPlayer owner;
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player p, boolean online) { public SpecialPlayerInventory(Player p, boolean online) {

View file

@ -41,7 +41,7 @@ public class OpenInvEntityListener implements Listener {
Player player = (Player) attacker; Player player = (Player) attacker;
if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, "OpenInv.openinv")) { if (!(player.getItemInHand().getType().getId() == OpenInv.getItemOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, "OpenInv.openinv")) {
return; return;
} }

View file

@ -79,7 +79,7 @@ public class OpenInvPlayerListener implements Listener {
} }
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.GetPlayerSilentChestStatus(player.getName())) { if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) {
event.setCancelled(true); event.setCancelled(true);
player.openInventory(player.getEnderChest()); player.openInventory(player.getEnderChest());
} }
@ -92,11 +92,11 @@ public class OpenInvPlayerListener implements Listener {
int y = event.getClickedBlock().getY(); int y = event.getClickedBlock().getY();
int z = event.getClickedBlock().getZ(); int z = event.getClickedBlock().getZ();
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.GetPlayerSilentChestStatus(player.getName())) { if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) {
silentchest = true; silentchest = true;
} }
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.GetPlayerAnyChestStatus(player.getName())) { if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player.getName())) {
try { try {
anychest = OpenInv.anySilentChest.IsAnyChestNeeded(player, x, y, z); anychest = OpenInv.anySilentChest.IsAnyChestNeeded(player, x, y, z);
} }
@ -129,7 +129,7 @@ public class OpenInvPlayerListener implements Listener {
} }
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { if (!(player.getItemInHand().getType().getId() == OpenInv.getItemOpenInvItem()) || (!OpenInv.getPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
return; return;
} }

View file

@ -1,6 +1,6 @@
name: OpenInv name: OpenInv
main: com.lishid.openinv.OpenInv main: com.lishid.openinv.OpenInv
version: 2.2.9 version: 2.3.0
author: lishid author: lishid
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.