Refactor GuiSlot implementation.

This commit is contained in:
Aust1n46 2021-04-15 23:10:46 -05:00
parent b0c311e0ea
commit e9a6da45fe
5 changed files with 47 additions and 66 deletions

View File

@ -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();

View File

@ -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() + "!"));

View File

@ -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<GuiSlot> guiSlots = new ArrayList<GuiSlot>();
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<GuiSlot> 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");
}
}
}

View File

@ -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;
}
}

View File

@ -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) {