diff --git a/src/lishid/openinv/OpenInv.java b/src/lishid/openinv/OpenInv.java index 9dbc46c..9c5cc92 100644 --- a/src/lishid/openinv/OpenInv.java +++ b/src/lishid/openinv/OpenInv.java @@ -82,6 +82,22 @@ public class OpenInv extends JavaPlugin { } } + public static boolean GetPlayerItemOpenInvStatus(String name) + { + return config.getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false); + } + + public static void SetPlayerItemOpenInvStatus(String name, boolean status) + { + config.setProperty("ItemOpenInv." + name.toLowerCase() + ".toggle", status); + config.save(); + } + + public static int GetItemOpenInvItem() + { + return config.getInt("ItemOpenInvItemID", 280); + } + public static Object GetFromConfig(String data, Object defaultValue) { Object val = config.getProperty(data); diff --git a/src/lishid/openinv/OpenInvEntityListener.java b/src/lishid/openinv/OpenInvEntityListener.java index 28fee5d..12620bc 100644 --- a/src/lishid/openinv/OpenInvEntityListener.java +++ b/src/lishid/openinv/OpenInvEntityListener.java @@ -1,8 +1,5 @@ package lishid.openinv; -import lishid.openinv.utils.OpenInvToggleState; - -import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -29,9 +26,8 @@ public class OpenInvEntityListener extends EntityListener{ Player player = (Player)attacker; - if(!(player.getItemInHand().getType() == Material.STICK) - || (OpenInvToggleState.openInvState.get(player.getName()) == null) - || !(OpenInvToggleState.openInvState.get(player.getName()) == 1) + if(!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) + || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !PermissionRelay.hasPermission(player, "openinv")) { return; diff --git a/src/lishid/openinv/OpenInvPlayerListener.java b/src/lishid/openinv/OpenInvPlayerListener.java index d571b26..e421af0 100644 --- a/src/lishid/openinv/OpenInvPlayerListener.java +++ b/src/lishid/openinv/OpenInvPlayerListener.java @@ -1,6 +1,6 @@ package lishid.openinv; -import lishid.openinv.utils.OpenInvToggleState; +import net.minecraft.server.Block; import org.bukkit.Material; import org.bukkit.block.Sign; @@ -35,11 +35,17 @@ public class OpenInvPlayerListener extends PlayerListener{ { if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if(event.getClickedBlock() == Block.CHEST || + event.getClickedBlock() == Block.FURNACE || + event.getClickedBlock() == Block.DISPENSER) + { + return; + } + Player player = event.getPlayer(); if(!(player.getItemInHand().getType() == Material.STICK) - || (OpenInvToggleState.openInvState.get(player.getName()) == null) - || !(OpenInvToggleState.openInvState.get(player.getName()) == 1) + || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !PermissionRelay.hasPermission(player, "openinv")) { return; diff --git a/src/lishid/openinv/commands/OpenInvPluginCommand.java b/src/lishid/openinv/commands/OpenInvPluginCommand.java index e8cd90a..94ae1d8 100644 --- a/src/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/lishid/openinv/commands/OpenInvPluginCommand.java @@ -4,13 +4,13 @@ import java.util.HashMap; import lishid.openinv.PermissionRelay; import lishid.openinv.OpenInv; -import lishid.openinv.utils.OpenInvToggleState; import lishid.openinv.utils.PlayerInventoryChest; import lishid.openinv.utils.OpenInvHistory; import net.minecraft.server.EntityPlayer; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -50,21 +50,21 @@ public class OpenInvPluginCommand implements CommandExecutor { { if(args[0].equalsIgnoreCase("check")) { - if(OpenInvToggleState.openInvState.containsKey(player.getName())) - player.sendMessage("OpenInv with stick is ON."); + if(OpenInv.GetPlayerItemOpenInvStatus(player.getName())) + player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON."); else - player.sendMessage("OpenInv with stick is OFF."); + player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF."); } } - if(OpenInvToggleState.openInvState.containsKey(player.getName())) + if(OpenInv.GetPlayerItemOpenInvStatus(player.getName())) { - OpenInvToggleState.openInvState.remove(player.getName()); - player.sendMessage("OpenInv with stick is OFF."); + OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false); + player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF."); } else { - OpenInvToggleState.openInvState.put(player.getName(), 1); - player.sendMessage("OpenInv with stick is ON."); + OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true); + player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON."); } return true; } diff --git a/src/lishid/openinv/utils/OpenInvToggleState.java b/src/lishid/openinv/utils/OpenInvToggleState.java deleted file mode 100644 index 3d5853a..0000000 --- a/src/lishid/openinv/utils/OpenInvToggleState.java +++ /dev/null @@ -1,7 +0,0 @@ -package lishid.openinv.utils; - -import java.util.HashMap; - -public class OpenInvToggleState { - public static HashMap openInvState = new HashMap(); -} diff --git a/src/plugin.yml b/src/plugin.yml index a13ca0d..862bbbf 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: lishid.openinv.OpenInv -version: 1.4.2 +version: 1.4.3 author: lishid description: > This plugin allows you to open another player's inventory as a chest