Update GalaxiEngine

The changes this time are to some of GalaxiEngine's core utilities... which means it took a lot of work this time.
This commit is contained in:
ME1312 2021-10-24 00:14:07 -04:00
parent 16c373b336
commit 3e074e365d
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
279 changed files with 1635 additions and 1621 deletions

View File

@ -28,7 +28,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiUtil</artifactId>
<version>21w27b</version>
<version>21w43f</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer;
@ -8,6 +7,7 @@ import net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import java.io.File;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
@ -23,7 +23,7 @@ public interface BungeeAPI {
* @return SubAPI BungeeCord Common
*/
static BungeeAPI getInstance() {
return ((BungeeCommon) ProxyServer.getInstance()).api.run();
return ((BungeeCommon) ProxyServer.getInstance()).api.get();
}
/**
@ -96,7 +96,7 @@ public interface BungeeAPI {
* @return Lang Values
*/
default String getLang(String channel, String key) {
if (Util.isNull(channel, key)) throw new NullPointerException();
Util.nullpo(channel, key);
return getLang(channel).get(key);
}
@ -105,7 +105,7 @@ public interface BungeeAPI {
*
* @return Directory
*/
UniversalFile getRuntimeDirectory();
File getRuntimeDirectory();
/**
* Gets the SubServers Version

View File

@ -1,21 +1,20 @@
package net.ME1312.SubServers.Bungee;
import net.ME1312.Galaxi.Library.Callback.ReturnRunnable;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.config.ServerInfo;
import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;
/**
* BungeeCord Common Layout Class
*/
public abstract class BungeeCommon extends BungeeCord {
private static BungeeCommon instance;
final ReturnRunnable<BungeeAPI> api;
final Supplier<BungeeAPI> api;
protected BungeeCommon(ReturnRunnable<BungeeAPI> api) throws IOException {
protected BungeeCommon(Supplier<BungeeAPI> api) throws IOException {
this.api = api;
instance = this;
}

View File

@ -1,10 +1,9 @@
package net.ME1312.SubServers.Bungee.Library.Compatibility;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.md_5.bungee.api.chat.BaseComponent;
import java.util.UUID;
import java.util.function.IntConsumer;
/**
* RemotePlayer Static Implementation Layout Class
@ -22,7 +21,7 @@ public abstract class RPSI {
* @param messages Messages to send
* @param response Success Status
*/
protected abstract void sendMessage(UUID[] players, String[] messages, Callback<Integer> response);
protected abstract void sendMessage(UUID[] players, String[] messages, IntConsumer response);
/**
* Sends messages to this player
@ -31,7 +30,7 @@ public abstract class RPSI {
* @param messages Messages to send
* @param response Success Status
*/
protected abstract void sendMessage(UUID[] players, BaseComponent[][] messages, Callback<Integer> response);
protected abstract void sendMessage(UUID[] players, BaseComponent[][] messages, IntConsumer response);
/**
* Transfers this player to another server
@ -40,7 +39,7 @@ public abstract class RPSI {
* @param server Target server
* @param response Success Status
*/
protected abstract void transfer(UUID[] players, String server, Callback<Integer> response);
protected abstract void transfer(UUID[] players, String server, IntConsumer response);
/**
* Disconnects this player from the network
@ -49,5 +48,5 @@ public abstract class RPSI {
* @param reason Disconnect Reason
* @param response Success status
*/
protected abstract void disconnect(UUID[] players, String reason, Callback<Integer> response);
protected abstract void disconnect(UUID[] players, String reason, IntConsumer response);
}

View File

@ -1,13 +1,12 @@
package net.ME1312.SubServers.Bungee.Library.Compatibility;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.net.InetSocketAddress;
import java.util.UUID;
import java.util.function.IntConsumer;
import static net.ME1312.SubServers.Bungee.Library.Compatibility.RPSI.instance;
@ -80,7 +79,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void broadcastMessage(String message, Callback<Integer> response) {
static void broadcastMessage(String message, IntConsumer response) {
broadcastMessage(new String[]{ message }, response);
}
@ -90,7 +89,7 @@ public interface RemotePlayer {
* @param messages Messages to send
* @param response Success Status
*/
static void broadcastMessage(String[] messages, Callback<Integer> response) {
static void broadcastMessage(String[] messages, IntConsumer response) {
sendMessage(null, messages, response);
}
@ -109,7 +108,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
default void sendMessage(String message, Callback<Integer> response) {
default void sendMessage(String message, IntConsumer response) {
sendMessage(new String[]{ message }, response);
}
@ -119,7 +118,7 @@ public interface RemotePlayer {
* @param messages Messages to send
* @param response Success Status
*/
default void sendMessage(String[] messages, Callback<Integer> response) {
default void sendMessage(String[] messages, IntConsumer response) {
sendMessage(new UUID[]{ getUniqueId() }, messages, response);
}
@ -140,7 +139,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void sendMessage(UUID[] players, String message, Callback<Integer> response) {
static void sendMessage(UUID[] players, String message, IntConsumer response) {
sendMessage(players, new String[]{ message }, response);
}
@ -151,7 +150,7 @@ public interface RemotePlayer {
* @param messages Messages to send
* @param response Success Status
*/
static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
static void sendMessage(UUID[] players, String[] messages, IntConsumer response) {
instance.sendMessage(players, messages, response);
}
@ -170,7 +169,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void broadcastMessage(BaseComponent message, Callback<Integer> response) {
static void broadcastMessage(BaseComponent message, IntConsumer response) {
broadcastMessage(new BaseComponent[]{ message }, response);
}
@ -180,7 +179,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void broadcastMessage(BaseComponent[] message, Callback<Integer> response) {
static void broadcastMessage(BaseComponent[] message, IntConsumer response) {
broadcastMessage(new BaseComponent[][]{ message }, response);
}
@ -199,7 +198,7 @@ public interface RemotePlayer {
* @param messages Messages to send
* @param response Success Status
*/
static void broadcastMessage(BaseComponent[][] messages, Callback<Integer> response) {
static void broadcastMessage(BaseComponent[][] messages, IntConsumer response) {
sendMessage(null, messages, response);
}
@ -218,7 +217,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
default void sendMessage(BaseComponent message, Callback<Integer> response) {
default void sendMessage(BaseComponent message, IntConsumer response) {
sendMessage(new BaseComponent[]{ message }, response);
}
@ -228,7 +227,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
default void sendMessage(BaseComponent[] message, Callback<Integer> response) {
default void sendMessage(BaseComponent[] message, IntConsumer response) {
sendMessage(new BaseComponent[][]{ message }, response);
}
@ -247,7 +246,7 @@ public interface RemotePlayer {
* @param messages Messages to send
* @param response Success Status
*/
default void sendMessage(BaseComponent[][] messages, Callback<Integer> response) {
default void sendMessage(BaseComponent[][] messages, IntConsumer response) {
sendMessage(new UUID[]{ getUniqueId() }, messages, response);
}
@ -268,7 +267,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void sendMessage(UUID[] players, BaseComponent message, Callback<Integer> response) {
static void sendMessage(UUID[] players, BaseComponent message, IntConsumer response) {
sendMessage(players, new BaseComponent[]{ message }, response);
}
@ -279,7 +278,7 @@ public interface RemotePlayer {
* @param message Message to send
* @param response Success Status
*/
static void sendMessage(UUID[] players, BaseComponent[] message, Callback<Integer> response) {
static void sendMessage(UUID[] players, BaseComponent[] message, IntConsumer response) {
sendMessage(players, new BaseComponent[][]{ message }, response);
}
@ -300,7 +299,7 @@ public interface RemotePlayer {
* @param messages Message to send
* @param response Success Status
*/
static void sendMessage(UUID[] players, BaseComponent[][] messages, Callback<Integer> response) {
static void sendMessage(UUID[] players, BaseComponent[][] messages, IntConsumer response) {
instance.sendMessage(players, messages, response);
}
@ -319,7 +318,7 @@ public interface RemotePlayer {
* @param server Target server
* @param response Success status
*/
default void transfer(String server, Callback<Integer> response) {
default void transfer(String server, IntConsumer response) {
transfer(new UUID[]{ getUniqueId() }, server, response);
}
@ -340,7 +339,7 @@ public interface RemotePlayer {
* @param server Target server
* @param response Success status
*/
static void transfer(UUID[] players, String server, Callback<Integer> response) {
static void transfer(UUID[] players, String server, IntConsumer response) {
instance.transfer(players, server, response);
}
@ -359,7 +358,7 @@ public interface RemotePlayer {
* @param server Target server
* @param response Success status
*/
default void transfer(ServerInfo server, Callback<Integer> response) {
default void transfer(ServerInfo server, IntConsumer response) {
transfer(new UUID[]{ getUniqueId() }, server, response);
}
@ -380,7 +379,7 @@ public interface RemotePlayer {
* @param server Target server
* @param response Success status
*/
static void transfer(UUID[] players, ServerInfo server, Callback<Integer> response) {
static void transfer(UUID[] players, ServerInfo server, IntConsumer response) {
instance.transfer(players, server.getName(), response);
}
@ -396,7 +395,7 @@ public interface RemotePlayer {
*
* @param response Success status
*/
default void disconnect(Callback<Integer> response) {
default void disconnect(IntConsumer response) {
disconnect((String) null, response);
}
@ -415,7 +414,7 @@ public interface RemotePlayer {
* @param reason Disconnect Reason
* @param response Success status
*/
default void disconnect(String reason, Callback<Integer> response) {
default void disconnect(String reason, IntConsumer response) {
disconnect(new UUID[]{ getUniqueId() }, reason, response);
}
@ -434,7 +433,7 @@ public interface RemotePlayer {
* @param players Players to select
* @param response Success status
*/
static void disconnect(UUID[] players, Callback<Integer> response) {
static void disconnect(UUID[] players, IntConsumer response) {
disconnect(players, null, response);
}
@ -455,7 +454,7 @@ public interface RemotePlayer {
* @param reason Disconnect Reason
* @param response Success status
*/
static void disconnect(UUID[] players, String reason, Callback<Integer> response) {
static void disconnect(UUID[] players, String reason, IntConsumer response) {
instance.disconnect(players, reason, response);
}
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Library.Fallback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.BungeeCommon;
@ -28,7 +29,7 @@ public class SmartFallback implements ReconnectHandler {
public SmartFallback(ObjectMap<String> settings) {
dns_forward = settings.getBoolean("DNS-Forward", false);
if (reconnect == null && settings.getBoolean("Reconnect", false))
reconnect = Util.getDespiteException(() -> Util.reflect(ProxyServer.getInstance().getPluginManager().getPlugin("reconnect_yaml").getClass().getClassLoader().loadClass("net.md_5.bungee.module.reconnect.yaml.YamlReconnectHandler").getConstructor()), null);
reconnect = Try.all.get(() -> Util.reflect(ProxyServer.getInstance().getPluginManager().getPlugin("reconnect_yaml").getClass().getClassLoader().loadClass("net.md_5.bungee.module.reconnect.yaml.YamlReconnectHandler").getConstructor()));
}
@Override
@ -177,7 +178,7 @@ public class SmartFallback implements ReconnectHandler {
* @param inspector Inspector
*/
public static void addInspector(FallbackInspector inspector) {
if (Util.isNull(inspector)) throw new NullPointerException();
Util.nullpo(inspector);
inspectors.add(inspector);
}
@ -187,8 +188,8 @@ public class SmartFallback implements ReconnectHandler {
* @param inspector Inspector
*/
public static void removeInspector(FallbackInspector inspector) {
if (Util.isNull(inspector)) throw new NullPointerException();
Util.isException(() -> inspectors.remove(inspector));
Util.nullpo(inspector);
Try.all.run(() -> inspectors.remove(inspector));
}
@Override

View File

@ -34,7 +34,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId>
<version>21w33a</version>
<version>21w43a</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -24,7 +24,7 @@ public class SubAddHostEvent extends Event implements SubEvent, Cancellable {
* @param host Host Being Added
*/
public SubAddHostEvent(UUID player, Host host) {
if (Util.isNull(host)) throw new NullPointerException();
Util.nullpo(host);
this.player = player;
this.host = host;
}

View File

@ -18,7 +18,7 @@ public class SubAddProxyEvent extends Event implements SubEvent {
* @param proxy Host Being Added
*/
public SubAddProxyEvent(Proxy proxy) {
if (Util.isNull(proxy)) throw new NullPointerException();
Util.nullpo(proxy);
this.proxy = proxy;
}

View File

@ -27,7 +27,7 @@ public class SubAddServerEvent extends Event implements SubEvent, Cancellable {
* @param server Server Starting
*/
public SubAddServerEvent(UUID player, Host host, Server server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.host = host;
this.server = server;

View File

@ -36,7 +36,7 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
* @param port Server Port Number
*/
public SubCreateEvent(UUID player, Host host, String name, SubCreator.ServerTemplate template, Version version, int port) {
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
Util.nullpo(host, name, template, port);
this.player = player;
this.host = host;
this.name = name;
@ -54,7 +54,7 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
* @param version Server Version
*/
public SubCreateEvent(UUID player, SubServer server, SubCreator.ServerTemplate template, Version version) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.update = server;
this.name = server.getName();

View File

@ -39,7 +39,7 @@ public class SubCreatedEvent extends Event implements SubEvent {
* @param success Success Status
*/
public SubCreatedEvent(UUID player, Host host, String name, SubCreator.ServerTemplate template, Version version, int port, SubServer server, boolean update, boolean success) {
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
Util.nullpo(host, name, template, port);
this.player = player;
this.host = host;
this.name = name;

View File

@ -30,7 +30,7 @@ public class SubEditServerEvent extends Event implements SubEvent, Cancellable {
* @param edit Edit to make
*/
public SubEditServerEvent(UUID player, Server server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
Util.nullpo(server, edit);
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;

View File

@ -20,7 +20,7 @@ public class SubNetworkConnectEvent extends Event implements SubEvent, Cancellab
* SubData Network Connect Event
*/
public SubNetworkConnectEvent(DataServer network, DataClient client) {
if (Util.isNull(network, client)) throw new NullPointerException();
Util.nullpo(network, client);
this.network = network;
this.client = client;
}

View File

@ -20,7 +20,7 @@ public class SubNetworkDisconnectEvent extends Event implements SubEvent {
* SubData Network Disconnect Event
*/
public SubNetworkDisconnectEvent(DataServer network, DataClient client, DisconnectReason reason) {
if (Util.isNull(network, client, reason)) throw new NullPointerException();
Util.nullpo(network, client, reason);
this.network = network;
this.client = client;
this.reason = reason;

View File

@ -18,7 +18,7 @@ public class SubNetworkLoginEvent extends Event implements SubEvent {
* SubData Network Login Event
*/
public SubNetworkLoginEvent(DataServer network, DataClient client) {
if (Util.isNull(network, client)) throw new NullPointerException();
Util.nullpo(network, client);
this.network = network;
this.client = client;
}

View File

@ -24,7 +24,7 @@ public class SubRemoveHostEvent extends Event implements SubEvent, Cancellable {
* @param host Host to be added
*/
public SubRemoveHostEvent(UUID player, Host host) {
if (Util.isNull(host)) throw new NullPointerException();
Util.nullpo(host);
this.player = player;
this.host = host;
}

View File

@ -18,7 +18,7 @@ public class SubRemoveProxyEvent extends Event implements SubEvent {
* @param proxy Host Being Added
*/
public SubRemoveProxyEvent(Proxy proxy) {
if (Util.isNull(proxy)) throw new NullPointerException();
Util.nullpo(proxy);
this.proxy = proxy;
}

View File

@ -27,7 +27,7 @@ public class SubRemoveServerEvent extends Event implements SubEvent, Cancellable
* @param server Server Starting
*/
public SubRemoveServerEvent(UUID player, Host host, Server server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.host = host;
this.server = server;

View File

@ -25,7 +25,7 @@ public class SubSendCommandEvent extends Event implements SubEvent, Cancellable
* @param server Server being Commanded
*/
public SubSendCommandEvent(UUID player, SubServer server, String command) {
if (Util.isNull(server, command)) throw new NullPointerException();
Util.nullpo(server, command);
this.player = player;
this.server = server;
this.command = command;

View File

@ -24,7 +24,7 @@ public class SubStartEvent extends Event implements SubEvent, Cancellable {
* @param server Server Starting
*/
public SubStartEvent(UUID player, SubServer server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.server = server;
}

View File

@ -19,7 +19,7 @@ public class SubStartedEvent extends Event implements SubEvent {
* @param server Server Starting
*/
public SubStartedEvent(SubServer server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.server = server;
}

View File

@ -26,7 +26,7 @@ public class SubStopEvent extends Event implements SubEvent, Cancellable {
* @param force If it was a Forced Shutdown
*/
public SubStopEvent(UUID player, SubServer server, boolean force) {
if (Util.isNull(server, force)) throw new NullPointerException();
Util.nullpo(server, force);
this.player = player;
this.server = server;
this.force = force;

View File

@ -18,7 +18,7 @@ public class SubStoppedEvent extends Event implements SubEvent {
* @param server Server that Stopped
*/
public SubStoppedEvent(SubServer server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.server = server;
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Compatibility.JNA;
@ -40,7 +41,7 @@ public class Executable {
}
static {
USE_SESSION_TRACKING = Platform.getSystem() != Platform.WINDOWS && Util.getDespiteException(() -> {
USE_SESSION_TRACKING = Platform.getSystem() != Platform.WINDOWS && Try.all.get(() -> {
Process test = Runtime.getRuntime().exec(new String[]{"setsid", "bash", "-c", "exit 0"});
test.waitFor(); // The purpose of this block is to test for the 'setsid' command
return test.exitValue() == 0;
@ -95,9 +96,9 @@ public class Executable {
if (process.isAlive()) {
Long pid;
if (Platform.getSystem() == Platform.WINDOWS) {
if ((pid = pid(process)) != null) Util.isException(() -> Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()}).waitFor());
if ((pid = pid(process)) != null) Try.all.run(() -> Runtime.getRuntime().exec(new String[]{"taskkill.exe", "/T", "/F", "/PID", pid.toString()}).waitFor());
} else if (USE_SESSION_TRACKING) {
if ((pid = pid(process)) != null) Util.isException(() -> Runtime.getRuntime().exec(new String[]{"bash", "-c", "kill -9 $(ps -s " + pid + " -o pid=)"}).waitFor());
if ((pid = pid(process)) != null) Try.all.run(() -> Runtime.getRuntime().exec(new String[]{"bash", "-c", "kill -9 $(ps -s " + pid + " -o pid=)"}).waitFor());
}
if (process.isAlive() && terminate9(process)) {

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Host.External;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubData.Server.DataClient;
@ -189,7 +190,7 @@ public class ExternalHost extends Host implements ClientHandler {
@Override
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
ExternalSubServer server = (ExternalSubServer) servers.get(name.toLowerCase());
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
@ -214,7 +215,7 @@ public class ExternalHost extends Host implements ClientHandler {
@Override
protected boolean recycleSubServer(UUID player, String name, boolean forced) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
ExternalSubServer s = (ExternalSubServer) servers.get(name.toLowerCase());
String server = s.getName();
@ -256,7 +257,7 @@ public class ExternalHost extends Host implements ClientHandler {
@Override
protected boolean deleteSubServer(UUID player, String name, boolean forced) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
ExternalSubServer s = (ExternalSubServer) servers.get(name.toLowerCase());
String server = s.getName();
@ -298,7 +299,7 @@ public class ExternalHost extends Host implements ClientHandler {
@Override
public boolean destroy() {
if (Util.getDespiteException(() -> Util.reflect(SubProxy.class.getDeclaredField("running"), plugin), true)) {
if (Try.all.get(() -> Util.reflect(SubProxy.class.getDeclaredField("running"), plugin), true)) {
return super.destroy();
}
return true;

View File

@ -1,19 +1,21 @@
package net.ME1312.SubServers.Bungee.Host.External;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
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.Container.Value;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
import net.ME1312.SubServers.Bungee.Event.SubCreatedEvent;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.SubServers.Bungee.Host.Host;
import net.ME1312.SubServers.Bungee.Host.SubCreator;
import net.ME1312.SubServers.Bungee.Host.SubLogger;
import net.ME1312.SubServers.Bungee.Host.SubServer;
import net.ME1312.SubServers.Bungee.Host.SubServer.StopAction;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExConfigureHost;
@ -30,6 +32,7 @@ import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.function.Consumer;
/**
* External SubCreator Class
@ -55,7 +58,7 @@ public class ExternalSubCreator extends SubCreator {
*/
public ExternalSubCreator(ExternalHost host, Range<Integer> ports, boolean log, String gitBash) {
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
if (Util.isNull(host, ports, log, gitBash)) throw new NullPointerException();
Util.nullpo(host, ports, log, gitBash);
this.host = host;
this.ports = ports;
this.log = new Container<Boolean>(log);
@ -67,10 +70,10 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void reload() {
templatesR.clear();
if (new UniversalFile(host.plugin.dir, "SubServers:Templates").exists()) for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
if (new File(host.plugin.dir, "SubServers/Templates").exists()) for (File file : new File(host.plugin.dir, "SubServers/Templates").listFiles()) {
try {
if (file.isDirectory() && !file.getName().endsWith(".x")) {
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()):new ObjectMap<String>();
ObjectMap<String> config = (new File(file, "template.yml").exists())? new YAMLConfig(new File(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()) : new ObjectMap<String>();
ServerTemplate template = loadTemplate(file.getName(), config.getBoolean("Enabled", true), config.getBoolean("Internal", false), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
templatesR.put(file.getName().toLowerCase(), template);
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
@ -81,7 +84,7 @@ public class ExternalSubCreator extends SubCreator {
}
}
if (host.available && !Util.getDespiteException(() -> Util.reflect(SubProxy.class.getDeclaredField("reloading"), host.plugin), false)) {
if (host.available && !Try.all.get(() -> Util.reflect(SubProxy.class.getDeclaredField("reloading"), host.plugin), false)) {
host.queue(new PacketExConfigureHost(host.plugin, host), new PacketExUploadTemplates(host.plugin, () -> {
if (enableRT == null || enableRT) host.queue(new PacketExDownloadTemplates(host.plugin, host));
}));
@ -89,8 +92,8 @@ public class ExternalSubCreator extends SubCreator {
}
@Override
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
if (Util.isNull(name, template)) throw new NullPointerException();
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback) {
Util.nullpo(name, template);
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -123,9 +126,9 @@ public class ExternalSubCreator extends SubCreator {
return false;
}
} else return false;
} private <T> void callback(StackTraceElement[] origin, Callback<T> callback, T value) {
} private <T> void callback(StackTraceElement[] origin, Consumer<T> callback, T value) {
if (callback != null) try {
callback.run(value);
callback.accept(value);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -134,8 +137,8 @@ public class ExternalSubCreator extends SubCreator {
}
@Override
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> callback) {
if (Util.isNull(server)) throw new NullPointerException();
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Consumer<Boolean> callback) {
Util.nullpo(server);
final ServerTemplate ft = (template == null)?server.getTemplate():template;
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -153,7 +156,7 @@ public class ExternalSubCreator extends SubCreator {
host.queue(new PacketExCreateServer(player, server, ft, version, logger.getExternalAddress(), data -> {
finish(player, server, server.getName(), ft, version, server.getAddress().getPort(), prefix, origin, data, s -> {
((ExternalSubServer) server).updating(false);
if (callback != null) callback.run(s != null);
if (callback != null) callback.accept(s != null);
});
this.thread.remove(name.toLowerCase());
}));
@ -165,7 +168,7 @@ public class ExternalSubCreator extends SubCreator {
} else return false;
}
private void finish(UUID player, SubServer update, String name, ServerTemplate template, Version version, int port, String prefix, StackTraceElement[] origin, ObjectMap<Integer> data, Callback<SubServer> callback) {
private void finish(UUID player, SubServer update, String name, ServerTemplate template, Version version, int port, String prefix, StackTraceElement[] origin, ObjectMap<Integer> data, Consumer<SubServer> callback) {
try {
if (data.getInt(0x0001) == 0) {
Logger.get(prefix).info("Saving...");
@ -201,14 +204,14 @@ public class ExternalSubCreator extends SubCreator {
}
server.setAll(config);
if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name));
if (update != null) Try.all.run(() -> update.getHost().forceRemoveSubServer(name));
subserver = host.constructSubServer(name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
subserver.setTemplate(server.getRawString("Template"));
for (String group : server.getStringList("Group")) subserver.addGroup(group);
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
SubServer.StopAction action = Try.all.get(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null) subserver.setStopAction(action);
if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys())
subserver.addExtra(extra, server.getMap("Extra").getObject(extra));
@ -320,7 +323,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
log.value(value);
}
@ -350,7 +353,7 @@ public class ExternalSubCreator extends SubCreator {
@Override
public ServerTemplate getTemplate(String name) {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
name = name.toLowerCase();
ServerTemplate template = templates.getOrDefault(name, null);

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Host.External;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
import net.ME1312.SubServers.Bungee.Host.SubLogger;
@ -20,8 +21,6 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* External Process Logger Class
@ -127,14 +126,14 @@ public class ExternalSubLogger extends SubLogger {
@Override
public void registerFilter(SubLogFilter filter) {
if (Util.isNull(filter)) throw new NullPointerException();
Util.nullpo(filter);
filters.add(filter);
}
@Override
public void unregisterFilter(SubLogFilter filter) {
if (Util.isNull(filter)) throw new NullPointerException();
Util.isException(() -> filters.remove(filter));
Util.nullpo(filter);
Try.all.run(() -> filters.remove(filter));
}
@Override

View File

@ -1,11 +1,11 @@
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.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.*;
@ -21,8 +21,11 @@ import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.ChatColor;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.function.Supplier;
/**
* External SubServer Class
@ -83,7 +86,7 @@ public class ExternalSubServer extends SubServerImpl {
}
private void init(ExternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
if (Util.isNull(host, name, enabled, port, motd, log, stopcmd, hidden, restricted)) throw new NullPointerException();
Util.nullpo(host, name, enabled, port, motd, log, stopcmd, hidden, restricted);
this.host = host;
this.enabled = enabled;
this.log = new Container<Boolean>(log);
@ -209,7 +212,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public boolean command(UUID player, String command) {
if (Util.isNull(command)) throw new NullPointerException();
Util.nullpo(command);
if (running) {
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command);
host.plugin.getPluginManager().callEvent(event);
@ -393,7 +396,7 @@ public class ExternalSubServer extends SubServerImpl {
case "stop-cmd":
case "stop-command":
if (value.isString()) {
if (!stopcmd.equals(value)) host.queue(new PacketExControlServer(this, Action.SET_STOP_COMMAND, value.asRawString()));
if (!stopcmd.equals(value.asRawString())) host.queue(new PacketExControlServer(this, Action.SET_STOP_COMMAND, value.asRawString()));
stopcmd = value.asRawString();
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
@ -404,7 +407,7 @@ public class ExternalSubServer extends SubServerImpl {
break;
case "stop-action":
if (value.isString()) {
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
StopAction action = Try.all.get(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null) {
stopaction = action;
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
@ -497,8 +500,8 @@ public class ExternalSubServer extends SubServerImpl {
if (!isRunning() && forward == null && state) start(player);
return c;
} else return -1;
} private <V> void waitFor(ReturnRunnable<V> method, V value) throws InterruptedException {
while (method.run() != value) {
} private <V> void waitFor(Supplier<V> method, V value) throws InterruptedException {
while (method.get() != value) {
Thread.sleep(250);
}
}
@ -533,7 +536,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
if (enabled != value) host.queue(new PacketExControlServer(this, Action.SET_ENABLED, (Boolean) value));
enabled = value;
}
@ -545,7 +548,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
if (log.value() != value) host.queue(new PacketExControlServer(this, Action.SET_LOGGING, (Boolean) value));
log.value(value);
}
@ -577,7 +580,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
if (!stopcmd.equals(value)) host.queue(new PacketExControlServer(this, Action.SET_STOP_COMMAND, value));
stopcmd = value;
}
@ -589,7 +592,7 @@ public class ExternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
Util.nullpo(action);
stopaction = action;
}
}

View File

@ -14,13 +14,16 @@ import com.google.common.collect.Range;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.net.InetAddress;
import java.util.*;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
/**
* Host Layout Class
*/
public abstract class Host implements ExtraDataHandler {
private ObjectMap<String> extra = new ObjectMap<String>();
public abstract class Host implements ExtraDataHandler<String> {
private final ObjectMap<String> extra = new ObjectMap<String>();
private final String signature;
private String nick = null;
@ -40,7 +43,7 @@ public abstract class Host implements ExtraDataHandler {
public Host(SubProxy plugin, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) {
if (name.contains(" ")) throw new InvalidHostException("Host names cannot have spaces: " + name);
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new InvalidHostException("Port range is not bound");
if (Util.isNull(plugin, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
Util.nullpo(plugin, name, enabled, ports, log, address, directory, gitBash);
signature = plugin.api.signAnonymousObject();
SubAPI.getInstance().getInternals().subprotocol.whitelist(address.getHostAddress());
}
@ -533,19 +536,19 @@ public abstract class Host implements ExtraDataHandler {
@Override
public void addExtra(String handle, Object value) {
if (Util.isNull(handle, value)) throw new NullPointerException();
Util.nullpo(handle, value);
extra.set(handle, value);
}
@Override
public boolean hasExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.getKeys().contains(handle);
}
@Override
public ObjectMapValue getExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.get(handle);
}
@ -556,7 +559,7 @@ public abstract class Host implements ExtraDataHandler {
@Override
public void removeExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
extra.remove(handle);
}

View File

@ -1,8 +1,8 @@
package net.ME1312.SubServers.Bungee.Host.Internal;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Directories;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
@ -121,7 +121,7 @@ public class InternalHost extends Host {
@Override
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
InternalSubServer server = (InternalSubServer) servers.get(name.toLowerCase());
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
plugin.getPluginManager().callEvent(event);
@ -153,22 +153,22 @@ public class InternalHost extends Host {
* @return Success Status
*/
protected boolean recycleSubServer(UUID player, String name, boolean forced, boolean multithreading) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
String server = servers.get(name.toLowerCase()).getName();
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
if (removeSubServer(player, server, forced)) {
Runnable method = () -> {
UniversalFile to = new UniversalFile(plugin.dir, "SubServers:Recently Deleted:" + server.toLowerCase());
File to = new File(plugin.dir, "SubServers/Recently Deleted/" + server.toLowerCase());
try {
if (from.exists()) {
Logger.get("SubServers").info("Moving Files...");
if (to.exists()) {
if (to.isDirectory()) Util.deleteDirectory(to);
if (to.isDirectory()) Directories.delete(to);
else to.delete();
}
to.mkdirs();
Util.copyDirectory(from, to);
Util.deleteDirectory(from);
Directories.copy(from, to);
Directories.delete(from);
}
} catch (Exception e) {
e.printStackTrace();
@ -215,7 +215,7 @@ public class InternalHost extends Host {
* @return Success Status
*/
protected boolean deleteSubServer(UUID player, String name, boolean forced, boolean multithreading) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
String server = servers.get(name.toLowerCase()).getName();
File from = new File(getPath(), servers.get(server.toLowerCase()).getPath());
if (removeSubServer(player, server, forced)) {
@ -223,7 +223,7 @@ public class InternalHost extends Host {
try {
if (from.exists()) {
Logger.get("SubServers").info("Removing Files...");
Util.deleteDirectory(from);
Directories.delete(from);
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -1,15 +1,15 @@
package net.ME1312.SubServers.Bungee.Host.Internal;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
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.Pair;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Directories;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
@ -37,9 +37,11 @@ import java.nio.file.LinkOption;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import static java.util.logging.Level.*;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
/**
* Internal SubCreator Class
@ -63,10 +65,10 @@ public class InternalSubCreator extends SubCreator {
private final String prefix;
private final InternalSubLogger log;
private final HashMap<String, String> replacements;
private final Callback<SubServer> callback;
private final Consumer<SubServer> callback;
private Process process;
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Callback<SubServer> callback) {
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Consumer<SubServer> callback) {
super("SubServers.Bungee::Internal_SubCreator_Process_Handler(" + name + ')');
this.player = player;
this.update = null;
@ -79,7 +81,7 @@ public class InternalSubCreator extends SubCreator {
this.callback = callback;
}
private CreatorTask(UUID player, SubServer server, ServerTemplate template, Version version, Callback<SubServer> callback) {
private CreatorTask(UUID player, SubServer server, ServerTemplate template, Version version, Consumer<SubServer> callback) {
super("SubServers.Bungee::Internal_SubCreator_Process_Handler(" + server.getName() + ')');
this.player = player;
this.update = server;
@ -183,7 +185,7 @@ public class InternalSubCreator extends SubCreator {
if (template.getBuildOptions().contains("Executable")) {
File cache = null;
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache:Templates:" + template.getName());
cache = new File(host.plugin.dir, "SubServers/Cache/Templates/" + template.getName());
cache.mkdirs();
var.put("cache", cache.getAbsolutePath());
}
@ -211,14 +213,14 @@ public class InternalSubCreator extends SubCreator {
if (cache != null) {
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache:Templates");
cache = new File(host.plugin.dir, "SubServers/Cache/Templates");
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache");
cache = new File(host.plugin.dir, "SubServers/Cache");
if (cache.isDirectory() && cache.listFiles().length == 0) cache.delete();
}
}
new UniversalFile(dir, "template.yml").delete();
new File(dir, "template.yml").delete();
if (error) throw new SubCreatorException();
return server;
}
@ -303,14 +305,14 @@ public class InternalSubCreator extends SubCreator {
}
server.setAll(config);
if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name));
if (update != null) Try.all.run(() -> update.getHost().forceRemoveSubServer(name));
subserver = host.constructSubServer(name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"),
server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted"));
if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display"));
subserver.setTemplate(server.getRawString("Template"));
for (String group : server.getStringList("Group")) subserver.addGroup(group);
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
SubServer.StopAction action = Try.all.get(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null) subserver.setStopAction(action);
if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys())
subserver.addExtra(extra, server.getMap("Extra").getObject(extra));
@ -329,16 +331,16 @@ public class InternalSubCreator extends SubCreator {
InternalSubCreator.this.thread.remove(name.toLowerCase());
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, subserver, update != null, true));
callback.run(subserver);
callback.accept(subserver);
} catch (Exception e) {
e.printStackTrace();
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, update, update != null, false));
callback.run(null);
callback.accept(null);
}
} else {
Logger.get(prefix).info("Couldn't build the server jar. Check the SubCreator logs for more detail.");
host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, update, update != null, false));
callback.run(null);
callback.accept(null);
}
InternalSubCreator.this.thread.remove(name.toLowerCase());
}
@ -354,7 +356,7 @@ public class InternalSubCreator extends SubCreator {
*/
public InternalSubCreator(InternalHost host, Range<Integer> ports, boolean log, String gitBash) {
if (!ports.hasLowerBound() || !ports.hasUpperBound()) throw new IllegalArgumentException("Port range is not bound");
if (Util.isNull(host, ports, log, gitBash)) throw new NullPointerException();
Util.nullpo(host, ports, log, gitBash);
this.host = host;
this.ports = ports;
this.log = new Container<Boolean>(log);
@ -367,11 +369,11 @@ public class InternalSubCreator extends SubCreator {
@Override
public void reload() {
templates.clear();
if (new UniversalFile(host.plugin.dir, "SubServers:Templates").exists())
for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
if (new File(host.plugin.dir, "SubServers/Templates").exists())
for (File file : new File(host.plugin.dir, "SubServers/Templates").listFiles()) {
try {
if (file.isDirectory() && !file.getName().endsWith(".x")) {
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists()) ? new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()) : new ObjectMap<String>();
ObjectMap<String> config = (new File(file, "template.yml").exists())? new YAMLConfig(new File(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()) : new ObjectMap<String>();
ServerTemplate template = loadTemplate(file.getName(), config.getBoolean("Enabled", true), config.getBoolean("Internal", false), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
templates.put(file.getName().toLowerCase(), template);
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
@ -385,8 +387,8 @@ public class InternalSubCreator extends SubCreator {
@SuppressWarnings("deprecation")
@Override
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
if (Util.isNull(name, template)) throw new NullPointerException();
public boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback) {
Util.nullpo(name, template);
if (host.isAvailable() && host.isEnabled() && template.isEnabled() && !SubAPI.getInstance().getSubServers().keySet().contains(name.toLowerCase()) && !SubCreator.isReserved(name) && (version != null || !template.requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -403,7 +405,7 @@ public class InternalSubCreator extends SubCreator {
CreatorTask task = new CreatorTask(player, name, template, version, port, server -> {
if (callback != null) try {
callback.run(server);
callback.accept(server);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -426,8 +428,8 @@ public class InternalSubCreator extends SubCreator {
@SuppressWarnings("deprecation")
@Override
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> callback) {
if (Util.isNull(server)) throw new NullPointerException();
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Consumer<Boolean> callback) {
Util.nullpo(server);
final ServerTemplate ft = (template == null)?server.getTemplate():template;
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) {
StackTraceElement[] origin = new Exception().getStackTrace();
@ -436,7 +438,7 @@ public class InternalSubCreator extends SubCreator {
CreatorTask task = new CreatorTask(player, server, ft, version, x -> {
((InternalSubServer) server).updating(false);
if (callback != null) try {
callback.run(x != null);
callback.accept(x != null);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -538,7 +540,7 @@ public class InternalSubCreator extends SubCreator {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
log.value(value);
}
@ -565,7 +567,7 @@ public class InternalSubCreator extends SubCreator {
@Override
public ServerTemplate getTemplate(String name) {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
ServerTemplate template = templates.getOrDefault(name.toLowerCase(), null);
if (template == null || template.isInternal()) {
@ -590,32 +592,32 @@ public class InternalSubCreator extends SubCreator {
boolean installed = false;
if (type == ServerType.SPIGOT) {
installed = true;
if (!new UniversalFile(dir, "plugins").exists()) new UniversalFile(dir, "plugins").mkdirs();
if (!new UniversalFile(dir, "plugins:SubServers.Client.jar").exists())
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
if (!new File(dir, "plugins").exists()) new File(dir, "plugins").mkdirs();
if (!new File(dir, "plugins/SubServers.Client.jar").exists())
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new File(dir, "plugins/SubServers.Client.jar").getPath());
} else if (type == ServerType.FORGE || type == ServerType.SPONGE) {
installed = true;
if (!new UniversalFile(dir, "mods").exists()) new UniversalFile(dir, "mods").mkdirs();
if (!new UniversalFile(dir, "mods:SubServers.Client.jar").exists())
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
if (!new File(dir, "mods").exists()) new File(dir, "mods").mkdirs();
if (!new File(dir, "mods/SubServers.Client.jar").exists())
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new File(dir, "mods/SubServers.Client.jar").getPath());
}
if (installed) {
YAMLSection config = new YAMLSection();
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
FileWriter writer = new FileWriter(new File(dir, "subdata.json"), false);
config.setAll(getSubData());
writer.write(config.toJSON().toString());
writer.close();
if (!new UniversalFile(dir, "subdata.rsa.key").exists() && new UniversalFile("SubServers:subdata.rsa.key").exists()) {
Files.copy(new UniversalFile("SubServers:subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
if (!new File(dir, "subdata.rsa.key").exists() && new File("SubServers/subdata.rsa.key").exists()) {
Files.copy(new File("SubServers/subdata.rsa.key").toPath(), new File(dir, "subdata.rsa.key").toPath());
}
}
}
private void updateDirectory(File from, File to, boolean overwrite) {
if (!to.exists()) {
Util.copyDirectory(from, to);
Directories.copy(from, to);
} else if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
String files[] = from.list();
@ -629,7 +631,7 @@ public class InternalSubCreator extends SubCreator {
try {
if (overwrite && (from.length() != to.length() || !Arrays.equals(generateSHA256(to), generateSHA256(from)))) {
if (to.exists()) {
if (to.isDirectory()) Util.deleteDirectory(to);
if (to.isDirectory()) Directories.delete(to);
else to.delete();
}
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING);

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Host.Internal;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubServers.Bungee.Host.SubLogFilter;
import net.ME1312.SubServers.Bungee.Host.SubLogger;
@ -189,14 +190,14 @@ public class InternalSubLogger extends SubLogger {
@Override
public void registerFilter(SubLogFilter filter) {
if (Util.isNull(filter)) throw new NullPointerException();
Util.nullpo(filter);
filters.add(filter);
}
@Override
public void unregisterFilter(SubLogFilter filter) {
if (Util.isNull(filter)) throw new NullPointerException();
Util.isException(() -> filters.remove(filter));
Util.nullpo(filter);
Try.all.run(() -> filters.remove(filter));
}
@Override

View File

@ -5,7 +5,7 @@ import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Container.Value;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.SubDataClient;
@ -18,15 +18,16 @@ import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer.Edit;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.ME1312.SubServers.Bungee.SubProxy;
import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.api.ChatColor;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
@ -93,7 +94,7 @@ public class InternalSubServer extends SubServerImpl {
}
private void init(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
Util.nullpo(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
this.host = host;
this.enabled = enabled;
this.log = new Container<Boolean>(log);
@ -107,12 +108,12 @@ public class InternalSubServer extends SubServerImpl {
this.logger = new InternalSubLogger(null, this, getName(), this.log, null);
this.thread = null;
this.command = null;
final UniversalFile[] locations = new UniversalFile[] {
new UniversalFile(this.directory, "plugins:SubServers.Client.jar"),
new UniversalFile(this.directory, "mods:SubServers.Client.jar")
final File[] locations = new File[] {
new File(this.directory, "plugins/SubServers.Client.jar"),
new File(this.directory, "mods/SubServers.Client.jar")
};
for (UniversalFile location : locations) {
for (File location : locations) {
if (location.exists()) {
try {
JarInputStream updated = new JarInputStream(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/client.jar"));
@ -275,7 +276,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public boolean command(UUID player, String command) {
if (Util.isNull(command)) throw new NullPointerException();
Util.nullpo(command);
if (thread != null && thread.isAlive()) {
SubSendCommandEvent event = new SubSendCommandEvent(player, this, command);
host.plugin.getPluginManager().callEvent(event);
@ -467,7 +468,7 @@ public class InternalSubServer extends SubServerImpl {
break;
case "stop-action":
if (value.isString()) {
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
StopAction action = Try.all.get(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null) {
stopaction = action;
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
@ -598,7 +599,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setEnabled(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
enabled = value;
}
@ -609,7 +610,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setLogging(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
log.value(value);
}
@ -640,7 +641,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopCommand(String value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
stopcmd = value;
}
@ -651,7 +652,7 @@ public class InternalSubServer extends SubServerImpl {
@Override
public void setStopAction(StopAction action) {
if (Util.isNull(action)) throw new NullPointerException();
Util.nullpo(action);
stopaction = action;
}
}

View File

@ -19,9 +19,9 @@ import java.util.*;
/**
* Proxy Class
*/
public class Proxy implements ClientHandler, ExtraDataHandler {
private HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
private ObjectMap<String> extra = new ObjectMap<String>();
public class Proxy implements ClientHandler, ExtraDataHandler<String> {
private final HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
private final ObjectMap<String> extra = new ObjectMap<String>();
private final String signature;
private boolean persistent = false;
private String nick = null;
@ -158,19 +158,19 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
@Override
public void addExtra(String handle, Object value) {
if (Util.isNull(handle, value)) throw new NullPointerException();
Util.nullpo(handle, value);
extra.set(handle, value);
}
@Override
public boolean hasExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.getKeys().contains(handle);
}
@Override
public ObjectMapValue getExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.get(handle);
}
@ -181,7 +181,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler {
@Override
public void removeExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
extra.remove(handle);
}

View File

@ -1,13 +1,14 @@
package net.ME1312.SubServers.Bungee.Host;
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.Util;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubData.Server.SubDataSerializable;
import net.ME1312.SubServers.Bungee.Library.Compatibility.RPSI;
import net.ME1312.SubServers.Bungee.Network.Packet.*;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketDisconnectPlayer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketMessagePlayer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketTransferPlayer;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.ProxyServer;
@ -19,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.UUID;
import java.util.function.IntConsumer;
/**
* Remote Player Class
@ -48,7 +50,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
* @param server Server the player is on
*/
public RemotePlayer(ProxiedPlayer player, ServerInfo server) {
if (Util.isNull(player)) throw new NullPointerException();
Util.nullpo(player);
this.local = player;
this.id = player.getUniqueId();
this.server = (server instanceof Server)? (Server) server : null;
@ -64,7 +66,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
* @param ip Player IP Address
*/
public RemotePlayer(String name, UUID id, Proxy proxy, ServerInfo server, InetSocketAddress ip) {
if (Util.isNull(name, id, proxy, ip)) throw new NullPointerException();
Util.nullpo(name, id, proxy, ip);
this.id = id;
this.name = name;
this.ip = ip;
@ -156,11 +158,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
// These overrides provide for the static methods in BungeeCommon
new RPSI() {
@Override
protected void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
protected void sendMessage(UUID[] players, String[] messages, IntConsumer response) {
StackTraceElement[] origin = new Exception().getStackTrace();
PacketMessagePlayer.run(Arrays.asList(players), new ContainedPair<>(messages, null), null, i -> {
try {
response.run(i);
response.accept(i);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -170,11 +172,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
}
@Override
protected void sendMessage(UUID[] players, BaseComponent[][] messages, Callback<Integer> response) {
protected void sendMessage(UUID[] players, BaseComponent[][] messages, IntConsumer response) {
StackTraceElement[] origin = new Exception().getStackTrace();
PacketMessagePlayer.run(Arrays.asList(players), new ContainedPair<>(null, messages), null, i -> {
try {
response.run(i);
response.accept(i);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -184,11 +186,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
}
@Override
protected void transfer(UUID[] players, String server, Callback<Integer> response) {
protected void transfer(UUID[] players, String server, IntConsumer response) {
StackTraceElement[] origin = new Exception().getStackTrace();
PacketTransferPlayer.run(Arrays.asList(players), server, i -> {
try {
response.run(i);
response.accept(i);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -198,11 +200,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
}
@Override
protected void disconnect(UUID[] players, String reason, Callback<Integer> response) {
protected void disconnect(UUID[] players, String reason, IntConsumer response) {
StackTraceElement[] origin = new Exception().getStackTrace();
PacketDisconnectPlayer.run(Arrays.asList(players), reason, i -> {
try {
response.run(i);
response.accept(i);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.setStackTrace(origin);
@ -218,11 +220,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(messages);
}
public static void broadcastMessage(String message, Callback<Integer> response) {
public static void broadcastMessage(String message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(message, response);
}
public static void broadcastMessage(String[] messages, Callback<Integer> response) {
public static void broadcastMessage(String[] messages, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(messages, response);
}
@ -230,11 +232,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, messages);
}
public static void sendMessage(UUID[] players, String message, Callback<Integer> response) {
public static void sendMessage(UUID[] players, String message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, message, response);
}
public static void sendMessage(UUID[] players, String[] messages, Callback<Integer> response) {
public static void sendMessage(UUID[] players, String[] messages, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, messages, response);
}
@ -242,11 +244,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(message);
}
public static void broadcastMessage(BaseComponent message, Callback<Integer> response) {
public static void broadcastMessage(BaseComponent message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(message, response);
}
public static void broadcastMessage(BaseComponent[] message, Callback<Integer> response) {
public static void broadcastMessage(BaseComponent[] message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(message, response);
}
@ -254,7 +256,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(messages);
}
public static void broadcastMessage(BaseComponent[][] messages, Callback<Integer> response) {
public static void broadcastMessage(BaseComponent[][] messages, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.broadcastMessage(messages, response);
}
@ -262,11 +264,11 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, message);
}
public static void sendMessage(UUID[] players, BaseComponent message, Callback<Integer> response) {
public static void sendMessage(UUID[] players, BaseComponent message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, message, response);
}
public static void sendMessage(UUID[] players, BaseComponent[] message, Callback<Integer> response) {
public static void sendMessage(UUID[] players, BaseComponent[] message, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, message, response);
}
@ -274,7 +276,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, messages);
}
public static void sendMessage(UUID[] players, BaseComponent[][] messages, Callback<Integer> response) {
public static void sendMessage(UUID[] players, BaseComponent[][] messages, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.sendMessage(players, messages, response);
}
@ -282,7 +284,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.transfer(players, server);
}
public static void transfer(UUID[] players, String server, Callback<Integer> response) {
public static void transfer(UUID[] players, String server, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.transfer(players, server, response);
}
@ -290,7 +292,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.transfer(players, server);
}
public static void transfer(UUID[] players, ServerInfo server, Callback<Integer> response) {
public static void transfer(UUID[] players, ServerInfo server, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.transfer(players, server, response);
}
@ -298,7 +300,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.disconnect(players);
}
public static void disconnect(UUID[] players, Callback<Integer> response) {
public static void disconnect(UUID[] players, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.disconnect(players, response);
}
@ -306,7 +308,7 @@ public class RemotePlayer implements net.ME1312.SubServers.Bungee.Library.Compat
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.disconnect(players, reason);
}
public static void disconnect(UUID[] players, String reason, Callback<Integer> response) {
public static void disconnect(UUID[] players, String reason, IntConsumer response) {
net.ME1312.SubServers.Bungee.Library.Compatibility.RemotePlayer.disconnect(players, reason, response);
}
}

View File

@ -13,7 +13,7 @@ import java.util.UUID;
/**
* Server Interface
*/
public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler {
public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler<String> {
/**
* Link a SubData Client to this Object

View File

@ -5,7 +5,6 @@ import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubRemoveProxyEvent;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExEditServer.Edit;
@ -13,7 +12,6 @@ import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.net.InetSocketAddress;
@ -71,7 +69,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@SuppressWarnings("deprecation")
private void init(String name, SocketAddress address, String motd, boolean hidden, boolean restricted) throws InvalidServerException {
if (Util.isNull(name, address, motd, hidden, restricted)) throw new NullPointerException();
Util.nullpo(name, address, motd, hidden, restricted);
if (name.contains(" ")) throw new InvalidServerException("Server names cannot have spaces: " + name);
SubAPI.getInstance().getInternals().subprotocol.whitelist(getAddress().getAddress().getHostAddress());
this.hidden = hidden;
@ -160,7 +158,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
@SuppressWarnings("deprecation")
public void addGroup(String value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
if (value.length() > 0 && !groups.contains(value)) {
groups.add(value);
Collections.sort(groups);
@ -170,7 +168,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
@SuppressWarnings("deprecation")
public void removeGroup(String value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
groups.remove(value);
Collections.sort(groups);
}
@ -194,7 +192,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
}
public void setMotd(String value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, value);
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
@ -206,7 +204,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
}
public void setRestricted(boolean value) {
if (Util.isNull(value)) throw new NullPointerException();
Util.nullpo(value);
try {
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value);
@ -241,7 +239,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
public void whitelist(UUID player) {
if (Util.isNull(player)) throw new NullPointerException();
Util.nullpo(player);
if (!whitelist.contains(player)) whitelist.add(player);
if (isRegistered()) for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExEditServer(this, Edit.WHITELIST_ADD, player));
@ -250,7 +248,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
public void unwhitelist(UUID player) {
if (Util.isNull(player)) throw new NullPointerException();
Util.nullpo(player);
whitelist.remove(player);
if (isRegistered()) for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) {
((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExEditServer(this, Edit.WHITELIST_REMOVE, player));
@ -269,19 +267,19 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
public void addExtra(String handle, Object value) {
if (Util.isNull(handle, value)) throw new NullPointerException();
Util.nullpo(handle, value);
extra.set(handle, value);
}
@Override
public boolean hasExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.getKeys().contains(handle);
}
@Override
public ObjectMapValue getExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
return extra.get(handle);
}
@ -292,7 +290,7 @@ public class ServerImpl extends BungeeServerInfo implements Server {
@Override
public void removeExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
Util.nullpo(handle);
extra.remove(handle);
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Host;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -12,6 +11,7 @@ import com.google.common.collect.Range;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.function.Consumer;
/**
* SubCreator Layout Class
@ -44,7 +44,7 @@ public abstract class SubCreator {
}
private ServerTemplate(String name, boolean enabled, boolean internal, String icon, File directory, ObjectMap<String> build, ObjectMap<String> options, boolean dynamic) {
if (Util.isNull(name, enabled, directory, build, options)) throw new NullPointerException();
Util.nullpo(name, enabled, directory, build, options);
if (name.contains(" ")) throw new InvalidTemplateException("Template names cannot have spaces: " + name);
this.name = name;
this.enabled = enabled;
@ -233,7 +233,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public abstract boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback);
public abstract boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback);
/**
* Create a SubServer
@ -259,7 +259,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public boolean create(String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
public boolean create(String name, ServerTemplate template, Version version, Integer port, Consumer<SubServer> callback) {
return create(null, name, template, version, port, callback);
}
@ -286,7 +286,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public abstract boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> callback);
public abstract boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Consumer<Boolean> callback);
/**
* Update a SubServer
@ -310,7 +310,7 @@ public abstract class SubCreator {
* @param callback Callback
* @return Success Status
*/
public boolean update(SubServer server, ServerTemplate template, Version version, Callback<Boolean> callback) {
public boolean update(SubServer server, ServerTemplate template, Version version, Consumer<Boolean> callback) {
return update(null, server, template, version, callback);
}

View File

@ -40,7 +40,7 @@ public interface SubServer extends Server {
* @param command Command
*/
public LoggedCommand(String command) {
if (Util.isNull(command)) throw new NullPointerException();
Util.nullpo(command);
this.date = Calendar.getInstance().getTime();
this.sender = null;
this.command = command;
@ -53,7 +53,7 @@ public interface SubServer extends Server {
* @param command Command
*/
public LoggedCommand(UUID sender, String command) {
if (Util.isNull(command)) throw new NullPointerException();
Util.nullpo(command);
this.date = Calendar.getInstance().getTime();
this.sender = sender;
this.command = command;
@ -67,7 +67,7 @@ public interface SubServer extends Server {
* @param command Command
*/
public LoggedCommand(Date date, UUID sender, String command) {
if (Util.isNull(date, command)) throw new NullPointerException();
Util.nullpo(date, command);
this.date = date;
this.sender = sender;
this.command = command;

View File

@ -1,13 +1,12 @@
package net.ME1312.SubServers.Bungee;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Try;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Logger;
/**
* SubServers/BungeeCord Launch Class
@ -26,7 +25,7 @@ public final class Launch {
System.setProperty("jdk.util.jar.enableMultiRelease", "force");
System.setProperty("apple.laf.useScreenMenuBar", "true");
if (Util.getDespiteException(() -> Class.forName("net.md_5.bungee.BungeeCord") == null, true)) {
if (Try.all.get(() -> Class.forName("net.md_5.bungee.BungeeCord") == null, true)) {
System.out.println("");
System.out.println("*******************************************");
System.out.println("*** Error: BungeeCord.jar Doesn't Exist ***");
@ -92,9 +91,9 @@ public final class Launch {
if (!options.has("noconsole")) {
try {
if (Util.getDespiteException(() -> Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole").getMethod("readCommands") != null, false)) { // Waterfall Setup
if (Try.all.get(() -> Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole").getMethod("readCommands") != null, false)) { // Waterfall Setup
Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole").getMethod("readCommands").invoke(null);
} else if (Util.getDespiteException(() -> Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole").getMethod("start") != null, false)) {
} else if (Try.all.get(() -> Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole").getMethod("start") != null, false)) {
Class console = Class.forName("io.github.waterfallmc.waterfall.console.WaterfallConsole");
console.getMethod("start").invoke(console.getConstructor().newInstance());
} else {

View File

@ -1,10 +1,11 @@
package net.ME1312.SubServers.Bungee.Library.Compatibility;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.SubServers.Bungee.SubAPI;
import com.google.common.io.Resources;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URL;
@ -28,8 +29,8 @@ public class JNA {
public static ClassLoader get() {
if (JNA == null) {
boolean announced = false;
UniversalFile library = new UniversalFile(SubAPI.getInstance().getInternals().dir, "SubServers:Cache:Libraries");
UniversalFile jna = new UniversalFile(library, "jna-" + JNA_VERSION + ".jar");
File library = new File(SubAPI.getInstance().getInternals().dir, "SubServers/Cache/Libraries");
File jna = new File(library, "jna-" + JNA_VERSION + ".jar");
jna.getParentFile().mkdirs();
if (!jna.exists()) {
announced = true;
@ -41,7 +42,7 @@ public class JNA {
e.printStackTrace();
}
}
UniversalFile platform = new UniversalFile(library, "jna-platform-" + JNA_VERSION + ".jar");
File platform = new File(library, "jna-platform-" + JNA_VERSION + ".jar");
platform.getParentFile().mkdirs();
if (!platform.exists()) {
if (!announced) System.out.println(">> Downloading JNA Library v" + JNA_VERSION);

View File

@ -5,10 +5,8 @@ import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.util.CaseInsensitiveMap;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* Legacy Server Map Translation Class

View File

@ -1,10 +1,13 @@
package net.ME1312.SubServers.Bungee.Library;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Directories;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.PrimitiveIterator;
import java.util.regex.Pattern;
/**
@ -19,7 +22,7 @@ public abstract class FileScanner {
* @param whitelist File Whitelist
*/
protected void scan(File dir, String... whitelist) throws IOException {
List<String> files = Util.searchDirectory(dir);
List<String> files = Directories.search(dir);
if (files.size() <= 0 || whitelist.length <= 0)
return;

View File

@ -4,14 +4,17 @@ import net.ME1312.SubData.Server.DataServer;
import net.ME1312.SubServers.Bungee.BungeeCommon;
import net.ME1312.SubServers.Bungee.SubAPI;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.protocol.ProtocolConstants;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URL;
@ -27,16 +30,6 @@ import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import net.md_5.bungee.protocol.ProtocolConstants;
public class Metrics {

View File

@ -3,9 +3,7 @@ package net.ME1312.SubServers.Bungee.Library;
import net.ME1312.Galaxi.Library.Util;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.regex.Pattern;
/**
* File Replacement Scanner

View File

@ -28,7 +28,7 @@ public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut
* @param plugin SubPlugin
*/
public PacketAddServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -9,12 +8,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Check Permission Packet
*/
public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
static HashMap<UUID, Callback<Boolean>[]> callbacks = new HashMap<UUID, Callback<Boolean>[]>();
static HashMap<UUID, Consumer<Boolean>[]> callbacks = new HashMap<UUID, Consumer<Boolean>[]>();
private UUID player;
private String permission;
private UUID tracker;
@ -32,7 +32,7 @@ public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObj
* @param callback Callbacks
*/
@SafeVarargs
public PacketCheckPermission(UUID player, String permission, Callback<Boolean>... callback) {
public PacketCheckPermission(UUID player, String permission, Consumer<Boolean>... callback) {
this.player = player;
this.permission = permission;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);

View File

@ -1,8 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
@ -10,6 +9,7 @@ import net.ME1312.SubData.Server.SubDataClient;
import net.md_5.bungee.api.ProxyServer;
import java.util.UUID;
import java.util.function.Consumer;
import static net.ME1312.SubServers.Bungee.Network.Packet.PacketCheckPermission.callbacks;
@ -34,7 +34,7 @@ public class PacketCheckPermissionResponse implements PacketObjectIn<Integer>, P
* @param tracker Receiver ID
*/
public PacketCheckPermissionResponse(UUID player, String permission, UUID tracker) {
this.result = Util.getDespiteException(() -> ProxyServer.getInstance().getPlayer(player).hasPermission(permission), false);
this.result = Try.all.get(() -> ProxyServer.getInstance().getPlayer(player).hasPermission(permission), false);
this.tracker = tracker;
}
@ -48,7 +48,7 @@ public class PacketCheckPermissionResponse implements PacketObjectIn<Integer>, P
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
for (Callback<Boolean> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data.getBoolean(0x0001));
for (Consumer<Boolean> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data.getBoolean(0x0001));
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -26,7 +26,7 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
* @param plugin SubPlugin
*/
public PacketCommandServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -26,7 +26,7 @@ public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObject
* @param plugin SubPlugin
*/
public PacketDeleteServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -1,7 +1,6 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -9,13 +8,13 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Proxy;
import net.ME1312.SubServers.Bungee.Host.RemotePlayer;
import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.*;
import java.util.function.IntConsumer;
/**
* Disconnect Player Packet
@ -59,7 +58,7 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
}
@SuppressWarnings("deprecation")
public static void run(List<UUID> ids, String reason, Callback<Integer> callback) {
public static void run(List<UUID> ids, String reason, IntConsumer callback) {
try {
Container<Integer> failures = new Container<>(0);
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
@ -81,10 +80,10 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
}
if (requests.size() == 0) {
callback.run(failures.value);
callback.accept(failures.value);
} else {
AsyncConsolidator merge = new AsyncConsolidator(() -> {
callback.run(failures.value);
callback.accept(failures.value);
});
for (Map.Entry<Proxy, List<UUID>> entry : requests.entrySet()) {
merge.reserve();
@ -96,7 +95,7 @@ public class PacketDisconnectPlayer implements PacketObjectIn<Integer>, PacketOb
}
} catch (Throwable e) {
e.printStackTrace();
callback.run(-1);
callback.accept(-1);
}
}

View File

@ -24,7 +24,7 @@ public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketO
* @param plugin SubPlugin
*/
public PacketDownloadGroupInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -36,7 +36,7 @@ public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketO
* @param tracker Receiver ID
*/
public PacketDownloadGroupInfo(SubProxy plugin, List<String> groups, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
this.tracker = tracker;

View File

@ -26,7 +26,7 @@ public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketOb
* @param plugin SubPlugin
*/
public PacketDownloadHostInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -38,7 +38,7 @@ public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketOb
* @param tracker Receiver ID
*/
public PacketDownloadHostInfo(SubProxy plugin, List<String> hosts, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
this.tracker = tracker;

View File

@ -26,7 +26,7 @@ public class PacketDownloadPlayerInfo implements PacketObjectIn<Integer>, Packet
* @param plugin SubPlugin
*/
public PacketDownloadPlayerInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -39,7 +39,7 @@ public class PacketDownloadPlayerInfo implements PacketObjectIn<Integer>, Packet
* @param tracker Receiver ID
*/
public PacketDownloadPlayerInfo(SubProxy plugin, List<String> names, List<UUID> ids, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
this.tracker = tracker;

View File

@ -26,7 +26,7 @@ public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketO
* @param plugin SubPlugin
*/
public PacketDownloadProxyInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -38,7 +38,7 @@ public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketO
* @param tracker Receiver ID
*/
public PacketDownloadProxyInfo(SubProxy plugin, List<String> proxies, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
this.tracker = tracker;

View File

@ -26,7 +26,7 @@ public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, Packet
* @param plugin SubPlugin
*/
public PacketDownloadServerInfo(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -38,7 +38,7 @@ public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, Packet
* @param tracker Receiver ID
*/
public PacketDownloadServerInfo(SubProxy plugin, List<String> servers, UUID tracker) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
this.tracker = tracker;

View File

@ -27,7 +27,7 @@ public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOu
* @param plugin SubPlugin
*/
public PacketEditServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -10,12 +9,13 @@ import net.ME1312.SubServers.Bungee.Host.External.ExternalSubServer;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Add Server External Host Packet
*/
public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private String name;
private boolean enabled;
private int port;
@ -35,7 +35,7 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
* New PacketExAddServer (Out)
*/
@SafeVarargs
public PacketExAddServer(ExternalSubServer server, UUID running, Callback<ObjectMap<Integer>>... callback) {
public PacketExAddServer(ExternalSubServer server, UUID running, Consumer<ObjectMap<Integer>>... callback) {
if (callback == null) throw new NullPointerException();
this.name = server.getName();
this.enabled = server.isEnabled();
@ -66,7 +66,7 @@ public class PacketExAddServer implements PacketObjectIn<Integer>, PacketObjectO
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
@ -43,7 +44,7 @@ public class PacketExConfigureHost implements PacketObjectIn<Integer>, PacketObj
public void receive(SubDataClient client, ObjectMap<Integer> data) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost && plugin.config.get().getMap("Hosts").getKeys().contains(((ExternalHost) client.getHandler()).getName())) {
client.sendPacket(new PacketExConfigureHost(plugin, (ExternalHost) client.getHandler()));
Util.isException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("enableRT"), ((ExternalHost) client.getHandler()).getCreator(), ((data == null || data.getBoolean(0x0000, false))?null:false)));
Try.all.run(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("enableRT"), ((ExternalHost) client.getHandler()).getCreator(), ((data == null || data.getBoolean(0x0000, false))?null:false)));
}
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
@ -12,12 +11,13 @@ import net.ME1312.SubServers.Bungee.Host.SubServer;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Create Server External Host Packet
*/
public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private UUID player;
private String name;
private SubCreator.ServerTemplate template;
@ -45,8 +45,8 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
* @param callback Callbacks
*/
@SafeVarargs
public PacketExCreateServer(UUID player, SubServer server, SubCreator.ServerTemplate template, Version version, UUID log, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(server, template, log, callback)) throw new NullPointerException();
public PacketExCreateServer(UUID player, SubServer server, SubCreator.ServerTemplate template, Version version, UUID log, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(server, template, log, callback);
this.player = player;
this.name = server.getName();
this.template = template;
@ -70,8 +70,8 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
* @param callback Callbacks
*/
@SafeVarargs
public PacketExCreateServer(UUID player, String name, SubCreator.ServerTemplate template, Version version, int port, UUID log, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, template, port, log, callback)) throw new NullPointerException();
public PacketExCreateServer(UUID player, String name, SubCreator.ServerTemplate template, Version version, int port, UUID log, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(name, template, port, log, callback);
this.player = player;
this.name = name;
this.template = template;
@ -117,7 +117,7 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -9,12 +8,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Delete Server External Host Packet
*/
public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private String name;
private ObjectMap<String> info;
private boolean recycle;
@ -33,8 +33,8 @@ public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObje
* @param callback Callbacks
*/
@SafeVarargs
public PacketExDeleteServer(String name, ObjectMap<String> info, boolean recycle, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, info, callback)) throw new NullPointerException();
public PacketExDeleteServer(String name, ObjectMap<String> info, boolean recycle, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(name, info, callback);
this.name = name;
this.info = info;
this.recycle = recycle;
@ -58,7 +58,7 @@ public class PacketExDeleteServer implements PacketObjectIn<Integer>, PacketObje
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -10,12 +9,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Disconnect External Player Packet
*/
public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private List<UUID> players;
private String reason;
private UUID id;
@ -33,8 +33,8 @@ public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, Packet
* @param callback Callbacks
*/
@SafeVarargs
public PacketExDisconnectPlayer(List<UUID> players, String reason, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(players, callback)) throw new NullPointerException();
public PacketExDisconnectPlayer(List<UUID> players, String reason, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(players, callback);
this.players = players;
this.reason = reason;
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -52,7 +52,7 @@ public class PacketExDisconnectPlayer implements PacketObjectIn<Integer>, Packet
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Directories;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Library.DataSize;
import net.ME1312.SubData.Server.Protocol.PacketIn;
@ -45,12 +46,12 @@ public class PacketExDownloadTemplates implements PacketIn, PacketStreamOut {
public void send(SubDataClient client, OutputStream stream) throws Throwable {
try {
if (client.getBlockSize() < DataSize.MBB) client.tempBlockSize(DataSize.MBB);
HashMap<String, ServerTemplate> map = Util.getDespiteException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("templates"), ((ExternalHost) client.getHandler()).getCreator()), new HashMap<>());
File dir = new UniversalFile(plugin.dir, "SubServers:Templates");
HashMap<String, ServerTemplate> map = Try.all.getOrSupply(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("templates"), ((ExternalHost) client.getHandler()).getCreator()), HashMap::new);
File dir = new File(plugin.dir, "SubServers/Templates");
ZipOutputStream zip = new ZipOutputStream(stream);
byte[] buffer = new byte[4096];
for (String file : Util.searchDirectory(dir)) {
for (String file : Directories.search(dir)) {
int index = file.indexOf(File.separatorChar);
if (index != -1 && !map.containsKey(file.substring(0, index).toLowerCase())) {
@ -67,7 +68,7 @@ public class PacketExDownloadTemplates implements PacketIn, PacketStreamOut {
}
zip.close();
Util.isException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("enableRT"), host.getCreator(), true));
Try.all.run(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("enableRT"), host.getCreator(), true));
} catch (Exception e) {
Logger.get("SubData").info("Problem encoding template files for Host: " + host.getName());
e.printStackTrace();

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -10,12 +9,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Message External Player Packet
*/
public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private List<UUID> players;
private List<String> legacy, raw;
private UUID id;
@ -34,7 +34,7 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
* @param callback Callbacks
*/
@SafeVarargs
public PacketExMessagePlayer(List<UUID> players, List<String> legacy, List<String> raw, Callback<ObjectMap<Integer>>... callback) {
public PacketExMessagePlayer(List<UUID> players, List<String> legacy, List<String> raw, Consumer<ObjectMap<Integer>>... callback) {
this.players = players;
this.legacy = legacy;
this.raw = raw;
@ -54,7 +54,7 @@ public class PacketExMessagePlayer implements PacketObjectIn<Integer>, PacketObj
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -9,12 +8,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Create Server External Host Packet
*/
public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private String name;
private UUID tracker;
@ -30,8 +30,8 @@ public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObje
* @param callback Callbacks
*/
@SafeVarargs
public PacketExRemoveServer(String name, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
public PacketExRemoveServer(String name, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(name, callback);
this.name = name;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
callbacks.put(tracker, callback);
@ -47,7 +47,7 @@ public class PacketExRemoveServer implements PacketObjectIn<Integer>, PacketObje
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -32,7 +32,7 @@ public class PacketExSyncPlayer implements PacketObjectIn<Integer>, PacketObject
* @param plugin SubPlugin
*/
public PacketExSyncPlayer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -10,12 +9,13 @@ import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Transfer External Player Packet
*/
public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private static HashMap<UUID, Consumer<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Consumer<ObjectMap<Integer>>[]>();
private List<UUID> players;
private String server;
private UUID id;
@ -33,8 +33,8 @@ public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketOb
* @param callback Callbacks
*/
@SafeVarargs
public PacketExTransferPlayer(List<UUID> players, String server, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(players, server, callback)) throw new NullPointerException();
public PacketExTransferPlayer(List<UUID> players, String server, Consumer<ObjectMap<Integer>>... callback) {
Util.nullpo(players, server, callback);
this.players = players;
this.server = server;
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -52,7 +52,7 @@ public class PacketExTransferPlayer implements PacketObjectIn<Integer>, PacketOb
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
for (Consumer<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data);
callbacks.remove(data.getUUID(0x0000));
}

View File

@ -1,7 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketOut;
@ -37,13 +37,13 @@ public class PacketExUploadTemplates implements PacketObjectIn<Integer>, PacketO
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) {
if (client.getHandler() != null && client.getHandler() instanceof ExternalHost) {
HashMap<String, SubCreator.ServerTemplate> map = Util.getDespiteException(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("templates"), ((ExternalHost) client.getHandler()).getCreator()), new HashMap<>());
UniversalFile templatedir = new UniversalFile(plugin.dir, "SubServers:Cache:Remote:Templates");
HashMap<String, SubCreator.ServerTemplate> map = Try.all.get(() -> Util.reflect(ExternalSubCreator.class.getDeclaredField("templates"), ((ExternalHost) client.getHandler()).getCreator()), new HashMap<>());
File templatedir = new File(plugin.dir, "SubServers/Cache/Remote/Templates");
ObjectMap<String> templates = new ObjectMap<>((Map<String, ?>) data.getObject(0x0000));
map.clear();
for (String name : templates.getKeys()) {
try {
UniversalFile dir = new UniversalFile(templatedir, name);
File dir = new File(templatedir, name);
SubCreator.ServerTemplate template = Util.reflect(SubCreator.class.getDeclaredMethod("loadTemplate", String.class, boolean.class, boolean.class, String.class, File.class, ObjectMap.class, ObjectMap.class),
((ExternalHost) client.getHandler()).getCreator(), name, templates.getMap(name).getBoolean("enabled"), templates.getMap(name).getBoolean("internal"), templates.getMap(name).getRawString("icon"), dir,
templates.getMap(name).getMap("build").clone(), templates.getMap(name).getMap("settings").clone());

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -30,7 +31,7 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
* @param plugin SubPlugin
*/
public PacketLinkExHost(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -41,7 +42,7 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
* @param message Message
*/
public PacketLinkExHost(int response, String message) {
if (Util.isNull(response)) throw new NullPointerException();
Util.nullpo(response);
this.response = response;
this.message = message;
}
@ -62,7 +63,7 @@ public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>,
Host host = hosts.get(data.getRawString(0x0000).toLowerCase());
if (host instanceof ExternalHost) {
Integer channel = data.getInt(0x0001);
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ExternalHost.class.getDeclaredField("subdata"), host), null);
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(ExternalHost.class.getDeclaredField("subdata"), host));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
((ExternalHost) host).setSubData(client, channel);
Logger.get("SubData").info(client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" [+"+channel+"]":""));

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -31,7 +32,7 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
* @param plugin SubPlugin
*/
public PacketLinkProxy(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -72,7 +73,7 @@ public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>,
isnew = true;
plugin.proxies.put(proxy.getName().toLowerCase(), proxy);
}
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(Proxy.class.getDeclaredField("subdata"), proxy), null);
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(Proxy.class.getDeclaredField("subdata"), proxy));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
proxy.setSubData(client, channel);
if (isnew) plugin.getPluginManager().callEvent(new SubAddProxyEvent(proxy));

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Library.DisconnectReason;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
@ -44,7 +45,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
* @param plugin SubPlugin
*/
public PacketLinkServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -56,7 +57,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
* @param message Message
*/
public PacketLinkServer(String name, int response, String message) {
if (Util.isNull(response)) throw new NullPointerException();
Util.nullpo(response);
this.name = name;
this.response = response;
this.message = message;
@ -137,7 +138,7 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
static long req = 1;
static long last = Calendar.getInstance().getTime().getTime();
private void link(SubDataClient client, Server server, int channel) throws Throwable {
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ServerImpl.class.getDeclaredField("subdata"), server), null);
HashMap<Integer, SubDataClient> subdata = Try.all.get(() -> Util.reflect(ServerImpl.class.getDeclaredField("subdata"), server));
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
server.setSubData(client, channel);
Logger.get("SubData").info(client.getAddress().toString() + " has been defined as " + ((server instanceof SubServer) ? "SubServer" : "Server") + ": " + server.getName() + ((channel > 0)?" [+"+channel+"]":""));
@ -148,11 +149,11 @@ public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>,
client.sendPacket(new PacketOutExReset("Rogue SubServer Detected"));
} else {
// Drop connection if host is unavailable for rogue checking (try again later)
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("close", DisconnectReason.class), client, DisconnectReason.CLOSE_REQUESTED));
Try.all.run(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("close", DisconnectReason.class), client, DisconnectReason.CLOSE_REQUESTED));
}
} else {
if (server instanceof SubServer && !Util.getDespiteException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("started"), server), true)) {
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("started"), server, true));
if (server instanceof SubServer && !Try.all.get(() -> Util.reflect(SubServerImpl.class.getDeclaredField("started"), server), true)) {
Try.all.run(() -> Util.reflect(SubServerImpl.class.getDeclaredField("started"), server, true));
SubStartedEvent event = new SubStartedEvent((SubServer) server);
ProxyServer.getInstance().getPluginManager().callEvent(event);
}

View File

@ -1,18 +1,15 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
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.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Proxy;
import net.ME1312.SubServers.Bungee.Host.RemotePlayer;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.ME1312.SubServers.Bungee.SubProxy;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
@ -20,6 +17,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.chat.ComponentSerializer;
import java.util.*;
import java.util.function.IntConsumer;
/**
* Message Player Packet
@ -63,7 +61,7 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
}
@SuppressWarnings("deprecation")
public static void run(List<UUID> ids, ContainedPair<String[], BaseComponent[][]> message, ObjectMap<Integer> data, Callback<Integer> callback) {
public static void run(List<UUID> ids, ContainedPair<String[], BaseComponent[][]> message, ObjectMap<Integer> data, IntConsumer callback) {
try {
Container<Integer> failures = new Container<>(0);
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
@ -101,10 +99,10 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
}
if (requests.size() == 0) {
callback.run(failures.value);
callback.accept(failures.value);
} else {
AsyncConsolidator merge = new AsyncConsolidator(() -> {
callback.run(failures.value);
callback.accept(failures.value);
});
List<String> legacy, raw;
if (data == null) {
@ -129,7 +127,7 @@ public class PacketMessagePlayer implements PacketObjectIn<Integer>, PacketObjec
}
} catch (Throwable e) {
e.printStackTrace();
callback.run((ids == null || ids.size() == 0)? 1 : ids.size());
callback.accept((ids == null || ids.size() == 0)? 1 : ids.size());
}
}

View File

@ -28,7 +28,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
* @param plugin
*/
public PacketOutExRunEvent(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}
@ -39,7 +39,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
* @param args Arguments
*/
public PacketOutExRunEvent(Class<? extends SubEvent> event, ObjectMap<String> args) {
if (Util.isNull(event, args)) throw new NullPointerException();
Util.nullpo(event, args);
this.type = event.getSimpleName();
this.args = args;
}

View File

@ -27,7 +27,7 @@ public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObject
* @param plugin SubPlugin
*/
public PacketRemoveServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -26,7 +26,7 @@ public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjec
* @param plugin SubPlugin
*/
public PacketRestartServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -27,7 +27,7 @@ public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectO
* @param plugin SubPlugin
*/
public PacketStartServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -26,7 +26,7 @@ public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOu
* @param plugin SubPlugin
*/
public PacketStopServer(SubProxy plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
}

View File

@ -1,7 +1,6 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.AsyncConsolidator;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
@ -16,6 +15,7 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.*;
import java.util.function.IntConsumer;
/**
* Transfer Player Packet
@ -58,7 +58,7 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
});
}
public static void run(List<UUID> ids, String name, Callback<Integer> callback) {
public static void run(List<UUID> ids, String name, IntConsumer callback) {
try {
Container<Integer> failures = new Container<>(0);
HashMap<Proxy, List<UUID>> requests = new HashMap<Proxy, List<UUID>>();
@ -81,10 +81,10 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
}
if (requests.size() == 0) {
callback.run(failures.value);
callback.accept(failures.value);
} else {
AsyncConsolidator merge = new AsyncConsolidator(() -> {
callback.run(failures.value);
callback.accept(failures.value);
});
for (Map.Entry<Proxy, List<UUID>> entry : requests.entrySet()) {
merge.reserve();
@ -96,7 +96,7 @@ public class PacketTransferPlayer implements PacketObjectIn<Integer>, PacketObje
}
} catch (Throwable e) {
e.printStackTrace();
callback.run(-1);
callback.accept(-1);
}
}

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Bungee.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.SubDataProtocol;
import net.ME1312.SubData.Server.SubDataServer;
@ -13,6 +12,7 @@ import net.ME1312.SubServers.Bungee.SubProxy;
import java.io.IOException;
import java.net.InetAddress;
import java.util.function.Consumer;
import java.util.logging.Logger;
/**
@ -154,7 +154,7 @@ public class SubProtocol extends SubDataProtocol {
@SuppressWarnings("deprecation")
@Override
public SubDataServer open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port, String cipher) throws IOException {
public SubDataServer open(Consumer<Runnable> scheduler, Logger logger, InetAddress address, int port, String cipher) throws IOException {
SubDataServer subdata = super.open(scheduler, logger, address, port, cipher);
SubProxy plugin = SubAPI.getInstance().getInternals();

View File

@ -2,7 +2,7 @@ package net.ME1312.SubServers.Bungee;
import net.ME1312.Galaxi.Library.Container.ContainedPair;
import net.ME1312.Galaxi.Library.Container.Pair;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.DataProtocol;
@ -19,6 +19,7 @@ import com.google.common.collect.Range;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.protocol.ProtocolConstants;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -93,7 +94,7 @@ public final class SubAPI implements BungeeAPI {
* @param handle Handle to Bind
*/
public void addHostDriver(Class<? extends Host> driver, String handle) {
if (Util.isNull(driver, handle)) throw new NullPointerException();
Util.nullpo(driver, handle);
if (plugin.hostDrivers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Driver already exists: " + handle);
plugin.hostDrivers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), driver);
}
@ -167,7 +168,7 @@ public final class SubAPI implements BungeeAPI {
* @throws InstantiationException
*/
public Host addHost(UUID player, String driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
Util.nullpo(driver, name, enabled, ports, log, address, directory, gitBash);
if (!getHostDrivers().contains(driver.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new InvalidHostException("Invalid Driver for host: " + name);
return addHost(player, plugin.hostDrivers.get(driver.toUpperCase().replace('-', '_').replace(' ', '_')), name, enabled, ports, log, address, directory, gitBash);
}
@ -212,7 +213,7 @@ public final class SubAPI implements BungeeAPI {
* @throws InstantiationException
*/
public Host addHost(UUID player, Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
Util.nullpo(driver, name, enabled, ports, log, address, directory, gitBash);
Host host = plugin.constructHost(driver, name, enabled, ports, log, address, directory, gitBash);
return addHost(player, host)?host:null;
}
@ -263,7 +264,7 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status
*/
public boolean removeHost(UUID player, String name) {
if (Util.isNull(name, getHost(name))) throw new NullPointerException();
Util.nullpo(name, getHost(name));
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@ -294,7 +295,7 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status
*/
public boolean forceRemoveHost(UUID player, String name) {
if (Util.isNull(name, getHost(name))) throw new NullPointerException();
Util.nullpo(name, getHost(name));
SubRemoveHostEvent event = new SubRemoveHostEvent(player, getHost(name));
plugin.getPluginManager().callEvent(event);
if (getHost(name).destroy()) {
@ -463,7 +464,7 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status
*/
public boolean removeServer(UUID player, String name) {
if (Util.isNull(name, getServer(name))) throw new NullPointerException();
Util.nullpo(name, getServer(name));
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name));
plugin.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
@ -490,7 +491,7 @@ public final class SubAPI implements BungeeAPI {
* @return Success Status
*/
public boolean forceRemoveServer(UUID player, String name) {
if (Util.isNull(name, getServer(name))) throw new NullPointerException();
Util.nullpo(name, getServer(name));
SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name));
plugin.getPluginManager().callEvent(event);
plugin.exServers.remove(name.toLowerCase());
@ -599,7 +600,7 @@ public final class SubAPI implements BungeeAPI {
* @return Remote Player
*/
public RemotePlayer getRemotePlayer(String name) {
if (Util.isNull(name)) throw new NullPointerException();
Util.nullpo(name);
for (RemotePlayer player : plugin.rPlayers.values()) {
if (player.getName().equalsIgnoreCase(name)) return player;
}
@ -613,7 +614,7 @@ public final class SubAPI implements BungeeAPI {
* @return Remote Player
*/
public RemotePlayer getRemotePlayer(UUID id) {
if (Util.isNull(id)) throw new NullPointerException();
Util.nullpo(id);
return plugin.rPlayers.getOrDefault(id, null);
}
@ -625,7 +626,7 @@ public final class SubAPI implements BungeeAPI {
* @param value Lang Value
*/
public void setLang(String channel, String key, String value) {
if (Util.isNull(channel, key, value)) throw new NullPointerException();
Util.nullpo(channel, key, value);
LinkedHashMap<String, String> map = (plugin.exLang.containsKey(channel.toLowerCase()))?plugin.exLang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
map.put(key, value);
plugin.exLang.put(channel.toLowerCase(), map);
@ -685,7 +686,7 @@ public final class SubAPI implements BungeeAPI {
*/
@SuppressWarnings("unchecked")
public <R> R getObjectBySignature(String signature) {
if (Util.isNull(signature)) throw new NullPointerException();
Util.nullpo(signature);
return (R) knownSignatures.getOrDefault(signature, null);
}
@ -703,7 +704,7 @@ public final class SubAPI implements BungeeAPI {
*
* @return Directory
*/
public UniversalFile getRuntimeDirectory() {
public File getRuntimeDirectory() {
return plugin.dir;
}
@ -743,12 +744,12 @@ public final class SubAPI implements BungeeAPI {
if (GAME_VERSION == null) {
if (System.getProperty("subservers.minecraft.version", "").length() > 0) {
return new Version[]{new Version(System.getProperty("subservers.minecraft.version"))};
} else if (Util.getDespiteException(() -> ProtocolConstants.SUPPORTED_VERSIONS != null, false)) {
} else if (Try.all.get(() -> ProtocolConstants.SUPPORTED_VERSIONS != null, false)) {
List<Version> versions = new LinkedList<Version>();
for (String version : ProtocolConstants.SUPPORTED_VERSIONS) versions.add(new Version(version));
Collections.sort(versions);
return versions.toArray(new Version[versions.size()]);
} else if (Util.getDespiteException(() -> plugin.getGameVersion() != null, false)) {
} else if (Try.all.get(() -> plugin.getGameVersion() != null, false)) {
String raw = plugin.getGameVersion();
if (raw.contains("-") || raw.contains(",")) {
List<Version> versions = new LinkedList<Version>();

View File

@ -1,11 +1,10 @@
package net.ME1312.SubServers.Bungee;
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.Container.Pair;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Platform;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.ClientHandler;
@ -33,6 +32,8 @@ import java.net.URL;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Plugin Command Class
@ -102,7 +103,7 @@ public final class SubCommand extends Command implements TabExecutor {
plugin.stopListeners();
plugin.getLogger().info("Closing player connections");
for (ProxiedPlayer player : plugin.getPlayers()) {
Util.isException(() -> player.disconnect(plugin.getTranslation("restart")));
Try.all.run(() -> player.disconnect(plugin.getTranslation("restart")));
}
plugin.shutdown();
case "*":
@ -432,7 +433,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (args.length > 1) {
ServerSelection select = selectServers(sender, args, 1, true);
if (select.subservers.length > 0) {
Callback<SubServer> starter = server -> {
Consumer<SubServer> starter = server -> {
Map<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(server.getName().toLowerCase()) || !(servers.get(server.getName().toLowerCase()) instanceof SubServer)) {
sender.sendMessage("SubServers > Could not restart server: Subserver " + server.getName() + " has disappeared");
@ -467,7 +468,7 @@ public final class SubCommand extends Command implements TabExecutor {
try {
server.waitFor();
Thread.sleep(100);
starter.run(server);
starter.accept(server);
} catch (Exception e) {
e.printStackTrace();
}
@ -475,7 +476,7 @@ public final class SubCommand extends Command implements TabExecutor {
success++;
}
} else {
starter.run(server);
starter.accept(server);
success++;
}
}
@ -583,7 +584,7 @@ public final class SubCommand extends Command implements TabExecutor {
sender.sendMessage("SubServers > That template is not enabled");
} else if (args.length <= 4 && plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3].toLowerCase()).requiresVersion()) {
sender.sendMessage("SubServers > That template requires a Minecraft version to be specified");
} else if (args.length > 5 && (Util.isException(() -> Integer.parseInt(args[5])) || Integer.parseInt(args[5]) <= 0 || Integer.parseInt(args[5]) > 65535)) {
} else if (args.length > 5 && (!Try.all.run(() -> Integer.parseInt(args[5])) || Integer.parseInt(args[5]) <= 0 || Integer.parseInt(args[5]) > 65535)) {
sender.sendMessage("SubServers > Invalid port number");
} else {
plugin.hosts.get(args[2].toLowerCase()).getCreator().create(args[1], plugin.hosts.get(args[2].toLowerCase()).getCreator().getTemplate(args[3].toLowerCase()), (args.length > 4)?new Version(args[4]):null, (args.length > 5)?Integer.parseInt(args[5]):null);
@ -877,7 +878,7 @@ public final class SubCommand extends Command implements TabExecutor {
return list;
} else {
if (args[0].equals("info") || args[0].equals("status")) {
ReturnRunnable<Collection<String>> getPlayers = () -> {
Supplier<Collection<String>> getPlayers = () -> {
LinkedList<String> names = new LinkedList<String>();
for (ProxiedPlayer player : plugin.getPlayers()) names.add(player.getName());
for (RemotePlayer player : plugin.api.getRemotePlayers().values()) if (!names.contains(player.getName())) names.add(player.getName());
@ -917,7 +918,7 @@ public final class SubCommand extends Command implements TabExecutor {
if (!list.contains(server.getName()) && server.getName().toLowerCase().startsWith(last))
list.add(Last + server.getName().substring(last.length()));
}
for (String player : getPlayers.run()) {
for (String player : getPlayers.get()) {
if (!list.contains(player) && player.toLowerCase().startsWith(last))
list.add(Last + player.substring(last.length()));
}
@ -958,8 +959,10 @@ public final class SubCommand extends Command implements TabExecutor {
list.add(Last + server.getName().substring(last.length()));
}
break;
case "u":
case "user":
case "player":
for (String player : getPlayers.run()) {
for (String player : getPlayers.get()) {
if (player.toLowerCase().startsWith(last))
list.add(Last + player.substring(last.length()));
}
@ -1072,7 +1075,7 @@ public final class SubCommand extends Command implements TabExecutor {
return 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) {
if (!Try.all.run(() -> Integer.parseInt(last)) || Integer.parseInt(last) <= 0 || Integer.parseInt(last) > 65535) {
return Collections.emptyList();
}
}

View File

@ -3,8 +3,9 @@ package net.ME1312.SubServers.Bungee;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
import net.ME1312.Galaxi.Library.Container.Container;
import net.ME1312.Galaxi.Library.Directories;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.ClientHandler;
@ -81,7 +82,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
private final HashMap<UUID, FallbackState> fallback = new HashMap<UUID, FallbackState>();
public final PrintStream out;
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
public final File dir = new File(System.getProperty("user.dir"));
public YAMLConfig config;
public YAMLConfig servers;
private YAMLConfig bungee;
@ -111,110 +112,110 @@ public final class SubProxy extends BungeeCommon implements Listener {
this.isPatched = isPatched;
Logger.get("SubServers").info("Loading SubServers.Bungee v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion()[api.getGameVersion().length - 1] + ")");
Util.isException(() -> new RemotePlayer(null)); // runs <clinit>
Try.all.run(() -> new RemotePlayer(null)); // runs <clinit>
this.out = out;
if (!(new UniversalFile(dir, "config.yml").exists())) {
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/bungee.yml", new UniversalFile(dir, "config.yml").getPath());
YAMLConfig tmp = new YAMLConfig(new UniversalFile("config.yml"));
if (!(new File(dir, "config.yml").exists())) {
Util.copyFromJar(SubProxy.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/bungee.yml", new File(dir, "config.yml").getPath());
YAMLConfig tmp = new YAMLConfig(new File("config.yml"));
tmp.get().set("stats", UUID.randomUUID().toString());
tmp.save();
Logger.get("SubServers").info("Created ./config.yml");
}
bungee = new YAMLConfig(new UniversalFile(dir, "config.yml"));
bungee = new YAMLConfig(new File(dir, "config.yml"));
UniversalFile dir = new UniversalFile(this.dir, "SubServers");
File dir = new File(this.dir, "SubServers");
dir.mkdir();
ConfigUpdater.updateConfig(new UniversalFile(dir, "config.yml"));
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
ConfigUpdater.updateConfig(new File(dir, "config.yml"));
config = new YAMLConfig(new File(dir, "config.yml"));
ConfigUpdater.updateServers(new UniversalFile(dir, "servers.yml"));
servers = new YAMLConfig(new UniversalFile(dir, "servers.yml"));
ConfigUpdater.updateServers(new File(dir, "servers.yml"));
servers = new YAMLConfig(new File(dir, "servers.yml"));
ConfigUpdater.updateLang(new UniversalFile(dir, "lang.yml"));
lang = new YAMLConfig(new UniversalFile(dir, "lang.yml"));
ConfigUpdater.updateLang(new File(dir, "lang.yml"));
lang = new YAMLConfig(new File(dir, "lang.yml"));
if (!(new UniversalFile(dir, "Templates").exists())) {
new UniversalFile(dir, "Templates").mkdirs();
if (!(new File(dir, "Templates").exists())) {
new File(dir, "Templates").mkdirs();
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Vanilla");
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Spigot");
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/paper.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/paper.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Paper");
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/purpur.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/purpur.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Purpur");
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Forge");
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Created ./SubServers/Templates/Sponge");
} else {
long stamp = Math.round(Math.random() * 100000);
Version version = new Version("2.16a+");
if (new UniversalFile(dir, "Templates:Vanilla:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Vanilla:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Vanilla").toPath(), new UniversalFile(dir, "Templates:Vanilla." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Vanilla/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Vanilla/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Vanilla").toPath(), new File(dir, "Templates/Vanilla." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Vanilla");
}
if (new UniversalFile(dir, "Templates:Spigot:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Spigot:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Spigot").toPath(), new UniversalFile(dir, "Templates:Spigot." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Spigot/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Spigot/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Spigot").toPath(), new File(dir, "Templates/Spigot." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Spigot");
}
if (new UniversalFile(dir, "Templates:Paper:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Paper:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Paper").toPath(), new UniversalFile(dir, "Templates:Paper." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/paper.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Paper/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Paper/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Paper").toPath(), new File(dir, "Templates/Paper." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/paper.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Paper");
}
if (new UniversalFile(dir, "Templates:Purpur:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Purpur:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Purpur").toPath(), new UniversalFile(dir, "Templates:Purpur." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/purpur.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Purpur/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Purpur/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Purpur").toPath(), new File(dir, "Templates/Purpur." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/purpur.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Purpur");
}
if (new UniversalFile(dir, "Templates:Forge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Forge:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Forge").toPath(), new UniversalFile(dir, "Templates:Forge." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Forge/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Forge/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Forge").toPath(), new File(dir, "Templates/Forge." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Forge");
}
if (new UniversalFile(dir, "Templates:Sponge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Sponge:template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new UniversalFile(dir, "Templates:Sponge").toPath(), new UniversalFile(dir, "Templates:Sponge." + stamp + ".x").toPath());
Util.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
if (new File(dir, "Templates/Sponge/template.yml").exists() && ((new YAMLConfig(new File(dir, "Templates/Sponge/template.yml"))).get().getVersion("Version", version)).compareTo(version) != 0) {
Files.move(new File(dir, "Templates/Sponge").toPath(), new File(dir, "Templates/Sponge." + stamp + ".x").toPath());
Directories.unzip(SubProxy.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new File(dir, "Templates"));
Logger.get("SubServers").info("Updated ./SubServers/Templates/Sponge");
}
}
Runnable clean = () -> {
try {
if (new UniversalFile(dir, "Recently Deleted").exists()) {
int f = new UniversalFile(dir, "Recently Deleted").listFiles().length;
for (File file : new UniversalFile(dir, "Recently Deleted").listFiles()) {
if (new File(dir, "Recently Deleted").exists()) {
int f = new File(dir, "Recently Deleted").listFiles().length;
for (File file : new File(dir, "Recently Deleted").listFiles()) {
try {
if (file.isDirectory()) {
if (new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json").exists()) {
FileReader reader = new FileReader(new UniversalFile(dir, "Recently Deleted:" + file.getName() + ":info.json"));
if (new File(dir, "Recently Deleted/" + file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(dir, "Recently Deleted/" + file.getName() + "/info.json"));
YAMLSection info = new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class));
reader.close();
if (info.contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) >= 7) {
Util.deleteDirectory(file);
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} else {
Util.deleteDirectory(file);
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} else {
Util.deleteDirectory(file);
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
@ -230,7 +231,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
}
}
if (f <= 0) {
Files.delete(new UniversalFile(dir, "Recently Deleted").toPath());
Files.delete(new File(dir, "Recently Deleted").toPath());
}
}
} catch (Exception e) {
@ -253,7 +254,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
PluginDescription description = new PluginDescription();
description.setName("SubServers-Bungee");
description.setMain(net.ME1312.SubServers.Bungee.Library.Compatibility.Plugin.class.getCanonicalName());
description.setFile(Util.getDespiteException(() -> new File(SubProxy.class.getProtectionDomain().getCodeSource().getLocation().toURI()), null));
description.setFile(Try.all.get(() -> new File(SubProxy.class.getProtectionDomain().getCodeSource().getLocation().toURI())));
description.setVersion(version.toString());
description.setAuthor("ME1312");
@ -346,9 +347,9 @@ public final class SubProxy extends BungeeCommon implements Listener {
if (!status) resetDate = begin;
reloading = true;
ConfigUpdater.updateConfig(new UniversalFile(dir, "SubServers:config.yml"));
ConfigUpdater.updateServers(new UniversalFile(dir, "SubServers:servers.yml"));
ConfigUpdater.updateLang(new UniversalFile(dir, "SubServers:lang.yml"));
ConfigUpdater.updateConfig(new File(dir, "SubServers/config.yml"));
ConfigUpdater.updateServers(new File(dir, "SubServers/servers.yml"));
ConfigUpdater.updateLang(new File(dir, "SubServers/lang.yml"));
YAMLSection prevconfig = config.get();
config.reload();
@ -363,7 +364,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
)) {
SubDataServer subdata = this.subdata;
subdata.close();
Util.isException(subdata::waitFor);
Try.all.run(subdata::waitFor);
}
PacketLinkServer.strict = config.get().getMap("Settings").getBoolean("Strict-Server-Linking", true);
@ -493,7 +494,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
edits.set("exec", this.servers.get().getMap("Servers").getMap(name).getRawString("Executable"));
if (!this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
edits.set("stop-cmd", this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
SubServer.StopAction action = Try.all.get(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null && action != server.getStopAction())
edits.set("stop-action", action.toString());
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
@ -533,7 +534,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
server.setHidden(this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
} // Apply these changes regardless of reset
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
SubServer.StopAction action = Try.all.get(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')));
if (action != null && action != server.getStopAction())
server.setStopAction(action);
if (!status && this.servers.get().getMap("Servers").getMap(name).getBoolean("Run-On-Launch"))
@ -629,8 +630,8 @@ public final class SubProxy extends BungeeCommon implements Listener {
} else if (ciphers[0].equals("RSA") || ciphers[0].equals("RSA-2048") || ciphers[0].equals("RSA-3072") || ciphers[0].equals("RSA-4096")) {
try {
int length = (ciphers[0].contains("-"))?Integer.parseInt(ciphers[0].split("-")[1]):2048;
if (!(new UniversalFile("SubServers:Cache").exists())) new UniversalFile("SubServers:Cache").mkdirs();
subprotocol.registerCipher("RSA", new RSA(length, new UniversalFile("SubServers:Cache:private.rsa.key"), new UniversalFile("SubServers:subdata.rsa.key")));
if (!(new File("SubServers/Cache").exists())) new File("SubServers/Cache").mkdirs();
subprotocol.registerCipher("RSA", new RSA(length, new File("SubServers/Cache/private.rsa.key"), new File("SubServers/subdata.rsa.key")));
cipher = "RSA" + cipher.substring(ciphers[0].length());
Logger.get("SubData").info("Encrypting SubData with RSA:");
@ -873,7 +874,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
}
Host constructHost(Class<? extends Host> driver, String name, boolean enabled, Range<Integer> ports, boolean log, InetAddress address, String directory, String gitBash) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
if (Util.isNull(driver, name, enabled, ports, log, address, directory, gitBash)) throw new NullPointerException();
Util.nullpo(driver, name, enabled, ports, log, address, directory, gitBash);
return driver.getConstructor(SubProxy.class, String.class, boolean.class, Range.class, boolean.class, InetAddress.class, String.class, String.class).newInstance(this, name, enabled, ports, log, address, directory, gitBash);
}
@ -960,7 +961,7 @@ public final class SubProxy extends BungeeCommon implements Listener {
lock.value = false;
if (mode) e.completeIntent(plugin);
}, ((InitialHandler) e.getConnection()).getHandshake().getProtocolVersion());
if (!mode) while (lock.value) Util.isException(() -> Thread.sleep(4));
if (!mode) while (lock.value) Try.all.run(() -> Thread.sleep(4));
}
}
} else if (dynamic) {

View File

@ -22,7 +22,7 @@ public class SubAddHostEvent extends Event implements SubEvent {
* @param host Host to be added
*/
public SubAddHostEvent(UUID player, String host) {
if (Util.isNull(host)) throw new NullPointerException();
Util.nullpo(host);
this.player = player;
this.host = host;
}

View File

@ -18,7 +18,7 @@ public class SubAddProxyEvent extends Event implements SubEvent {
* @param proxy Host Being Added
*/
public SubAddProxyEvent(String proxy) {
if (Util.isNull(proxy)) throw new NullPointerException();
Util.nullpo(proxy);
this.proxy = proxy;
}

View File

@ -23,7 +23,7 @@ public class SubAddServerEvent extends Event implements SubEvent {
* @param server Server Starting
*/
public SubAddServerEvent(UUID player, String host, String server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.host = host;
this.server = server;

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Client.Bukkit.Event;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
@ -12,6 +11,7 @@ import org.bukkit.event.HandlerList;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Server Create Event
@ -36,7 +36,7 @@ public class SubCreateEvent extends Event implements SubEvent {
* @param port Server Port Number
*/
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port, boolean update) {
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
Util.nullpo(host, name, template, port);
this.player = player;
this.update = update;
this.host = host;
@ -69,10 +69,10 @@ public class SubCreateEvent extends Event implements SubEvent {
*
* @param callback Updating Server
*/
public void getUpdatingServer(Callback<SubServer> callback) {
public void getUpdatingServer(Consumer<SubServer> callback) {
if (!update) {
try {
callback.run(null);
callback.accept(null);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.printStackTrace();

View File

@ -1,6 +1,5 @@
package net.ME1312.SubServers.Client.Bukkit.Event;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
@ -12,6 +11,7 @@ import org.bukkit.event.HandlerList;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import java.util.function.Consumer;
/**
* Server Created Event
@ -37,7 +37,7 @@ public class SubCreatedEvent extends Event implements SubEvent {
* @param port Server Port Number
*/
public SubCreatedEvent(UUID player, String host, String name, String template, Version version, int port, boolean update, boolean success) {
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
Util.nullpo(host, name, template, port);
this.player = player;
this.success = success;
this.update = update;
@ -80,10 +80,10 @@ public class SubCreatedEvent extends Event implements SubEvent {
*
* @param callback Updating Server
*/
public void getServer(Callback<SubServer> callback) {
public void getServer(Consumer<SubServer> callback) {
if (!update && !success) {
try {
callback.run(null);
callback.accept(null);
} catch (Throwable e) {
Throwable ew = new InvocationTargetException(e);
ew.printStackTrace();

View File

@ -28,7 +28,7 @@ public class SubEditServerEvent extends Event implements SubEvent {
* @param edit Edit to make
*/
public SubEditServerEvent(UUID player, String server, Pair<String, ?> edit) {
if (Util.isNull(server, edit)) throw new NullPointerException();
Util.nullpo(server, edit);
ObjectMap<String> section = new ObjectMap<String>();
section.set(".", edit.value());
this.player = player;

View File

@ -17,7 +17,7 @@ public class SubNetworkConnectEvent extends Event implements SubEvent {
* SubData Network Connect Event
*/
public SubNetworkConnectEvent(DataClient network) {
if (Util.isNull(network)) throw new NullPointerException();
Util.nullpo(network);
this.network = network;
}

View File

@ -19,7 +19,7 @@ public class SubNetworkDisconnectEvent extends Event implements SubEvent {
* SubData Network Disconnect Event
*/
public SubNetworkDisconnectEvent(DataClient network, DisconnectReason reason) {
if (Util.isNull(network, reason)) throw new NullPointerException();
Util.nullpo(network, reason);
this.network = network;
this.reason = reason;
}

View File

@ -22,7 +22,7 @@ public class SubRemoveHostEvent extends Event implements SubEvent {
* @param host Server Starting
*/
public SubRemoveHostEvent(UUID player, String host) {
if (Util.isNull(host)) throw new NullPointerException();
Util.nullpo(host);
this.player = player;
this.host = host;
}

View File

@ -18,7 +18,7 @@ public class SubRemoveProxyEvent extends Event implements SubEvent {
* @param proxy Host Being Added
*/
public SubRemoveProxyEvent(String proxy) {
if (Util.isNull(proxy)) throw new NullPointerException();
Util.nullpo(proxy);
this.proxy = proxy;
}

View File

@ -23,7 +23,7 @@ public class SubRemoveServerEvent extends Event implements SubEvent {
* @param server Server Starting
*/
public SubRemoveServerEvent(UUID player, String host, String server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.host = host;
this.server = server;

View File

@ -23,7 +23,7 @@ public class SubSendCommandEvent extends Event implements SubEvent {
* @param server Server being Commanded
*/
public SubSendCommandEvent(UUID player, String server, String command) {
if (Util.isNull(server, command)) throw new NullPointerException();
Util.nullpo(server, command);
this.player = player;
this.server = server;
this.command = command;

View File

@ -23,7 +23,7 @@ public class SubStartEvent extends Event implements SubEvent {
* @param server Server Starting
*/
public SubStartEvent(UUID player, String server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.player = player;
this.server = server;
}

View File

@ -19,7 +19,7 @@ public class SubStartedEvent extends Event implements SubEvent {
* @param server Server that Started
*/
public SubStartedEvent(String server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.server = server;
}

View File

@ -25,7 +25,7 @@ public class SubStopEvent extends Event implements SubEvent {
* @param force If it was a Forced Shutdown
*/
public SubStopEvent(UUID player, String server, boolean force) {
if (Util.isNull(server, force)) throw new NullPointerException();
Util.nullpo(server, force);
this.player = player;
this.server = server;
this.force = force;

View File

@ -18,7 +18,7 @@ public class SubStoppedEvent extends Event implements SubEvent {
* @param server Server that Stopped
*/
public SubStoppedEvent(String server) {
if (Util.isNull(server)) throw new NullPointerException();
Util.nullpo(server);
this.server = server;
}

View File

@ -1,10 +1,10 @@
package net.ME1312.SubServers.Client.Bukkit.Graphic;
import net.ME1312.Galaxi.Library.Callback.Callback;
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.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Try;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.SubDataClient;
@ -29,6 +29,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.util.HashMap;
import java.util.UUID;
import java.util.function.Consumer;
import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permits;
@ -36,7 +37,7 @@ import static net.ME1312.SubServers.Client.Bukkit.Library.ObjectPermission.permi
* Default GUI Listener
*/
public class DefaultUIHandler implements UIHandler, Listener {
private HashMap<UUID, Callback<YAMLSection>> input = new HashMap<UUID, Callback<YAMLSection>>();
private HashMap<UUID, Consumer<YAMLSection>> input = new HashMap<UUID, Consumer<YAMLSection>>();
private HashMap<UUID, DefaultUIRenderer> gui = new HashMap<UUID, DefaultUIRenderer>();
private boolean enabled = true;
private SubPlugin plugin;
@ -47,7 +48,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
* @param plugin Event
*/
public DefaultUIHandler(SubPlugin plugin) {
if (Util.isNull(plugin)) throw new NullPointerException();
Util.nullpo(plugin);
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@ -71,7 +72,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (gui.open && event.getClickedInventory() != null && title != null) {
if (plugin.api.getSubDataNetwork()[0] == null) {
new IllegalStateException("SubData is not connected").printStackTrace();
} else if (Util.isException(() -> plugin.api.getLangChannels())) {
} else if (!Try.all.run(() -> plugin.api.getLangChannels())) {
new IllegalStateException("There are no lang options available at this time").printStackTrace();
} else if (title.equals(plugin.api.getLang("SubServers", "Interface.Host-Menu.Title"))) { // Host Menu
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) {
@ -168,7 +169,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (m.getString("message").length() <= 0) {
((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]).setPort(null);
gui.hostCreator((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]);
} else if (Util.isException(() -> Integer.parseInt(m.getString("message"))) || Integer.parseInt(m.getString("message")) <= 0 || Integer.parseInt(m.getString("message")) > 65535) {
} else if (!Try.all.run(() -> Integer.parseInt(m.getString("message"))) || Integer.parseInt(m.getString("message")) <= 0 || Integer.parseInt(m.getString("message")) > 65535) {
if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Port.Invalid-Title"), 4 * 20))
player.sendMessage(plugin.api.getLang("SubServers", "Interface.Host-Creator.Edit-Port.Invalid"));
Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastVisitedObjects[0]), 4 * 20);
@ -354,9 +355,9 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.stop")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> json) {
public void accept(ObjectMap<String> json) {
try {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
@ -378,9 +379,9 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (permits((SubServer) gui.lastVisitedObjects[0], player, "subservers.subserver.%.*", "subservers.subserver.%.terminate")) {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
final Value<Boolean> listening = new Container<Boolean>(true);
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
PacketInExRunEvent.callback("SubStoppedEvent", new Consumer<ObjectMap<String>>() {
@Override
public void run(ObjectMap<String> json) {
public void accept(ObjectMap<String> json) {
try {
if (listening.value()) if (!json.getString("server").equalsIgnoreCase(((SubServer) gui.lastVisitedObjects[0]).getName())) {
PacketInExRunEvent.callback("SubStoppedEvent", this);
@ -466,7 +467,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (!event.isCancelled() && enabled && input.containsKey(event.getPlayer().getUniqueId())) {
YAMLSection data = new YAMLSection();
data.set("message", event.getMessage());
input.get(event.getPlayer().getUniqueId()).run(data);
input.get(event.getPlayer().getUniqueId()).accept(data);
input.remove(event.getPlayer().getUniqueId());
event.setCancelled(true);
}
@ -482,7 +483,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
if (!event.isCancelled() && enabled && input.containsKey(event.getPlayer().getUniqueId())) {
YAMLSection data = new YAMLSection();
data.set("message", (event.getMessage().startsWith("/"))?event.getMessage().substring(1):event.getMessage());
input.get(event.getPlayer().getUniqueId()).run(data);
input.get(event.getPlayer().getUniqueId()).accept(data);
input.remove(event.getPlayer().getUniqueId());
event.setCancelled(true);
}

Some files were not shown because too many files have changed in this diff Show More