Update GalaxiEngine

This commit is contained in:
ME1312 2020-11-14 02:07:25 -05:00
parent c0197759f4
commit 8d21771857
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
68 changed files with 674 additions and 631 deletions

View File

@ -30,13 +30,13 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,6 +1,6 @@
package net.ME1312.SubServers.Bungee.Library.Compatibility;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor;
@ -39,7 +39,7 @@ public abstract class CommandX extends Command implements TabExecutor {
* @param args Arguments (including the final unfinished one)
* @return An Error Message (if there was one, otherwise null) and a List of Suggestions
*/
public abstract NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args);
public abstract Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args);
/**
* Override the BungeeCord Method of {@link #suggestArguments(CommandSender, String[])}
@ -50,6 +50,6 @@ public abstract class CommandX extends Command implements TabExecutor {
*/
@Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
return suggestArguments(sender, args).get();
return suggestArguments(sender, args).value();
}
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.md_5.bungee.api.CommandSender;
import java.util.LinkedList;
@ -34,7 +35,7 @@ public class CommandX extends net.ME1312.SubServers.Bungee.Library.Compatibility
}
@Override
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
public Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
return command.suggestArguments(sender, args);
}
@ -43,27 +44,27 @@ public class CommandX extends net.ME1312.SubServers.Bungee.Library.Compatibility
*
* @param sender Sender
* @param command Command to validate
* @return NamedContainer with a String error message and a Integer that represents where the command was deemed invalid
* @return Pair with a String error message and a Integer that represents where the command was deemed invalid
*/
public NamedContainer<String, Integer> validateCommand(CommandSender sender, String command) {
List<NamedContainer<String, Integer>> split = new LinkedList<NamedContainer<String, Integer>>();
public Pair<String, Integer> validateCommand(CommandSender sender, String command) {
List<Pair<String, Integer>> split = new LinkedList<Pair<String, Integer>>();
String cmd = command;
int i;
while ((i = cmd.indexOf((int) ' ')) < 0) {
i++;
String arg = cmd.substring(i);
split.add(new NamedContainer<>(arg.contains(" ")?arg.substring(0, arg.indexOf((int) ' ')):arg, i));
split.add(new ContainedPair<>(arg.contains(" ")?arg.substring(0, arg.indexOf((int) ' ')):arg, i));
cmd = arg;
}
List<String> args = new LinkedList<String>();
NamedContainer<String, Integer> response = null;
Pair<String, Integer> response = null;
i = 0;
for (NamedContainer<String, Integer> arg : split) {
for (Pair<String, Integer> arg : split) {
if (i > 0) {
args.add(arg.name());
NamedContainer<String, List<String>> suggestions = suggestArguments(sender, args.toArray(new String[args.size() - 1]));
if (suggestions.name() != null) response = new NamedContainer<>(suggestions.name(), arg.get());
args.add(arg.key());
Pair<String, List<String>> suggestions = suggestArguments(sender, args.toArray(new String[args.size() - 1]));
if (suggestions.key() != null) response = new ContainedPair<>(suggestions.key(), arg.value());
}
i++;
}

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -50,7 +50,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Bungee.Event;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubServers.Bungee.Library.SubEvent;
import net.ME1312.Galaxi.Library.Util;
import net.md_5.bungee.api.plugin.Cancellable;
@ -18,7 +19,7 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
private boolean cancelled = false;
private UUID player;
private Server server;
private NamedContainer<String, ObjectMapValue> edit;
private Pair<String, ObjectMapValue> edit;
private boolean perm;
/**
@ -29,13 +30,13 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, Server server, NamedContainer<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, Server server, Pair<String, ?> edit, boolean permanent) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.get());
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new NamedContainer<String, ObjectMapValue>(edit.name(), section.get("."));
this.edit = new ContainedPair<String, ObjectMapValue>(edit.key(), section.get("."));
this.perm = permanent;
}
@ -58,7 +59,7 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
*
* @return Edit to be made
*/
public NamedContainer<String, ObjectMapValue> getEdit() {
public Pair<String, ObjectMapValue> getEdit() {
return edit;
}

View File

@ -3,8 +3,10 @@ package net.ME1312.SubServers.Bungee.Host.External;
import com.google.common.collect.Range;
import net.ME1312.Galaxi.Library.*;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
import net.ME1312.SubServers.Bungee.Event.SubCreatedEvent;
@ -36,9 +38,9 @@ public class ExternalSubCreator extends SubCreator {
private Boolean enableRT = false;
private ExternalHost host;
private Range<Integer> ports;
private Container<Boolean> log;
private Value<Boolean> log;
private String gitBash;
private TreeMap<String, NamedContainer<Integer, ExternalSubLogger>> thread;
private TreeMap<String, Pair<Integer, ExternalSubLogger>> thread;
/**
* Creates an External SubCreator
@ -55,7 +57,7 @@ public class ExternalSubCreator extends SubCreator {
this.ports = ports;
this.log = new Container<Boolean>(log);
this.gitBash = gitBash;
this.thread = new TreeMap<String, NamedContainer<Integer, ExternalSubLogger>>();
this.thread = new TreeMap<String, Pair<Integer, ExternalSubLogger>>();
reload();
}
@ -93,15 +95,15 @@ public class ExternalSubCreator extends SubCreator {
Container<Integer> i = new Container<Integer>(ports.lowerEndpoint() - 1);
port = Util.getNew(getAllReservedAddresses(), () -> {
do {
i.set(i.get() + 1);
if (i.get() > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
} while (!ports.contains(i.get()));
return new InetSocketAddress(host.getAddress(), i.get());
++i.value;
if (i.value > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
} while (!ports.contains(i.value));
return new InetSocketAddress(host.getAddress(), i.value);
}).getPort();
}
String prefix = name + File.separator + "Creator";
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
thread.put(name.toLowerCase(), new NamedContainer<>(port, logger));
thread.put(name.toLowerCase(), new ContainedPair<>(port, logger));
final int fport = port;
final SubCreateEvent event = new SubCreateEvent(player, host, name, template, version, port);
@ -140,7 +142,7 @@ public class ExternalSubCreator extends SubCreator {
String prefix = name + File.separator + "Updater";
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, true));
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
thread.put(name.toLowerCase(), new NamedContainer<>(server.getAddress().getPort(), logger));
thread.put(name.toLowerCase(), new ContainedPair<>(server.getAddress().getPort(), logger));
final SubCreateEvent event = new SubCreateEvent(player, server, version);
host.plugin.getPluginManager().callEvent(event);
@ -230,7 +232,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void terminate() {
HashMap<String, NamedContainer<Integer, ExternalSubLogger>> thread = new HashMap<String, NamedContainer<Integer, ExternalSubLogger>>();
HashMap<String, Pair<Integer, ExternalSubLogger>> thread = new HashMap<String, Pair<Integer, ExternalSubLogger>>();
thread.putAll(this.thread);
for (String i : thread.keySet()) {
terminate(i);
@ -247,7 +249,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void waitFor() throws InterruptedException {
HashMap<String, NamedContainer<Integer, ExternalSubLogger>> thread = new HashMap<String, NamedContainer<Integer, ExternalSubLogger>>();
HashMap<String, Pair<Integer, ExternalSubLogger>> thread = new HashMap<String, Pair<Integer, ExternalSubLogger>>();
thread.putAll(this.thread);
for (String i : thread.keySet()) {
waitFor(i);
@ -285,7 +287,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public List<SubLogger> getLoggers() {
List<SubLogger> loggers = new ArrayList<SubLogger>();
HashMap<String, NamedContainer<Integer, ExternalSubLogger>> temp = new HashMap<String, NamedContainer<Integer, ExternalSubLogger>>();
HashMap<String, Pair<Integer, ExternalSubLogger>> temp = new HashMap<String, Pair<Integer, ExternalSubLogger>>();
temp.putAll(thread);
for (String i : temp.keySet()) {
loggers.add(getLogger(i));
@ -295,18 +297,18 @@ public class ExternalSubCreator extends SubCreator {
@Override
public SubLogger getLogger(String name) {
return this.thread.get(name.toLowerCase()).get();
return this.thread.get(name.toLowerCase()).value();
}
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
log.set(value);
log.value(value);
}
@Override
@ -317,7 +319,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public List<Integer> getReservedPorts() {
List<Integer> ports = new ArrayList<Integer>();
for (NamedContainer<Integer, ExternalSubLogger> task : thread.values()) ports.add(task.name());
for (Pair<Integer, ExternalSubLogger> task : thread.values()) ports.add(task.key());
return ports;
}

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Host.External;
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
import net.ME1312.SubServers.Bungee.Host.SubLogger;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketInExLogMessage;
@ -29,7 +29,7 @@ public class ExternalSubLogger extends SubLogger {
private Object handle;
UUID id = null;
String name;
Container<Boolean> log;
Value<Boolean> log;
private List<SubLogFilter> filters = new CopyOnWriteArrayList<>();
File file;
private PrintWriter writer = null;
@ -43,7 +43,7 @@ public class ExternalSubLogger extends SubLogger {
* @param log Console Logging Status
* @param file File to log to (or null for disabled)
*/
ExternalSubLogger(Object user, String name, Container<Boolean> log, File file) {
ExternalSubLogger(Object user, String name, Value<Boolean> log, File file) {
this.handle = user;
this.name = name;
this.log = log;
@ -103,7 +103,7 @@ public class ExternalSubLogger extends SubLogger {
}
// Filter Message
boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.get() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo));
boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.value() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo));
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
filters.addAll(this.filters);
for (SubLogFilter filter : filters)
@ -182,6 +182,6 @@ public class ExternalSubLogger extends SubLogger {
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
}

View File

@ -1,14 +1,16 @@
package net.ME1312.SubServers.Bungee.Host.External;
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.SubServers.Bungee.Event.*;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExEditServer;
import net.md_5.bungee.BungeeServerInfo;
@ -27,7 +29,7 @@ import java.util.UUID;
public class ExternalSubServer extends SubServerImpl {
private ExternalHost host;
private boolean enabled;
private Container<Boolean> log;
private Value<Boolean> log;
private String dir;
String exec;
private String stopcmd;
@ -222,7 +224,7 @@ public class ExternalSubServer extends SubServerImpl {
for (String key : edit.getKeys()) {
pending.remove(key);
ObjectMapValue value = edit.get(key);
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value), perma);
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
try {
@ -335,8 +337,8 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "log":
if (value.isBoolean()) {
if (log.get() != value.asBoolean()) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value.asBoolean()));
log.set(value.asBoolean());
if (log.value() != value.asBoolean()) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value.asBoolean()));
log.value(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
this.host.plugin.servers.save();
@ -505,7 +507,7 @@ public class ExternalSubServer extends SubServerImpl {
public void setDisplayName(String value) {
super.setDisplayName(value);
logger.name = getDisplayName();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("display", value), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", value), false));
}
@Override
@ -521,22 +523,22 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("enabled", value), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("enabled", value), false));
if (enabled != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_ENABLED, (Boolean) value));
enabled = value;
}
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("log", value), false));
if (log.get() != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value));
log.set(value);
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("log", value), false));
if (log.value() != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value));
log.value(value);
}
@Override
@ -567,7 +569,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-cmd", value), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-cmd", value), false));
if (!stopcmd.equals(value)) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_STOP_COMMAND, value));
stopcmd = value;
}
@ -580,7 +582,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-action", action), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-action", action), false));
stopaction = action;
}
}

View File

@ -5,8 +5,10 @@ import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.*;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
import net.ME1312.SubServers.Bungee.Event.SubCreatedEvent;
@ -42,7 +44,7 @@ public class InternalSubCreator extends SubCreator {
private HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
private InternalHost host;
private Range<Integer> ports;
private Container<Boolean> log;
private Value<Boolean> log;
private String gitBash;
private TreeMap<String, CreatorTask> thread;
@ -379,13 +381,13 @@ public class InternalSubCreator extends SubCreator {
StackTraceElement[] origin = new Exception().getStackTrace();
if (port == null) {
Container<Integer> i = new Container<Integer>(ports.lowerEndpoint() - 1);
Value<Integer> i = new Container<Integer>(ports.lowerEndpoint() - 1);
port = Util.getNew(getAllReservedAddresses(), () -> {
do {
i.set(i.get() + 1);
if (i.get() > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
} while (!ports.contains(i.get()));
return new InetSocketAddress(host.getAddress(), i.get());
i.value(i.value() + 1);
if (i.value() > ports.upperEndpoint()) throw new IllegalStateException("There are no more ports available in range: " + ports.toString());
} while (!ports.contains(i.value()));
return new InetSocketAddress(host.getAddress(), i.value());
}).getPort();
}
@ -522,13 +524,13 @@ public class InternalSubCreator extends SubCreator {
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
log.set(value);
log.value(value);
}
@Override
@ -554,15 +556,15 @@ public class InternalSubCreator extends SubCreator {
return getTemplates().get(name.toLowerCase());
}
private static NamedContainer<YAMLSection, Map<String, Object>> subdata = null;
private static Pair<YAMLSection, Map<String, Object>> subdata = null;
private Map<String, Object> getSubData() {
if (subdata == null || host.plugin.config.get() != subdata.name()) {
if (subdata == null || host.plugin.config.get() != subdata.key()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("Address", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1").replace("0.0.0.0", "127.0.0.1"));
if (host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) map.put("Password", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password"));
subdata = new NamedContainer<>(host.plugin.config.get(), map);
subdata = new ContainedPair<>(host.plugin.config.get(), map);
}
return subdata.get();
return subdata.value();
}
private void generateClient(File dir, ServerType type, String name) throws IOException {

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee.Host.Internal;
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
import net.ME1312.SubServers.Bungee.Host.SubLogger;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.SubAPI;
@ -24,7 +24,7 @@ public class InternalSubLogger extends SubLogger {
Process process;
private Object handle;
String name;
Container<Boolean> log;
Value<Boolean> log;
private List<SubLogFilter> filters = new CopyOnWriteArrayList<>();
File file;
private PrintWriter writer = null;
@ -41,7 +41,7 @@ public class InternalSubLogger extends SubLogger {
* @param log Console Logging Status
* @param file File to log to (or null for disabled)
*/
InternalSubLogger(Process process, Object user, String name, Container<Boolean> log, File file) {
InternalSubLogger(Process process, Object user, String name, Value<Boolean> log, File file) {
this.process = process;
this.handle = user;
this.name = name;
@ -121,7 +121,7 @@ public class InternalSubLogger extends SubLogger {
}
// Filter Message
boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.get() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo));
boolean allow = (SubAPI.getInstance().getInternals().sudo == getHandler() && SubAPI.getInstance().getInternals().canSudo) || (log.value() && (SubAPI.getInstance().getInternals().sudo == null || !SubAPI.getInstance().getInternals().canSudo));
List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
filters.addAll(this.filters);
for (SubLogFilter filter : filters)
@ -199,6 +199,6 @@ public class InternalSubLogger extends SubLogger {
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
}

View File

@ -1,13 +1,15 @@
package net.ME1312.SubServers.Bungee.Host.Internal;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.SubServers.Bungee.Event.*;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -30,7 +32,7 @@ import java.util.jar.JarInputStream;
public class InternalSubServer extends SubServerImpl {
private InternalHost host;
private boolean enabled;
private Container<Boolean> log;
private Value<Boolean> log;
private String dir;
private File directory;
private String executable;
@ -287,7 +289,7 @@ public class InternalSubServer extends SubServerImpl {
for (String key : edit.getKeys()) {
pending.remove(key);
ObjectMapValue value = edit.get(key);
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
SubEditServerEvent event = new SubEditServerEvent(player, this, new ContainedPair<String, ObjectMapValue>(key, value), perma);
host.plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
try {
@ -397,7 +399,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "log":
if (value.isBoolean()) {
log.set(value.asBoolean());
log.value(value.asBoolean());
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
this.host.plugin.servers.save();
@ -577,20 +579,20 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("enabled", value), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("enabled", value), false));
enabled = value;
}
@Override
public boolean isLogging() {
return log.get();
return log.value();
}
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("log", value), false));
log.set(value);
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("log", value), false));
log.value(value);
}
@Override
@ -621,7 +623,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-cmd", value), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-cmd", value), false));
stopcmd = value;
}
@ -633,7 +635,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-action", action), false));
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("stop-action", action), false));
stopaction = action;
}
}

