Skip to content

Commit

Permalink
Fixes for Client UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jun 6, 2021
1 parent ba6af4d commit b707f2c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 15 deletions.
Expand Up @@ -89,7 +89,7 @@ public void click(InventoryClickEvent event) {
} 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())) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public void click(InventoryClickEvent event) {
} 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())) {
Expand All @@ -219,7 +219,7 @@ public void click(InventoryClickEvent event) {
} 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<PluginRenderer<Host>> plugin = new Container<PluginRenderer<Host>>(null);
for (PluginRenderer<Host> renderer : DefaultUIRenderer.hostPlugins.values()) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public void click(InventoryClickEvent event) {
} 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));
}
Expand All @@ -281,7 +281,7 @@ public void click(InventoryClickEvent event) {
} 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())) {
Expand Down Expand Up @@ -424,7 +424,7 @@ public void run(ObjectMap<String> json) {
} 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<PluginRenderer<SubServer>> plugin = new Container<PluginRenderer<SubServer>>(null);
for (PluginRenderer<SubServer> renderer : DefaultUIRenderer.subserverPlugins.values()) {
Expand Down
@@ -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;
}
}
Expand Up @@ -6,6 +6,7 @@
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;
Expand All @@ -19,11 +20,13 @@ public final class SubAPI extends ClientAPI {
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
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;
}

Expand Down Expand Up @@ -107,6 +110,26 @@ public Map<String, String> getLang(String channel) {
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
*
Expand Down
Expand Up @@ -23,7 +23,7 @@
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;
Expand All @@ -35,7 +35,7 @@

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) {
Expand Down
Expand Up @@ -11,7 +11,6 @@
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;
Expand All @@ -35,6 +34,8 @@
import java.util.*;
import java.util.concurrent.TimeUnit;

import static net.ME1312.SubServers.Client.Bukkit.Library.AccessMode.*;

/**
* SubServers Client Plugin Class
*/
Expand Down Expand Up @@ -116,16 +117,16 @@ public void onEnable() {
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();
}

Expand Down
@@ -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;
}
}
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -21,11 +22,13 @@ public final class SubAPI extends ClientAPI {
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
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;
}

Expand Down Expand Up @@ -109,6 +112,26 @@ public Map<String, String> getLang(String channel) {
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
*
Expand Down
Expand Up @@ -44,6 +44,8 @@
import java.util.*;
import java.util.concurrent.TimeUnit;

import static net.ME1312.SubServers.Client.Sponge.Library.AccessMode.NO_COMMANDS;

/**
* SubServers Client Plugin Class
*/
Expand All @@ -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;

Expand Down Expand Up @@ -136,8 +138,8 @@ public void enable(GameInitializationEvent event) {
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");
}

Expand Down

0 comments on commit b707f2c

Please sign in to comment.