From b707f2cc0c250d0bad9316466a761472322fd5b6 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sun, 6 Jun 2021 17:01:28 -0400 Subject: [PATCH] Fixes for Client UI --- .../Bukkit/Graphic/DefaultUIHandler.java | 12 +++++----- .../Client/Bukkit/Library/AccessMode.java | 15 ++++++++++++ .../SubServers/Client/Bukkit/SubAPI.java | 23 +++++++++++++++++++ .../SubServers/Client/Bukkit/SubCommand.java | 4 ++-- .../SubServers/Client/Bukkit/SubPlugin.java | 9 ++++---- .../Client/Sponge/Library/AccessMode.java | 15 ++++++++++++ .../SubServers/Client/Sponge/SubAPI.java | 23 +++++++++++++++++++ .../SubServers/Client/Sponge/SubPlugin.java | 8 ++++--- 8 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/AccessMode.java create mode 100644 SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Library/AccessMode.java diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/DefaultUIHandler.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/DefaultUIHandler.java index 8a99dc6a..7756dec5 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/DefaultUIHandler.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/DefaultUIHandler.java @@ -89,7 +89,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Host-Menu.Server-Menu"))) { player.closeInventory(); gui.serverMenu(1, null, null); - } else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.api.getLang("SubServers", "Interface.Host-Menu.No-Hosts"))) { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.Host-Menu.No-Hosts"))) { player.closeInventory(); String obj; if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get(0).startsWith(ChatColor.GRAY.toString())) { @@ -193,7 +193,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { player.closeInventory(); gui.hostCreator((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]); - } else { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Template.No-Templates"))) { player.closeInventory(); String obj; if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get(0).startsWith(ChatColor.GRAY.toString())) { @@ -219,7 +219,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { player.closeInventory(); gui.back(); - } else { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.Host-Plugin.No-Plugins"))) { player.closeInventory(); final Value> plugin = new Container>(null); for (PluginRenderer renderer : DefaultUIRenderer.hostPlugins.values()) { @@ -254,7 +254,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Group-Menu.Server-Menu"))) { player.closeInventory(); gui.serverMenu(1, null, null); - } else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.api.getLang("SubServers", "Interface.Group-Menu.No-Groups"))) { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.Group-Menu.No-Groups"))) { player.closeInventory(); gui.serverMenu(1, null, ChatColor.stripColor(item)); } @@ -281,7 +281,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { player.closeInventory(); gui.back(); - } else if (!item.equals(ChatColor.RESET.toString()) && !item.startsWith(ChatColor.WHITE.toString()) && !item.equals(plugin.api.getLang("SubServers", "Interface.Server-Menu.No-Servers"))) { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.startsWith(ChatColor.WHITE.toString()) && !item.equals(plugin.api.getLang("SubServers", "Interface.Server-Menu.No-Servers"))) { player.closeInventory(); String obj; if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get(0).startsWith(ChatColor.GRAY.toString())) { @@ -424,7 +424,7 @@ public class DefaultUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) { player.closeInventory(); gui.back(); - } else { + } else if ((item.length() != 0 && !item.equals(ChatColor.RESET.toString())) && !item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.No-Plugins"))) { player.closeInventory(); Value> plugin = new Container>(null); for (PluginRenderer renderer : DefaultUIRenderer.subserverPlugins.values()) { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/AccessMode.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/AccessMode.java new file mode 100644 index 00000000..3a052169 --- /dev/null +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/AccessMode.java @@ -0,0 +1,15 @@ +package net.ME1312.SubServers.Client.Bukkit.Library; + +/** + * SubServers.Client Access Mode Enum + */ +public enum AccessMode { + DEFAULT(0), + NO_COMMANDS(-1), + NO_INTEGRATIONS(-2), + ; + public final byte value; + AccessMode(int value) { + this.value = (byte) value; + } +} diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java index b6dff8a1..40551091 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubAPI.java @@ -6,6 +6,7 @@ import net.ME1312.SubData.Client.DataClient; import net.ME1312.SubData.Client.DataProtocol; import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler; +import net.ME1312.SubServers.Client.Bukkit.Library.AccessMode; import net.ME1312.SubServers.Client.Common.ClientAPI; import org.bukkit.Bukkit; @@ -19,11 +20,13 @@ public final class SubAPI extends ClientAPI { LinkedList reloadListeners = new LinkedList(); private final SubPlugin plugin; private static SubAPI api; + AccessMode access; String name; SubAPI(SubPlugin plugin) { this.plugin = plugin; GAME_VERSION = getGameVersion(); + access = AccessMode.DEFAULT; api = this; } @@ -107,6 +110,26 @@ public final class SubAPI extends ClientAPI { return new LinkedHashMap<>(plugin.lang.value().get(channel.toLowerCase())); } + /** + * Get the plugin's access mode + * + * @return Access Mode + */ + public AccessMode getAccessMode() { + return access; + } + + /** + * Set the plugin's access mode + * + * @param mode Access Mode + */ + public void setAccessMode(AccessMode mode) { + if (mode.value <= access.value && !plugin.isEnabled()) { + access = mode; + } + } + /** * Gets the Graphics Handler * diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java index 952ea190..abca994a 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java @@ -23,7 +23,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.command.defaults.BukkitCommand; +import org.bukkit.command.Command; import org.bukkit.entity.Player; import java.io.BufferedReader; @@ -35,7 +35,7 @@ import java.util.*; import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permits; -public final class SubCommand extends BukkitCommand { +public final class SubCommand extends Command { private SubPlugin plugin; public SubCommand(SubPlugin plugin, String name) { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java index 237471f9..711ecf8b 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java @@ -11,7 +11,6 @@ import net.ME1312.SubData.Client.DataClient; import net.ME1312.SubData.Client.Encryption.AES; import net.ME1312.SubData.Client.Encryption.DHE; import net.ME1312.SubData.Client.Encryption.RSA; -import net.ME1312.SubData.Client.Library.DataSize; import net.ME1312.SubData.Client.Library.DisconnectReason; import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubServers.Client.Bukkit.Graphic.DefaultUIHandler; @@ -35,6 +34,8 @@ import java.nio.file.StandardCopyOption; import java.util.*; import java.util.concurrent.TimeUnit; +import static net.ME1312.SubServers.Client.Bukkit.Library.AccessMode.*; + /** * SubServers Client Plugin Class */ @@ -116,16 +117,16 @@ public final class SubPlugin extends JavaPlugin { System.out.println("SubData > Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391")); connect(null); - if (!config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) { + gui = new DefaultUIHandler(this); + if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) { CommandMap cmd = Util.reflect(Bukkit.getServer().getClass().getDeclaredField("commandMap"), Bukkit.getServer()); - gui = new DefaultUIHandler(this); cmd.register("subservers", new SubCommand(this, "subservers")); cmd.register("subservers", new SubCommand(this, "subserver")); cmd.register("subservers", new SubCommand(this, "sub")); } - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + if (api.access.value > NO_INTEGRATIONS.value && Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new net.ME1312.SubServers.Client.Bukkit.Library.Compatibility.PlaceholderImpl(this).register(); } diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Library/AccessMode.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Library/AccessMode.java new file mode 100644 index 00000000..0de9d8a3 --- /dev/null +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Library/AccessMode.java @@ -0,0 +1,15 @@ +package net.ME1312.SubServers.Client.Sponge.Library; + +/** + * SubServers.Client Access Mode Enum + */ +public enum AccessMode { + DEFAULT(0), + NO_COMMANDS(-1), + NO_INTEGRATIONS(-2), + ; + public final byte value; + AccessMode(int value) { + this.value = (byte) value; + } +} diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubAPI.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubAPI.java index d67f953c..b7c6ad3e 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubAPI.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubAPI.java @@ -7,6 +7,7 @@ import net.ME1312.SubData.Client.DataProtocol; import net.ME1312.SubData.Client.SubDataClient; import net.ME1312.SubServers.Client.Common.ClientAPI; import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler; +import net.ME1312.SubServers.Client.Sponge.Library.AccessMode; import org.spongepowered.api.Platform; import org.spongepowered.api.Sponge; @@ -21,11 +22,13 @@ public final class SubAPI extends ClientAPI { LinkedList reloadListeners = new LinkedList(); private final SubPlugin plugin; private static SubAPI api; + AccessMode access; String name; SubAPI(SubPlugin plugin) { this.plugin = plugin; GAME_VERSION = getGameVersion(); + access = AccessMode.DEFAULT; api = this; } @@ -109,6 +112,26 @@ public final class SubAPI extends ClientAPI { return new LinkedHashMap<>(plugin.lang.value().get(channel.toLowerCase())); } + /** + * Get the plugin's access mode + * + * @return Access Mode + */ + public AccessMode getAccessMode() { + return access; + } + + /** + * Set the plugin's access mode + * + * @param mode Access Mode + */ + public void setAccessMode(AccessMode mode) { + if (mode.value <= access.value && !plugin.running) { + access = mode; + } + } + /** * Gets the Graphics Handler * diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java index aa1c3c55..8943cdd2 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java @@ -44,6 +44,8 @@ import java.nio.file.StandardCopyOption; import java.util.*; import java.util.concurrent.TimeUnit; +import static net.ME1312.SubServers.Client.Sponge.Library.AccessMode.NO_COMMANDS; + /** * SubServers Client Plugin Class */ @@ -63,7 +65,7 @@ public final class SubPlugin { @Inject public PluginContainer plugin; @Inject public Game game; - private boolean running = false; + boolean running = false; private long resetDate = 0; private boolean reconnect = false; @@ -136,8 +138,8 @@ public final class SubPlugin { log.info("Connecting to /" + config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391")); connect(null); - if (!config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) { - //gui = new InternalUIHandler(this); + //gui = new InternalUIHandler(this); + if (api.access.value > NO_COMMANDS.value && !config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) { Sponge.getCommandManager().register(plugin, new SubCommand(this).spec(), "sub", "subserver", "subservers"); }