View File

@ -6,7 +6,7 @@ import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.ExtraDataHandler;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExSyncPlayer;

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.ExtraDataHandler;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubData.Server.DataClient;
import net.md_5.bungee.api.config.ServerInfo;

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubEditServerEvent;
@ -8,7 +9,7 @@ import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExRunEvent;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExUpdateWhitelist;
@ -126,10 +127,10 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@SuppressWarnings("deprecation")
public void setDisplayName(String value) {
if (value == null || value.length() == 0 || getName().equals(value)) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("display", getName()), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", getName()), false));
this.nick = null;
} else {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("display", value), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("display", value), false));
this.nick = value;
}
}
@ -177,14 +178,14 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@SuppressWarnings("deprecation")
public void setHidden(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("hidden", value), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("hidden", value), false));
this.hidden = value;
}
@SuppressWarnings("deprecation")
public void setMotd(String value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("motd", value), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("motd", value), false));
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, value);
} catch (Exception e) {
@ -195,7 +196,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@SuppressWarnings("deprecation")
public void setRestricted(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("restricted", value), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("restricted", value), false));
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value);
} catch (Exception e) {

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubServers.Bungee.Event.SubEditServerEvent;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubServers.Bungee.SubAPI;
import java.io.File;
@ -15,7 +16,7 @@ import java.util.*;
* SubServer Layout Class
*/
public abstract class SubServerImpl extends ServerImpl implements SubServer {
private List<NamedContainer<String, String>> incompatibilities = new ArrayList<NamedContainer<String, String>>();
private List<Pair<String, String>> incompatibilities = new ArrayList<Pair<String, String>>();
private SubCreator.ServerTemplate templateV = null;
private String templateS = null;
protected boolean started;
@ -107,14 +108,14 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
@Override
public void setTemplate(String template) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("template", template), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("template", template), false));
this.templateV = null;
this.templateS = template;
}
@Override
public void setTemplate(SubCreator.ServerTemplate template) {
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("template", (template != null)?template.getName():null), false));
SubAPI.getInstance().getInternals().getPluginManager().callEvent(new SubEditServerEvent(null, this, new ContainedPair<String, Object>("template", (template != null)?template.getName():null), false));
this.templateV = template;
this.templateS = (template != null)?template.getName():null;
}
@ -139,7 +140,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
public void toggleCompatibility(SubServer... server) {
for (SubServer s : server) {
if (!equals(s)) {
NamedContainer<String, String> info = new NamedContainer<String, String>(s.getHost().getName(), s.getName());
Pair<String, String> info = new ContainedPair<String, String>(s.getHost().getName(), s.getName());
if (isCompatible(s)) {
incompatibilities.add(info);
if (s.isCompatible(this)) toggleCompatibility(this);
@ -153,17 +154,17 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
@Override
public boolean isCompatible(SubServer server) {
return !incompatibilities.contains(new NamedContainer<String, String>(server.getHost().getName(), server.getName()));
return !incompatibilities.contains(new ContainedPair<String, String>(server.getHost().getName(), server.getName()));
}
@Override
public List<SubServer> getIncompatibilities() {
List<SubServer> servers = new ArrayList<SubServer>();
List<NamedContainer<String, String>> temp = new ArrayList<NamedContainer<String, String>>();
List<Pair<String, String>> temp = new ArrayList<Pair<String, String>>();
temp.addAll(incompatibilities);
for (NamedContainer<String, String> info : temp) {
for (Pair<String, String> info : temp) {
try {
SubServer server = SubAPI.getInstance().getHost(info.name()).getSubServer(info.get());
SubServer server = SubAPI.getInstance().getHost(info.key()).getSubServer(info.value());
if (server == null) throw new NullPointerException();
servers.add(server);
} catch (Throwable e) {

View File

@ -148,8 +148,8 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
ObjectMap<String> args = new ObjectMap<String>();
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
args.set("server", event.getServer().getName());
args.set("edit", event.getEdit().name());
args.set("value", event.getEdit().get().asObject());
args.set("edit", event.getEdit().key());
args.set("value", event.getEdit().value().asObject());
args.set("perm", event.isPermanent());
broadcast(new PacketOutExRunEvent(event.getClass(), args));
}

View File

@ -156,7 +156,7 @@ public class SubProtocol extends SubDataProtocol {
subdata.on.connect(client -> {
if (!plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(client.getServer(), client)).isCancelled()) {
client.on.ready(c -> plugin.getPluginManager().callEvent(new SubNetworkLoginEvent(c.getServer(), c)));
client.on.closed(c -> plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent(c.get().getServer(), c.get(), c.name())));
client.on.closed(c -> plugin.getPluginManager().callEvent(new SubNetworkDisconnectEvent(c.value().getServer(), c.value(), c.key())));
return true;
} else return false;
});

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee;
import com.google.common.collect.Range;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.SubData.Server.DataProtocol;
import net.ME1312.SubData.Server.DataServer;
import net.ME1312.SubServers.Bungee.Event.SubAddHostEvent;
@ -9,7 +10,7 @@ import net.ME1312.SubServers.Bungee.Event.SubRemoveHostEvent;
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -363,10 +364,10 @@ public final class SubAPI implements BungeeAPI {
* @param name Group name
* @return a Server Group
*/
public NamedContainer<String, List<Server>> getGroup(String name) {
public Pair<String, List<Server>> getGroup(String name) {
if (Util.isNull(name)) throw new NullPointerException();
for (Map.Entry<String, List<Server>> group : getLowercaseGroups().entrySet()) {
if (group.getKey().equalsIgnoreCase(name)) return new NamedContainer<>(group.getKey(), group.getValue());
if (group.getKey().equalsIgnoreCase(name)) return new ContainedPair<>(group.getKey(), group.getValue());
}
return null;
}
@ -535,7 +536,7 @@ public final class SubAPI implements BungeeAPI {
}
/**
* Get the Master Proxy Container
* Get the Master Proxy Value
*
* @return Master Proxy
*/

View File

@ -3,12 +3,13 @@ package net.ME1312.SubServers.Bungee;
import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.SubServers.Bungee.Library.Compatibility.CommandX;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.ClientHandler;
@ -41,17 +42,17 @@ import static net.ME1312.SubServers.Bungee.Library.Compatibility.Galaxi.GalaxiCo
*/
@SuppressWarnings("deprecation")
public final class SubCommand extends CommandX {
static HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>> players = new HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>>();
static HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>> players = new HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>>();
private SubProxy plugin;
private String label;
static NamedContainer<SubCommand, CommandX> newInstance(SubProxy plugin, String command) {
NamedContainer<SubCommand, CommandX> cmd = new NamedContainer<>(new SubCommand(plugin, command), null);
CommandX now = cmd.name();
static Pair<SubCommand, CommandX> newInstance(SubProxy plugin, String command) {
Pair<SubCommand, CommandX> cmd = new ContainedPair<>(new SubCommand(plugin, command), null);
CommandX now = cmd.key();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
// now = new net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
cmd.value(now);
return cmd;
}
@ -175,7 +176,7 @@ public final class SubCommand extends CommandX {
message += ChatColor.GOLD + group + ChatColor.RESET + ": ";
List<String> names = new ArrayList<String>();
Map<String, Server> servers = plugin.api.getServers();
for (Server server : plugin.api.getGroup(group).get()) names.add(server.getName());
for (Server server : plugin.api.getGroup(group).value()) names.add(server.getName());
Collections.sort(names);
for (String name : names) {
if (i != 0) message += div;
@ -322,11 +323,11 @@ public final class SubCommand extends CommandX {
}
};
Runnable getGroup = () -> {
NamedContainer<String, List<Server>> group = plugin.api.getGroup(name);
Pair<String, List<Server>> group = plugin.api.getGroup(name);
if (group != null) {
sender.sendMessage("SubServers > Info on group: " + ChatColor.WHITE + group.name());
sender.sendMessage(" -> Servers: " + ((group.get().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.get().size()));
for (Server server : group.get()) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
sender.sendMessage("SubServers > Info on group: " + ChatColor.WHITE + group.key());
sender.sendMessage(" -> Servers: " + ((group.value().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.value().size()));
for (Server server : group.value()) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
} else {
if (type == null) {
getServer.run();
@ -853,31 +854,31 @@ public final class SubCommand extends CommandX {
* @return The validator's response and list of possible arguments
*/
@SuppressWarnings("unchecked")
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
public Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
String Last = (args.length > 0)?args[args.length - 1]:"";
String last = Last.toLowerCase();
if (sender instanceof ProxiedPlayer && (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| !players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).get())) {
|| !players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).value())) {
if (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) && players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
&& players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() == null) {
&& players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() == null) {
// do nothing
} else if (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| Calendar.getInstance().getTime().getTime() - players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() >= TimeUnit.MINUTES.toMillis(1)) {
|| Calendar.getInstance().getTime().getTime() - players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() >= TimeUnit.MINUTES.toMillis(1)) {
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof Server) || ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), false));
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
} else {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(null, false));
HashMap<ServerInfo, Pair<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(null, false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
((SubDataClient) ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0]).sendPacket(new PacketCheckPermission(((ProxiedPlayer) sender).getUniqueId(), "subservers.command", result -> {
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), result));
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), result));
}));
}
}
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
} else if (args.length <= 1) {
List<String> cmds = new ArrayList<>();
cmds.addAll(Arrays.asList("help", "list", "info", "status", "version", "start", "restart", "stop", "kill", "terminate", "cmd", "command", "create", "update", "upgrade"));
@ -886,7 +887,7 @@ public final class SubCommand extends CommandX {
for (String cmd : cmds) {
if (cmd.startsWith(last)) list.add(Last + cmd.substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
} else {
if (args[0].equals("info") || args[0].equals("status")) {
ReturnRunnable<Collection<String>> getPlayers = () -> {
@ -933,7 +934,7 @@ public final class SubCommand extends CommandX {
if (!list.contains(player) && player.toLowerCase().startsWith(last))
list.add(Last + player.substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
@ -977,9 +978,9 @@ public final class SubCommand extends CommandX {
}
break;
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else if (!(sender instanceof ProxiedPlayer) && (args[0].equals("reload") || args[0].equals("restore"))) {
if (args[0].equals("reload")) {
@ -989,15 +990,15 @@ public final class SubCommand extends CommandX {
for (String complete : completes) {
if (complete.toLowerCase().startsWith(last)) list.add(Last + complete.substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else /* if (args[0].equals("restore")) */ {
if (args.length == 2) {
return new NamedContainer<>(null, Collections.singletonList("<Subserver>"));
return new ContainedPair<>(null, Collections.singletonList("<Subserver>"));
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
}
} else if (args[0].equals("start") ||
@ -1023,7 +1024,7 @@ public final class SubCommand extends CommandX {
if (Arrays.binarySearch(select.selection, name.toLowerCase()) < 0 && name.toLowerCase().startsWith(last)) list.add(Last + name.substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", select.last):null, list);
} else if (last.startsWith(":")) {
Map<String, List<Server>> groups = plugin.api.getGroups();
if (groups.size() > 0) {
@ -1034,7 +1035,7 @@ public final class SubCommand extends CommandX {
if (Arrays.binarySearch(select.selection, group.toLowerCase()) < 0 && group.toLowerCase().startsWith(last)) list.add(Last + group.substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Group").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Group").replace("$str$", select.last):null, list);
} else {
Map<String, SubServer> subservers = plugin.api.getSubServers();
if (subservers.size() > 0) {
@ -1044,31 +1045,31 @@ public final class SubCommand extends CommandX {
if (Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", select.last):null, list);
}
} else if (args[0].equals("cmd") || args[0].equals("command")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Collections.singletonList("<Command>"));
return new ContainedPair<>(null, Collections.singletonList("<Command>"));
} else {
return new NamedContainer<>(null, Collections.singletonList("[Args...]"));
return new ContainedPair<>(null, Collections.singletonList("[Args...]"));
}
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Arrays.asList("[Template]", "[Version]"));
return new ContainedPair<>(null, Arrays.asList("[Template]", "[Version]"));
} else if (select.args.length == 4) {
return new NamedContainer<>(null, Collections.singletonList("<Version>"));
return new ContainedPair<>(null, Collections.singletonList("<Version>"));
}
}
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
} else if (args[0].equals("create")) {
if (args.length == 2) {
return new NamedContainer<>(null, Collections.singletonList("<Name>"));
return new ContainedPair<>(null, Collections.singletonList("<Name>"));
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
for (Host host : plugin.api.getHosts().values()) {
if (host.getName().toLowerCase().startsWith(last)) list.add(Last + host.getName().substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", args[0]):null, list);
} else if (args.length == 4) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = plugin.api.getHosts();
@ -1079,18 +1080,18 @@ public final class SubCommand extends CommandX {
if (template.getName().toLowerCase().startsWith(last)) list.add(Last + template.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
} else if (args.length == 5) {
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
return new ContainedPair<>(null, Collections.singletonList("[Version]"));
} else if (args.length == 6) {
if (last.length() > 0) {
if (Util.isException(() -> Integer.parseInt(last)) || Integer.parseInt(last) <= 0 || Integer.parseInt(last) > 65535) {
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
return new ContainedPair<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
}
}
return new NamedContainer<>(null, Collections.singletonList("[Port]"));
return new ContainedPair<>(null, Collections.singletonList("[Port]"));
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else if (sender instanceof ProxiedPlayer && (args[0].equals("tp") || args[0].equals("teleport"))) {
if (args.length == 2 || args.length == 3) {
@ -1119,12 +1120,12 @@ public final class SubCommand extends CommandX {
for (Server server : plugin.api.getServers().values()) {
if (server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else {
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]), Collections.emptyList());
return new ContainedPair<>(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]), Collections.emptyList());
}
}
}
@ -1149,13 +1150,13 @@ public final class SubCommand extends CommandX {
);
}
static NamedContainer<BungeeServer, CommandX> newInstance(SubProxy plugin, String command) {
NamedContainer<BungeeServer, CommandX> cmd = new NamedContainer<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.name();
static Pair<BungeeServer, CommandX> newInstance(SubProxy plugin, String command) {
Pair<BungeeServer, CommandX> cmd = new ContainedPair<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.key();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
// now = new net.ME1312.SubServers.Bungee.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
cmd.value(now);
return cmd;
}
@ -1211,16 +1212,16 @@ public final class SubCommand extends CommandX {
* @param args Arguments
* @return The validator's response and list of possible arguments
*/
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
public Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
if (args.length <= 1) {
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
List<String> list = new ArrayList<String>();
for (Server server : plugin.api.getServers().values()) {
if (server.getName().toLowerCase().startsWith(last) && !server.isHidden()) list.add(server.getName());
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Bungee.Server.Invalid").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Bungee.Server.Invalid").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
}
}

View File

@ -3,7 +3,7 @@ package net.ME1312.SubServers.Bungee;
import com.dosse.upnp.UPnP;
import com.google.common.collect.Range;
import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
@ -85,7 +85,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
public SubProtocol subprotocol;
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.16.4a");
public static final Version version = Version.fromString("2.17a");
public final Proxy mProxy;
public boolean canSudo = false;
@ -657,13 +657,13 @@ public final class SubProxy extends BungeeCommon implements Listener {
private void post() {
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/server"))
getPluginManager().registerCommand(plugin, SubCommand.BungeeServer.newInstance(this, "server").get());
getPluginManager().registerCommand(plugin, SubCommand.BungeeServer.newInstance(this, "server").value());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(plugin, new SubCommand.BungeeList(this, "glist"));
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "sub").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subservers").value());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subserver").value());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "sub").value());
GalaxiCommand.group(SubCommand.class);
if (getReconnectHandler() != null && getReconnectHandler().getClass().equals(SmartFallback.class))
@ -876,7 +876,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
if (!e.getConnection().getListener().isPingPassthrough()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(override.getMotd()), null));
} else {
PrimitiveContainer<Boolean> lock = new PrimitiveContainer<>(true);
Container<Boolean> lock = new Container<>(true);
boolean mode = plugin != null;
if (mode) e.registerIntent(plugin);
((BungeeServerInfo) override).ping((ping, error) -> {

View File

@ -48,7 +48,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -62,7 +62,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,8 +1,9 @@
package net.ME1312.SubServers.Client.Bukkit.Event;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
import net.ME1312.Galaxi.Library.Util;
import org.bukkit.event.Event;
@ -16,7 +17,7 @@ import java.util.UUID;
public class SubEditServerEvent extends Event implements SubEvent {
private UUID player;
private String server;
private NamedContainer<String, ObjectMapValue<String>> edit;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
@ -27,13 +28,13 @@ public class SubEditServerEvent extends Event implements SubEvent {
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.get());
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.contains(".")?section.get("."):null);
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.contains(".")?section.get("."):null);
this.perm = permanent;
}
@ -56,7 +57,7 @@ public class SubEditServerEvent extends Event implements SubEvent {
*
* @return Edit to be made
*/
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Client.Bukkit.Graphic;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
@ -220,18 +221,18 @@ public class DefaultUIHandler implements UIHandler, Listener {
gui.back();
} else {
player.closeInventory();
final Container<PluginRenderer<Host>> plugin = new Container<PluginRenderer<Host>>(null);
final Value<PluginRenderer<Host>> plugin = new Container<PluginRenderer<Host>>(null);
for (PluginRenderer<Host> renderer : DefaultUIRenderer.hostPlugins.values()) {
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.set(renderer);
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.value(renderer);
}
if (plugin.get() == null) {
if (plugin.value() == null) {
gui.reopen();
} else {
gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.Host-Plugin.Title").replace("$str$", ((Host) gui.lastVisitedObjects[0]).getName())));
this.plugin.api.getHost(((Host) gui.lastVisitedObjects[0]).getName(), host -> {
if (host != null) {
gui.setDownloading(null);
plugin.get().open(player, host);
plugin.value().open(player, host);
} else {
gui.back();
}
@ -348,12 +349,12 @@ public class DefaultUIHandler implements UIHandler, Listener {
player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Container<Boolean> listening = new Container<Boolean>(true);
final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> json) {
try {
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
} else {
Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 5);
@ -364,7 +365,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
((SubServer) gui.lastVisitedObjects[0]).stop(player.getUniqueId(), response -> {
if (response != 0) {
gui.reopen();
listening.set(false);
listening.value(false);
} else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Stop.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName()));
});
} else gui.reopen();
@ -372,12 +373,12 @@ public class DefaultUIHandler implements UIHandler, Listener {
player.closeInventory();
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Container<Boolean> listening = new Container<Boolean>(true);
final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> json) {
try {
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
} else {
gui.reopen();
@ -388,7 +389,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
((SubServer) gui.lastVisitedObjects[0]).terminate(player.getUniqueId(), response -> {
if (response != 0) {
gui.reopen();
listening.set(false);
listening.value(false);
} else gui.setDownloading(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Terminate.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName()));
});
} else gui.reopen();
@ -425,18 +426,18 @@ public class DefaultUIHandler implements UIHandler, Listener {
gui.back();
} else {
player.closeInventory();
Container<PluginRenderer<SubServer>> plugin = new Container<PluginRenderer<SubServer>>(null);
Value<PluginRenderer<SubServer>> plugin = new Container<PluginRenderer<SubServer>>(null);
for (PluginRenderer<SubServer> renderer : DefaultUIRenderer.subserverPlugins.values()) {
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.set(renderer);
if (item.equals(renderer.getIcon().getItemMeta().getDisplayName())) plugin.value(renderer);
}
if (plugin.get() == null) {
if (plugin.value() == null) {
gui.reopen();
} else {
gui.setDownloading(ChatColor.stripColor(this.plugin.api.getLang("SubServers", "Interface.SubServer-Plugin.Title").replace("$str$", ((SubServer) gui.lastVisitedObjects[0]).getName())));
this.plugin.api.getSubServer(((SubServer) gui.lastVisitedObjects[0]).getName(), subserver -> {
if (subserver != null) {
gui.setDownloading(null);
plugin.get().open(player, subserver);
plugin.value().open(player, subserver);
} else {
gui.back();
}

View File

@ -1,7 +1,9 @@
package net.ME1312.SubServers.Client.Bukkit.Graphic;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Common.Network.API.Host;
import net.ME1312.SubServers.Client.Common.Network.API.Server;
@ -116,16 +118,16 @@ public class DefaultUIRenderer extends UIRenderer {
i = ((count < 9) ? ((9 - count) / 2) : 0);
boolean even = (count & 1) == 0 && count < 9;
NamedContainer<String, Short> enabled, disabled;
Pair<String, Short> enabled, disabled;
for (Host host : index) {
if (index.indexOf(host) >= min && index.indexOf(host) <= max) {
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
enabled = (((i & 1) == 0) ? new NamedContainer<>("BLUE_STAINED_GLASS_PANE", (short) 3) : new NamedContainer<>("LIGHT_BLUE_STAINED_GLASS_PANE", (short) 11));
disabled = (((i & 1) == 0) ? new NamedContainer<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new NamedContainer<>("RED_STAINED_GLASS_PANE", (short) 14));
enabled = (((i & 1) == 0) ? new ContainedPair<>("BLUE_STAINED_GLASS_PANE", (short) 3) : new ContainedPair<>("LIGHT_BLUE_STAINED_GLASS_PANE", (short) 11));
disabled = (((i & 1) == 0) ? new ContainedPair<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new ContainedPair<>("RED_STAINED_GLASS_PANE", (short) 14));
if (host.isAvailable() && host.isEnabled()) {
block = createItem("STAINED_GLASS_PANE", enabled.name(), enabled.get());
block = createItem("STAINED_GLASS_PANE", enabled.key(), enabled.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.AQUA + host.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
@ -135,7 +137,7 @@ public class DefaultUIRenderer extends UIRenderer {
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) lore.add(ChatColor.WHITE + host.getAddress().getHostAddress());
blockMeta.setLore(lore);
} else {
block = createItem("STAINED_GLASS_PANE", disabled.name(), disabled.get());
block = createItem("STAINED_GLASS_PANE", disabled.key(), disabled.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.RED + host.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
@ -709,14 +711,14 @@ public class DefaultUIRenderer extends UIRenderer {
i = ((count < 9) ? ((9 - count) / 2) : 0);
boolean even = (count & 1) == 0 && count < 9;
NamedContainer<String, Short> color;
Pair<String, Short> color;
for (String group : index) {
if (index.indexOf(group) >= min && index.indexOf(group) <= max) {
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
color = (((i & 1) == 0) ? new NamedContainer<>("ORANGE_STAINED_GLASS_PANE", (short) 1) : new NamedContainer<>("YELLOW_STAINED_GLASS_PANE", (short) 4));
color = (((i & 1) == 0) ? new ContainedPair<>("ORANGE_STAINED_GLASS_PANE", (short) 1) : new ContainedPair<>("YELLOW_STAINED_GLASS_PANE", (short) 4));
block = createItem("STAINED_GLASS_PANE", color.name(), color.get());
block = createItem("STAINED_GLASS_PANE", color.key(), color.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.GOLD + group);
LinkedList<String> lore = new LinkedList<String>();
@ -785,13 +787,13 @@ public class DefaultUIRenderer extends UIRenderer {
public void serverMenu(final int page, final String host, final String group) {
setDownloading(ChatColor.stripColor((host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", host)));
Container<String> hostname = new Container<String>(host);
Container<List<Server>> servercontainer = new Container<List<Server>>(new LinkedList<Server>());
Value<String> hostname = new Container<String>(host);
Value<List<Server>> servercontainer = new Container<List<Server>>(new LinkedList<Server>());
Runnable renderer = () -> {
setDownloading(null);
lastPage = page;
List<Server> servers = servercontainer.get();
List<Server> servers = servercontainer.value();
lastVisitedObjects[0] = host;
lastVisitedObjects[1] = group;
windowHistory.add(() -> serverMenu(page, host, group));
@ -809,7 +811,7 @@ public class DefaultUIRenderer extends UIRenderer {
int count = (servers.size() == 0)?27:((servers.size() - min >= max)?36:servers.size() - min);
int area = (count % 9 == 0) ? count : ((count / 9) + 1) * 9;
Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", hostname.get()));
Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.api.getLang("SubServers", "Interface.Server-Menu.Title"):plugin.api.getLang("SubServers", "Interface.Group-SubServer.Title").replace("$str$", group)):plugin.api.getLang("SubServers", "Interface.Host-SubServer.Title").replace("$str$", hostname.value()));
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
block.setItemMeta(divMeta);
while (i < area) {
@ -820,19 +822,19 @@ public class DefaultUIRenderer extends UIRenderer {
i = ((count < 9) ? ((9 - count) / 2) : 0);
boolean even = (count & 1) == 0 && count < 9;
NamedContainer<String, Short> external, online, temp, offline, disabled;
Pair<String, Short> external, online, temp, offline, disabled;
for (Server server : servers) {
if (servers.indexOf(server) >= min && servers.indexOf(server) <= max) {
if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv);
external = (((i & 1) == 0) ? new NamedContainer<>("WHITE_STAINED_GLASS_PANE", (short) 0) : new NamedContainer<>("LIGHT_GRAY_STAINED_GLASS_PANE", (short) 8));
online = (((i & 1) == 0) ? new NamedContainer<>("LIME_STAINED_GLASS_PANE", (short) 5) : new NamedContainer<>("GREEN_STAINED_GLASS_PANE", (short) 13));
temp = (((i & 1) == 0) ? new NamedContainer<>("LIGHT_BLUE_STAINED_GLASS_PANE", (short) 3) : new NamedContainer<>("BLUE_STAINED_GLASS_PANE", (short) 11));
offline = (((i & 1) == 0) ? new NamedContainer<>("YELLOW_STAINED_GLASS_PANE", (short) 4) : new NamedContainer<>("ORANGE_STAINED_GLASS_PANE", (short) 1));
disabled = (((i & 1) == 0) ? new NamedContainer<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new NamedContainer<>("RED_STAINED_GLASS_PANE", (short) 14));
external = (((i & 1) == 0) ? new ContainedPair<>("WHITE_STAINED_GLASS_PANE", (short) 0) : new ContainedPair<>("LIGHT_GRAY_STAINED_GLASS_PANE", (short) 8));
online = (((i & 1) == 0) ? new ContainedPair<>("LIME_STAINED_GLASS_PANE", (short) 5) : new ContainedPair<>("GREEN_STAINED_GLASS_PANE", (short) 13));
temp = (((i & 1) == 0) ? new ContainedPair<>("LIGHT_BLUE_STAINED_GLASS_PANE", (short) 3) : new ContainedPair<>("BLUE_STAINED_GLASS_PANE", (short) 11));
offline = (((i & 1) == 0) ? new ContainedPair<>("YELLOW_STAINED_GLASS_PANE", (short) 4) : new ContainedPair<>("ORANGE_STAINED_GLASS_PANE", (short) 1));
disabled = (((i & 1) == 0) ? new ContainedPair<>("MAGENTA_STAINED_GLASS_PANE", (short) 2) : new ContainedPair<>("RED_STAINED_GLASS_PANE", (short) 14));
if (!(server instanceof SubServer)) {
block = createItem("STAINED_GLASS_PANE", external.name(), external.get());
block = createItem("STAINED_GLASS_PANE", external.key(), external.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.WHITE + server.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
@ -844,8 +846,8 @@ public class DefaultUIRenderer extends UIRenderer {
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
blockMeta.setLore(lore);
} else if (((SubServer) server).isRunning()) {
NamedContainer<String, Short> blockinfo = (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER)?temp:online;
block = createItem("STAINED_GLASS_PANE", blockinfo.name(), blockinfo.get());
Pair<String, Short> blockinfo = (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER)?temp:online;
block = createItem("STAINED_GLASS_PANE", blockinfo.key(), blockinfo.value());
blockMeta = block.getItemMeta();
LinkedList<String> lore = new LinkedList<String>();
if (!server.getName().equals(server.getDisplayName()))
@ -858,7 +860,7 @@ public class DefaultUIRenderer extends UIRenderer {
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
blockMeta.setLore(lore);
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
block = createItem("STAINED_GLASS_PANE", offline.name(), offline.get());
block = createItem("STAINED_GLASS_PANE", offline.key(), offline.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.YELLOW + server.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
@ -868,7 +870,7 @@ public class DefaultUIRenderer extends UIRenderer {
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
blockMeta.setLore(lore);
} else {
block = createItem("STAINED_GLASS_PANE", disabled.name(), disabled.get());
block = createItem("STAINED_GLASS_PANE", disabled.key(), disabled.value());
blockMeta = block.getItemMeta();
blockMeta.setDisplayName(ChatColor.RED + server.getDisplayName());
LinkedList<String> lore = new LinkedList<String>();
@ -953,8 +955,8 @@ public class DefaultUIRenderer extends UIRenderer {
if (object == null) {
if (hasHistory()) back();
} else {
hostname.set(object.getDisplayName());
servercontainer.get().addAll(object.getSubServers().values());
hostname.value(object.getDisplayName());
servercontainer.value().addAll(object.getSubServers().values());
renderer.run();
}
});
@ -963,13 +965,13 @@ public class DefaultUIRenderer extends UIRenderer {
if (servers == null) {
if (hasHistory()) back();
} else {
servercontainer.get().addAll(servers.get());
servercontainer.value().addAll(servers.value());
renderer.run();
}
});
} else {
plugin.api.getServers(servers -> {
servercontainer.get().addAll(servers.values());
servercontainer.value().addAll(servers.values());
renderer.run();
});
}

View File

@ -1,7 +1,9 @@
package net.ME1312.SubServers.Client.Bukkit.Graphic;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Common.Network.API.Host;
@ -23,7 +25,7 @@ import java.util.regex.Pattern;
public abstract class UIRenderer {
static HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>();
static HashMap<String, PluginRenderer<SubServer>> subserverPlugins = new HashMap<String, PluginRenderer<SubServer>>();
private NamedContainer<String, Integer> tdownload = null;
private Pair<String, Integer> tdownload = null;
private int download = -1;
private final UUID player;
private SubPlugin plugin;
@ -149,22 +151,22 @@ public abstract class UIRenderer {
download = -1;
}, 50L);
} if (subtitle != null && tdownload == null) {
tdownload = new NamedContainer<String, Integer>(subtitle, 0);
final Container<Integer> delay = new Container<Integer>(0);
tdownload = new ContainedPair<String, Integer>(subtitle, 0);
final Value<Integer> delay = new Container<Integer>(0);
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (tdownload != null) {
String word = ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title"));
int i = 0;
int start = (tdownload.get() - 3 < 0)?0: tdownload.get()-3;
int end = (tdownload.get() >= word.length())?word.length(): tdownload.get();
String str = plugin.api.getLang("SubServers", (delay.get() > 7 && start == 0)?"Interface.Generic.Downloading.Title-Color-Alt":"Interface.Generic.Downloading.Title-Color");
delay.set(delay.get() + 1);
if (delay.get() > 7) tdownload.set(tdownload.get() + 1);
if (tdownload.get() >= word.length() + 3) {
tdownload.set(0);
delay.set(0);
int start = (tdownload.value() - 3 < 0)?0: tdownload.value()-3;
int end = (tdownload.value() >= word.length())?word.length(): tdownload.value();
String str = plugin.api.getLang("SubServers", (delay.value() > 7 && start == 0)?"Interface.Generic.Downloading.Title-Color-Alt":"Interface.Generic.Downloading.Title-Color");
delay.value(delay.value() + 1);
if (delay.value() > 7) tdownload.value(tdownload.value() + 1);
if (tdownload.value() >= word.length() + 3) {
tdownload.value(0);
delay.value(0);
}
for (char c : word.toCharArray()) {
@ -174,7 +176,7 @@ public abstract class UIRenderer {
if (i == end) str += plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color");
}
str += '\n' + plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt") + tdownload.name();
str += '\n' + plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt") + tdownload.key();
sendTitle(str, 0, 10, 5);
Bukkit.getScheduler().runTaskLater(plugin, this, 1);
} else {
@ -183,7 +185,7 @@ public abstract class UIRenderer {
}
});
} else if (subtitle != null) {
tdownload.rename(subtitle);
tdownload.key(subtitle);
} else {
if (tdownload != null) {
tdownload = null;
@ -213,17 +215,17 @@ public abstract class UIRenderer {
* @return ItemStack
*/
public ItemStack parseItem(String str, ItemStack def) {
final Container<String> item = new Container<String>(str);
final Value<String> item = new Container<String>(str);
if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) {
try {
// int
Matcher matcher = Pattern.compile("(?i)^(\\d+)$").matcher(item.get());
Matcher matcher = Pattern.compile("(?i)^(\\d+)$").matcher(item.value());
if (matcher.find()) {
return ItemStack.class.getConstructor(int.class, int.class).newInstance(Integer.parseInt(matcher.group(1)), 1);
}
// int:int
matcher.reset();
matcher = Pattern.compile("(?i)^(\\d+):(\\d+)$").matcher(item.get());
matcher = Pattern.compile("(?i)^(\\d+):(\\d+)$").matcher(item.value());
if (matcher.find()) {
return ItemStack.class.getConstructor(int.class, int.class, short.class).newInstance(Integer.parseInt(matcher.group(1)), 1, Short.parseShort(matcher.group(2)));
}
@ -232,27 +234,27 @@ public abstract class UIRenderer {
}
}
// minecraft:name
if (item.get().toLowerCase().startsWith("minecraft:")) {
item.set(item.get().substring(10));
if (item.value().toLowerCase().startsWith("minecraft:")) {
item.value(item.value().substring(10));
} else
// bukkit:name
if (item.get().toLowerCase().startsWith("bukkit:")) {
item.set(item.get().substring(7));
if (item.value().toLowerCase().startsWith("bukkit:")) {
item.value(item.value().substring(7));
if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) {
return new ItemStack(Material.valueOf(item.get().toUpperCase()), 1);
if (!Util.isException(() -> Material.valueOf(item.value().toUpperCase()))) {
return new ItemStack(Material.valueOf(item.value().toUpperCase()), 1);
}
}
// material name
if (plugin.api.getGameVersion().compareTo(new Version("1.13")) < 0) {
if (!Util.isException(() -> Material.valueOf(item.get().toUpperCase()))) {
return new ItemStack(Material.valueOf(item.get().toUpperCase()), 1);
if (!Util.isException(() -> Material.valueOf(item.value().toUpperCase()))) {
return new ItemStack(Material.valueOf(item.value().toUpperCase()), 1);
}
} else try {
if (Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.get().toUpperCase(), false) != null) {
return new ItemStack((Material) Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.get().toUpperCase(), false), 1);
if (Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.value().toUpperCase(), false) != null) {
return new ItemStack((Material) Material.class.getMethod("getMaterial", String.class, boolean.class).invoke(null, item.value().toUpperCase(), false), 1);
}
} catch (Exception e) {}

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketOut;
@ -35,7 +36,7 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
try {
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new ContainedPair<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Bukkit.getLogger().info("SubData > Lang Settings Downloaded");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();

View File

@ -1,11 +1,12 @@
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Client.Bukkit.Event.*;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
import org.bukkit.Bukkit;
@ -85,7 +86,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
@Override
public void run(ObjectMap<String> data) {
if (plugin.isEnabled()) {
Bukkit.getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new NamedContainer<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
Bukkit.getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
callback("SubEditServerEvent", this);
}
}

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Client.Bukkit.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -166,11 +166,11 @@ public class SubProtocol extends SubDataProtocol {
subdata.sendPacket(new PacketDownloadLang());
subdata.on.ready(client -> Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.value(), client.key());
if (plugin.isEnabled()) {
Bukkit.getPluginManager().callEvent(event);
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", Pair.class), plugin, client));
} else map.put(0, null);
});

View File

@ -92,7 +92,7 @@ public final class SubAPI extends ClientAPI {
* @return SubServers Lang Channel list
*/
public Collection<String> getLangChannels() {
return plugin.lang.get().keySet();
return plugin.lang.value().keySet();
}
/**
@ -103,7 +103,7 @@ public final class SubAPI extends ClientAPI {
*/
public Map<String, String> getLang(String channel) {
if (Util.isNull(channel)) throw new NullPointerException();
return new LinkedHashMap<>(plugin.lang.get().get(channel.toLowerCase()));
return new LinkedHashMap<>(plugin.lang.value().get(channel.toLowerCase()));
}
/**

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Client.Bukkit;
import net.ME1312.Galaxi.Library.*;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
@ -254,9 +255,9 @@ public final class SubCommand extends BukkitCommand {
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "group") + ChatColor.WHITE + group.name());
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers") + ((group.get().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.get().size()));
for (Server server : group.get()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "group") + ChatColor.WHITE + group.key());
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers") + ((group.value().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.value().size()));
for (Server server : group.value()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
} else {
if (type == null) {
getServer.run();
@ -338,8 +339,8 @@ public final class SubCommand extends BukkitCommand {
if (args.length > 1) {
selectServers(sender, args, 1, true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.start"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running").replace("$int$", running.value.toString()));
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start").replace("$int$", success.value.toString()));
@ -437,19 +438,19 @@ public final class SubCommand extends BukkitCommand {
});
// Step 3: Receive command Responses
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart").replace("$int$", success.value.toString()));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
if (data.name() != 0) listening.remove(data.get().getName().toLowerCase());
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
if (data.key() != 0) listening.remove(data.value().getName().toLowerCase());
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", data.get().getName()));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", data.value().getName()));
break;
case 5:
starter.run(data.get());
starter.run(data.value());
case 0:
success.value++;
break;
@ -471,14 +472,14 @@ public final class SubCommand extends BukkitCommand {
merge.reserve();
if (self == null) {
listening.put(server.getName().toLowerCase(), server);
server.stop(player, response -> stopper.run(new NamedContainer<>(response, server)));
server.stop(player, response -> stopper.run(new ContainedPair<>(response, server)));
} else if (self != server) {
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, server.getName(), data -> stopper.run(new NamedContainer<>(data.getInt(0x0001), server))));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, server.getName(), data -> stopper.run(new ContainedPair<>(data.getInt(0x0001), server))));
}
}
if (self != null) {
final SubServer fself = self;
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, self.getName(), data -> stopper.run(new NamedContainer<>(data.getInt(0x0001), fself))));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, self.getName(), data -> stopper.run(new ContainedPair<>(data.getInt(0x0001), fself))));
}
}
});
@ -489,17 +490,17 @@ public final class SubCommand extends BukkitCommand {
if (args.length > 1) {
selectServers(sender, args, 1, true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.stop"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Not-Running").replace("$int$", running.value.toString()));
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop").replace("$int$", success.value.toString()));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Disappeared").replace("$str$", data.get().getName()));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Stop.Disappeared").replace("$str$", data.value().getName()));
break;
case 5:
running.value++;
@ -521,11 +522,11 @@ public final class SubCommand extends BukkitCommand {
for (SubServer server : select.subservers) {
merge.reserve();
if (self != server) server.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new NamedContainer<>(response, server)));
if (self != server) server.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new ContainedPair<>(response, server)));
}
if (self != null) {
final SubServer fself = self;
fself.stop((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new NamedContainer<>(response, fself)));
fself.stop((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new ContainedPair<>(response, fself)));
}
}
});
@ -536,17 +537,17 @@ public final class SubCommand extends BukkitCommand {
if (args.length > 1) {
selectServers(sender, args, 1, true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.terminate"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Not-Running").replace("$int$", running.value.toString()));
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate").replace("$int$", success.value.toString()));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Disappeared").replace("$str$", data.get().getName()));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Terminate.Disappeared").replace("$str$", data.value().getName()));
break;
case 5:
running.value++;
@ -568,11 +569,11 @@ public final class SubCommand extends BukkitCommand {
for (SubServer server : select.subservers) {
merge.reserve();
if (self != server) server.terminate((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new NamedContainer<>(response, server)));
if (self != server) server.terminate((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new ContainedPair<>(response, server)));
}
if (self != null) {
final SubServer fself = self;
fself.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new NamedContainer<>(response, fself)));
fself.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new ContainedPair<>(response, fself)));
}
}
});
@ -590,8 +591,8 @@ public final class SubCommand extends BukkitCommand {
builder.append(select.args[i]);
}
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString()));
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString()));
@ -675,7 +676,7 @@ public final class SubCommand extends BukkitCommand {
Version version = (select.args.length > 2)?new Version(select.args[(template == null)?2:3]):null;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString()));
});
@ -841,13 +842,13 @@ public final class SubCommand extends BukkitCommand {
LinkedList<String> args = new LinkedList<String>();
LinkedList<String> selection = new LinkedList<String>();
LinkedList<Server> select = new LinkedList<Server>();
Container<String> last = new Container<String>(null);
Value<String> last = new Container<String>(null);
// Step 1
Container<Integer> ic = new Container<Integer>(0);
while (ic.get() < index) {
args.add(rargs[ic.get()]);
ic.set(ic.get() + 1);
Value<Integer> ic = new Container<Integer>(0);
while (ic.value() < index) {
args.add(rargs[ic.value()]);
ic.value(ic.value() + 1);
}
// Step 3
@ -855,10 +856,10 @@ public final class SubCommand extends BukkitCommand {
Runnable finished = () -> {
args.add(completed.toString());
int i = ic.get();
int i = ic.value();
while (i < rargs.length) {
args.add(rargs[i]);
last.set(null);
last.value(null);
i++;
}
@ -899,7 +900,7 @@ public final class SubCommand extends BukkitCommand {
}
try {
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.get()));
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.value()));
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -909,9 +910,9 @@ public final class SubCommand extends BukkitCommand {
// Step 2
AsyncConsolidator merge = new AsyncConsolidator(finished);
for (boolean run = true; run && ic.get() < rargs.length; ic.set(ic.get() + 1)) {
String current = rargs[ic.get()];
last.set(current);
for (boolean run = true; run && ic.value() < rargs.length; ic.value(ic.value() + 1)) {
String current = rargs[ic.value()];
last.value(current);
completed.append(current);
if (current.endsWith(",")) {
current = current.substring(0, current.length() - 1);
@ -973,7 +974,7 @@ public final class SubCommand extends BukkitCommand {
for (String name : self.getGroups()) {
merge2.reserve();
plugin.api.getGroup(name, group -> {
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) select.add(server);
}
merge2.release();
@ -992,14 +993,14 @@ public final class SubCommand extends BukkitCommand {
plugin.api.getGroup(current, group -> {
if (group != null) {
int i = 0;
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) {
select.add(server);
i++;
}
}
if (i <= 0) {
String msg = plugin.api.getLang("SubServers", "Command.Generic.No-" + ((mode)?"Sub":"") + "Servers-In-Group").replace("$str$", group.name());
String msg = plugin.api.getLang("SubServers", "Command.Generic.No-" + ((mode)?"Sub":"") + "Servers-In-Group").replace("$str$", group.key());
if (sender != null) sender.sendMessage(msg);
msgs.add(msg);
}

View File

@ -12,7 +12,7 @@ import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.SubServers.Client.Bukkit.Library.Metrics;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -39,7 +39,7 @@ import java.util.concurrent.TimeUnit;
*/
public final class SubPlugin extends JavaPlugin {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
Pair<Long, Map<String, Map<String, String>>> lang = null;
public YAMLConfig config;
public SubProtocol subprotocol;
@ -188,9 +188,9 @@ public final class SubPlugin extends JavaPlugin {
}
}
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
private void connect(Pair<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.key() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.key() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
if (disconnect != null) Bukkit.getLogger().info("SubData > Attempting reconnect in " + reconnect + " seconds");
Bukkit.getScheduler().runTaskLaterAsynchronously(this, new Runnable() {

View File

@ -1,6 +1,6 @@
name: SubServers-Client-Bukkit
main: net.ME1312.SubServers.Client.Bukkit.SubPlugin
version: "2.16.4a"
version: "2.17a"
authors: ["ME1312"]
softdepend: [TitleManager, PlaceholderAPI]
website: "https://github.com/ME1312/SubServers-2"

View File

@ -20,13 +20,13 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Client.Common;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.DataProtocol;
@ -81,7 +81,7 @@ public abstract class ClientAPI {
* @param name Group name
* @param callback a Server Group
*/
public void getGroup(String name, Callback<NamedContainer<String, List<Server>>> callback) {
public void getGroup(String name, Callback<Pair<String, List<Server>>> callback) {
requestGroup(null, name, callback);
}
@ -311,7 +311,7 @@ public abstract class ClientAPI {
}
/**
* Get the Master Proxy Container
* Get the Master Proxy Value
*
* @param callback Master Proxy
*/

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Common.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util;
@ -160,10 +161,10 @@ public class Host {
*
* @return Remote Player Collection
*/
public Collection<NamedContainer<String, UUID>> getGlobalPlayers() {
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
public Collection<Pair<String, UUID>> getGlobalPlayers() {
List<Pair<String, UUID>> players = new ArrayList<Pair<String, UUID>>();
for (String id : raw.getMap("players").getKeys()) {
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
players.add(new ContainedPair<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
}
return players;
}
@ -188,7 +189,7 @@ public class Host {
if (players == null) {
LinkedList<UUID> ids = new LinkedList<UUID>();
for (SubServer server : getSubServers().values()) for (NamedContainer<String, UUID> player : server.getGlobalPlayers()) ids.add(player.get());
for (SubServer server : getSubServers().values()) for (Pair<String, UUID> player : server.getGlobalPlayers()) ids.add(player.value());
client().sendPacket(new PacketDownloadPlayerInfo(ids, data -> {
LinkedList<RemotePlayer> players = new LinkedList<RemotePlayer>();
for (String player : data.getKeys()) {

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Common.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util;
@ -116,10 +117,10 @@ public class Proxy {
*
* @return Remote Player Collection
*/
public Collection<NamedContainer<String, UUID>> getPlayers() {
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
public Collection<Pair<String, UUID>> getPlayers() {
List<Pair<String, UUID>> players = new ArrayList<Pair<String, UUID>>();
for (String id : raw.getMap("players").getKeys()) {
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
players.add(new ContainedPair<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
}
return players;
}

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Common.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
@ -124,10 +125,10 @@ public class Server {
*
* @return Remote Player Collection
*/
public Collection<NamedContainer<String, UUID>> getGlobalPlayers() {
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
public Collection<Pair<String, UUID>> getGlobalPlayers() {
List<Pair<String, UUID>> players = new ArrayList<Pair<String, UUID>>();
for (String id : raw.getMap("players").getKeys()) {
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
players.add(new ContainedPair<String, UUID>(raw.getMap("players").getRawString(id), UUID.fromString(id)));
}
return players;
}

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Common.Network.API;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.SubDataClient;
@ -128,11 +129,11 @@ public final class SimplifiedData {
* @param name Group name
* @param callback a Server Group
*/
public static void requestGroup(DataClient client, String name, Callback<NamedContainer<String, List<Server>>> callback) {
public static void requestGroup(DataClient client, String name, Callback<Pair<String, List<Server>>> callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
client(client).sendPacket(new PacketDownloadGroupInfo(Collections.singletonList(name), data -> {
NamedContainer<String, List<Server>> group = null;
Pair<String, List<Server>> group = null;
if (data.getKeys().size() > 0) {
String key = new LinkedList<String>(data.getKeys()).getFirst();
List<Server> servers = new ArrayList<Server>();
@ -143,7 +144,7 @@ public final class SimplifiedData {
servers.add(new Server(client, data.getMap(key).getMap(server)));
}
}
group = new NamedContainer<>(key, servers);
group = new ContainedPair<>(key, servers);
}
try {

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Client.Common.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;

View File

@ -30,7 +30,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -44,7 +44,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,8 +1,9 @@
package net.ME1312.SubServers.Client.Sponge.Event;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
import net.ME1312.Galaxi.Library.Util;
import org.spongepowered.api.event.cause.Cause;
@ -16,7 +17,7 @@ import java.util.UUID;
public class SubEditServerEvent extends AbstractEvent implements SubEvent {
private UUID player;
private String server;
private NamedContainer<String, ObjectMapValue<String>> edit;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
@ -27,13 +28,13 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.get());
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.contains(".")?section.get("."):null);
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.contains(".")?section.get("."):null);
this.perm = permanent;
}
@ -56,7 +57,7 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
*
* @return Edit to be made
*/
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}

View File

@ -1,8 +1,10 @@
package net.ME1312.SubServers.Client.Sponge.Graphic;
import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ChatColor;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ChatColor;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Common.Network.API.Host;
@ -23,7 +25,7 @@ import java.util.concurrent.TimeUnit;
public abstract class UIRenderer {
static HashMap<String, PluginRenderer<Host>> hostPlugins = new HashMap<String, PluginRenderer<Host>>();
static HashMap<String, PluginRenderer<SubServer>> subserverPlugins = new HashMap<String, PluginRenderer<SubServer>>();
private NamedContainer<String, Integer> tdownload = null;
private Pair<String, Integer> tdownload = null;
private UUID download = null;
private final UUID player;
private SubPlugin plugin;
@ -134,22 +136,22 @@ public abstract class UIRenderer {
download = null;
}).delay(2500, TimeUnit.MILLISECONDS).submit(plugin).getUniqueId();
} if (subtitle != null && tdownload == null) {
tdownload = new NamedContainer<String, Integer>(subtitle, 0);
final Container<Integer> delay = new Container<Integer>(0);
tdownload = new ContainedPair<String, Integer>(subtitle, 0);
final Value<Integer> delay = new Container<Integer>(0);
Sponge.getScheduler().createTaskBuilder().execute(new Runnable() {
@Override
public void run() {
if (tdownload != null) {
String word = ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title"));
int i = 0;
int start = (tdownload.get() - 3 < 0)?0: tdownload.get()-3;
int end = (tdownload.get() >= word.length())?word.length(): tdownload.get();
String str = plugin.api.getLang("SubServers", (delay.get() > 7 && start == 0)?"Interface.Generic.Downloading.Title-Color-Alt":"Interface.Generic.Downloading.Title-Color");
delay.set(delay.get() + 1);
if (delay.get() > 7) tdownload.set(tdownload.get() + 1);
if (tdownload.get() >= word.length() + 3) {
tdownload.set(0);
delay.set(0);
int start = (tdownload.value() - 3 < 0)?0: tdownload.value()-3;
int end = (tdownload.value() >= word.length())?word.length(): tdownload.value();
String str = plugin.api.getLang("SubServers", (delay.value() > 7 && start == 0)?"Interface.Generic.Downloading.Title-Color-Alt":"Interface.Generic.Downloading.Title-Color");
delay.value(delay.value() + 1);
if (delay.value() > 7) tdownload.value(tdownload.value() + 1);
if (tdownload.value() >= word.length() + 3) {
tdownload.value(0);
delay.value(0);
}
for (char c : word.toCharArray()) {
@ -159,7 +161,7 @@ public abstract class UIRenderer {
if (i == end) str += plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color");
}
str += '\n' + plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt") + tdownload.name();
str += '\n' + plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Title-Color-Alt") + tdownload.key();
sendTitle(str, 0, 10, 5);
Sponge.getScheduler().createTaskBuilder().execute(this).delay(50, TimeUnit.MILLISECONDS).submit(plugin);
} else {
@ -168,7 +170,7 @@ public abstract class UIRenderer {
}
}).submit(plugin);
} else if (subtitle != null) {
tdownload.rename(subtitle);
tdownload.key(subtitle);
} else {
if (tdownload != null) {
tdownload = null;
@ -198,20 +200,20 @@ public abstract class UIRenderer {
* @return ItemStack
*/
public ItemStack parseItem(String str, ItemStack def) {
final Container<String> item = new Container<String>(str);
final Value<String> item = new Container<String>(str);
// minecraft:name
if (item.get().toLowerCase().startsWith("minecraft:")) {
item.set(item.get().substring(10));
if (item.value().toLowerCase().startsWith("minecraft:")) {
item.value(item.value().substring(10));
} else
// bukkit:name (ignored on sponge)
if (item.get().toLowerCase().startsWith("bukkit:")) {
item.set(item.get().substring(7));
if (item.value().toLowerCase().startsWith("bukkit:")) {
item.value(item.value().substring(7));
}
// material name
if (!Util.isException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null))) {
return ItemStack.builder().itemType((ItemType) Util.getDespiteException(() -> ItemTypes.class.getDeclaredField(item.get().toUpperCase()).get(null), null)).quantity(1).build();
if (!Util.isException(() -> ItemTypes.class.getDeclaredField(item.value().toUpperCase()).get(null))) {
return ItemStack.builder().itemType((ItemType) Util.getDespiteException(() -> ItemTypes.class.getDeclaredField(item.value().toUpperCase()).get(null), null)).quantity(1).build();
}
return def;

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketOut;
@ -37,7 +38,7 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
public void receive(SubDataSender client, ObjectMap<Integer> data) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.getConnection()), null);
try {
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new ContainedPair<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
log.info("Lang Settings Downloaded");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();

View File

@ -1,8 +1,9 @@
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.SubDataSender;
@ -72,7 +73,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new NamedContainer<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new ContainedPair<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
callback("SubEditServerEvent", this);
}
});

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Client.Sponge.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -173,11 +173,11 @@ public class SubProtocol extends SubDataProtocol {
subdata.sendPacket(new PacketDownloadLang());
subdata.on.ready(client -> Sponge.getEventManager().post(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.value(), client.key());
Sponge.getEventManager().post(event);
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("running"), plugin), true)) {
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
Util.isException(() -> Util.reflect(SubPlugin.class.getDeclaredMethod("connect", Pair.class), plugin, client));
} else map.put(0, null);
});

View File

@ -94,7 +94,7 @@ public final class SubAPI extends ClientAPI {
* @return SubServers Lang Channel list
*/
public Collection<String> getLangChannels() {
return plugin.lang.get().keySet();
return plugin.lang.value().keySet();
}
/**
@ -105,7 +105,7 @@ public final class SubAPI extends ClientAPI {
*/
public Map<String, String> getLang(String channel) {
if (Util.isNull(channel)) throw new NullPointerException();
return new LinkedHashMap<>(plugin.lang.get().get(channel.toLowerCase()));
return new LinkedHashMap<>(plugin.lang.value().get(channel.toLowerCase()));
}
/**
@ -152,7 +152,7 @@ public final class SubAPI extends ClientAPI {
*/
public Version getServerVersion() {
PluginContainer container = null;
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getValue", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null);
return (container == null || !container.getVersion().isPresent())?null:new Version(container.getVersion().get());
}

View File

@ -2,15 +2,16 @@ package net.ME1312.SubServers.Client.Sponge;
import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ChatColor;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Sponge.Library.Compatibility.ListArgument;
@ -176,7 +177,7 @@ public final class SubCommand implements CommandExecutor {
@SuppressWarnings("unchecked")
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
PluginContainer container = Util.getDespiteException(() -> (PluginContainer) org.spongepowered.api.Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
PluginContainer container = Util.getDespiteException(() -> (PluginContainer) org.spongepowered.api.Platform.class.getMethod("getValue", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null);
if (container == null) container = Util.getDespiteException(() -> (PluginContainer) org.spongepowered.api.Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null);
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Version").replace("$str$", "SubServers.Client.Sponge")));
@ -545,9 +546,9 @@ public final class SubCommand implements CommandExecutor {
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "group")).toBuilder().append(Text.builder(group.name()).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers")).toBuilder().append(Text.builder((group.get().size() <= 0)?"(none)":Integer.toString(group.get().size())).color((group.get().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
for (Server server : group.get()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']')).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "group")).toBuilder().append(Text.builder(group.key()).color(TextColors.WHITE).build()).build());
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Servers")).toBuilder().append(Text.builder((group.value().size() <= 0)?"(none)":Integer.toString(group.value().size())).color((group.value().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
for (Server server : group.value()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']')).color(TextColors.WHITE).build()).build());
} else {
if (type == null) {
getServer.run();
@ -641,8 +642,8 @@ public final class SubCommand implements CommandExecutor {
if (s.isPresent()) {
selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.start"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Start.Running").replace("$int$", running.value.toString())));
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Start").replace("$int$", success.value.toString())));
@ -752,19 +753,19 @@ public final class SubCommand implements CommandExecutor {
});
// Step 3: Receive command Responses
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Restart").replace("$int$", success.value.toString())));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
if (data.name() != 0) listening.remove(data.get().getName().toLowerCase());
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
if (data.key() != 0) listening.remove(data.value().getName().toLowerCase());
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", data.get().getName())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Restart.Disappeared").replace("$str$", data.value().getName())));
break;
case 5:
starter.run(data.get());
starter.run(data.value());
case 0:
success.value++;
break;
@ -786,14 +787,14 @@ public final class SubCommand implements CommandExecutor {
merge.reserve();
if (self == null) {
listening.put(server.getName().toLowerCase(), server);
server.stop(player, response -> stopper.run(new NamedContainer<>(response, server)));
server.stop(player, response -> stopper.run(new ContainedPair<>(response, server)));
} else if (self != server) {
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, server.getName(), data -> stopper.run(new NamedContainer<>(data.getInt(0x0001), server))));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, server.getName(), data -> stopper.run(new ContainedPair<>(data.getInt(0x0001), server))));
}
}
if (self != null) {
final SubServer fself = self;
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, self.getName(), data -> stopper.run(new NamedContainer<>(data.getInt(0x0001), fself))));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketRestartServer(player, self.getName(), data -> stopper.run(new ContainedPair<>(data.getInt(0x0001), fself))));
}
}
});
@ -816,17 +817,17 @@ public final class SubCommand implements CommandExecutor {
if (s.isPresent()) {
selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.stop"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Stop.Not-Running").replace("$int$", running.value.toString())));
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Stop").replace("$int$", success.value.toString())));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Disappeared").replace("$str$", data.get().getName())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Disappeared").replace("$str$", data.value().getName())));
break;
case 5:
running.value++;
@ -848,11 +849,11 @@ public final class SubCommand implements CommandExecutor {
for (SubServer server : select.subservers) {
merge.reserve();
if (self != server) server.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new NamedContainer<>(response, server)));
if (self != server) server.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new ContainedPair<>(response, server)));
}
if (self != null) {
final SubServer fself = self;
self.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new NamedContainer<>(response, fself)));
self.stop((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new ContainedPair<>(response, fself)));
}
}
});
@ -875,17 +876,17 @@ public final class SubCommand implements CommandExecutor {
if (s.isPresent()) {
selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.terminate"), select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Terminate.Not-Running").replace("$int$", running.value.toString())));
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Terminate").replace("$int$", success.value.toString())));
});
Callback<NamedContainer<Integer, SubServer>> stopper = data -> {
switch (data.name()) {
Callback<Pair<Integer, SubServer>> stopper = data -> {
switch (data.key()) {
case 3:
case 4:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Disappeared").replace("$str$", data.get().getName())));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Disappeared").replace("$str$", data.value().getName())));
break;
case 5:
running.value++;
@ -907,11 +908,11 @@ public final class SubCommand implements CommandExecutor {
for (SubServer server : select.subservers) {
merge.reserve();
if (self != server) server.terminate((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new NamedContainer<>(response, server)));
if (self != server) server.terminate((sender instanceof Player)?((Player) sender).getUniqueId():null, response -> stopper.run(new ContainedPair<>(response, server)));
}
if (self != null) {
final SubServer fself = self;
fself.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new NamedContainer<>(response, fself)));
fself.terminate((sender instanceof Player) ? ((Player) sender).getUniqueId() : null, response -> stopper.run(new ContainedPair<>(response, fself)));
}
}
});
@ -936,8 +937,8 @@ public final class SubCommand implements CommandExecutor {
selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.command"), select -> {
if (select.subservers.length > 0) {
if (command.isPresent()) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command.Not-Running").replace("$int$", running.value.toString())));
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Command").replace("$int$", success.value.toString())));
@ -1066,7 +1067,7 @@ public final class SubCommand implements CommandExecutor {
if (select.subservers.length > 0) {
boolean ts = ft == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString())));
});
@ -1144,19 +1145,19 @@ public final class SubCommand implements CommandExecutor {
if (server != null) {
if (permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport")) {
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
Container<Boolean> msg = new Container<>(false);
Value<Boolean> msg = new Container<>(false);
Callback<Player> action = target -> {
if (target == sender || permits(server, sender, "subservers.server.%.*", "subservers.server.%.teleport-others")) {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Teleport").replace("$str$", target.getName())));
plugin.pmc(target, "Connect", server.getName());
} else if (!msg.get()) {
msg.set(true);
} else if (!msg.value()) {
msg.value(true);
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.server." + server.getName() + ".teleport-others")));
}
};
Optional<Player> player;
PrimitiveContainer<Set<Entity>> entities = new PrimitiveContainer<>(null);
Container<Set<Entity>> entities = new Container<>(null);
if (name == null) {
action.run((Player) sender);
} else if ((player = plugin.game.getServer().getPlayer(name)).isPresent()) {
@ -1319,8 +1320,8 @@ public final class SubCommand implements CommandExecutor {
// Step 2
AsyncConsolidator merge = new AsyncConsolidator(finished);
for (Container<Integer> ic = new Container<Integer>(0); ic.get() < selection.length; ic.set(ic.get() + 1)) {
String current = selection[ic.get()];
for (Value<Integer> ic = new Container<Integer>(0); ic.value() < selection.length; ic.value(ic.value() + 1)) {
String current = selection[ic.value()];
if (current.length() > 0) {
merge.reserve();
@ -1376,7 +1377,7 @@ public final class SubCommand implements CommandExecutor {
for (String name : self.getGroups()) {
merge2.reserve();
plugin.api.getGroup(name, group -> {
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) select.add(server);
}
merge2.release();
@ -1395,14 +1396,14 @@ public final class SubCommand implements CommandExecutor {
plugin.api.getGroup(current, group -> {
if (group != null) {
int i = 0;
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) {
select.add(server);
i++;
}
}
if (i <= 0) {
Text msg = ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.No-" + ((mode)?"Sub":"") + "Servers-In-Group").replace("$str$", group.name()));
Text msg = ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Generic.No-" + ((mode)?"Sub":"") + "Servers-In-Group").replace("$str$", group.key()));
if (sender != null) sender.sendMessage(msg);
msgs.add(msg);
}

View File

@ -13,7 +13,7 @@ import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubServers.Client.Sponge.Library.Metrics;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -46,10 +46,10 @@ import java.util.concurrent.TimeUnit;
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.16.4a", url = "https://github.com/ME1312/SubServers-2", description = "Take control of the server manager — from your servers")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.17a", url = "https://github.com/ME1312/SubServers-2", description = "Take control of the server manager — from your servers")
public final class SubPlugin {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
Pair<Long, Map<String, Map<String, String>>> lang = null;
public YAMLConfig config;
public SubProtocol subprotocol;
@ -202,9 +202,9 @@ public final class SubPlugin {
}
}
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
private void connect(Pair<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.key() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.key() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Logger log = LoggerFactory.getLogger("SubData");
if (disconnect != null) log.info("Attempting reconnect in " + reconnect + " seconds");

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Console.Library;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import org.fusesource.jansi.AnsiOutputStream;
import java.io.IOException;
@ -48,8 +49,8 @@ public class HTMLogger extends AnsiOutputStream {
* @return HTMLogger
*/
public static <T extends HTMLogger> T wrap(final OutputStream raw, HTMConstructor<T> constructor) {
final Container<T> html = new Container<T>(null);
html.set(constructor.construct(raw, new OutputStream() {
final Value<T> html = new Container<T>(null);
html.value(constructor.construct(raw, new OutputStream() {
private boolean nbsp = false;
@Override
@ -74,14 +75,14 @@ public class HTMLogger extends AnsiOutputStream {
raw.write(BYTES_GT);
break;
case 10:
html.get().closeAttributes();
html.value().closeAttributes();
default:
raw.write(data);
}
}
}
}));
return html.get();
return html.value();
}
protected HTMLogger(final OutputStream raw, OutputStream wrapped) {
super(wrapped);

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@ -34,7 +34,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,9 +1,10 @@
package net.ME1312.SubServers.Host.Event;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Event.Event;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import java.util.UUID;
@ -14,7 +15,7 @@ import java.util.UUID;
public class SubEditServerEvent extends Event {
private UUID player;
private String server;
private NamedContainer<String, ObjectMapValue<String>> edit;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
@ -25,13 +26,13 @@ public class SubEditServerEvent extends Event {
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.get());
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.get("."));
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.get("."));
this.perm = permanent;
}
@ -54,7 +55,7 @@ public class SubEditServerEvent extends Event {
*
* @return Edit to be made
*/
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}

View File

@ -7,7 +7,7 @@ import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
@ -42,10 +42,10 @@ import java.util.jar.Manifest;
/**
* SubServers.Host Main Class
*/
@App(name = "SubServers.Host", version = "2.16.4a", authors = "ME1312", website = "https://github.com/ME1312/SubServers-2", description = "Host subservers on separate machines")
@App(name = "SubServers.Host", version = "2.17a", authors = "ME1312", website = "https://github.com/ME1312/SubServers-2", description = "Host subservers on separate machines")
public final class ExHost {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
Pair<Long, Map<String, Map<String, String>>> lang = null;
public HashMap<String, SubCreatorImpl.ServerTemplate> templatesR = new HashMap<String, SubCreatorImpl.ServerTemplate>();
public HashMap<String, SubCreatorImpl.ServerTemplate> templates = new HashMap<String, SubCreatorImpl.ServerTemplate>();
public HashMap<String, SubServerImpl> servers = new HashMap<String, SubServerImpl>();
@ -274,9 +274,9 @@ public final class ExHost {
}
}
private void connect(java.util.logging.Logger log, NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
private void connect(java.util.logging.Logger log, Pair<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.key() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.key() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::SubData_Reconnect_Handler");
if (disconnect != null) ;

View File

@ -1,12 +1,13 @@
package net.ME1312.SubServers.Host.Executable;
import com.sun.org.apache.xpath.internal.operations.Bool;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
@ -524,23 +525,23 @@ public class SubCreatorImpl {
return this.thread.get(name).log;
}
private static NamedContainer<YAMLSection, String> address = null;
private static Pair<YAMLSection, String> address = null;
private String getAddress() {
if (address == null || host.config.get() != address.name()) {
address = new NamedContainer<>(host.config.get(), host.config.get().getMap("Settings").getRawString("Server-Bind"));
if (address == null || host.config.get() != address.key()) {
address = new ContainedPair<>(host.config.get(), host.config.get().getMap("Settings").getRawString("Server-Bind"));
}
return address.get();
return address.value();
}
private static NamedContainer<YAMLSection, Map<String, Object>> subdata = null;
private static Pair<YAMLSection, Map<String, Object>> subdata = null;
private Map<String, Object> getSubData() {
if (subdata == null || host.config.get() != subdata.name()) {
if (subdata == null || host.config.get() != subdata.key()) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("Address", host.config.get().getMap("Settings").getMap("SubData").getRawString("Address"));
if (host.config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) map.put("Password", host.config.get().getMap("Settings").getMap("SubData").getRawString("Password"));
subdata = new NamedContainer<>(host.config.get(), map);
subdata = new ContainedPair<>(host.config.get(), map);
}
return subdata.get();
return subdata.value();
}
private void generateClient(File dir, ServerType type, String name) throws IOException {

View File

@ -1,10 +1,10 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Log.LogStream;
import net.ME1312.Galaxi.Library.Log.Logger;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Library.DisconnectReason;
@ -29,7 +29,7 @@ public class SubLoggerImpl {
final Logger logger;
final String name;
UUID address;
Container<Boolean> log;
Value<Boolean> log;
static boolean logn = true;
static boolean logc = true;
File file;
@ -49,7 +49,7 @@ public class SubLoggerImpl {
* @param log Console Logging Status
* @param file File to log to (or null for disabled)
*/
SubLoggerImpl(Process process, Object user, String name, UUID address, Container<Boolean> log, File file) {
SubLoggerImpl(Process process, Object user, String name, UUID address, Value<Boolean> log, File file) {
this.process = process;
this.handle = user;
this.logger = new Logger(name);
@ -77,15 +77,15 @@ public class SubLoggerImpl {
ExHost host = SubAPI.getInstance().getInternals();
if (logn) Util.isException(() -> {
channel = (SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0].openChannel();
channel.on.closed(new Callback<NamedContainer<DisconnectReason, DataClient>>() {
channel.on.closed(new Callback<Pair<DisconnectReason, DataClient>>() {
@Override
public void run(NamedContainer<DisconnectReason, DataClient> client) {
public void run(Pair<DisconnectReason, DataClient> client) {
if (started && SubLoggerImpl.this.process != null && process == SubLoggerImpl.this.process && process.isAlive()) {
int reconnect = host.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60);
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("reconnect"), host), false) && reconnect > 0
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
&& client.key() != DisconnectReason.PROTOCOL_MISMATCH && client.key() != DisconnectReason.ENCRYPTION_MISMATCH) {
Timer timer = new Timer(SubAPI.getInstance().getAppInfo().getName() + "::Log_Reconnect_Handler");
Callback<NamedContainer<DisconnectReason, DataClient>> run = this;
Callback<Pair<DisconnectReason, DataClient>> run = this;
reconnect++;
timer.scheduleAtFixedRate(new TimerTask() {
@Override
@ -161,10 +161,10 @@ public class SubLoggerImpl {
}
// Log to NETWORK
if (log.get() && channel != null && !channel.isClosed()) channel.sendPacket(new PacketOutExLogMessage(address, line));
if (log.value() && channel != null && !channel.isClosed()) channel.sendPacket(new PacketOutExLogMessage(address, line));
// Log to CONSOLE
if (log.get() && logc) level.println(TextColor.convertColor(msg));
if (log.value() && logc) level.println(TextColor.convertColor(msg));
// Log to FILE
if (writer != null) {
@ -230,7 +230,7 @@ public class SubLoggerImpl {
* @return Logging Status
*/
public boolean isLogging() {
return log.get();
return log.value();
}
/**

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Host.Executable;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -24,7 +25,7 @@ public class SubServerImpl {
private String name;
private boolean enabled;
private int port;
private Container<Boolean> log;
private Value<Boolean> log;
private String dir;
private File directory;
private String executable;
@ -250,7 +251,7 @@ public class SubServerImpl {
* @return Logging Status
*/
public boolean isLogging() {
return log.get();
return log.value();
}
/**
@ -260,7 +261,7 @@ public class SubServerImpl {
*/
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
log.set(value);
log.value(value);
}
/**

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketOut;
@ -37,7 +38,7 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
public void receive(SubDataSender client, ObjectMap<Integer> data) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.getConnection()), null);
try {
Util.reflect(ExHost.class.getDeclaredField("lang"), host, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Util.reflect(ExHost.class.getDeclaredField("lang"), host, new ContainedPair<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
log.info("Lang Settings Downloaded");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();

View File

@ -2,8 +2,9 @@ package net.ME1312.SubServers.Host.Network.Packet;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Host.Event.*;
@ -70,7 +71,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
callback("SubEditServerEvent", this);
}
});

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Host.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -165,13 +165,13 @@ public class SubProtocol extends SubDataProtocol {
subdata.sendPacket(new PacketOutExRequestQueue());
subdata.on.ready(client -> host.engine.getPluginManager().executeEvent(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.value(), client.key());
host.engine.getPluginManager().executeEvent(event);
if (Util.getDespiteException(() -> Util.reflect(ExHost.class.getDeclaredField("running"), host), true)) {
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.value()), null);
log.info("Attempting reconnect in " + host.config.get().getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getInt("Reconnect", 60) + " seconds");
Util.isException(() -> Util.reflect(ExHost.class.getDeclaredMethod("connect", Logger.class, NamedContainer.class), host, log, client));
Util.isException(() -> Util.reflect(ExHost.class.getDeclaredMethod("connect", Logger.class, Pair.class), host, log, client));
} else map.put(0, null);
});

View File

@ -79,7 +79,7 @@ public final class SubAPI extends ClientAPI {
* @return SubServers Lang Channel list
*/
public Collection<String> getLangChannels() {
return host.lang.get().keySet();
return host.lang.value().keySet();
}
/**
@ -90,7 +90,7 @@ public final class SubAPI extends ClientAPI {
*/
public Map<String, String> getLang(String channel) {
if (Util.isNull(channel)) throw new NullPointerException();
return new LinkedHashMap<>(host.lang.get().get(channel.toLowerCase()));
return new LinkedHashMap<>(host.lang.value().get(channel.toLowerCase()));
}
/**

View File

@ -5,10 +5,10 @@ import net.ME1312.Galaxi.Engine.Library.ConsoleReader;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.Galaxi.Plugin.Command.Command;
@ -243,9 +243,9 @@ public class SubCommand {
});
Runnable getGroup = () -> host.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage("Info on group: " + TextColor.WHITE + group.name());
sender.sendMessage(" -> Servers: " + ((group.get().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + group.get().size()));
for (Server server : group.get()) sender.sendMessage(" - " + TextColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
sender.sendMessage("Info on group: " + TextColor.WHITE + group.key());
sender.sendMessage(" -> Servers: " + ((group.value().size() <= 0)?TextColor.GRAY + "(none)":TextColor.AQUA.toString() + group.value().size()));
for (Server server : group.value()) sender.sendMessage(" - " + TextColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
} else {
if (type == null) {
getServer.run();
@ -332,11 +332,11 @@ public class SubCommand {
ReturnRunnable<Collection<String>> getPlayers = () -> {
LinkedList<String> names = new LinkedList<String>();
if (proxyMasterCache != null)
for (NamedContainer<String, UUID> player : proxyMasterCache.getPlayers())
names.add(player.name());
for (Pair<String, UUID> player : proxyMasterCache.getPlayers())
names.add(player.key());
for (Proxy proxy : proxyCache.values())
for (NamedContainer<String, UUID> player : proxy.getPlayers())
if (!names.contains(player.name())) names.add(player.name());
for (Pair<String, UUID> player : proxy.getPlayers())
if (!names.contains(player.key())) names.add(player.key());
Collections.sort(names);
return names;
};
@ -445,8 +445,8 @@ public class SubCommand {
if (args.length > 0) {
selectServers(sender, args, 0, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(running.value + " subserver"+((running.value == 1)?" was":"s were") + " already running");
if (success.value > 0) sender.sendMessage("Started " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -559,7 +559,7 @@ public class SubCommand {
// Step 1-3: Restart Servers / Receive command Responses
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("Restarting " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -602,8 +602,8 @@ public class SubCommand {
if (args.length > 0) {
selectServers(sender, args, 0, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(running.value + " subserver"+((running.value == 1)?" was":"s were") + " already offline");
if (success.value > 0) sender.sendMessage("Stopping " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -646,8 +646,8 @@ public class SubCommand {
if (args.length > 0) {
selectServers(sender, args, 0, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(running.value + " subserver"+((running.value == 1)?" was":"s were") + " already offline");
if (success.value > 0) sender.sendMessage("Terminated " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -700,8 +700,8 @@ public class SubCommand {
builder.append(select.args[i]);
}
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage(running.value + " subserver"+((running.value == 1)?" was":"s were") + " offline");
if (success.value > 0) sender.sendMessage("Sent command to " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -836,7 +836,7 @@ public class SubCommand {
Version version = (select.args.length > 1)?new Version(select.args[(template == null)?1:2]):null;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("Updating " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -920,8 +920,8 @@ public class SubCommand {
if (args.length > 0) {
selectServers(sender, args, 0, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("Removing " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -978,13 +978,13 @@ public class SubCommand {
LinkedList<String> args = new LinkedList<String>();
LinkedList<String> selection = new LinkedList<String>();
LinkedList<Server> select = new LinkedList<Server>();
Container<String> last = new Container<String>(null);
Value<String> last = new Container<String>(null);
// Step 1
Container<Integer> ic = new Container<Integer>(0);
while (ic.get() < index) {
args.add(rargs[ic.get()]);
ic.set(ic.get() + 1);
Value<Integer> ic = new Container<Integer>(0);
while (ic.value() < index) {
args.add(rargs[ic.value()]);
ic.value(ic.value() + 1);
}
// Step 3
@ -992,10 +992,10 @@ public class SubCommand {
Runnable finished = () -> {
args.add(completed.toString());
int i = ic.get();
int i = ic.value();
while (i < rargs.length) {
args.add(rargs[i]);
last.set(null);
last.value(null);
i++;
}
@ -1018,7 +1018,7 @@ public class SubCommand {
}
try {
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.get()));
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.value()));
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -1028,9 +1028,9 @@ public class SubCommand {
// Step 2
AsyncConsolidator merge = new AsyncConsolidator(finished);
for (boolean run = true; run && ic.get() < rargs.length; ic.set(ic.get() + 1)) {
String current = rargs[ic.get()];
last.set(current);
for (boolean run = true; run && ic.value() < rargs.length; ic.value(ic.value() + 1)) {
String current = rargs[ic.value()];
last.value(current);
completed.append(current);
if (current.endsWith(",")) {
current = current.substring(0, current.length() - 1);
@ -1083,14 +1083,14 @@ public class SubCommand {
host.api.getGroup(current, group -> {
if (group != null) {
int i = 0;
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) {
select.add(server);
i++;
}
}
if (i <= 0) {
String msg = "There are no " + ((mode)?"sub":"") + "servers in group: " + group.name();
String msg = "There are no " + ((mode)?"sub":"") + "servers in group: " + group.key();
if (sender != null) sender.sendMessage(msg);
msgs.add(msg);
}

View File

@ -30,14 +30,14 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>20w33a</version>
<version>20w46b</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -57,7 +57,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>20w46b</version>
<version>20w46d</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

View File

@ -1,8 +1,9 @@
package net.ME1312.SubServers.Sync.Event;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubServers.Sync.Library.SubEvent;
import net.ME1312.Galaxi.Library.Util;
import net.md_5.bungee.api.plugin.Event;
@ -15,7 +16,7 @@ import java.util.UUID;
public class SubEditServerEvent extends Event implements SubEvent {
private UUID player;
private String server;
private NamedContainer<String, ObjectMapValue<String>> edit;
private Pair<String, ObjectMapValue<String>> edit;
private boolean perm;
/**
@ -26,13 +27,13 @@ public class SubEditServerEvent extends Event implements SubEvent {
* @param edit Edit to make
* @param permanent If the change is permanent
*/
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit, boolean permanent) {
if (Util.isNull(server, edit)) throw new NullPointerException();
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.get());
section.set(".", edit.value());
this.player = player;
this.server = server;
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.get("."));
this.edit = new ContainedPair<String, ObjectMapValue<String>>(edit.key(), section.get("."));
this.perm = permanent;
}
@ -55,7 +56,7 @@ public class SubEditServerEvent extends Event implements SubEvent {
*
* @return Edit to be made
*/
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
public Pair<String, ObjectMapValue<String>> getEdit() {
return edit;
}

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Sync;
import com.dosse.upnp.UPnP;
import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.SubData.Client.DataClient;
import net.ME1312.SubData.Client.Encryption.AES;
import net.ME1312.SubData.Client.Encryption.DHE;
@ -18,7 +18,7 @@ import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubServers.Sync.Library.Compatibility.Plugin;
import net.ME1312.SubServers.Sync.Library.Metrics;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -56,7 +56,7 @@ import java.util.concurrent.TimeUnit;
*/
public final class ExProxy extends BungeeCommon implements Listener {
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
Pair<Long, Map<String, Map<String, String>>> lang = null;
public final Map<String, ServerImpl> servers = new TreeMap<String, ServerImpl>();
public final HashMap<UUID, ServerImpl> rPlayerLinkS = new HashMap<UUID, ServerImpl>();
public final HashMap<UUID, String> rPlayerLinkP = new HashMap<UUID, String>();
@ -69,7 +69,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
public final Plugin plugin;
public final SubAPI api = new SubAPI(this);
public SubProtocol subprotocol;
public static final Version version = Version.fromString("2.16.4a");
public static final Version version = Version.fromString("2.17a");
public final boolean isPatched;
public final boolean isGalaxi;
@ -197,9 +197,9 @@ public final class ExProxy extends BungeeCommon implements Listener {
}
}
private void connect(NamedContainer<DisconnectReason, DataClient> disconnect) throws IOException {
private void connect(Pair<DisconnectReason, DataClient> disconnect) throws IOException {
int reconnect = config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60);
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.name() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.name() != DisconnectReason.ENCRYPTION_MISMATCH)) {
if (disconnect == null || (this.reconnect && reconnect > 0 && disconnect.key() != DisconnectReason.PROTOCOL_MISMATCH && disconnect.key() != DisconnectReason.ENCRYPTION_MISMATCH)) {
long reset = resetDate;
Timer timer = new Timer("SubServers.Sync::SubData_Reconnect_Handler");
timer.scheduleAtFixedRate(new TimerTask() {
@ -225,13 +225,13 @@ public final class ExProxy extends BungeeCommon implements Listener {
private void post() {
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/server"))
getPluginManager().registerCommand(plugin, SubCommand.BungeeServer.newInstance(this, "server").get());
getPluginManager().registerCommand(plugin, SubCommand.BungeeServer.newInstance(this, "server").value());
if (!config.get().getMap("Settings").getRawStringList("Disabled-Overrides", Collections.emptyList()).contains("/glist"))
getPluginManager().registerCommand(plugin, new SubCommand.BungeeList(this, "glist"));
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subservers").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subserver").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "sub").get());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subservers").value());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "subserver").value());
getPluginManager().registerCommand(plugin, SubCommand.newInstance(this, "sub").value());
GalaxiCommand.group(SubCommand.class);
if (getReconnectHandler() != null && getReconnectHandler().getClass().equals(SmartFallback.class))
@ -280,12 +280,12 @@ public final class ExProxy extends BungeeCommon implements Listener {
}
}
ArrayList<CachedPlayer> remove = new ArrayList<CachedPlayer>();
for (NamedContainer<String, UUID> player : proxy.getPlayers()) { // Remove players that shouldn't exist
if (getPlayer(player.get()) == null) {
remove.add(rPlayers.get(player.get()));
rPlayerLinkS.remove(player.get());
rPlayerLinkP.remove(player.get());
rPlayers.remove(player.get());
for (Pair<String, UUID> player : proxy.getPlayers()) { // Remove players that shouldn't exist
if (getPlayer(player.value()) == null) {
remove.add(rPlayers.get(player.value()));
rPlayerLinkS.remove(player.value());
rPlayerLinkP.remove(player.value());
rPlayers.remove(player.value());
}
}
for (UUID player : Util.getBackwards(rPlayerLinkP, api.getName().toLowerCase())) { // Remove players that shouldn't exist (internally)
@ -410,7 +410,7 @@ public final class ExProxy extends BungeeCommon implements Listener {
if (!e.getConnection().getListener().isPingPassthrough()) {
e.setResponse(new ServerPing(e.getResponse().getVersion(), e.getResponse().getPlayers(), new TextComponent(override.getMotd()), null));
} else {
PrimitiveContainer<Boolean> lock = new PrimitiveContainer<>(true);
Container<Boolean> lock = new Container<>(true);
boolean mode = plugin != null;
if (mode) e.registerIntent(plugin);
((BungeeServerInfo) override).ping((ping, error) -> {
@ -648,18 +648,18 @@ public final class ExProxy extends BungeeCommon implements Listener {
public void edit(SubEditServerEvent e) {
if (servers.keySet().contains(e.getServer().toLowerCase())) {
ServerImpl server = servers.get(e.getServer().toLowerCase());
switch (e.getEdit().name().toLowerCase()) {
switch (e.getEdit().key().toLowerCase()) {
case "display":
server.setDisplayName(e.getEdit().get().asString());
server.setDisplayName(e.getEdit().value().asString());
break;
case "motd":
server.setMotd(ChatColor.translateAlternateColorCodes('&', e.getEdit().get().asString()));
server.setMotd(ChatColor.translateAlternateColorCodes('&', e.getEdit().value().asString()));
break;
case "restricted":
server.setRestricted(e.getEdit().get().asBoolean());
server.setRestricted(e.getEdit().value().asBoolean());
break;
case "hidden":
server.setHidden(e.getEdit().get().asBoolean());
server.setHidden(e.getEdit().value().asBoolean());
break;
}
}

View File

@ -1,7 +1,8 @@
package net.ME1312.SubServers.Sync.Network.Packet;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketOut;
@ -35,7 +36,7 @@ public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketOut {
@Override
public void receive(SubDataSender client, ObjectMap<Integer> data) {
try {
Util.reflect(ExProxy.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Util.reflect(ExProxy.class.getDeclaredField("lang"), plugin, new ContainedPair<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
Logger.get("SubData").info("Lang Settings Downloaded");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();

View File

@ -1,8 +1,9 @@
package net.ME1312.SubServers.Sync.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.SubServers.Sync.ExProxy;
@ -71,7 +72,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> data) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new NamedContainer<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
ProxyServer.getInstance().getPluginManager().callEvent(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("server"), new ContainedPair<String, Object>(data.getRawString("edit"), data.get("value")), data.getBoolean("perm")));
callback("SubEditServerEvent", this);
}
});

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Sync.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.SubDataClient;
@ -197,12 +197,12 @@ public class SubProtocol extends SubDataProtocol {
}));
subdata.on.ready(client -> plugin.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.value(), client.key());
plugin.getPluginManager().callEvent(event);
if (plugin.isRunning) {
net.ME1312.SubServers.Bungee.Library.Compatibility.Logger.get("SubData").info("Attempting reconnect in " + plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 60) + " seconds");
Util.isException(() -> Util.reflect(ExProxy.class.getDeclaredMethod("connect", NamedContainer.class), plugin, client));
Util.isException(() -> Util.reflect(ExProxy.class.getDeclaredMethod("connect", Pair.class), plugin, client));
} else map.put(0, null);
});

View File

@ -134,7 +134,7 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
* @return SubServers Lang Channel list
*/
public Collection<String> getLangChannels() {
return plugin.lang.get().keySet();
return plugin.lang.value().keySet();
}
/**
@ -145,7 +145,7 @@ public final class SubAPI extends ClientAPI implements BungeeAPI {
*/
public Map<String, String> getLang(String channel) {
if (Util.isNull(channel)) throw new NullPointerException();
return new LinkedHashMap<>(plugin.lang.get().get(channel.toLowerCase()));
return new LinkedHashMap<>(plugin.lang.value().get(channel.toLowerCase()));
}
/**

View File

@ -4,13 +4,14 @@ import com.google.gson.Gson;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
import net.ME1312.Galaxi.Library.Container.PrimitiveContainer;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataSender;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.NamedContainer;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Library.Compatibility.CommandX;
@ -44,7 +45,7 @@ import static net.ME1312.SubServers.Bungee.Library.Compatibility.Galaxi.GalaxiCo
@SuppressWarnings("deprecation")
public final class SubCommand extends CommandX {
static HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>> permitted = new HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>>();
static HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>> permitted = new HashMap<UUID, HashMap<ServerInfo, Pair<Long, Boolean>>>();
private TreeMap<String, Proxy> proxyCache = new TreeMap<String, Proxy>();
private TreeMap<String, Host> hostCache = new TreeMap<String, Host>();
private TreeMap<String, List<Server>> groupCache = new TreeMap<String, List<Server>>();
@ -53,13 +54,13 @@ public final class SubCommand extends CommandX {
private ExProxy plugin;
private String label;
static NamedContainer<SubCommand, CommandX> newInstance(ExProxy plugin, String command) {
NamedContainer<SubCommand, CommandX> cmd = new NamedContainer<>(new SubCommand(plugin, command), null);
CommandX now = cmd.name();
static Pair<SubCommand, CommandX> newInstance(ExProxy plugin, String command) {
Pair<SubCommand, CommandX> cmd = new ContainedPair<>(new SubCommand(plugin, command), null);
CommandX now = cmd.key();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
// now = new net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
cmd.value(now);
return cmd;
}
@ -277,9 +278,9 @@ public final class SubCommand extends CommandX {
});
Runnable getGroup = () -> plugin.api.getGroup(name, group -> {
if (group != null) {
sender.sendMessage("SubServers > Info on group: " + ChatColor.WHITE + group.name());
sender.sendMessage(" -> Servers: " + ((group.get().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.get().size()));
for (Server server : group.get()) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
sender.sendMessage("SubServers > Info on group: " + ChatColor.WHITE + group.key());
sender.sendMessage(" -> Servers: " + ((group.value().size() <= 0)?ChatColor.GRAY + "(none)":ChatColor.AQUA.toString() + group.value().size()));
for (Server server : group.value()) sender.sendMessage(" - " + ChatColor.WHITE + server.getDisplayName() + ((server.getName().equals(server.getDisplayName()))?"":" ["+server.getName()+']'));
} else {
if (type == null) {
getServer.run();
@ -361,8 +362,8 @@ public final class SubCommand extends CommandX {
if (args.length > 1) {
selectServers(sender, args, 1, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " already running");
if (success.value > 0) sender.sendMessage("SubServers > Started " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -463,7 +464,7 @@ public final class SubCommand extends CommandX {
// Step 1-3: Restart Servers / Receive command Responses
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("SubServers > Restarting " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -495,8 +496,8 @@ public final class SubCommand extends CommandX {
if (args.length > 1) {
selectServers(sender, args, 1, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " already offline");
if (success.value > 0) sender.sendMessage("SubServers > Stopping " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -528,8 +529,8 @@ public final class SubCommand extends CommandX {
if (args.length > 1) {
selectServers(sender, args, 1, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " already offline");
if (success.value > 0) sender.sendMessage("SubServers > Terminated " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -568,8 +569,8 @@ public final class SubCommand extends CommandX {
builder.append(select.args[i]);
}
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (running.value > 0) sender.sendMessage("SubServers > " + running.value + " subserver"+((running.value == 1)?" was":"s were") + " offline");
if (success.value > 0) sender.sendMessage("SubServers > Sent command to " + success.value + " subserver"+((success.value == 1)?"":"s"));
@ -649,7 +650,7 @@ public final class SubCommand extends CommandX {
Version version = (select.args.length > 2)?new Version(select.args[(template == null)?2:3]):null;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("SubServers > Updating " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -704,8 +705,8 @@ public final class SubCommand extends CommandX {
if (args.length > 1) {
selectServers(sender, args, 1, true, select -> {
if (select.subservers.length > 0) {
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
PrimitiveContainer<Integer> running = new PrimitiveContainer<Integer>(0);
Container<Integer> success = new Container<Integer>(0);
Container<Integer> running = new Container<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("SubServers > Removing " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
@ -761,13 +762,13 @@ public final class SubCommand extends CommandX {
LinkedList<String> args = new LinkedList<String>();
LinkedList<String> selection = new LinkedList<String>();
LinkedList<Server> select = new LinkedList<Server>();
Container<String> last = new Container<String>(null);
Value<String> last = new Container<String>(null);
// Step 1
Container<Integer> ic = new Container<Integer>(0);
while (ic.get() < index) {
args.add(rargs[ic.get()]);
ic.set(ic.get() + 1);
Value<Integer> ic = new Container<Integer>(0);
while (ic.value() < index) {
args.add(rargs[ic.value()]);
ic.value(ic.value() + 1);
}
// Step 3
@ -775,10 +776,10 @@ public final class SubCommand extends CommandX {
Runnable finished = () -> {
args.add(completed.toString());
int i = ic.get();
int i = ic.value();
while (i < rargs.length) {
args.add(rargs[i]);
last.set(null);
last.value(null);
i++;
}
@ -801,7 +802,7 @@ public final class SubCommand extends CommandX {
}
try {
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.get()));
callback.run(new ServerSelection(msgs, selection, servers, subservers, args, last.value()));
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -811,9 +812,9 @@ public final class SubCommand extends CommandX {
// Step 2
AsyncConsolidator merge = new AsyncConsolidator(finished);
for (boolean run = true; run && ic.get() < rargs.length; ic.set(ic.get() + 1)) {
String current = rargs[ic.get()];
last.set(current);
for (boolean run = true; run && ic.value() < rargs.length; ic.value(ic.value() + 1)) {
String current = rargs[ic.value()];
last.value(current);
completed.append(current);
if (current.endsWith(",")) {
current = current.substring(0, current.length() - 1);
@ -866,14 +867,14 @@ public final class SubCommand extends CommandX {
plugin.api.getGroup(current, group -> {
if (group != null) {
int i = 0;
for (Server server : group.get()) {
for (Server server : group.value()) {
if (!mode || server instanceof SubServer) {
select.add(server);
i++;
}
}
if (i <= 0) {
String msg = "SubServers > There are no " + ((mode)?"sub":"") + "servers in group: " + group.name();
String msg = "SubServers > There are no " + ((mode)?"sub":"") + "servers in group: " + group.key();
if (sender != null) sender.sendMessage(msg);
msgs.add(msg);
}
@ -960,35 +961,35 @@ public final class SubCommand extends CommandX {
* @return The validator's response and list of possible arguments
*/
@SuppressWarnings("unchecked")
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
public Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
String Last = (args.length > 0)?args[args.length - 1]:"";
String last = Last.toLowerCase();
if (plugin.api.getSubDataNetwork()[0] == null) {
if (sender instanceof ConsoleCommandSender)
new IllegalStateException("SubData is not connected").printStackTrace();
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
} else if (sender instanceof ProxiedPlayer && (!permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| !permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).get())) {
|| !permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).value())) {
if (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) && permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
&& permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() == null) {
&& permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() == null) {
// do nothing
} else if (!permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !permitted.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| Calendar.getInstance().getTime().getTime() - permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() >= TimeUnit.MINUTES.toMillis(1)) {
|| Calendar.getInstance().getTime().getTime() - permitted.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).key() >= TimeUnit.MINUTES.toMillis(1)) {
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof ServerImpl) || ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), false));
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), false));
permitted.put(((ProxiedPlayer) sender).getUniqueId(), map);
} else {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(null, false));
HashMap<ServerInfo, Pair<Long, Boolean>> map = (permitted.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))? permitted.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, Pair<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(null, false));
permitted.put(((ProxiedPlayer) sender).getUniqueId(), map);
((SubDataSender) ((ServerImpl) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0]).sendPacket(new PacketCheckPermission(((ProxiedPlayer) sender).getUniqueId(), "subservers.command", result -> {
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), result));
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new ContainedPair<>(Calendar.getInstance().getTime().getTime(), result));
}));
}
}
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
} else if (args.length <= 1) {
List<String> cmds = new ArrayList<>();
cmds.addAll(Arrays.asList("help", "list", "info", "status", "version", "start", "restart", "stop", "kill", "terminate", "cmd", "command", "create", "update", "upgrade"));
@ -1000,7 +1001,7 @@ public final class SubCommand extends CommandX {
for (String cmd : cmds) {
if (cmd.startsWith(last)) list.add(Last + cmd.substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]):null, list);
} else {
if (args[0].equals("info") || args[0].equals("status")) {
ReturnRunnable<Collection<String>> getPlayers = () -> {
@ -1049,7 +1050,7 @@ public final class SubCommand extends CommandX {
if (!list.contains(player) && player.toLowerCase().startsWith(last))
list.add(Last + player.substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
@ -1093,16 +1094,16 @@ public final class SubCommand extends CommandX {
}
break;
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Info.Unknown").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else if (!(sender instanceof ProxiedPlayer) && (args[0].equals("restore"))) {
/* if (args[0].equals("restore")) */ {
if (args.length == 2) {
return new NamedContainer<>(null, Collections.singletonList("<Subserver>"));
return new ContainedPair<>(null, Collections.singletonList("<Subserver>"));
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
}
} else if (args[0].equals("start") ||
@ -1128,7 +1129,7 @@ public final class SubCommand extends CommandX {
if (Arrays.binarySearch(select.selection, name.toLowerCase()) < 0 && name.toLowerCase().startsWith(last)) list.add(Last + name.substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", select.last):null, list);
} else if (last.startsWith(":")) {
Map<String, List<Server>> groups = groupCache;
if (groups.size() > 0) {
@ -1139,7 +1140,7 @@ public final class SubCommand extends CommandX {
if (Arrays.binarySearch(select.selection, group.toLowerCase()) < 0 && group.toLowerCase().startsWith(last)) list.add(Last + group.substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Group").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Group").replace("$str$", select.last):null, list);
} else {
Map<String, ServerImpl> subservers = plugin.servers;
if (subservers.size() > 0) {
@ -1149,32 +1150,32 @@ public final class SubCommand extends CommandX {
if (server instanceof SubServerImpl && Arrays.binarySearch(select.selection, server.getName().toLowerCase()) < 0 && server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", select.last):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", select.last):null, list);
}
} else if (args[0].equals("cmd") || args[0].equals("command")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Collections.singletonList("<Command>"));
return new ContainedPair<>(null, Collections.singletonList("<Command>"));
} else {
return new NamedContainer<>(null, Collections.singletonList("[Args...]"));
return new ContainedPair<>(null, Collections.singletonList("[Args...]"));
}
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Arrays.asList("[Template]", "[Version]"));
return new ContainedPair<>(null, Arrays.asList("[Template]", "[Version]"));
} else if (select.args.length == 4) {
return new NamedContainer<>(null, Collections.singletonList("<Version>"));
return new ContainedPair<>(null, Collections.singletonList("<Version>"));
}
}
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
} else if (args[0].equals("create")) {
updateCache();
if (args.length == 2) {
return new NamedContainer<>(null, Collections.singletonList("<Name>"));
return new ContainedPair<>(null, Collections.singletonList("<Name>"));
} else if (args.length == 3) {
List<String> list = new ArrayList<String>();
for (Host host : hostCache.values()) {
if (host.getName().toLowerCase().startsWith(last)) list.add(Last + host.getName().substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Host").replace("$str$", args[0]):null, list);
} else if (args.length == 4) {
List<String> list = new ArrayList<String>();
Map<String, Host> hosts = hostCache;
@ -1185,18 +1186,18 @@ public final class SubCommand extends CommandX {
if (template.getName().toLowerCase().startsWith(last)) list.add(Last + template.getName().substring(last.length()));
}
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
} else if (args.length == 5) {
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
return new ContainedPair<>(null, Collections.singletonList("[Version]"));
} else if (args.length == 6) {
if (last.length() > 0) {
if (Util.isException(() -> Integer.parseInt(last)) || Integer.parseInt(last) <= 0 || Integer.parseInt(last) > 65535) {
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
return new ContainedPair<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
}
}
return new NamedContainer<>(null, Collections.singletonList("[Port]"));
return new ContainedPair<>(null, Collections.singletonList("[Port]"));
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else if (sender instanceof ProxiedPlayer && (args[0].equals("tp") || args[0].equals("teleport"))) {
if (args.length == 2 || args.length == 3) {
@ -1225,12 +1226,12 @@ public final class SubCommand extends CommandX {
for (ServerImpl server : plugin.servers.values()) {
if (server.getName().toLowerCase().startsWith(last)) list.add(Last + server.getName().substring(last.length()));
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-Server").replace("$str$", args[0]):null, list);
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
} else {
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]), Collections.emptyList());
return new ContainedPair<>(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Subcommand").replace("$str$", args[0]), Collections.emptyList());
}
}
}
@ -1437,13 +1438,13 @@ public final class SubCommand extends CommandX {
);
}
static NamedContainer<BungeeServer, CommandX> newInstance(ExProxy plugin, String command) {
NamedContainer<BungeeServer, CommandX> cmd = new NamedContainer<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.name();
static Pair<BungeeServer, CommandX> newInstance(ExProxy plugin, String command) {
Pair<BungeeServer, CommandX> cmd = new ContainedPair<>(new BungeeServer(plugin, command), null);
CommandX now = cmd.key();
//if (plugin.api.getGameVersion()[plugin.api.getGameVersion().length - 1].compareTo(new Version("1.13")) >= 0) { // TODO Future Command Validator API?
// now = new net.ME1312.SubServers.Sync.Library.Compatibility.mc1_13.CommandX(cmd.name());
//}
cmd.set(now);
cmd.value(now);
return cmd;
}
@ -1499,7 +1500,7 @@ public final class SubCommand extends CommandX {
* @param args Arguments
* @return The validator's response and list of possible arguments
*/
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
public Pair<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
if (args.length <= 1) {
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
List<String> list = new ArrayList<String>();
@ -1507,15 +1508,15 @@ public final class SubCommand extends CommandX {
for (ServerImpl server : plugin.servers.values()) {
if (!server.isHidden()) list.add(server.getName());
}
return new NamedContainer<>(null, new LinkedList<>(list));
return new ContainedPair<>(null, new LinkedList<>(list));
} else {
for (ServerImpl server : plugin.servers.values()) {
if (server.getName().toLowerCase().startsWith(last) && !server.isHidden()) list.add(server.getName());
}
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Bungee.Server.Invalid").replace("$str$", args[0]):null, list);
return new ContainedPair<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Bungee.Server.Invalid").replace("$str$", args[0]):null, list);
}
} else {
return new NamedContainer<>(null, Collections.emptyList());
return new ContainedPair<>(null, Collections.emptyList());
}
}
}