General refactoring

This commit is contained in:
ShadowRanger 2015-06-22 20:15:28 +10:00
parent d988becf1f
commit ded568ec3f
16 changed files with 53 additions and 52 deletions

1
.gitignore vendored
View file

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

View file

@ -4,7 +4,7 @@
<groupId>com.lishid</groupId>
<artifactId>openinv</artifactId>
<packaging>jar</packaging>
<version>2.2.9</version>
<version>2.3.0</version>
<name>OpenInv</name>
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>

View file

@ -67,13 +67,13 @@ public class OpenInv extends JavaPlugin {
mainPlugin = this;
FileConfiguration config = getConfig();
config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
config.set("notifySilentChest", config.getBoolean("notifySilentChest", true));
config.set("notifyAnyChest", config.getBoolean("notifyAnyChest", true));
config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
config.addDefault("ItemOpenInvItemID", 280);
config.addDefault("CheckForUpdates", true);
config.addDefault("NotifySilentChest", true);
config.addDefault("NotifyAnyChest", true);
config.addDefault("notifySilentChest", true);
config.addDefault("notifyAnyChest", true);
config.options().copyDefaults(true);
saveConfig();
@ -89,49 +89,49 @@ public class OpenInv extends JavaPlugin {
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
}
public static boolean NotifySilentChest() {
return mainPlugin.getConfig().getBoolean("NotifySilentChest", true);
public static boolean notifySilentChest() {
return mainPlugin.getConfig().getBoolean("notifySilentChest", true);
}
public static boolean NotifyAnyChest() {
return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true);
public static boolean notifyAnyChest() {
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);
}
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.saveConfig();
}
public static boolean GetPlayerSilentChestStatus(String name) {
public static boolean getPlayerSilentChestStatus(String name) {
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.saveConfig();
}
public static boolean GetPlayerAnyChestStatus(String name) {
public static boolean getPlayerAnyChestStatus(String name) {
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.saveConfig();
}
public static int GetItemOpenInvItem() {
public static int getItemOpenInvItem() {
if (mainPlugin.getConfig().get("ItemOpenInvItemID") == null) {
SaveToConfig("ItemOpenInvItemID", 280);
saveToConfig("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);
if (val == null) {
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.saveConfig();
}
@ -162,7 +162,7 @@ public class OpenInv extends JavaPlugin {
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 + " (aliases: oi, inv, open)");
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[0].equalsIgnoreCase("check")) {
if (OpenInv.GetPlayerAnyChestStatus(sender.getName()))
if (OpenInv.getPlayerAnyChestStatus(sender.getName()))
sender.sendMessage("AnyChest is ON.");
else
sender.sendMessage("AnyChest is OFF.");
}
}
OpenInv.SetPlayerAnyChestStatus(sender.getName(), !OpenInv.GetPlayerAnyChestStatus(sender.getName()));
sender.sendMessage("AnyChest is now " + (OpenInv.GetPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
OpenInv.setPlayerAnyChestStatus(sender.getName(), !OpenInv.getPlayerAnyChestStatus(sender.getName()));
sender.sendMessage("AnyChest is now " + (OpenInv.getPlayerAnyChestStatus(sender.getName()) ? "On" : "Off") + ".");
return true;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -111,10 +111,12 @@ public class SilentInventory implements ITileInventory {
return inv.getContents();
}
@Override
public void onOpen(CraftHumanEntity craftHumanEntity) {
inv.onOpen(craftHumanEntity);
}
@Override
public void onClose(CraftHumanEntity 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.*;
public class SpecialEnderChest extends InventorySubcontainer {
private CraftInventory inventory = new CraftInventory(this);
private InventoryEnderChest enderChest;
private CraftPlayer owner;
private final CraftInventory inventory = new CraftInventory(this);
private final InventoryEnderChest enderChest;
private final CraftPlayer owner;
private boolean playerOnline = false;
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.*;
public class SpecialPlayerInventory extends PlayerInventory {
private CraftInventory inventory = new CraftInventory(this);
private ItemStack[] extra = new ItemStack[5];
private CraftPlayer owner;
private final CraftInventory inventory = new CraftInventory(this);
private final ItemStack[] extra = new ItemStack[5];
private final CraftPlayer owner;
private boolean playerOnline = false;
public SpecialPlayerInventory(Player p, boolean online) {

View file

@ -41,7 +41,7 @@ public class OpenInvEntityListener implements Listener {
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;
}

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 (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.GetPlayerSilentChestStatus(player.getName())) {
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player.getName())) {
event.setCancelled(true);
player.openInventory(player.getEnderChest());
}
@ -92,11 +92,11 @@ public class OpenInvPlayerListener implements Listener {
int y = event.getClickedBlock().getY();
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;
}
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.GetPlayerAnyChestStatus(player.getName())) {
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player.getName())) {
try {
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 (!(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;
}

View file

@ -1,6 +1,6 @@
name: OpenInv
main: com.lishid.openinv.OpenInv
version: 2.2.9
version: 2.3.0
author: lishid
description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time.