mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 10:39:05 +00:00
Refactor GuiSlot implementation.
This commit is contained in:
parent
b0c311e0ea
commit
e9a6da45fe
@ -46,7 +46,7 @@ import mineverse.Aust1n46.chat.command.chat.Channel;
|
|||||||
import mineverse.Aust1n46.chat.command.mute.MuteContainer;
|
import mineverse.Aust1n46.chat.command.mute.MuteContainer;
|
||||||
import mineverse.Aust1n46.chat.database.Database;
|
import mineverse.Aust1n46.chat.database.Database;
|
||||||
import mineverse.Aust1n46.chat.database.PlayerData;
|
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.json.JsonFormatInfo;
|
||||||
import mineverse.Aust1n46.chat.listeners.ChatListener;
|
import mineverse.Aust1n46.chat.listeners.ChatListener;
|
||||||
import mineverse.Aust1n46.chat.listeners.CommandListener;
|
import mineverse.Aust1n46.chat.listeners.CommandListener;
|
||||||
@ -80,7 +80,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
// Misc --------------------------------
|
// Misc --------------------------------
|
||||||
public static AliasInfo aaInfo;
|
public static AliasInfo aaInfo;
|
||||||
public static JsonFormatInfo jfInfo;
|
public static JsonFormatInfo jfInfo;
|
||||||
public static GuiSlotInfo gsInfo;
|
|
||||||
public boolean quickchat = true;
|
public boolean quickchat = true;
|
||||||
private static final Logger log = Logger.getLogger("Minecraft");
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
@ -157,7 +156,8 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
// Channel information reference
|
// Channel information reference
|
||||||
aaInfo = new AliasInfo(this);
|
aaInfo = new AliasInfo(this);
|
||||||
jfInfo = new JsonFormatInfo(this);
|
jfInfo = new JsonFormatInfo(this);
|
||||||
gsInfo = new GuiSlotInfo();
|
|
||||||
|
GuiSlot.initialize();
|
||||||
|
|
||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
||||||
PlayerData.loadLegacyPlayerData();
|
PlayerData.loadLegacyPlayerData();
|
||||||
|
@ -105,7 +105,7 @@ public class VentureChatGui implements VentureCommand {
|
|||||||
skull.setDurability((short) 3);
|
skull.setDurability((short) 3);
|
||||||
inv.setItem(0, skull);
|
inv.setItem(0, skull);
|
||||||
|
|
||||||
for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) {
|
for(GuiSlot g : GuiSlot.getGuiSlots()) {
|
||||||
if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
|
if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
|
||||||
if(this.checkSlot(g.getSlot())) {
|
if(this.checkSlot(g.getSlot())) {
|
||||||
MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + 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);
|
skull.setDurability((short) 3);
|
||||||
inv.setItem(0, skull);
|
inv.setItem(0, skull);
|
||||||
|
|
||||||
for(GuiSlot g : MineverseChat.gsInfo.getGuiSlots()) {
|
for(GuiSlot g : GuiSlot.getGuiSlots()) {
|
||||||
if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
|
if(!g.hasPermission() || mcp.getPlayer().hasPermission(g.getPermission())) {
|
||||||
if(this.checkSlot(g.getSlot())) {
|
if(this.checkSlot(g.getSlot())) {
|
||||||
MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
|
MineverseChat.getInstance().getServer().getConsoleSender().sendMessage(Format.FormatStringAll("&cGUI: " + g.getName() + " has invalid slot: " + g.getSlot() + "!"));
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
package mineverse.Aust1n46.chat.gui;
|
package mineverse.Aust1n46.chat.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import mineverse.Aust1n46.chat.MineverseChat;
|
||||||
|
|
||||||
public class GuiSlot {
|
public class GuiSlot {
|
||||||
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
|
private static List<GuiSlot> guiSlots = new ArrayList<GuiSlot>();
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
private String command;
|
private String command;
|
||||||
private String permission;
|
private String permission;
|
||||||
@ -21,32 +30,50 @@ public class GuiSlot {
|
|||||||
this.slot = slot;
|
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() {
|
public String getText() {
|
||||||
return this.text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommand() {
|
public String getCommand() {
|
||||||
return this.command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return this.permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getIcon() {
|
public Material getIcon() {
|
||||||
return this.icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDurability() {
|
public int getDurability() {
|
||||||
return this.durability;
|
return durability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSlot() {
|
public int getSlot() {
|
||||||
return this.slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission() {
|
public boolean hasPermission() {
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -252,7 +252,7 @@ public class CommandListener implements CommandExecutor, Listener {
|
|||||||
mcp.getPlayer().closeInventory();
|
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()) {
|
if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
|
||||||
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
|
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
|
||||||
if(target != null) {
|
if(target != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user