From e9a6da45feed96bae81997f7869a44f86d4ed151 Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Thu, 15 Apr 2021 23:10:46 -0500 Subject: [PATCH] Refactor GuiSlot implementation. --- .../Aust1n46/chat/MineverseChat.java | 6 +- .../chat/command/chat/VentureChatGui.java | 4 +- src/mineverse/Aust1n46/chat/gui/GuiSlot.java | 55 ++++++++++++++----- .../Aust1n46/chat/gui/GuiSlotInfo.java | 46 ---------------- .../chat/listeners/CommandListener.java | 2 +- 5 files changed, 47 insertions(+), 66 deletions(-) delete mode 100644 src/mineverse/Aust1n46/chat/gui/GuiSlotInfo.java diff --git a/src/mineverse/Aust1n46/chat/MineverseChat.java b/src/mineverse/Aust1n46/chat/MineverseChat.java index f794eba..fe60424 100644 --- a/src/mineverse/Aust1n46/chat/MineverseChat.java +++ b/src/mineverse/Aust1n46/chat/MineverseChat.java @@ -46,7 +46,7 @@ import mineverse.Aust1n46.chat.command.chat.Channel; import mineverse.Aust1n46.chat.command.mute.MuteContainer; import mineverse.Aust1n46.chat.database.Database; import mineverse.Aust1n46.chat.database.PlayerData; -import mineverse.Aust1n46.chat.gui.GuiSlotInfo; +import mineverse.Aust1n46.chat.gui.GuiSlot; import mineverse.Aust1n46.chat.json.JsonFormatInfo; import mineverse.Aust1n46.chat.listeners.ChatListener; import mineverse.Aust1n46.chat.listeners.CommandListener; @@ -80,7 +80,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener { // Misc -------------------------------- public static AliasInfo aaInfo; public static JsonFormatInfo jfInfo; - public static GuiSlotInfo gsInfo; public boolean quickchat = true; private static final Logger log = Logger.getLogger("Minecraft"); @@ -157,7 +156,8 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener { // Channel information reference aaInfo = new AliasInfo(this); jfInfo = new JsonFormatInfo(this); - gsInfo = new GuiSlotInfo(); + + GuiSlot.initialize(); Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data")); PlayerData.loadLegacyPlayerData(); diff --git a/src/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java b/src/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java index fddf716..2819926 100644 --- a/src/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java +++ b/src/mineverse/Aust1n46/chat/command/chat/VentureChatGui.java @@ -105,7 +105,7 @@ public class VentureChatGui implements VentureCommand { skull.setDurability((short) 3); inv.setItem(0, skull); - for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) { + for(GuiSlot g : GuiSlot.getGuiSlots()) { if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) { if(this.checkSlot(g.getSlot())) { MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!")); @@ -164,7 +164,7 @@ public class VentureChatGui implements VentureCommand { skull.setDurability((short) 3); inv.setItem(0, skull); - for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) { + for(GuiSlot g : GuiSlot.getGuiSlots()) { if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) { if(this.checkSlot(g.getSlot())) { MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!")); diff --git a/src/mineverse/Aust1n46/chat/gui/GuiSlot.java b/src/mineverse/Aust1n46/chat/gui/GuiSlot.java index 41a4e4a..5ca5c89 100644 --- a/src/mineverse/Aust1n46/chat/gui/GuiSlot.java +++ b/src/mineverse/Aust1n46/chat/gui/GuiSlot.java @@ -1,8 +1,17 @@ package mineverse.Aust1n46.chat.gui; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; + +import mineverse.Aust1n46.chat.MineverseChat; public class GuiSlot { + private static MineverseChat plugin = MineverseChat.getInstance(); + private static List guiSlots = new ArrayList(); + private String text; private String command; private String permission; @@ -10,7 +19,7 @@ public class GuiSlot { private String name; private int durability; private int slot; - + public GuiSlot(String name, String icon, int durability, String text, String permission, String command, int slot) { this.name = name; this.text = text; @@ -21,35 +30,53 @@ public class GuiSlot { this.slot = slot; } + public static void initialize() { + ConfigurationSection cs = plugin.getConfig().getConfigurationSection("venturegui"); + for (String key : cs.getKeys(false)) { + String name = key; + String icon = cs.getString(key + ".icon"); + int durability = cs.getInt(key + ".durability"); + String text = cs.getString(key + ".text"); + String permission = cs.getString(key + ".permission"); + String command = cs.getString(key + ".command"); + int slot = cs.getInt(key + ".slot"); + guiSlots.add(new GuiSlot(name, icon, durability, text, permission, command, slot)); + } + } + + public static List getGuiSlots() { + return guiSlots; + } + public String getText() { - return this.text; + return text; } public String getCommand() { - return this.command; - } + return command; + } public String getPermission() { - return this.permission; + return permission; } public Material getIcon() { - return this.icon; + return icon; } - + public int getDurability() { - return this.durability; + return durability; } - + public String getName() { - return this.name; + return name; } - + public int getSlot() { - return this.slot; + return slot; } - + public boolean hasPermission() { return !permission.equalsIgnoreCase("venturechat.none"); } -} \ No newline at end of file +} diff --git a/src/mineverse/Aust1n46/chat/gui/GuiSlotInfo.java b/src/mineverse/Aust1n46/chat/gui/GuiSlotInfo.java deleted file mode 100644 index 8a66cb1..0000000 --- a/src/mineverse/Aust1n46/chat/gui/GuiSlotInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -package mineverse.Aust1n46.chat.gui; - -import org.bukkit.configuration.ConfigurationSection; - -import mineverse.Aust1n46.chat.MineverseChat; - -public class GuiSlotInfo { - private GuiSlot[] gs; - private MineverseChat plugin = MineverseChat.getInstance(); - - public GuiSlotInfo() { - String name; - String text; - String icon; - int durability; - String command; - String permission; - int slot; - ConfigurationSection cs = plugin.getConfig().getConfigurationSection("venturegui"); - gs = new GuiSlot[cs.getKeys(false).size()]; - int x = 0; - for(String key : cs.getKeys(false)) { - name = key; - icon = cs.getString(key + ".icon"); - durability = cs.getInt(key + ".durability"); - text = cs.getString(key + ".text"); - permission = cs.getString(key + ".permission"); - command = cs.getString(key + ".command"); - slot = cs.getInt(key + ".slot"); - GuiSlot g = new GuiSlot(name, icon, durability, text, permission, command, slot); - gs[x ++] = g; - } - } - - public GuiSlot[] getGuiSlots() { - return this.gs; - } - - public GuiSlot getGuiSlot(String name) { - for(GuiSlot g : this.gs) { - if(g.getName().equalsIgnoreCase(name)) - return g; - } - return null; - } -} \ No newline at end of file diff --git a/src/mineverse/Aust1n46/chat/listeners/CommandListener.java b/src/mineverse/Aust1n46/chat/listeners/CommandListener.java index 710494e..e75dde1 100644 --- a/src/mineverse/Aust1n46/chat/listeners/CommandListener.java +++ b/src/mineverse/Aust1n46/chat/listeners/CommandListener.java @@ -252,7 +252,7 @@ public class CommandListener implements CommandExecutor, Listener { mcp.getPlayer().closeInventory(); } } - for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) { + for(GuiSlot g : GuiSlot.getGuiSlots()) { if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) { String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + ""); if(target != null) {