mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-01-25 17:11:20 +01:00
Mirror changes in SubServers.Client.Sponge
This commit is contained in:
parent
7059b5cad7
commit
9ef878ba12
@ -1,11 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Bukkit.Library.Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Illegal Packet Exception
|
|
||||||
*/
|
|
||||||
public class IllegalPacketException extends IllegalStateException {
|
|
||||||
public IllegalPacketException() {}
|
|
||||||
public IllegalPacketException(String s) {
|
|
||||||
super(s);
|
|
||||||
}
|
|
||||||
}
|
|
@ -396,7 +396,7 @@ public final class SubCommand extends BukkitCommand {
|
|||||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Disabled"));
|
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Disabled"));
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Incompatible"));
|
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Incompatible").replace("$str$", data.getString(0x0002)));
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
case 0:
|
case 0:
|
||||||
@ -421,8 +421,8 @@ public final class SubCommand extends BukkitCommand {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Callback<ObjectMap<Integer>> stopper = data -> {
|
Callback<ObjectMap<Integer>> stopper = data -> {
|
||||||
if (data.getInt(0x0000) != 0) listening.set(false);
|
if (data.getInt(0x0001) != 0) listening.set(false);
|
||||||
switch (data.getInt(0x0000)) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Unknown"));
|
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Unknown"));
|
||||||
break;
|
break;
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
<id>sponge-repo</id>
|
<id>sponge-repo</id>
|
||||||
<url>https://repo.spongepowered.org/maven</url>
|
<url>https://repo.spongepowered.org/maven</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>me1312-repo</id>
|
||||||
|
<url>https://src.me1312.net/maven</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -24,9 +28,15 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.msgpack</groupId>
|
<groupId>net.ME1312.Galaxi</groupId>
|
||||||
<artifactId>msgpack-core</artifactId>
|
<artifactId>GalaxiUtil</artifactId>
|
||||||
<version>0.8.16</version>
|
<version>19w19c</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.ME1312.SubData</groupId>
|
||||||
|
<artifactId>Client</artifactId>
|
||||||
|
<version>19w19f</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -64,7 +74,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<tasks>
|
<tasks>
|
||||||
<mkdir dir="${project.build.directory}" />
|
<mkdir dir="${project.build.directory}" />
|
||||||
<copy file="${basedir}/../config.yml" todir="${project.build.directory}/classes" />
|
|
||||||
<copy file="${basedir}/../../LICENSE" todir="${project.build.directory}/classes" />
|
<copy file="${basedir}/../../LICENSE" todir="${project.build.directory}/classes" />
|
||||||
</tasks>
|
</tasks>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Client.Sponge.Event;
|
|||||||
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ import java.util.UUID;
|
|||||||
public class SubEditServerEvent extends AbstractEvent implements SubEvent {
|
public class SubEditServerEvent extends AbstractEvent implements SubEvent {
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private String server;
|
private String server;
|
||||||
private NamedContainer<String, YAMLValue> edit;
|
private NamedContainer<String, ObjectMapValue<String>> edit;
|
||||||
private boolean perm;
|
private boolean perm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,11 +29,11 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
|
|||||||
*/
|
*/
|
||||||
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
|
public SubEditServerEvent(UUID player, String server, NamedContainer<String, ?> edit, boolean permanent) {
|
||||||
if (Util.isNull(server, edit)) throw new NullPointerException();
|
if (Util.isNull(server, edit)) throw new NullPointerException();
|
||||||
YAMLSection section = new YAMLSection();
|
ObjectMap<String> section = new ObjectMap<String>();
|
||||||
section.set(".", edit.get());
|
section.set(".", edit.get());
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.edit = new NamedContainer<String, YAMLValue>(edit.name(), section.contains(".")?section.get("."):null);
|
this.edit = new NamedContainer<String, ObjectMapValue<String>>(edit.name(), section.contains(".")?section.get("."):null);
|
||||||
this.perm = permanent;
|
this.perm = permanent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public class SubEditServerEvent extends AbstractEvent implements SubEvent {
|
|||||||
*
|
*
|
||||||
* @return Edit to be made
|
* @return Edit to be made
|
||||||
*/
|
*/
|
||||||
public NamedContainer<String, YAMLValue> getEdit() {
|
public NamedContainer<String, ObjectMapValue<String>> getEdit() {
|
||||||
return edit;
|
return edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.DataClient;
|
||||||
|
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
@ -8,16 +11,45 @@ import org.spongepowered.api.event.impl.AbstractEvent;
|
|||||||
* SubData Network Disconnect Event
|
* SubData Network Disconnect Event
|
||||||
*/
|
*/
|
||||||
public class SubNetworkDisconnectEvent extends AbstractEvent implements SubEvent {
|
public class SubNetworkDisconnectEvent extends AbstractEvent implements SubEvent {
|
||||||
|
private DataClient network;
|
||||||
|
private DisconnectReason reason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SubData Network Disconnect Event
|
||||||
|
*/
|
||||||
|
public SubNetworkDisconnectEvent(DataClient network, DisconnectReason reason) {
|
||||||
|
if (Util.isNull(network, reason)) throw new NullPointerException();
|
||||||
|
this.network = network;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SubData network
|
||||||
|
*
|
||||||
|
* @return SubData Network
|
||||||
|
*/
|
||||||
|
public DataClient getNetwork() {
|
||||||
|
return network;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the reason the client disconnected
|
||||||
|
*
|
||||||
|
* @return Disconnect Reason
|
||||||
|
*/
|
||||||
|
public DisconnectReason getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cause of this Event
|
* Gets the cause of this Event
|
||||||
*
|
*
|
||||||
* @deprecated Use simplified methods where available
|
* @deprecated Use simplified methods where available
|
||||||
* @return An empty cause list
|
* @return Disconnect Reason
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Cause getCause() {
|
public Cause getCause() {
|
||||||
return Cause.builder().build(getContext());
|
return Cause.builder().append(reason).build(getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package net.ME1312.SubServers.Client.Sponge.Event;
|
|||||||
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import org.spongepowered.api.event.cause.Cause;
|
import org.spongepowered.api.event.cause.Cause;
|
||||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Graphic;
|
package net.ME1312.SubServers.Client.Sponge.Graphic;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
|
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Container;
|
import net.ME1312.Galaxi.Library.Container;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
@ -99,7 +99,7 @@ public abstract class UIRenderer {
|
|||||||
*/
|
*/
|
||||||
public boolean sendTitle(String str, int fadein, int stay, int fadeout) {
|
public boolean sendTitle(String str, int fadein, int stay, int fadeout) {
|
||||||
if (Util.isNull(str, fadein, stay, fadeout)) throw new NullPointerException();
|
if (Util.isNull(str, fadein, stay, fadeout)) throw new NullPointerException();
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Use-Title-Messages", true)) {
|
||||||
String line1, line2;
|
String line1, line2;
|
||||||
if (!str.startsWith("\n") && str.contains("\n")) {
|
if (!str.startsWith("\n") && str.contains("\n")) {
|
||||||
line1 = str.split("\\n")[0];
|
line1 = str.split("\\n")[0];
|
||||||
@ -127,7 +127,7 @@ public abstract class UIRenderer {
|
|||||||
* @param subtitle Subtitle to display (or null to hide)
|
* @param subtitle Subtitle to display (or null to hide)
|
||||||
*/
|
*/
|
||||||
public void setDownloading(String subtitle) {
|
public void setDownloading(String subtitle) {
|
||||||
if (subtitle != null && !plugin.config.get().getSection("Settings").getBoolean("Use-Title-Messages", true)) {
|
if (subtitle != null && !plugin.config.get().getMap("Settings").getBoolean("Use-Title-Messages", true)) {
|
||||||
if (download != null && Sponge.getScheduler().getTaskById(download).isPresent()) Sponge.getScheduler().getTaskById(download).get().cancel();
|
if (download != null && Sponge.getScheduler().getTaskById(download).isPresent()) Sponge.getScheduler().getTaskById(download).get().cancel();
|
||||||
download = Sponge.getScheduler().createTaskBuilder().execute(() -> {
|
download = Sponge.getScheduler().createTaskBuilder().execute(() -> {
|
||||||
if (tdownload != null) Sponge.getServer().getPlayer(player).get().sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Interface.Generic.Downloading").replace("$str$", subtitle)));
|
if (tdownload != null) Sponge.getServer().getPlayer(player).get().sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Interface.Generic.Downloading").replace("$str$", subtitle)));
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback Class
|
|
||||||
*/
|
|
||||||
public interface Callback<T> {
|
|
||||||
/**
|
|
||||||
* Run the Callback
|
|
||||||
*
|
|
||||||
* @param obj Object
|
|
||||||
*/
|
|
||||||
void run(T obj);
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Config;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* YAML Config Class
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class YAMLConfig {
|
|
||||||
private File file;
|
|
||||||
private Yaml yaml;
|
|
||||||
private YAMLSection config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates/Loads a YAML Formatted Config
|
|
||||||
*
|
|
||||||
* @param file
|
|
||||||
* @throws IOException
|
|
||||||
* @throws YAMLException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public YAMLConfig(File file) throws IOException, YAMLException {
|
|
||||||
if (Util.isNull(file)) throw new NullPointerException();
|
|
||||||
this.file = file;
|
|
||||||
this.yaml = new Yaml(getDumperOptions());
|
|
||||||
if (file.exists()) {
|
|
||||||
InputStream stream = new FileInputStream(file);
|
|
||||||
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
|
|
||||||
stream.close();
|
|
||||||
} else {
|
|
||||||
this.config = new YAMLSection(null, null, null, yaml);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Config Contents
|
|
||||||
*
|
|
||||||
* @return Config Contents
|
|
||||||
*/
|
|
||||||
public YAMLSection get() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Config Contents
|
|
||||||
*
|
|
||||||
* @param value Value
|
|
||||||
*/
|
|
||||||
public void set(YAMLSection value) {
|
|
||||||
if (Util.isNull(value)) throw new NullPointerException();
|
|
||||||
config = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reload Config Contents
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void reload() throws IOException {
|
|
||||||
if (file.exists()) {
|
|
||||||
InputStream stream = new FileInputStream(file);
|
|
||||||
this.config = new YAMLSection((LinkedHashMap<String, ?>) yaml.loadAs(stream, LinkedHashMap.class), null, null, yaml);
|
|
||||||
stream.close();
|
|
||||||
} else {
|
|
||||||
this.config = new YAMLSection(null, null, null, yaml);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save Config Contents
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void save() throws IOException {
|
|
||||||
if (!file.exists()) file.createNewFile();
|
|
||||||
FileWriter writer = new FileWriter(file);
|
|
||||||
yaml.dump(config.map, writer);
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (object instanceof YAMLConfig) {
|
|
||||||
return get().equals(((YAMLConfig) object).get());
|
|
||||||
} else {
|
|
||||||
return super.equals(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return yaml.dump(config.map);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static DumperOptions getDumperOptions() {
|
|
||||||
DumperOptions options = new DumperOptions();
|
|
||||||
options.setAllowUnicode(false);
|
|
||||||
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
|
||||||
options.setIndent(2);
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,402 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Config;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* YAML Value Class
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({"unchecked", "unused"})
|
|
||||||
public class YAMLValue {
|
|
||||||
protected Object obj;
|
|
||||||
protected String label;
|
|
||||||
protected YAMLSection up;
|
|
||||||
private Yaml yaml;
|
|
||||||
|
|
||||||
protected YAMLValue(Object obj, YAMLSection up, String label, Yaml yaml) {
|
|
||||||
this.obj = obj;
|
|
||||||
this.label = label;
|
|
||||||
this.yaml = yaml;
|
|
||||||
this.up = up;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the YAML Section this Object was defined in
|
|
||||||
*
|
|
||||||
* @return YAML Section
|
|
||||||
*/
|
|
||||||
public YAMLSection getDefiningSection() {
|
|
||||||
return up;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object
|
|
||||||
*
|
|
||||||
* @return Object
|
|
||||||
*/
|
|
||||||
public Object asObject() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as List
|
|
||||||
*
|
|
||||||
* @return List
|
|
||||||
*/
|
|
||||||
public List<?> asObjectList() {
|
|
||||||
return (List<?>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Boolean
|
|
||||||
*
|
|
||||||
* @return Boolean
|
|
||||||
*/
|
|
||||||
public Boolean asBoolean() {
|
|
||||||
return (Boolean) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as List
|
|
||||||
*
|
|
||||||
* @return List
|
|
||||||
*/
|
|
||||||
public List<Boolean> asBooleanList() {
|
|
||||||
return (List<Boolean>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as YAML Section
|
|
||||||
*
|
|
||||||
* @return YAML Section
|
|
||||||
*/
|
|
||||||
public YAMLSection asSection() {
|
|
||||||
if (obj != null) return new YAMLSection((Map<String, ?>) obj, up, label, yaml);
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as YAML Section List
|
|
||||||
*
|
|
||||||
* @return YAML Section List
|
|
||||||
*/
|
|
||||||
public List<YAMLSection> asSectionList() {
|
|
||||||
if (obj != null) {
|
|
||||||
List<YAMLSection> values = new ArrayList<YAMLSection>();
|
|
||||||
for (Map<String, ?> value : (List<? extends Map<String, ?>>) obj) {
|
|
||||||
values.add(new YAMLSection(value, null, null, yaml));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Double
|
|
||||||
*
|
|
||||||
* @return Double
|
|
||||||
*/
|
|
||||||
public Double asDouble() {
|
|
||||||
return ((Number) obj).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Double List
|
|
||||||
*
|
|
||||||
* @return Double List
|
|
||||||
*/
|
|
||||||
public List<Double> asDoubleList() {
|
|
||||||
return (List<Double>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Float
|
|
||||||
*
|
|
||||||
* @return Float
|
|
||||||
*/
|
|
||||||
public Float asFloat() {
|
|
||||||
return ((Number) obj).floatValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Float List
|
|
||||||
*
|
|
||||||
* @return Float List
|
|
||||||
*/
|
|
||||||
public List<Float> asFloatList() {
|
|
||||||
return (List<Float>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Integer
|
|
||||||
*
|
|
||||||
* @return Integer
|
|
||||||
*/
|
|
||||||
public Integer asInt() {
|
|
||||||
return ((Number) obj).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Integer List
|
|
||||||
*
|
|
||||||
* @return Integer List
|
|
||||||
*/
|
|
||||||
public List<Integer> asIntList() {
|
|
||||||
return (List<Integer>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Long
|
|
||||||
*
|
|
||||||
* @return Long
|
|
||||||
*/
|
|
||||||
public Long asLong() {
|
|
||||||
return ((Number) obj).longValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Long List
|
|
||||||
*
|
|
||||||
* @return Long List
|
|
||||||
*/
|
|
||||||
public List<Long> asLongList() {
|
|
||||||
return (List<Long>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Short by Handle
|
|
||||||
*
|
|
||||||
* @return Short
|
|
||||||
*/
|
|
||||||
public Short asShort() {
|
|
||||||
return ((Number) obj).shortValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Short List by Handle
|
|
||||||
*
|
|
||||||
* @return Short List
|
|
||||||
*/
|
|
||||||
public List<Short> asShortList() {
|
|
||||||
return (List<Short>) obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Unparsed String
|
|
||||||
*
|
|
||||||
* @return Unparsed String
|
|
||||||
*/
|
|
||||||
public String asRawString() {
|
|
||||||
if (obj != null) return obj.toString();
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Unparsed String List
|
|
||||||
*
|
|
||||||
* @return Unparsed String List
|
|
||||||
*/
|
|
||||||
public List<String> asRawStringList() {
|
|
||||||
if (obj != null) {
|
|
||||||
List<String> values = new ArrayList<String>();
|
|
||||||
for (Object value : (List<?>) obj) {
|
|
||||||
values.add(value.toString());
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as String
|
|
||||||
*
|
|
||||||
* @return String
|
|
||||||
*/
|
|
||||||
public String asString() {
|
|
||||||
if (obj != null) return Util.unescapeJavaString(asRawString());
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as String List
|
|
||||||
*
|
|
||||||
* @return String List
|
|
||||||
*/
|
|
||||||
public List<String> asStringList() {
|
|
||||||
if (obj != null) {
|
|
||||||
List<String> values = new ArrayList<String>();
|
|
||||||
for (String value : asRawStringList()) {
|
|
||||||
values.add(Util.unescapeJavaString(value));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Colored String
|
|
||||||
*
|
|
||||||
* @param color Color Char to parse
|
|
||||||
* @return Colored String
|
|
||||||
*/
|
|
||||||
public String asColoredString(char color) {
|
|
||||||
if (Util.isNull(color)) throw new NullPointerException();
|
|
||||||
if (obj != null) return ChatColor.parseColor(color, asString());
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Colored String List
|
|
||||||
*
|
|
||||||
* @param color Color Char to parse
|
|
||||||
* @return Colored String List
|
|
||||||
*/
|
|
||||||
public List<String> asColoredStringList(char color) {
|
|
||||||
if (obj != null) {
|
|
||||||
if (Util.isNull(color)) throw new NullPointerException();
|
|
||||||
List<String> values = new ArrayList<String>();
|
|
||||||
for (String value : asStringList()) {
|
|
||||||
values.add(ChatColor.parseColor(color, value));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as UUID
|
|
||||||
*
|
|
||||||
* @return UUID
|
|
||||||
*/
|
|
||||||
public UUID asUUID() {
|
|
||||||
if (obj != null) return UUID.fromString(asRawString());
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as UUID List
|
|
||||||
*
|
|
||||||
* @return UUID List
|
|
||||||
*/
|
|
||||||
public List<UUID> asUUIDList() {
|
|
||||||
if (obj != null) {
|
|
||||||
List<UUID> values = new ArrayList<UUID>();
|
|
||||||
for (String value : (List<String>) obj) {
|
|
||||||
values.add(UUID.fromString(value));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Version
|
|
||||||
*
|
|
||||||
* @return Version
|
|
||||||
*/
|
|
||||||
public Version asVersion() {
|
|
||||||
if (obj != null) return Version.fromString(asRawString());
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Object as Version List
|
|
||||||
*
|
|
||||||
* @return Version List
|
|
||||||
*/
|
|
||||||
public List<Version> asVersionList() {
|
|
||||||
if (obj != null) {
|
|
||||||
List<Version> values = new ArrayList<Version>();
|
|
||||||
for (String value : (List<String>) obj) {
|
|
||||||
values.add(Version.fromString(value));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
} else return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is Null
|
|
||||||
*
|
|
||||||
* @return Null Status
|
|
||||||
*/
|
|
||||||
public boolean isNull() {
|
|
||||||
return obj == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a Boolean
|
|
||||||
*
|
|
||||||
* @return Boolean Status
|
|
||||||
*/
|
|
||||||
public boolean isBoolean() {
|
|
||||||
return (obj instanceof Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a YAML Section
|
|
||||||
*
|
|
||||||
* @return YAML Section Status
|
|
||||||
*/
|
|
||||||
public boolean isSection() {
|
|
||||||
return (obj instanceof Map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a List
|
|
||||||
*
|
|
||||||
* @return List Status
|
|
||||||
*/
|
|
||||||
public boolean isList() {
|
|
||||||
return (obj instanceof List);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a Number
|
|
||||||
*
|
|
||||||
* @return Number Status
|
|
||||||
*/
|
|
||||||
public boolean isNumber() {
|
|
||||||
return (obj instanceof Number);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a String
|
|
||||||
*
|
|
||||||
* @return String Status
|
|
||||||
*/
|
|
||||||
public boolean isString() {
|
|
||||||
return (obj instanceof String);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if object is a UUID
|
|
||||||
*
|
|
||||||
* @return UUID Status
|
|
||||||
*/
|
|
||||||
public boolean isUUID() {
|
|
||||||
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (obj == null) {
|
|
||||||
return object == null;
|
|
||||||
} else {
|
|
||||||
if (object instanceof YAMLValue) {
|
|
||||||
return obj.equals(((YAMLValue) object).obj);
|
|
||||||
} else {
|
|
||||||
return obj.equals(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if (obj != null) return obj.toString();
|
|
||||||
else return "null";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Container Class
|
|
||||||
*
|
|
||||||
* @param <V> Item
|
|
||||||
*/
|
|
||||||
public class Container<V> {
|
|
||||||
private V obj;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Container
|
|
||||||
*
|
|
||||||
* @param item Object to Store
|
|
||||||
*/
|
|
||||||
public Container(V item) {
|
|
||||||
obj = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grabs the Object
|
|
||||||
*
|
|
||||||
* @return The Object
|
|
||||||
*/
|
|
||||||
public V get() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overwrite the Object
|
|
||||||
*
|
|
||||||
* @param value Object to Store
|
|
||||||
*/
|
|
||||||
public void set(V value) {
|
|
||||||
obj = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (object instanceof Container) {
|
|
||||||
if (obj == null || ((Container) object).get() == null) {
|
|
||||||
return obj == ((Container) object).get();
|
|
||||||
} else {
|
|
||||||
return obj.equals(((Container) object).get());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.equals(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Illegal Packet Exception
|
|
||||||
*/
|
|
||||||
public class IllegalPacketException extends IllegalStateException {
|
|
||||||
public IllegalPacketException() {}
|
|
||||||
public IllegalPacketException(String s) {
|
|
||||||
super(s);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extra Data Handler Layout Class
|
|
||||||
*/
|
|
||||||
public interface ExtraDataHandler {
|
|
||||||
/**
|
|
||||||
* Add an extra value to this Object
|
|
||||||
*
|
|
||||||
* @param handle Handle
|
|
||||||
* @param value Value
|
|
||||||
*/
|
|
||||||
void addExtra(String handle, Object value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if an extra value exists
|
|
||||||
*
|
|
||||||
* @param handle Handle
|
|
||||||
* @return Value Status
|
|
||||||
*/
|
|
||||||
boolean hasExtra(String handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an extra value
|
|
||||||
*
|
|
||||||
* @param handle Handle
|
|
||||||
* @return Value
|
|
||||||
*/
|
|
||||||
YAMLValue getExtra(String handle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the extra value section
|
|
||||||
*
|
|
||||||
* @return Extra Value Section
|
|
||||||
*/
|
|
||||||
YAMLSection getExtra();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an extra value from this Object
|
|
||||||
*
|
|
||||||
* @param handle Handle
|
|
||||||
*/
|
|
||||||
void removeExtra(String handle);
|
|
||||||
}
|
|
@ -8,10 +8,7 @@ import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
|||||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.spongepowered.api.Platform;
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.config.ConfigDir;
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
|
||||||
import org.spongepowered.api.scheduler.Scheduler;
|
import org.spongepowered.api.scheduler.Scheduler;
|
||||||
import org.spongepowered.api.scheduler.Task;
|
import org.spongepowered.api.scheduler.Task;
|
||||||
|
|
||||||
@ -95,7 +92,7 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.logger = plugin.logger;
|
this.logger = plugin.log;
|
||||||
this.configDir = plugin.dir.getParentFile().toPath();
|
this.configDir = plugin.dir.getParentFile().toPath();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Named Container Class
|
|
||||||
* @param <T> Name
|
|
||||||
* @param <V> Item
|
|
||||||
*/
|
|
||||||
public class NamedContainer<T, V> extends Container<V> {
|
|
||||||
private T name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a TaggedContainer
|
|
||||||
*
|
|
||||||
* @param name Tag to Bind
|
|
||||||
* @param item Object to Store
|
|
||||||
*/
|
|
||||||
public NamedContainer(T name, V item) {
|
|
||||||
super(item);
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the name of the Container
|
|
||||||
*
|
|
||||||
* @return Container name
|
|
||||||
*/
|
|
||||||
public T name() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renames the Container
|
|
||||||
*
|
|
||||||
* @param name New Container Name
|
|
||||||
*/
|
|
||||||
public void rename(T name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (object instanceof NamedContainer) {
|
|
||||||
if (name == null || ((NamedContainer) object).name() == null) {
|
|
||||||
return name == ((NamedContainer) object).name() && super.equals(object);
|
|
||||||
} else {
|
|
||||||
return name.equals(((NamedContainer) object).name()) && super.equals(object);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return super.equals(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Universal File Class
|
|
||||||
*/
|
|
||||||
public class UniversalFile extends File {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a File Link. Path names are separated by ':'
|
|
||||||
*
|
|
||||||
* @param pathname Path name
|
|
||||||
*/
|
|
||||||
public UniversalFile(String pathname) {
|
|
||||||
super(pathname.replace(".:", System.getProperty("user.dir") + ":").replace(':', File.separatorChar));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a File Link. Path names are separated by the divider
|
|
||||||
*
|
|
||||||
* @param pathname Path name
|
|
||||||
* @param divider Divider to use
|
|
||||||
*/
|
|
||||||
public UniversalFile(String pathname, char divider) {
|
|
||||||
super(pathname.replace("." + divider, System.getProperty("user.dir") + divider).replace(divider, File.separatorChar));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a File Link.
|
|
||||||
*
|
|
||||||
* @see File
|
|
||||||
* @param file File
|
|
||||||
*/
|
|
||||||
public UniversalFile(File file) {
|
|
||||||
super(file.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a File. Path names are separated by the ':'
|
|
||||||
*
|
|
||||||
* @see File
|
|
||||||
* @param parent Parent File
|
|
||||||
* @param child Path name
|
|
||||||
*/
|
|
||||||
public UniversalFile(File parent, String child) {
|
|
||||||
super(parent, child.replace(':', File.separatorChar));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a File. Path names are separated by the divider
|
|
||||||
*
|
|
||||||
* @see File
|
|
||||||
* @param parent Parent File
|
|
||||||
* @param child Path name
|
|
||||||
* @param divider Divider to use
|
|
||||||
*/
|
|
||||||
public UniversalFile(File parent, String child, char divider) {
|
|
||||||
super(parent, child.replace(divider, File.separatorChar));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Universal File Path (separated by ':')
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getUniversalPath() {
|
|
||||||
return getPath().replace(File.separatorChar, ':');
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,75 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.Library.Updates;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||||
|
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||||
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SubServers Configuration Updater
|
||||||
|
*/
|
||||||
|
public class ConfigUpdater {
|
||||||
|
private static final Version UNSIGNED = new Version(new SimpleDateFormat("yy'w'ww'zz'").format(Calendar.getInstance().getTime()));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update SubServers' config.yml
|
||||||
|
*
|
||||||
|
* @param file File to bring up-to-date
|
||||||
|
*/
|
||||||
|
public static void updateConfig(File file) throws IOException {
|
||||||
|
YAMLConfig config = new YAMLConfig(file);
|
||||||
|
YAMLSection existing = config.get().clone();
|
||||||
|
YAMLSection updated = existing.clone();
|
||||||
|
YAMLSection rewritten = new YAMLSection();
|
||||||
|
|
||||||
|
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
|
||||||
|
Version now = SubAPI.getInstance().getPluginBuild();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
if (now == null) now = UNSIGNED;
|
||||||
|
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
|
||||||
|
|
||||||
|
i++;
|
||||||
|
System.out.println("SubServers > Created ./config/subservers-client-sponge/config.yml");
|
||||||
|
} else {
|
||||||
|
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||||
|
if (existing.getMap("Settings", new YAMLSection()).contains("Ingame-Access"))
|
||||||
|
updated.getMap("Settings").safeSet("API-Only-Mode", !existing.getMap("Settings").getBoolean("Ingame-Access"));
|
||||||
|
|
||||||
|
existing = updated.clone();
|
||||||
|
i++;
|
||||||
|
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||||
|
// // do something
|
||||||
|
// i++
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (i > 0) System.out.println("SubServers > Updated ./config/subservers-client-sponge/config.yml (" + i + " pass" + ((i != 1)?"es":"") + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
YAMLSection settings = new YAMLSection();
|
||||||
|
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||||
|
settings.set("API-Only-Mode", updated.getMap("Settings", new YAMLSection()).getBoolean("API-Only-Mode", false));
|
||||||
|
settings.set("Show-Addresses", updated.getMap("Settings", new YAMLSection()).getBoolean("Show-Addresses", false));
|
||||||
|
settings.set("Use-Title-Messages", updated.getMap("Settings", new YAMLSection()).getBoolean("Use-Title-Messages", true));
|
||||||
|
|
||||||
|
YAMLSection subdata = new YAMLSection();
|
||||||
|
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Name")) subdata.set("Name", updated.getMap("Settings").getMap("SubData").getRawString("Name"));
|
||||||
|
subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Address", "127.0.0.1:4391"));
|
||||||
|
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password")) subdata.set("Password", updated.getMap("Settings").getMap("SubData").getRawString("Password"));
|
||||||
|
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Reconnect")) subdata.set("Reconnect", updated.getMap("Settings").getMap("SubData").getInt("Reconnect"));
|
||||||
|
settings.set("SubData", subdata);
|
||||||
|
|
||||||
|
rewritten.set("Settings", settings);
|
||||||
|
|
||||||
|
config.set(rewritten);
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,400 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.LinkOption;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubServers Utility Class
|
|
||||||
*/
|
|
||||||
public final class Util {
|
|
||||||
private Util(){}
|
|
||||||
public interface ExceptionReturnRunnable<R> {
|
|
||||||
R run() throws Throwable;
|
|
||||||
}
|
|
||||||
public interface ExceptionRunnable {
|
|
||||||
void run() throws Throwable;
|
|
||||||
}
|
|
||||||
public interface ReturnRunnable<R> {
|
|
||||||
R run();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks values to make sure they're not null
|
|
||||||
*
|
|
||||||
* @param values Values to check
|
|
||||||
* @return If any are null
|
|
||||||
*/
|
|
||||||
public static boolean isNull(Object... values) {
|
|
||||||
boolean ret = false;
|
|
||||||
for (Object value : values) {
|
|
||||||
if (value == null) ret = true;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get keys by value from map
|
|
||||||
*
|
|
||||||
* @param map Map to search
|
|
||||||
* @param value Value to search for
|
|
||||||
* @param <K> Key
|
|
||||||
* @param <V> Value
|
|
||||||
* @return Search results
|
|
||||||
*/
|
|
||||||
public static <K, V> List<K> getBackwards(Map<K, V> map, V value) {
|
|
||||||
List<K> values = new ArrayList<K>();
|
|
||||||
|
|
||||||
for (K key : map.keySet()) {
|
|
||||||
if (map.get(key).equals(value)) {
|
|
||||||
values.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an item from a map ignoring case
|
|
||||||
*
|
|
||||||
* @param map Map to search
|
|
||||||
* @param key Key to search with
|
|
||||||
* @param <V> Value
|
|
||||||
* @return Search Result
|
|
||||||
*/
|
|
||||||
public static <V> V getCaseInsensitively(Map<String, V> map, String key) {
|
|
||||||
HashMap<String, String> insensitivity = new HashMap<String, String>();
|
|
||||||
for (String item : map.keySet()) insensitivity.put(item.toLowerCase(), item);
|
|
||||||
if (insensitivity.keySet().contains(key.toLowerCase())) {
|
|
||||||
return map.get(insensitivity.get(key.toLowerCase()));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a new Variable that doesn't match the existing Variables
|
|
||||||
*
|
|
||||||
* @param existing Existing Variables
|
|
||||||
* @param generator Variable Generator
|
|
||||||
* @param <V> Variable Type
|
|
||||||
* @return Variable
|
|
||||||
*/
|
|
||||||
public static <V> V getNew(Collection<? extends V> existing, ReturnRunnable<V> generator) {
|
|
||||||
V result = null;
|
|
||||||
while (result == null) {
|
|
||||||
V tmp = generator.run();
|
|
||||||
if (!existing.contains(tmp)) result = tmp;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read Everything from Reader
|
|
||||||
*
|
|
||||||
* @param rd Reader
|
|
||||||
* @return Reader Contents
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static String readAll(Reader rd) throws IOException {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
int cp;
|
|
||||||
while ((cp = rd.read()) != -1) {
|
|
||||||
sb.append((char) cp);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy from the Class Loader
|
|
||||||
*
|
|
||||||
* @param loader ClassLoader
|
|
||||||
* @param resource Location From
|
|
||||||
* @param destination Location To
|
|
||||||
*/
|
|
||||||
public static void copyFromJar(ClassLoader loader, String resource, String destination) {
|
|
||||||
InputStream resStreamIn = loader.getResourceAsStream(resource);
|
|
||||||
File resDestFile = new File(destination);
|
|
||||||
try {
|
|
||||||
OutputStream resStreamOut = new FileOutputStream(resDestFile);
|
|
||||||
int readBytes;
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
while ((readBytes = resStreamIn.read(buffer)) > 0) {
|
|
||||||
resStreamOut.write(buffer, 0, readBytes);
|
|
||||||
}
|
|
||||||
resStreamOut.close();
|
|
||||||
resStreamIn.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Field's value using Reflection
|
|
||||||
*
|
|
||||||
* @param field Field to grab
|
|
||||||
* @param instance Object Instance (Null for static fields)
|
|
||||||
* @param <R> Return Type
|
|
||||||
* @return Field Value
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <R> R reflect(Field field, Object instance) throws IllegalAccessException {
|
|
||||||
R value;
|
|
||||||
field.setAccessible(true);
|
|
||||||
value = (R) field.get(instance);
|
|
||||||
field.setAccessible(false);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a Field's value using Reflection
|
|
||||||
*
|
|
||||||
* @param field Field to write to
|
|
||||||
* @param instance Object Instance (Null for static fields)
|
|
||||||
* @param value Value to write
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
*/
|
|
||||||
public static void reflect(Field field, Object instance, Object value) throws IllegalAccessException {
|
|
||||||
field.setAccessible(true);
|
|
||||||
field.set(instance, value);
|
|
||||||
field.setAccessible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call a method using Reflection
|
|
||||||
*
|
|
||||||
* @param method Method to call
|
|
||||||
* @param instance Object Instance (Null for static methods)
|
|
||||||
* @param arguments Method Arguments
|
|
||||||
* @param <R> Return Type
|
|
||||||
* @return Returned Value
|
|
||||||
* @throws InvocationTargetException
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <R> R reflect(Method method, Object instance, Object... arguments) throws InvocationTargetException, IllegalAccessException {
|
|
||||||
R value;
|
|
||||||
method.setAccessible(true);
|
|
||||||
value = (R) method.invoke(instance, arguments);
|
|
||||||
method.setAccessible(false);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct an object using Reflection
|
|
||||||
*
|
|
||||||
* @param constructor Constructor to use
|
|
||||||
* @param arguments Constructor Arguments
|
|
||||||
* @param <R> Return Type
|
|
||||||
* @return New Instance
|
|
||||||
* @throws InvocationTargetException
|
|
||||||
* @throws IllegalAccessException
|
|
||||||
* @throws InstantiationException
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <R> R reflect(Constructor<?> constructor, Object... arguments) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
|
||||||
R value;
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
value = (R) constructor.newInstance(arguments);
|
|
||||||
constructor.setAccessible(false);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a variable from a method which may throw an exception
|
|
||||||
*
|
|
||||||
* @param runnable Runnable
|
|
||||||
* @param def Default value when an exception is thrown
|
|
||||||
* @param <R> Variable Type
|
|
||||||
* @return Returns value or default depending on if an exception is thrown
|
|
||||||
*/
|
|
||||||
public static <R> R getDespiteException(ExceptionReturnRunnable<R> runnable, R def) {
|
|
||||||
try {
|
|
||||||
return runnable.run();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if an Exception will occur
|
|
||||||
*
|
|
||||||
* @param runnable Runnable
|
|
||||||
* @return If an Exception occured
|
|
||||||
*/
|
|
||||||
public static boolean isException(ExceptionRunnable runnable) {
|
|
||||||
try {
|
|
||||||
runnable.run();
|
|
||||||
return false;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a Directory
|
|
||||||
*
|
|
||||||
* @param folder Location
|
|
||||||
*/
|
|
||||||
public static void deleteDirectory(File folder) {
|
|
||||||
File[] files = folder.listFiles();
|
|
||||||
if(files!=null) {
|
|
||||||
for(File f : files) {
|
|
||||||
if(f.isDirectory() && !Files.isSymbolicLink(f.toPath())) {
|
|
||||||
deleteDirectory(f);
|
|
||||||
} else try {
|
|
||||||
Files.delete(f.toPath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
folder.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy a Directory
|
|
||||||
*
|
|
||||||
* @param from Source
|
|
||||||
* @param to Destination
|
|
||||||
*/
|
|
||||||
public static void copyDirectory(File from, File to) {
|
|
||||||
if (from.isDirectory() && !Files.isSymbolicLink(from.toPath())) {
|
|
||||||
if (!to.exists()) {
|
|
||||||
to.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
String files[] = from.list();
|
|
||||||
|
|
||||||
for (String file : files) {
|
|
||||||
File srcFile = new File(from, file);
|
|
||||||
File destFile = new File(to, file);
|
|
||||||
|
|
||||||
copyDirectory(srcFile, destFile);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Files.copy(from.toPath(), to.toPath(), LinkOption.NOFOLLOW_LINKS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a Random Integer
|
|
||||||
*
|
|
||||||
* @param min Minimum Value
|
|
||||||
* @param max Maximum Value
|
|
||||||
* @return Random Integer
|
|
||||||
*/
|
|
||||||
public static int random(int min, int max) {
|
|
||||||
return new Random().nextInt((max - min) + 1) + min;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse escapes in a Java String
|
|
||||||
*
|
|
||||||
* @param str String
|
|
||||||
* @return Unescaped String
|
|
||||||
*/
|
|
||||||
public static String unescapeJavaString(String str) {
|
|
||||||
StringBuilder sb = new StringBuilder(str.length());
|
|
||||||
|
|
||||||
for (int i = 0; i < str.length(); i++) {
|
|
||||||
int ch = str.codePointAt(i);
|
|
||||||
if (ch == '\\') {
|
|
||||||
int nextChar = (i == str.length() - 1) ? '\\' : str
|
|
||||||
.codePointAt(i + 1);
|
|
||||||
// Octal escape?
|
|
||||||
if (nextChar >= '0' && nextChar <= '7') {
|
|
||||||
StringBuilder code = new StringBuilder();
|
|
||||||
code.appendCodePoint(nextChar);
|
|
||||||
i++;
|
|
||||||
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
|
|
||||||
&& str.codePointAt(i + 1) <= '7') {
|
|
||||||
code.appendCodePoint(str.codePointAt(i + 1));
|
|
||||||
i++;
|
|
||||||
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
|
|
||||||
&& str.codePointAt(i + 1) <= '7') {
|
|
||||||
code.appendCodePoint(str.codePointAt(i + 1));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append((char) Integer.parseInt(code.toString(), 8));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (nextChar) {
|
|
||||||
case '\\':
|
|
||||||
ch = '\\';
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
ch = '\b';
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
ch = '\f';
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
ch = '\n';
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ch = '\r';
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
ch = '\t';
|
|
||||||
break;
|
|
||||||
case '\"':
|
|
||||||
ch = '\"';
|
|
||||||
break;
|
|
||||||
case '\'':
|
|
||||||
ch = '\'';
|
|
||||||
break;
|
|
||||||
// Hex Unicode Char: u????
|
|
||||||
// Hex Unicode Codepoint: u{??????}
|
|
||||||
case 'u':
|
|
||||||
try {
|
|
||||||
if (i >= str.length() - 4) throw new IllegalStateException();
|
|
||||||
StringBuilder escape = new StringBuilder();
|
|
||||||
int offset = 2;
|
|
||||||
|
|
||||||
if (str.codePointAt(i + 2) != '{') {
|
|
||||||
if (i >= str.length() - 5) throw new IllegalStateException();
|
|
||||||
while (offset <= 5) {
|
|
||||||
Integer.toString(str.codePointAt(i + offset), 16);
|
|
||||||
escape.appendCodePoint(str.codePointAt(i + offset));
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
offset--;
|
|
||||||
} else {
|
|
||||||
offset++;
|
|
||||||
while (str.codePointAt(i + offset) != '}') {
|
|
||||||
Integer.toString(str.codePointAt(i + offset), 16);
|
|
||||||
escape.appendCodePoint(str.codePointAt(i + offset));
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append(new String(new int[]{
|
|
||||||
Integer.parseInt(escape.toString(), 16)
|
|
||||||
}, 0, 1));
|
|
||||||
|
|
||||||
i += offset;
|
|
||||||
continue;
|
|
||||||
} catch (Throwable e){
|
|
||||||
sb.append('\\');
|
|
||||||
ch = 'u';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
sb.appendCodePoint(ch);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,411 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Version;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Version Class
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class Version implements Serializable, Comparable<Version> {
|
|
||||||
private final Version parent;
|
|
||||||
private final VersionType type;
|
|
||||||
private final String string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version
|
|
||||||
*
|
|
||||||
* @param string Version String
|
|
||||||
*/
|
|
||||||
public Version(String string) {
|
|
||||||
this(VersionType.VERSION, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version
|
|
||||||
*
|
|
||||||
* @param type Version Type
|
|
||||||
* @param string Version String
|
|
||||||
*/
|
|
||||||
public Version(VersionType type, String string) {
|
|
||||||
this(null, type, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version (Appending the parent)
|
|
||||||
*
|
|
||||||
* @param parent Parent Version
|
|
||||||
* @param string Version String
|
|
||||||
*/
|
|
||||||
public Version(Version parent, String string) {
|
|
||||||
this(parent, VersionType.VERSION, string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version (Appending the parent)
|
|
||||||
*
|
|
||||||
* @param parent Parent Version
|
|
||||||
* @param type Version Type
|
|
||||||
* @param string Version String
|
|
||||||
*/
|
|
||||||
public Version(Version parent, VersionType type, String string) {
|
|
||||||
if (Util.isNull(string, type)) throw new NullPointerException();
|
|
||||||
this.parent = parent;
|
|
||||||
this.type = type;
|
|
||||||
this.string = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version
|
|
||||||
*
|
|
||||||
* @param ints Version Numbers (Will be separated with dots)
|
|
||||||
*/
|
|
||||||
public Version(int... ints) {
|
|
||||||
this(VersionType.VERSION, ints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version
|
|
||||||
*
|
|
||||||
* @param type Version Type
|
|
||||||
* @param ints Version Numbers (Will be separated with dots)
|
|
||||||
*/
|
|
||||||
public Version(VersionType type, int... ints) {
|
|
||||||
this(null, type, ints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version (Appending the parent)
|
|
||||||
*
|
|
||||||
* @param parent Parent Version
|
|
||||||
* @param ints Version Numbers (Will be separated with dots)
|
|
||||||
*/
|
|
||||||
public Version(Version parent, int... ints) {
|
|
||||||
this(parent, VersionType.VERSION, ints);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a Version (Appending the parent)
|
|
||||||
*
|
|
||||||
* @param parent Parent Version
|
|
||||||
* @param type Version Type
|
|
||||||
* @param ints Version Numbers (Will be separated with dots)
|
|
||||||
*/
|
|
||||||
public Version(Version parent, VersionType type, int... ints) {
|
|
||||||
if (Util.isNull(type)) throw new NullPointerException();
|
|
||||||
this.parent = parent;
|
|
||||||
this.type = type;
|
|
||||||
String string = Integer.toString(ints[0]);
|
|
||||||
int i = 0;
|
|
||||||
if (ints.length != 1) {
|
|
||||||
do {
|
|
||||||
i++;
|
|
||||||
string = string + "." + ints[i];
|
|
||||||
} while ((i + 1) != ints.length);
|
|
||||||
}
|
|
||||||
this.string = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a Version from a string
|
|
||||||
*
|
|
||||||
* @param string String to parse
|
|
||||||
* @see #toFullString() <b>#toFullString()</b> returns a valid string
|
|
||||||
* @see #toFullString() <b>#toString()</b> returns a valid string
|
|
||||||
*/
|
|
||||||
public static Version fromString(String string) {
|
|
||||||
Matcher regex = Pattern.compile("(rv|p?[abrv]|[su])?([^/]+)", Pattern.CASE_INSENSITIVE).matcher(string);
|
|
||||||
Version current = null;
|
|
||||||
while (regex.find()) {
|
|
||||||
try {
|
|
||||||
VersionType type = VersionType.VERSION;
|
|
||||||
if (regex.group(1) != null) switch (regex.group(1).toLowerCase()) {
|
|
||||||
case "pa":
|
|
||||||
type = VersionType.PRE_ALPHA;
|
|
||||||
break;
|
|
||||||
case "a":
|
|
||||||
type = VersionType.ALPHA;
|
|
||||||
break;
|
|
||||||
case "pv":
|
|
||||||
type = VersionType.PREVIEW;
|
|
||||||
break;
|
|
||||||
case "pb":
|
|
||||||
type = VersionType.PRE_BETA;
|
|
||||||
break;
|
|
||||||
case "b":
|
|
||||||
type = VersionType.BETA;
|
|
||||||
break;
|
|
||||||
case "s":
|
|
||||||
type = VersionType.SNAPSHOT;
|
|
||||||
break;
|
|
||||||
case "pr":
|
|
||||||
type = VersionType.PRE_RELEASE;
|
|
||||||
break;
|
|
||||||
case "r":
|
|
||||||
type = VersionType.RELEASE;
|
|
||||||
break;
|
|
||||||
case "rv":
|
|
||||||
type = VersionType.REVISION;
|
|
||||||
break;
|
|
||||||
case "u":
|
|
||||||
type = VersionType.UPDATE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = new Version(current, type, regex.group(2));
|
|
||||||
} catch (Throwable e) {}
|
|
||||||
}
|
|
||||||
if (current == null) throw new IllegalArgumentException("Could not find version in string: " + string);
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default toString() method<br>
|
|
||||||
* <br>
|
|
||||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
|
||||||
* <b style="font-family: consolas">1.0.0/pa7</b>
|
|
||||||
*
|
|
||||||
* @return Version as a String
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return ((parent == null)?"":parent.toString()+'/'+type.shortname) + string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The full toString() method<br>
|
|
||||||
* <br>
|
|
||||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
|
||||||
* <b style="font-family: consolas">r1.0.0/pa7</b>
|
|
||||||
*
|
|
||||||
* @return Version as a String
|
|
||||||
*/
|
|
||||||
public String toFullString() {
|
|
||||||
return ((parent == null)?"":parent.toFullString()+'/') + type.shortname + string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The extended toString() method<br>
|
|
||||||
* <br>
|
|
||||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
|
||||||
* <b style="font-family: consolas">1.0.0 pre-alpha 7</b>
|
|
||||||
*
|
|
||||||
* @return Version as a String
|
|
||||||
*/
|
|
||||||
public String toExtendedString() {
|
|
||||||
return ((parent == null)?"":parent.toExtendedString()+' '+type.longname+' ') + string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The full extended toString() method<br>
|
|
||||||
* <br>
|
|
||||||
* <b style="font-family: consolas">new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7")</b> would return:<br>
|
|
||||||
* <b style="font-family: consolas">release 1.0.0 pre-alpha 7</b>
|
|
||||||
*
|
|
||||||
* @return Version as a String
|
|
||||||
*/
|
|
||||||
public String toFullExtendedString() {
|
|
||||||
return ((parent == null)?"":parent.toFullExtendedString()+' ') + type.longname + ' ' + string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object object) {
|
|
||||||
if (object instanceof Version) {
|
|
||||||
return equals((Version) object);
|
|
||||||
} else {
|
|
||||||
return super.equals(object);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See if Versions are Equal
|
|
||||||
*
|
|
||||||
* @param version Version to Compare to
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean equals(Version version) {
|
|
||||||
return compareTo(version) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns 1 if Greater than
|
|
||||||
* Returns 0 if Equal
|
|
||||||
* Returns -1 if Less than
|
|
||||||
*//**
|
|
||||||
*
|
|
||||||
* Compare Versions
|
|
||||||
*
|
|
||||||
* @param version Version to Compare to
|
|
||||||
*/
|
|
||||||
public int compareTo(Version version) {
|
|
||||||
return compare(this, version);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See if Versions are Equal
|
|
||||||
*
|
|
||||||
* @param ver1 Version to Compare
|
|
||||||
* @param ver2 Version to Compare
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static boolean equals(Version ver1, Version ver2) {
|
|
||||||
return compare(ver1, ver2) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns 1 if Greater than
|
|
||||||
* Returns 0 if Equal
|
|
||||||
* Returns -1 if Less than
|
|
||||||
*//**
|
|
||||||
* Compare Versions
|
|
||||||
*
|
|
||||||
* @param ver1 Version to Compare
|
|
||||||
* @param ver2 Version to Compare
|
|
||||||
*/
|
|
||||||
public static int compare(Version ver1, Version ver2) {
|
|
||||||
if (ver1 == null && ver2 == null) {
|
|
||||||
// Both versions are null
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ver1 == null) {
|
|
||||||
// Version one is null
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ver2 == null) {
|
|
||||||
// Version two is null
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedList<Version> stack1 = new LinkedList<Version>();
|
|
||||||
stack1.add(ver1);
|
|
||||||
while (ver1.parent != null) {
|
|
||||||
ver1 = ver1.parent;
|
|
||||||
stack1.add(ver1);
|
|
||||||
}
|
|
||||||
Collections.reverse(stack1);
|
|
||||||
|
|
||||||
LinkedList<Version> stack2 = new LinkedList<Version>();
|
|
||||||
stack2.add(ver2);
|
|
||||||
while (ver2.parent != null) {
|
|
||||||
ver2 = ver2.parent;
|
|
||||||
stack2.add(ver2);
|
|
||||||
}
|
|
||||||
Collections.reverse(stack2);
|
|
||||||
|
|
||||||
int id;
|
|
||||||
for (id = 0; id < stack1.size(); id++) {
|
|
||||||
if (id >= stack2.size()) {
|
|
||||||
// Version one still has children when version two does not...
|
|
||||||
if (stack1.get(id).type.stageid < 0) {
|
|
||||||
// ...making version two the official version
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
// ...however the direct child of version one has a stageid higher than or equal to a release
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = stack1.get(id).compare(stack2.get(id));
|
|
||||||
if (result != 0) {
|
|
||||||
// Versions are not the same, return the result
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (id < stack2.size()) {
|
|
||||||
// Version one does not children when version two still does...
|
|
||||||
if (stack2.get(id).type.stageid < 0) {
|
|
||||||
// ...making version one the official version
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
// ...however the direct child of version two has a stageid higher than or equal to a release
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Compares versions ignoring parent/child relationships
|
|
||||||
*/
|
|
||||||
private int compare(Version version) {
|
|
||||||
if (this.type.stageid > version.type.stageid) {
|
|
||||||
// Version one has a type of a later stage than version two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.type.stageid < version.type.stageid) {
|
|
||||||
// Version one has a type of an earlier stage than version two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
|
||||||
|
|
||||||
int number1, number2;
|
|
||||||
String suffix1, suffix2;
|
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
|
||||||
if (!tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
if (number1 != 0 || suffix1.length() != 0) {
|
|
||||||
// Version one is longer than number two, and non-zero
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer1.MoveNext());
|
|
||||||
|
|
||||||
// Version one is longer than version two, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
|
|
||||||
if (number1 < number2) {
|
|
||||||
// Number one is less than number two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (number1 > number2) {
|
|
||||||
// Number one is greater than number two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean empty1 = suffix1.length() == 0;
|
|
||||||
boolean empty2 = suffix2.length() == 0;
|
|
||||||
|
|
||||||
if (empty1 && empty2) continue; // No suffixes
|
|
||||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
|
||||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
|
||||||
|
|
||||||
// Lexical comparison of suffixes
|
|
||||||
int result = suffix1.compareTo(suffix2);
|
|
||||||
if (result != 0) return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
if (number2 != 0 || suffix2.length() != 0) {
|
|
||||||
// Version one is longer than version two, and non-zero
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer2.MoveNext());
|
|
||||||
|
|
||||||
// Version two is longer than version one, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Version;
|
|
||||||
|
|
||||||
final class VersionTokenizer {
|
|
||||||
private final String _versionString;
|
|
||||||
private final int _length;
|
|
||||||
|
|
||||||
private int _position;
|
|
||||||
private int _number;
|
|
||||||
private String _suffix;
|
|
||||||
private boolean _hasValue;
|
|
||||||
|
|
||||||
protected int getNumber() {
|
|
||||||
return _number;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getSuffix() {
|
|
||||||
return _suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean hasValue() {
|
|
||||||
return _hasValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected VersionTokenizer(String versionString) {
|
|
||||||
if (versionString == null)
|
|
||||||
throw new IllegalArgumentException("versionString is null");
|
|
||||||
|
|
||||||
_versionString = versionString;
|
|
||||||
_length = versionString.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean MoveNext() {
|
|
||||||
_number = 0;
|
|
||||||
_suffix = "";
|
|
||||||
_hasValue = false;
|
|
||||||
|
|
||||||
// No more characters
|
|
||||||
if (_position >= _length)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_hasValue = true;
|
|
||||||
|
|
||||||
while (_position < _length) {
|
|
||||||
char c = _versionString.charAt(_position);
|
|
||||||
if (c < '0' || c > '9') break;
|
|
||||||
_number = _number * 10 + (c - '0');
|
|
||||||
_position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int suffixStart = _position;
|
|
||||||
|
|
||||||
while (_position < _length) {
|
|
||||||
char c = _versionString.charAt(_position);
|
|
||||||
if (c == '.') break;
|
|
||||||
_position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
_suffix = _versionString.substring(suffixStart, _position);
|
|
||||||
|
|
||||||
if (_position < _length) _position++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Library.Version;
|
|
||||||
|
|
||||||
public enum VersionType {
|
|
||||||
PRE_ALPHA(-6, "pa", "pre-alpha"),
|
|
||||||
ALPHA(-5, "a", "alpha"),
|
|
||||||
PREVIEW(-4, "pv", "preview"),
|
|
||||||
PRE_BETA(-4, "pb", "pre-beta"),
|
|
||||||
BETA(-3, "b", "beta"),
|
|
||||||
SNAPSHOT(-2, "s", "snapshot"),
|
|
||||||
PRE_RELEASE(-1, "pr", "pre-release"),
|
|
||||||
RELEASE(0, "r", "release"),
|
|
||||||
REVISION(0, "rv", "revision"),
|
|
||||||
VERSION(0, "v", "version"),
|
|
||||||
UPDATE(0, "u", "update"),
|
|
||||||
;
|
|
||||||
final short stageid;
|
|
||||||
final String shortname, longname;
|
|
||||||
VersionType(int stageid, String shortname, String longname) {
|
|
||||||
this.stageid = (short) stageid;
|
|
||||||
this.shortname = shortname;
|
|
||||||
this.longname = longname;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +1,17 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketAddServer;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDeleteServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadHostInfo;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadHostInfo;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketRemoveServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -13,7 +19,7 @@ import java.util.*;
|
|||||||
public class Host {
|
public class Host {
|
||||||
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
HashMap<String, SubServer> servers = new HashMap<String, SubServer>();
|
||||||
private SubCreator creator;
|
private SubCreator creator;
|
||||||
YAMLSection raw;
|
ObjectMap<String> raw;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +27,7 @@ public class Host {
|
|||||||
*
|
*
|
||||||
* @param raw Raw representation of the Host
|
* @param raw Raw representation of the Host
|
||||||
*/
|
*/
|
||||||
public Host(YAMLSection raw) {
|
public Host(ObjectMap<String> raw) {
|
||||||
load(raw);
|
load(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,14 +36,14 @@ public class Host {
|
|||||||
return obj instanceof Host && getSignature().equals(((Host) obj).getSignature());
|
return obj instanceof Host && getSignature().equals(((Host) obj).getSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(YAMLSection raw) {
|
private void load(ObjectMap<String> raw) {
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||||
|
|
||||||
servers.clear();
|
servers.clear();
|
||||||
this.creator = new SubCreator(this, raw.getSection("creator"));
|
this.creator = new SubCreator(this, raw.getMap("creator"));
|
||||||
for (String server : raw.getSection("servers").getKeys()) {
|
for (String server : raw.getMap("servers").getKeys()) {
|
||||||
servers.put(server.toLowerCase(), new SubServer(this, raw.getSection("servers").getSection(server)));
|
servers.put(server.toLowerCase(), new SubServer(this, raw.getMap("servers").getMap(server)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,16 +52,16 @@ public class Host {
|
|||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getSection("hosts").getSection(name))));
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> load(data.getMap(name))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the SubData Client Address
|
* Gets the SubData Client Channel IDs
|
||||||
*
|
*
|
||||||
* @return SubData Client Address (or null if unlinked/unsupported)
|
* @return SubData Client Channel ID Array (may be empty if unsupported)
|
||||||
*/
|
*/
|
||||||
public String getSubData() {
|
public UUID[] getSubData() {
|
||||||
return raw.getRawString("subdata", null);
|
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,6 +238,380 @@ public class Host {
|
|||||||
return getSubServers().get(name.toLowerCase());
|
return getSubServers().get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a SubServer
|
||||||
|
*
|
||||||
|
* @param name Name of Server
|
||||||
|
* @param enabled Enabled Status
|
||||||
|
* @param port Port Number
|
||||||
|
* @param motd Motd of the Server
|
||||||
|
* @param log Logging Status
|
||||||
|
* @param directory Directory
|
||||||
|
* @param executable Executable String
|
||||||
|
* @param stopcmd Command to Stop the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param response Response Code
|
||||||
|
* @return The SubServer
|
||||||
|
*/
|
||||||
|
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||||
|
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player adding
|
||||||
|
* @param name Name of Server
|
||||||
|
* @param enabled Enabled Status
|
||||||
|
* @param port Port Number
|
||||||
|
* @param motd Motd of the Server
|
||||||
|
* @param log Logging Status
|
||||||
|
* @param directory Directory
|
||||||
|
* @param executable Executable String
|
||||||
|
* @param stopcmd Command to Stop the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param response Response Code
|
||||||
|
* @return The SubServer
|
||||||
|
*/
|
||||||
|
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, enabled, getName(), port, motd, log, directory, executable, stopcmd, hidden, restricted, data -> {
|
||||||
|
try {
|
||||||
|
response.run(data.getInt(0x0001));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a SubServer
|
||||||
|
*
|
||||||
|
* @param name Name of Server
|
||||||
|
* @param enabled Enabled Status
|
||||||
|
* @param port Port Number
|
||||||
|
* @param motd Motd of the Server
|
||||||
|
* @param log Logging Status
|
||||||
|
* @param directory Directory
|
||||||
|
* @param executable Executable String
|
||||||
|
* @param stopcmd Command to Stop the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @return The SubServer
|
||||||
|
*/
|
||||||
|
public void addSubServer(String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||||
|
addSubServer(null, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player adding
|
||||||
|
* @param name Name of Server
|
||||||
|
* @param enabled Enabled Status
|
||||||
|
* @param port Port Number
|
||||||
|
* @param motd Motd of the Server
|
||||||
|
* @param log Logging Status
|
||||||
|
* @param directory Directory
|
||||||
|
* @param executable Executable String
|
||||||
|
* @param stopcmd Command to Stop the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @return The SubServer
|
||||||
|
*/
|
||||||
|
public void addSubServer(UUID player, String name, boolean enabled, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted) {
|
||||||
|
addSubServer(player, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void removeSubServer(String name) throws InterruptedException {
|
||||||
|
removeSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void removeSubServer(UUID player, String name) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeSubServer(player, name, false, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Removal of a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void forceRemoveSubServer(String name) throws InterruptedException {
|
||||||
|
forceRemoveSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void forceRemoveSubServer(UUID player, String name) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeSubServer(player, name, true, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void removeSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
removeSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void removeSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeSubServer(player, name, false, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Removal of a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRemoveSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
forceRemoveSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Removal of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRemoveSubServer(UUID player, String name, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeSubServer(player, name, true, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeSubServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||||
|
try {
|
||||||
|
response.run(data.getInt(0x0001));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void recycleSubServer(String name) throws InterruptedException {
|
||||||
|
recycleSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void recycleSubServer(UUID player, String name) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, true, false, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void forceRecycleSubServer(String name) throws InterruptedException {
|
||||||
|
forceRecycleSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
*/
|
||||||
|
public void forceRecycleSubServer(UUID player, String name) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, true, true, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void recycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
recycleSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void recycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, true, false, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forced the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRecycleSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
forceRecycleSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer (will move to 'Recently Deleted')
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRecycleSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, true, true, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void deleteSubServer(String name) throws InterruptedException {
|
||||||
|
deleteSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void deleteSubServer(UUID player, String name) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, false, false, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forced the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void forceDeleteSubServer(String name) throws InterruptedException {
|
||||||
|
forceDeleteSubServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void forceDeleteSubServer(UUID player, String name) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, false, true, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void deleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
deleteSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void deleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, false, false, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forced the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void forceDeleteSubServer(String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
forceDeleteSubServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forces the Deletion of a SubServer
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param name SubServer Name
|
||||||
|
* @return Success Status
|
||||||
|
*/
|
||||||
|
public void forceDeleteSubServer(UUID player, String name, Callback<Integer> response) throws InterruptedException {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
deleteSubServer(player, name, false, true, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteSubServer(UUID player, String name, boolean recycle, boolean force, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDeleteServer(player, name, recycle, force, data -> {
|
||||||
|
try {
|
||||||
|
response.run(data.getInt(0x0001));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Signature of this Object
|
* Get the Signature of this Object
|
||||||
*
|
*
|
||||||
@ -258,7 +638,7 @@ public class Host {
|
|||||||
*/
|
*/
|
||||||
public boolean hasExtra(String handle) {
|
public boolean hasExtra(String handle) {
|
||||||
if (Util.isNull(handle)) throw new NullPointerException();
|
if (Util.isNull(handle)) throw new NullPointerException();
|
||||||
return raw.getSection("extra").getKeys().contains(handle);
|
return raw.getMap("extra").getKeys().contains(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -267,9 +647,9 @@ public class Host {
|
|||||||
* @param handle Handle
|
* @param handle Handle
|
||||||
* @return Value
|
* @return Value
|
||||||
*/
|
*/
|
||||||
public YAMLValue getExtra(String handle) {
|
public ObjectMapValue<String> getExtra(String handle) {
|
||||||
if (Util.isNull(handle)) throw new NullPointerException();
|
if (Util.isNull(handle)) throw new NullPointerException();
|
||||||
return raw.getSection("extra").get(handle);
|
return raw.getMap("extra").get(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -277,8 +657,8 @@ public class Host {
|
|||||||
*
|
*
|
||||||
* @return Extra Value Section
|
* @return Extra Value Section
|
||||||
*/
|
*/
|
||||||
public YAMLSection getExtra() {
|
public ObjectMap<String> getExtra() {
|
||||||
return raw.getSection("extra").clone();
|
return raw.getMap("extra").clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,13 +666,7 @@ public class Host {
|
|||||||
*
|
*
|
||||||
* @return Raw Host
|
* @return Raw Host
|
||||||
*/
|
*/
|
||||||
public YAMLSection getRaw() {
|
public ObjectMap<String> getRaw() {
|
||||||
return raw.clone();
|
return raw.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String toString() {
|
|
||||||
return raw.toJSON().toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLValue;
|
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadProxyInfo;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadProxyInfo;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Proxy {
|
public class Proxy {
|
||||||
YAMLSection raw;
|
ObjectMap<String> raw;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,7 +19,7 @@ public class Proxy {
|
|||||||
*
|
*
|
||||||
* @param raw Raw representation of the Proxy
|
* @param raw Raw representation of the Proxy
|
||||||
*/
|
*/
|
||||||
public Proxy(YAMLSection raw) {
|
public Proxy(ObjectMap<String> raw) {
|
||||||
load(raw);
|
load(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ public class Proxy {
|
|||||||
return obj instanceof Proxy && getSignature().equals(((Proxy) obj).getSignature());
|
return obj instanceof Proxy && getSignature().equals(((Proxy) obj).getSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void load(YAMLSection raw) {
|
private void load(ObjectMap<String> raw) {
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||||
}
|
}
|
||||||
@ -37,16 +38,16 @@ public class Proxy {
|
|||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getSection("proxies").getSection(name))));
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> load(data.getMap(name))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the SubData Client
|
* Gets the SubData Client Channel IDs
|
||||||
*
|
*
|
||||||
* @return SubData Client (or null if not linked)
|
* @return SubData Client Channel ID Array
|
||||||
*/
|
*/
|
||||||
public String getSubData() {
|
public UUID[] getSubData() {
|
||||||
return raw.getRawString("subdata", null);
|
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,8 +84,8 @@ public class Proxy {
|
|||||||
*/
|
*/
|
||||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||||
for (String id : raw.getSection("players").getKeys()) {
|
for (String id : raw.getMap("players").getKeys()) {
|
||||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
@ -115,7 +116,7 @@ public class Proxy {
|
|||||||
*/
|
*/
|
||||||
public boolean hasExtra(String handle) {
|
public boolean hasExtra(String handle) {
|
||||||
if (Util.isNull(handle)) throw new NullPointerException();
|
if (Util.isNull(handle)) throw new NullPointerException();
|
||||||
return raw.getSection("extra").getKeys().contains(handle);
|
return raw.getMap("extra").getKeys().contains(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,9 +125,9 @@ public class Proxy {
|
|||||||
* @param handle Handle
|
* @param handle Handle
|
||||||
* @return Value
|
* @return Value
|
||||||
*/
|
*/
|
||||||
public YAMLValue getExtra(String handle) {
|
public ObjectMapValue<String> getExtra(String handle) {
|
||||||
if (Util.isNull(handle)) throw new NullPointerException();
|
if (Util.isNull(handle)) throw new NullPointerException();
|
||||||
return raw.getSection("extra").get(handle);
|
return raw.getMap("extra").get(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,8 +135,8 @@ public class Proxy {
|
|||||||
*
|
*
|
||||||
* @return Extra Value Section
|
* @return Extra Value Section
|
||||||
*/
|
*/
|
||||||
public YAMLSection getExtra() {
|
public ObjectMap<String> getExtra() {
|
||||||
return raw.getSection("extra").clone();
|
return raw.getMap("extra").clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,13 +144,7 @@ public class Proxy {
|
|||||||
*
|
*
|
||||||
* @return Raw Proxy
|
* @return Raw Proxy
|
||||||
*/
|
*/
|
||||||
public YAMLSection getRaw() {
|
public ObjectMap<String> getRaw() {
|
||||||
return raw.clone();
|
return raw.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String toString() {
|
|
||||||
return raw.toJSON().toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerInfo;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadServerInfo;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Server {
|
public class Server {
|
||||||
YAMLSection raw;
|
ObjectMap<String> raw;
|
||||||
long timestamp;
|
long timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,7 +18,7 @@ public class Server {
|
|||||||
*
|
*
|
||||||
* @param raw Raw representation of the Server
|
* @param raw Raw representation of the Server
|
||||||
*/
|
*/
|
||||||
public Server(YAMLSection raw) {
|
public Server(ObjectMap<String> raw) {
|
||||||
load(raw);
|
load(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ public class Server {
|
|||||||
return obj instanceof Server && getSignature().equals(((Server) obj).getSignature());
|
return obj instanceof Server && getSignature().equals(((Server) obj).getSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
void load(YAMLSection raw) {
|
void load(ObjectMap<String> raw) {
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
this.timestamp = Calendar.getInstance().getTime().getTime();
|
this.timestamp = Calendar.getInstance().getTime().getTime();
|
||||||
}
|
}
|
||||||
@ -36,16 +37,16 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
String name = getName();
|
String name = getName();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getSection("servers").getSection(name))));
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> load(data.getMap(name))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the SubData Client Address
|
* Gets the SubData Client Channel IDs
|
||||||
*
|
*
|
||||||
* @return SubData Client Address (or null if not linked)
|
* @return SubData Client Channel ID Array
|
||||||
*/
|
*/
|
||||||
public String getSubData() {
|
public UUID[] getSubData() {
|
||||||
return raw.getRawString("subdata", null);
|
return raw.getUUIDList("subdata", Collections.emptyList()).toArray(new UUID[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,8 +91,8 @@ public class Server {
|
|||||||
*/
|
*/
|
||||||
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
public Collection<NamedContainer<String, UUID>> getPlayers() {
|
||||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||||
for (String id : raw.getSection("players").getKeys()) {
|
for (String id : raw.getMap("players").getKeys()) {
|
||||||
players.add(new NamedContainer<String, UUID>(raw.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
players.add(new NamedContainer<String, UUID>(raw.getMap("players").getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
@ -165,13 +166,7 @@ public class Server {
|
|||||||
*
|
*
|
||||||
* @return Raw Server
|
* @return Raw Server
|
||||||
*/
|
*/
|
||||||
public YAMLSection getRaw() {
|
public ObjectMap<String> getRaw() {
|
||||||
return raw.clone();
|
return raw.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String toString() {
|
|
||||||
return raw.toJSON().toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCreateServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCreateServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
@ -16,14 +17,14 @@ import java.util.UUID;
|
|||||||
public class SubCreator {
|
public class SubCreator {
|
||||||
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
HashMap<String, ServerTemplate> templates = new HashMap<String, ServerTemplate>();
|
||||||
Host host;
|
Host host;
|
||||||
YAMLSection raw;
|
ObjectMap<String> raw;
|
||||||
|
|
||||||
SubCreator(Host host, YAMLSection raw) {
|
SubCreator(Host host, ObjectMap<String> raw) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
|
|
||||||
for (String template : raw.getSection("templates").getKeys()) {
|
for (String template : raw.getMap("templates").getKeys()) {
|
||||||
templates.put(template.toLowerCase(), new ServerTemplate(raw.getSection("templates").getSection(template)));
|
templates.put(template.toLowerCase(), new ServerTemplate(raw.getMap("templates").getMap(template)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,12 +34,12 @@ public class SubCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ServerTemplate {
|
public static class ServerTemplate {
|
||||||
private YAMLSection raw;
|
private ObjectMap<String> raw;
|
||||||
private ServerType type;
|
private ServerType type;
|
||||||
|
|
||||||
public ServerTemplate(YAMLSection raw) {
|
public ServerTemplate(ObjectMap<String> raw) {
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
this.type = (Util.isException(() -> ServerType.valueOf(raw.getRawString("type").toUpperCase())))?ServerType.valueOf(raw.getRawString("type").toUpperCase()):ServerType.CUSTOM;
|
this.type = (Util.isException(() -> ServerType.valueOf(raw.getRawString("type").toUpperCase())))? ServerType.valueOf(raw.getRawString("type").toUpperCase()): ServerType.CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,15 +87,13 @@ public class SubCreator {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String toString() {
|
* Get whether this Template requires the Version argument
|
||||||
YAMLSection tinfo = new YAMLSection();
|
*
|
||||||
tinfo.set("enabled", isEnabled());
|
* @return Version Requirement
|
||||||
tinfo.set("name", getName());
|
*/
|
||||||
tinfo.set("display", getDisplayName());
|
public boolean requiresVersion() {
|
||||||
tinfo.set("icon", getIcon());
|
return raw.getBoolean("version-req");
|
||||||
tinfo.set("type", getType().toString());
|
|
||||||
return tinfo.toJSON();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public enum ServerType {
|
public enum ServerType {
|
||||||
@ -116,16 +115,16 @@ public class SubCreator {
|
|||||||
* @param player Player Creating
|
* @param player Player Creating
|
||||||
* @param name Server Name
|
* @param name Server Name
|
||||||
* @param template Server Template
|
* @param template Server Template
|
||||||
* @param version Server Version
|
* @param version Server Version (may be null)
|
||||||
* @param port Server Port Number
|
* @param port Server Port Number (null to auto-select)
|
||||||
* @param response Response Code
|
* @param response Response Code
|
||||||
*/
|
*/
|
||||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||||
if (Util.isNull(response)) throw new NullPointerException();
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||||
try {
|
try {
|
||||||
response.run(data.getInt("r"));
|
response.run(data.getInt(0x0001));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Throwable ew = new InvocationTargetException(e);
|
Throwable ew = new InvocationTargetException(e);
|
||||||
ew.setStackTrace(origin);
|
ew.setStackTrace(origin);
|
||||||
@ -139,8 +138,8 @@ public class SubCreator {
|
|||||||
*
|
*
|
||||||
* @param name Server Name
|
* @param name Server Name
|
||||||
* @param template Server Template
|
* @param template Server Template
|
||||||
* @param version Server Version
|
* @param version Server Version (may be null)
|
||||||
* @param port Server Port Number
|
* @param port Server Port Number (null to auto-select)
|
||||||
* @param response Response Code
|
* @param response Response Code
|
||||||
*/
|
*/
|
||||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||||
@ -153,8 +152,8 @@ public class SubCreator {
|
|||||||
* @param player Player Creating
|
* @param player Player Creating
|
||||||
* @param name Server Name
|
* @param name Server Name
|
||||||
* @param template Server Template
|
* @param template Server Template
|
||||||
* @param version Server Version
|
* @param version Server Version (may be null)
|
||||||
* @param port Server Port Number
|
* @param port Server Port Number (null to auto-select)
|
||||||
*/
|
*/
|
||||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||||
create(player, name, template, version, port, i -> {});
|
create(player, name, template, version, port, i -> {});
|
||||||
@ -165,8 +164,8 @@ public class SubCreator {
|
|||||||
*
|
*
|
||||||
* @param name Server Name
|
* @param name Server Name
|
||||||
* @param template Server Template
|
* @param template Server Template
|
||||||
* @param version Server Version
|
* @param version Server Version (may be null)
|
||||||
* @param port Server Port Number
|
* @param port Server Port Number (null to auto-select)
|
||||||
*/
|
*/
|
||||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||||
create(name, template, version, port, i -> {});
|
create(name, template, version, port, i -> {});
|
||||||
@ -200,10 +199,4 @@ public class SubCreator {
|
|||||||
if (Util.isNull(name)) throw new NullPointerException();
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
return getTemplates().get(name.toLowerCase());
|
return getTemplates().get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String toString() {
|
|
||||||
return raw.toJSON().toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
package net.ME1312.SubServers.Client.Sponge.Network.API;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCommandServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCommandServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketDownloadHostInfo;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketEditServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStartServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStartServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStopServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStopServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SubServer extends Server {
|
public class SubServer extends Server {
|
||||||
private List<SubServer> incompatibilities = null;
|
private List<SubServer> incompatibilities = null;
|
||||||
@ -23,6 +26,7 @@ public class SubServer extends Server {
|
|||||||
NONE,
|
NONE,
|
||||||
RESTART,
|
RESTART,
|
||||||
REMOVE_SERVER,
|
REMOVE_SERVER,
|
||||||
|
RECYCLE_SERVER,
|
||||||
DELETE_SERVER;
|
DELETE_SERVER;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,7 +40,7 @@ public class SubServer extends Server {
|
|||||||
*
|
*
|
||||||
* @param raw JSON representation of the Server
|
* @param raw JSON representation of the Server
|
||||||
*/
|
*/
|
||||||
public SubServer(YAMLSection raw) {
|
public SubServer(ObjectMap<String> raw) {
|
||||||
super(raw);
|
super(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ public class SubServer extends Server {
|
|||||||
* @param host Host
|
* @param host Host
|
||||||
* @param raw JSON representation of the Server
|
* @param raw JSON representation of the Server
|
||||||
*/
|
*/
|
||||||
SubServer(Host host, YAMLSection raw) {
|
SubServer(Host host, ObjectMap<String> raw) {
|
||||||
super(raw);
|
super(raw);
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
@ -72,9 +76,9 @@ public class SubServer extends Server {
|
|||||||
public void start(UUID player, Callback<Integer> response) {
|
public void start(UUID player, Callback<Integer> response) {
|
||||||
if (Util.isNull(response)) throw new NullPointerException();
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStartServer(player, getName(), data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(player, getName(), data -> {
|
||||||
try {
|
try {
|
||||||
response.run(data.getInt("r"));
|
response.run(data.getInt(0x0001));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Throwable ew = new InvocationTargetException(e);
|
Throwable ew = new InvocationTargetException(e);
|
||||||
ew.setStackTrace(origin);
|
ew.setStackTrace(origin);
|
||||||
@ -117,9 +121,9 @@ public class SubServer extends Server {
|
|||||||
public void stop(UUID player, Callback<Integer> response) {
|
public void stop(UUID player, Callback<Integer> response) {
|
||||||
if (Util.isNull(response)) throw new NullPointerException();
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), false, data -> {
|
||||||
try {
|
try {
|
||||||
response.run(data.getInt("r"));
|
response.run(data.getInt(0x0001));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Throwable ew = new InvocationTargetException(e);
|
Throwable ew = new InvocationTargetException(e);
|
||||||
ew.setStackTrace(origin);
|
ew.setStackTrace(origin);
|
||||||
@ -162,9 +166,9 @@ public class SubServer extends Server {
|
|||||||
public void terminate(UUID player, Callback<Integer> response) {
|
public void terminate(UUID player, Callback<Integer> response) {
|
||||||
if (Util.isNull(response)) throw new NullPointerException();
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer(player, getName(), true, data -> {
|
||||||
try {
|
try {
|
||||||
response.run(data.getInt("r"));
|
response.run(data.getInt(0x0001));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Throwable ew = new InvocationTargetException(e);
|
Throwable ew = new InvocationTargetException(e);
|
||||||
ew.setStackTrace(origin);
|
ew.setStackTrace(origin);
|
||||||
@ -208,9 +212,9 @@ public class SubServer extends Server {
|
|||||||
public void command(UUID player, String command, Callback<Integer> response) {
|
public void command(UUID player, String command, Callback<Integer> response) {
|
||||||
if (Util.isNull(command, response)) throw new NullPointerException();
|
if (Util.isNull(command, response)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
SubAPI.getInstance().getSubDataNetwork().sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer(player, getName(), command, data -> {
|
||||||
try {
|
try {
|
||||||
response.run(data.getInt("r"));
|
response.run(data.getInt(0x0001));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Throwable ew = new InvocationTargetException(e);
|
Throwable ew = new InvocationTargetException(e);
|
||||||
ew.setStackTrace(origin);
|
ew.setStackTrace(origin);
|
||||||
@ -248,6 +252,104 @@ public class SubServer extends Server {
|
|||||||
command(command, i -> {});
|
command(command, i -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server
|
||||||
|
*
|
||||||
|
* @param player Player Editing
|
||||||
|
* @param edit Edits
|
||||||
|
* @param response Negative Response Code -or- Positive Success Status
|
||||||
|
*/
|
||||||
|
public void edit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||||
|
edit(player, edit, false, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server
|
||||||
|
*
|
||||||
|
* @param edit Edits
|
||||||
|
* @param response Negative Response Code -or- Positive Success Status
|
||||||
|
*/
|
||||||
|
public void edit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||||
|
edit(null, edit, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server
|
||||||
|
*
|
||||||
|
* @param player Player Editing
|
||||||
|
* @param edit Edits
|
||||||
|
*/
|
||||||
|
public void edit(UUID player, ObjectMap<String> edit) {
|
||||||
|
edit(player, edit, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server
|
||||||
|
*
|
||||||
|
* @param edit Edits
|
||||||
|
*/
|
||||||
|
public void edit(ObjectMap<String> edit) {
|
||||||
|
edit(null, edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server (& Saves Changes)
|
||||||
|
*
|
||||||
|
* @param player Player Editing
|
||||||
|
* @param edit Edits
|
||||||
|
* @param response Negative Response Code -or- Positive Success Status
|
||||||
|
*/
|
||||||
|
public void permaEdit(UUID player, ObjectMap<String> edit, Callback<Integer> response) {
|
||||||
|
edit(player, edit, true, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server (& Saves Changes)
|
||||||
|
*
|
||||||
|
* @param edit Edits
|
||||||
|
* @param response Negative Response Code -or- Positive Success Status
|
||||||
|
*/
|
||||||
|
public void permaEdit(ObjectMap<String> edit, Callback<Integer> response) {
|
||||||
|
permaEdit(null, edit, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server (& Saves Changes)
|
||||||
|
*
|
||||||
|
* @param player Player Editing
|
||||||
|
* @param edit Edits
|
||||||
|
*/
|
||||||
|
public void permaEdit(UUID player, ObjectMap<String> edit) {
|
||||||
|
permaEdit(player, edit, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the Server (& Saves Changes)
|
||||||
|
*
|
||||||
|
* @param edit Edits
|
||||||
|
*/
|
||||||
|
public void permaEdit(ObjectMap<String> edit) {
|
||||||
|
permaEdit(null, edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void edit(UUID player, ObjectMap<String> edit, boolean perma, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketEditServer(player, getName(), edit, perma, data -> {
|
||||||
|
try {
|
||||||
|
if (data.getInt(0x0001) != 0) {
|
||||||
|
response.run(data.getInt(0x0001) * -1);
|
||||||
|
} else {
|
||||||
|
response.run(data.getInt(0x0002));
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Server is Running
|
* If the Server is Running
|
||||||
*
|
*
|
||||||
@ -303,6 +405,31 @@ public class SubServer extends Server {
|
|||||||
return raw.getBoolean("enabled");
|
return raw.getBoolean("enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if the Server is Enabled
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
*/
|
||||||
|
public void setEnabled(boolean value) {
|
||||||
|
setEnabled(value, b -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if the Server is Enabled
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
* @param response Success Status
|
||||||
|
*/
|
||||||
|
public void setEnabled(boolean value, Callback<Boolean> response) {
|
||||||
|
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||||
|
ObjectMap<String> edit = new ObjectMap<String>();
|
||||||
|
edit.set("enabled", value);
|
||||||
|
edit(edit, r -> {
|
||||||
|
if (r > 0) raw.set("enabled", value);
|
||||||
|
response.run(r > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Server is accepting requests to edit()
|
* If the Server is accepting requests to edit()
|
||||||
*
|
*
|
||||||
@ -321,6 +448,31 @@ public class SubServer extends Server {
|
|||||||
return raw.getBoolean("log");
|
return raw.getBoolean("log");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if the Server is Logging
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
*/
|
||||||
|
public void setLogging(boolean value) {
|
||||||
|
setLogging(value, b -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if the Server is Logging
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
* @param response Success Status
|
||||||
|
*/
|
||||||
|
public void setLogging(boolean value, Callback<Boolean> response) {
|
||||||
|
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||||
|
ObjectMap<String> edit = new ObjectMap<String>();
|
||||||
|
edit.set("log", value);
|
||||||
|
edit(edit, r -> {
|
||||||
|
if (r > 0) raw.set("log", value);
|
||||||
|
response.run(r > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Server Directory Path
|
* Get the Server Directory Path
|
||||||
*
|
*
|
||||||
@ -348,6 +500,31 @@ public class SubServer extends Server {
|
|||||||
return raw.getRawString("stop-cmd");
|
return raw.getRawString("stop-cmd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Command that Stops the Server
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
*/
|
||||||
|
public void setStopCommand(String value) {
|
||||||
|
setStopCommand(value, b -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Command that Stops the Server
|
||||||
|
*
|
||||||
|
* @param value Value
|
||||||
|
* @param response Success Status
|
||||||
|
*/
|
||||||
|
public void setStopCommand(String value, Callback<Boolean> response) {
|
||||||
|
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||||
|
ObjectMap<String> edit = new ObjectMap<String>();
|
||||||
|
edit.set("stop-cmd", value);
|
||||||
|
edit(edit, r -> {
|
||||||
|
if (r > 0) raw.set("stop-cmd", value);
|
||||||
|
response.run(r > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the action the Server will take when it stops
|
* Get the action the Server will take when it stops
|
||||||
*
|
*
|
||||||
@ -357,6 +534,31 @@ public class SubServer extends Server {
|
|||||||
return Util.getDespiteException(() -> StopAction.valueOf(raw.getRawString("stop-action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
return Util.getDespiteException(() -> StopAction.valueOf(raw.getRawString("stop-action").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the action the Server will take when it stops
|
||||||
|
*
|
||||||
|
* @param action Stop Action
|
||||||
|
*/
|
||||||
|
public void setStopAction(StopAction action) {
|
||||||
|
setStopAction(action, b -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the action the Server will take when it stops
|
||||||
|
*
|
||||||
|
* @param action Stop Action
|
||||||
|
* @param response Success Status
|
||||||
|
*/
|
||||||
|
public void setStopAction(StopAction action, Callback<Boolean> response) {
|
||||||
|
if (Util.isNull(action, response)) throw new NullPointerException();
|
||||||
|
ObjectMap<String> edit = new ObjectMap<String>();
|
||||||
|
edit.set("stop-action", action.toString());
|
||||||
|
edit(edit, r -> {
|
||||||
|
if (r > 0) raw.set("stop-action", action.toString());
|
||||||
|
response.run(r > 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a Server is compatible
|
* Checks if a Server is compatible
|
||||||
*
|
*
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import org.msgpack.value.Value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubData Cipher Layout Class
|
|
||||||
*/
|
|
||||||
public interface Cipher {
|
|
||||||
/**
|
|
||||||
* Get the name of this Cipher
|
|
||||||
*
|
|
||||||
* @return Cipher Name
|
|
||||||
*/
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encrypt JSON Data
|
|
||||||
*
|
|
||||||
* @param key Key to Encrypt Data with
|
|
||||||
* @param data Data to Encrypt
|
|
||||||
* @return Encrypted Data Array
|
|
||||||
*/
|
|
||||||
Value encrypt(String key, YAMLSection data) throws Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrypt Encrypted JSON Data
|
|
||||||
*
|
|
||||||
* @param key Key to Decrypt Data with
|
|
||||||
* @param data Encrypted Data Array
|
|
||||||
* @return JSON Data
|
|
||||||
*/
|
|
||||||
YAMLSection decrypt(String key, Value data) throws Exception;
|
|
||||||
}
|
|
@ -1,332 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Encryption;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import org.msgpack.core.MessagePack;
|
|
||||||
import org.msgpack.core.MessagePacker;
|
|
||||||
import org.msgpack.value.Value;
|
|
||||||
import org.msgpack.value.ValueFactory;
|
|
||||||
|
|
||||||
import javax.crypto.*;
|
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
|
||||||
import javax.crypto.spec.PBEKeySpec;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.security.spec.InvalidParameterSpecException;
|
|
||||||
import java.security.spec.KeySpec;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class to perform password-based AES encryption and decryption in CBC mode.
|
|
||||||
* 128, 192, and 256-bit encryption are supported, provided that the latter two
|
|
||||||
* are permitted by the Java runtime's jurisdiction policy files.
|
|
||||||
* <br/>
|
|
||||||
* The public interface for this class consists of the static methods
|
|
||||||
* {@link #encrypt} and {@link #decrypt}, which encrypt and decrypt arbitrary
|
|
||||||
* streams of data, respectively.
|
|
||||||
*
|
|
||||||
* @author dweymouth@gmail.com
|
|
||||||
*/
|
|
||||||
public final class AES implements net.ME1312.SubServers.Client.Sponge.Network.Cipher {
|
|
||||||
|
|
||||||
// AES specification
|
|
||||||
private static final String CIPHER_SPEC = "AES/CBC/PKCS5Padding";
|
|
||||||
|
|
||||||
// Key derivation specification
|
|
||||||
private static final String KEYGEN_SPEC = "PBKDF2WithHmacSHA1";
|
|
||||||
private static final int SALT_LENGTH = 16; // in bytes
|
|
||||||
private static final int AUTH_KEY_LENGTH = 8; // in bytes
|
|
||||||
private static final int ITERATIONS = 32768;
|
|
||||||
|
|
||||||
// Process input/output streams in chunks
|
|
||||||
private static final int BUFFER_SIZE = 1024;
|
|
||||||
|
|
||||||
// Hold Data for use by SubData Cipher methods
|
|
||||||
private final int keyLength;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for use as a SubData Cipher
|
|
||||||
*/
|
|
||||||
public AES(int keyLength) {
|
|
||||||
this.keyLength = keyLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return a new pseudorandom salt of the specified length
|
|
||||||
*/
|
|
||||||
private static byte[] generateSalt(int length) {
|
|
||||||
Random r = new SecureRandom();
|
|
||||||
byte[] salt = new byte[length];
|
|
||||||
r.nextBytes(salt);
|
|
||||||
return salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Derive an AES encryption key and authentication key from given password and salt,
|
|
||||||
* using PBKDF2 key stretching. The authentication key is 64 bits long.
|
|
||||||
* @param keyLength
|
|
||||||
* length of the AES key in bits (128, 192, or 256)
|
|
||||||
* @param password
|
|
||||||
* the password from which to derive the keys
|
|
||||||
* @param salt
|
|
||||||
* the salt from which to derive the keys
|
|
||||||
* @return a Keys object containing the two generated keys
|
|
||||||
*/
|
|
||||||
private static Keys keygen(int keyLength, char[] password, byte[] salt) {
|
|
||||||
SecretKeyFactory factory;
|
|
||||||
try {
|
|
||||||
factory = SecretKeyFactory.getInstance(KEYGEN_SPEC);
|
|
||||||
} catch (NoSuchAlgorithmException impossible) { return null; }
|
|
||||||
// derive a longer key, then split into AES key and authentication key
|
|
||||||
KeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, keyLength + AUTH_KEY_LENGTH * 8);
|
|
||||||
SecretKey tmp = null;
|
|
||||||
try {
|
|
||||||
tmp = factory.generateSecret(spec);
|
|
||||||
} catch (InvalidKeySpecException impossible) { }
|
|
||||||
byte[] fullKey = tmp.getEncoded();
|
|
||||||
SecretKey authKey = new SecretKeySpec( // key for password authentication
|
|
||||||
Arrays.copyOfRange(fullKey, 0, AUTH_KEY_LENGTH), "AES");
|
|
||||||
SecretKey encKey = new SecretKeySpec( // key for AES encryption
|
|
||||||
Arrays.copyOfRange(fullKey, AUTH_KEY_LENGTH, fullKey.length), "AES");
|
|
||||||
return new Keys(encKey, authKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encrypts a stream of data. The encrypted stream consists of a header
|
|
||||||
* followed by the raw AES data. The header is broken down as follows:<br/>
|
|
||||||
* <ul>
|
|
||||||
* <li><b>keyLength</b>: AES key length in bytes (valid for 16, 24, 32) (1 byte)</li>
|
|
||||||
* <li><b>salt</b>: pseudorandom salt used to derive keys from password (16 bytes)</li>
|
|
||||||
* <li><b>authentication key</b> (derived from password and salt, used to
|
|
||||||
* check validity of password upon decryption) (8 bytes)</li>
|
|
||||||
* <li><b>IV</b>: pseudorandom AES initialization vector (16 bytes)</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param keyLength
|
|
||||||
* key length to use for AES encryption (must be 128, 192, or 256)
|
|
||||||
* @param password
|
|
||||||
* password to use for encryption
|
|
||||||
* @param input
|
|
||||||
* an arbitrary byte stream to encrypt
|
|
||||||
* @param output
|
|
||||||
* stream to which encrypted data will be written
|
|
||||||
* @throws AES.InvalidKeyLengthException
|
|
||||||
* if keyLength is not 128, 192, or 256
|
|
||||||
* @throws AES.StrongEncryptionNotAvailableException
|
|
||||||
* if keyLength is 192 or 256, but the Java runtime's jurisdiction
|
|
||||||
* policy files do not allow 192- or 256-bit encryption
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static void encrypt(int keyLength, String password, InputStream input, OutputStream output)
|
|
||||||
throws InvalidKeyLengthException, StrongEncryptionNotAvailableException, IOException {
|
|
||||||
// Check validity of key length
|
|
||||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
|
||||||
throw new InvalidKeyLengthException(keyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate salt and derive keys for authentication and encryption
|
|
||||||
byte[] salt = generateSalt(SALT_LENGTH);
|
|
||||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
|
||||||
|
|
||||||
// initialize AES encryption
|
|
||||||
Cipher encrypt = null;
|
|
||||||
try {
|
|
||||||
encrypt = Cipher.getInstance(CIPHER_SPEC);
|
|
||||||
encrypt.init(Cipher.ENCRYPT_MODE, keys.encryption);
|
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException impossible) { }
|
|
||||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
|
||||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get initialization vector
|
|
||||||
byte[] iv = null;
|
|
||||||
try {
|
|
||||||
iv = encrypt.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
|
|
||||||
} catch (InvalidParameterSpecException impossible) { }
|
|
||||||
|
|
||||||
// write authentication and AES initialization data
|
|
||||||
output.write(keyLength / 8);
|
|
||||||
output.write(salt);
|
|
||||||
output.write(keys.authentication.getEncoded());
|
|
||||||
output.write(iv);
|
|
||||||
|
|
||||||
// read data from input into buffer, encrypt and write to output
|
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
|
||||||
int numRead;
|
|
||||||
byte[] encrypted = null;
|
|
||||||
while ((numRead = input.read(buffer)) > 0) {
|
|
||||||
encrypted = encrypt.update(buffer, 0, numRead);
|
|
||||||
if (encrypted != null) {
|
|
||||||
output.write(encrypted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try { // finish encryption - do final block
|
|
||||||
encrypted = encrypt.doFinal();
|
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException impossible) { }
|
|
||||||
if (encrypted != null) {
|
|
||||||
output.write(encrypted);
|
|
||||||
}
|
|
||||||
output.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method calls to {@link #encrypt(int, String, InputStream, OutputStream)}, simplified for the {@link net.ME1312.SubServers.Client.Sponge.Network.Cipher} interface.
|
|
||||||
*
|
|
||||||
* @param key Key to Encrypt Data with
|
|
||||||
* @param data Data to Encrypt
|
|
||||||
* @return Encrypted Data Array
|
|
||||||
*/
|
|
||||||
public Value encrypt(String key, YAMLSection data) throws Exception {
|
|
||||||
ByteArrayOutputStream unencrypted = new ByteArrayOutputStream();
|
|
||||||
MessagePacker packer = MessagePack.newDefaultPacker(unencrypted);
|
|
||||||
packer.packValue(data.msgPack());
|
|
||||||
packer.close();
|
|
||||||
|
|
||||||
ByteArrayOutputStream encrypted = new ByteArrayOutputStream();
|
|
||||||
encrypt(keyLength, key, new ByteArrayInputStream(unencrypted.toByteArray()), encrypted);
|
|
||||||
return ValueFactory.newBinary(encrypted.toByteArray(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return "AES_" + keyLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrypts a stream of data that was encrypted by {@link #encrypt}.
|
|
||||||
* @param password
|
|
||||||
* the password used to encrypt/decrypt the stream
|
|
||||||
* @param input
|
|
||||||
* stream of encrypted data to be decrypted
|
|
||||||
* @param output
|
|
||||||
* stream to which decrypted data will be written
|
|
||||||
* @return the key length for the decrypted stream (128, 192, or 256)
|
|
||||||
* @throws AES.InvalidPasswordException
|
|
||||||
* if the given password was not used to encrypt the data
|
|
||||||
* @throws AES.InvalidAESStreamException
|
|
||||||
* if the given input stream is not a valid AES-encrypted stream
|
|
||||||
* @throws AES.StrongEncryptionNotAvailableException
|
|
||||||
* if the stream is 192 or 256-bit encrypted, and the Java runtime's
|
|
||||||
* jurisdiction policy files do not allow for AES-192 or 256
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static int decrypt(String password, InputStream input, OutputStream output)
|
|
||||||
throws InvalidPasswordException, InvalidAESStreamException, IOException,
|
|
||||||
StrongEncryptionNotAvailableException {
|
|
||||||
int keyLength = input.read() * 8;
|
|
||||||
// Check validity of key length
|
|
||||||
if (keyLength != 128 && keyLength != 192 && keyLength != 256) {
|
|
||||||
throw new InvalidAESStreamException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// read salt, generate keys, and authenticate password
|
|
||||||
byte[] salt = new byte[SALT_LENGTH];
|
|
||||||
input.read(salt);
|
|
||||||
Keys keys = keygen(keyLength, password.toCharArray(), salt);
|
|
||||||
byte[] authRead = new byte[AUTH_KEY_LENGTH];
|
|
||||||
input.read(authRead);
|
|
||||||
if (!Arrays.equals(keys.authentication.getEncoded(), authRead)) {
|
|
||||||
throw new InvalidPasswordException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize AES decryption
|
|
||||||
byte[] iv = new byte[16]; // 16-byte I.V. regardless of key size
|
|
||||||
input.read(iv);
|
|
||||||
Cipher decrypt = null;
|
|
||||||
try {
|
|
||||||
decrypt = Cipher.getInstance(CIPHER_SPEC);
|
|
||||||
decrypt.init(Cipher.DECRYPT_MODE, keys.encryption, new IvParameterSpec(iv));
|
|
||||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException
|
|
||||||
| InvalidAlgorithmParameterException impossible) { }
|
|
||||||
catch (InvalidKeyException e) { // 192 or 256-bit AES not available
|
|
||||||
throw new StrongEncryptionNotAvailableException(keyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
// read data from input into buffer, decrypt and write to output
|
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
|
||||||
int numRead;
|
|
||||||
byte[] decrypted;
|
|
||||||
while ((numRead = input.read(buffer)) > 0) {
|
|
||||||
decrypted = decrypt.update(buffer, 0, numRead);
|
|
||||||
if (decrypted != null) {
|
|
||||||
output.write(decrypted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try { // finish decryption - do final block
|
|
||||||
decrypted = decrypt.doFinal();
|
|
||||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
|
||||||
throw new InvalidAESStreamException(e);
|
|
||||||
}
|
|
||||||
if (decrypted != null) {
|
|
||||||
output.write(decrypted);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.flush();
|
|
||||||
return keyLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method calls to {@link #decrypt(String, InputStream, OutputStream)}), simplified for the {@link net.ME1312.SubServers.Client.Sponge.Network.Cipher} interface.
|
|
||||||
*
|
|
||||||
* @param key Key to Decrypt Data with
|
|
||||||
* @param data Encrypted Data Array
|
|
||||||
* @return JSON Data
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public YAMLSection decrypt(String key, Value data) throws Exception {
|
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
||||||
decrypt(key, new ByteArrayInputStream(data.asBinaryValue().asByteArray()), bytes);
|
|
||||||
return new YAMLSection(MessagePack.newDefaultUnpacker(bytes.toByteArray()).unpackValue().asMapValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A tuple of encryption and authentication keys returned by {@link #keygen}
|
|
||||||
*/
|
|
||||||
private static class Keys {
|
|
||||||
public final SecretKey encryption, authentication;
|
|
||||||
public Keys(SecretKey encryption, SecretKey authentication) {
|
|
||||||
this.encryption = encryption;
|
|
||||||
this.authentication = authentication;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if an attempt is made to decrypt a stream with an incorrect password.
|
|
||||||
*/
|
|
||||||
public static class InvalidPasswordException extends Exception { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if an attempt is made to encrypt a stream with an invalid AES key length.
|
|
||||||
*/
|
|
||||||
public static class InvalidKeyLengthException extends Exception {
|
|
||||||
InvalidKeyLengthException(int length) {
|
|
||||||
super("Invalid AES key length: " + length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if 192- or 256-bit AES encryption or decryption is attempted,
|
|
||||||
* but not available on the particular Java platform.
|
|
||||||
*/
|
|
||||||
public static class StrongEncryptionNotAvailableException extends Exception {
|
|
||||||
public StrongEncryptionNotAvailableException(int keySize) {
|
|
||||||
super(keySize + "-bit AES encryption is not available on this Java platform.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown if an attempt is made to decrypt an invalid AES stream.
|
|
||||||
*/
|
|
||||||
public static class InvalidAESStreamException extends Exception {
|
|
||||||
public InvalidAESStreamException() { super(); };
|
|
||||||
public InvalidAESStreamException(Exception e) { super(e); }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,123 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.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.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add Server Packet
|
||||||
|
*/
|
||||||
|
public class PacketAddServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
|
private UUID player;
|
||||||
|
private String name;
|
||||||
|
private ObjectMap<String> opt;
|
||||||
|
private boolean subserver;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketAddServer (In)
|
||||||
|
*/
|
||||||
|
public PacketAddServer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCreateServer [Server] (Out)
|
||||||
|
*
|
||||||
|
* @param player Player who added
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param ip IP of the Server
|
||||||
|
* @param port Port of the Server
|
||||||
|
* @param motd MOTD of the Server
|
||||||
|
* @param hidden If the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketAddServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(name, ip, port, motd, hidden, restricted)) throw new NullPointerException();
|
||||||
|
this.player = player;
|
||||||
|
this.name = name;
|
||||||
|
this.subserver = false;
|
||||||
|
|
||||||
|
ObjectMap<String> opt = new ObjectMap<String>();
|
||||||
|
opt.set("address", ip.getHostAddress() + ':' + port);
|
||||||
|
opt.set("motd", motd);
|
||||||
|
opt.set("restricted", restricted);
|
||||||
|
opt.set("hidden", hidden);
|
||||||
|
this.opt = opt;
|
||||||
|
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketAddServer [SubServer] (Out)
|
||||||
|
*
|
||||||
|
* @param player Player who Added
|
||||||
|
* @param name Name of Server
|
||||||
|
* @param enabled Enabled Status
|
||||||
|
* @param host Host of Server
|
||||||
|
* @param port Port Number
|
||||||
|
* @param motd Motd of the Server
|
||||||
|
* @param log Logging Status
|
||||||
|
* @param directory Directory
|
||||||
|
* @param executable Executable String
|
||||||
|
* @param stopcmd Command to Stop the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketAddServer(UUID player, String name, boolean enabled, String host, int port, String motd, boolean log, String directory, String executable, String stopcmd, boolean hidden, boolean restricted, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
|
||||||
|
this.player = player;
|
||||||
|
this.name = name;
|
||||||
|
this.subserver = true;
|
||||||
|
|
||||||
|
ObjectMap<String> opt = new ObjectMap<String>();
|
||||||
|
opt.set("enabled", enabled);
|
||||||
|
opt.set("host", host);
|
||||||
|
opt.set("port", port);
|
||||||
|
opt.set("motd", motd);
|
||||||
|
opt.set("log", log);
|
||||||
|
opt.set("dir", directory);
|
||||||
|
opt.set("exec", executable);
|
||||||
|
opt.set("stop-cmd", stopcmd);
|
||||||
|
opt.set("restricted", restricted);
|
||||||
|
opt.set("hidden", hidden);
|
||||||
|
this.opt = opt;
|
||||||
|
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, name);
|
||||||
|
data.set(0x0002, subserver);
|
||||||
|
data.set(0x0003, opt);
|
||||||
|
if (player != null) data.set(0x0004, player);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -1,52 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public final class PacketAuthorization implements PacketIn, PacketOut {
|
|
||||||
private SubPlugin plugin;
|
|
||||||
private Logger log = null;
|
|
||||||
|
|
||||||
public PacketAuthorization(SubPlugin plugin) {
|
|
||||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
|
||||||
this.plugin = plugin;
|
|
||||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public YAMLSection generate() {
|
|
||||||
YAMLSection json = new YAMLSection();
|
|
||||||
json.set("password", plugin.config.get().getSection("Settings").getSection("SubData").getString("Password"));
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(YAMLSection data) {
|
|
||||||
try {
|
|
||||||
if (data.getInt("r") == 0) {
|
|
||||||
Util.isException(() -> Util.reflect(SubDataClient.class.getDeclaredMethod("sendPacket", NamedContainer.class), plugin.subdata, new NamedContainer<String, PacketOut>(null, new PacketLinkServer(plugin))));
|
|
||||||
} else {
|
|
||||||
log.info("Could not authorize SubData connection: " + data.getRawString("m"));
|
|
||||||
plugin.subdata.destroy(0);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Version getVersion() {
|
|
||||||
return new Version("2.11.0a");
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,77 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.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.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Packet Check Permission
|
||||||
|
*/
|
||||||
|
public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private static HashMap<UUID, Callback<Boolean>[]> callbacks = new HashMap<UUID, Callback<Boolean>[]>();
|
||||||
|
private String name;
|
||||||
|
private UUID player;
|
||||||
|
private String permission;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCheckPermission (In)
|
||||||
|
*/
|
||||||
|
public PacketCheckPermission() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCheckPermission (Out)
|
||||||
|
*
|
||||||
|
* @param player Player to check on
|
||||||
|
* @param permission Permission to check
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketCheckPermission(UUID player, String permission, Callback<Boolean>... callback) {
|
||||||
|
this(null, player, permission, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCheckPermission (Out)
|
||||||
|
*
|
||||||
|
* @param server Server to check on
|
||||||
|
* @param player Player to check on
|
||||||
|
* @param permission Permission to check
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketCheckPermission(String server, UUID player, String permission, Callback<Boolean>... callback) {
|
||||||
|
this.name = server;
|
||||||
|
this.player = player;
|
||||||
|
this.permission = permission;
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, player);
|
||||||
|
data.set(0x0002, permission);
|
||||||
|
if (name != null) data.set(0x0003, name);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -13,12 +13,12 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Command Server Packet
|
* Command Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketCommandServer implements PacketIn, PacketOut {
|
public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private String server;
|
private String server;
|
||||||
private String command;
|
private String command;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketCommandServer (In)
|
* New PacketCommandServer (In)
|
||||||
@ -34,33 +34,33 @@ public class PacketCommandServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketCommandServer(UUID player, String server, String command, Callback<YAMLSection>... callback) {
|
public PacketCommandServer(UUID player, String server, String command, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(server, command, callback)) throw new NullPointerException();
|
if (Util.isNull(server, command, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, tracker);
|
||||||
if (player != null) data.set("player", player.toString());
|
data.set(0x0001, server);
|
||||||
data.set("server", server);
|
data.set(0x0002, command);
|
||||||
data.set("command", command);
|
if (player != null) data.set(0x0003, player.toString());
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.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;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
|
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -14,15 +15,16 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Create Server Packet
|
* Create Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketCreateServer implements PacketIn, PacketOut {
|
public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private String name;
|
private String name;
|
||||||
private String host;
|
private String host;
|
||||||
private String template;
|
private String template;
|
||||||
private Version version;
|
private Version version;
|
||||||
private Integer port;
|
private Integer port;
|
||||||
private String id;
|
private boolean waitfor;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketCreateServer (In)
|
* New PacketCreateServer (In)
|
||||||
@ -41,16 +43,34 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<YAMLSection>... callback) {
|
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(name, host, template, version, callback)) throw new NullPointerException();
|
this(player, name, host, template, version, port, false, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCreateServer (Out)
|
||||||
|
*
|
||||||
|
* @param player Player Creating
|
||||||
|
* @param name Server Name
|
||||||
|
* @param host Host to use
|
||||||
|
* @param template Server Template
|
||||||
|
* @param version Server Version
|
||||||
|
* @param port Server Port
|
||||||
|
* @param waitfor Wait until completion to send callback
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketCreateServer(UUID player, String name, String host, String template, Version version, Integer port, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(name, host, template, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.template = template;
|
this.template = template;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.waitfor = waitfor;
|
||||||
callbacks.put(id, callback);
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +81,20 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketCreateServer(UUID player, UIRenderer.CreatorOptions options, Callback<YAMLSection>... callback) {
|
public PacketCreateServer(UUID player, UIRenderer.CreatorOptions options, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
this(player, options, false, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketCreateServer (Out)
|
||||||
|
*
|
||||||
|
* @param player Player Creating
|
||||||
|
* @param options Creator UI Options
|
||||||
|
* @param waitfor Wait until completion to send callback
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketCreateServer(UUID player, UIRenderer.CreatorOptions options, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(options, callback)) throw new NullPointerException();
|
if (Util.isNull(options, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.name = options.getName();
|
this.name = options.getName();
|
||||||
@ -69,34 +102,34 @@ public class PacketCreateServer implements PacketIn, PacketOut {
|
|||||||
this.template = options.getTemplate();
|
this.template = options.getTemplate();
|
||||||
this.version = options.getVersion();
|
this.version = options.getVersion();
|
||||||
this.port = options.getPort();
|
this.port = options.getPort();
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.waitfor = waitfor;
|
||||||
callbacks.put(id, callback);
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, tracker);
|
||||||
if (player != null) data.set("player", player.toString());
|
data.set(0x0001, name);
|
||||||
YAMLSection creator = new YAMLSection();
|
data.set(0x0002, host);
|
||||||
creator.set("name", name);
|
data.set(0x0003, template);
|
||||||
creator.set("host", host);
|
if (version != null) data.set(0x0004, version);
|
||||||
creator.set("template", template);
|
if (port != null) data.set(0x0005, port);
|
||||||
creator.set("version", version);
|
if (player != null) data.set(0x0006, player);
|
||||||
if (port != null) creator.set("port", port);
|
if (waitfor) data.set(0x0007, true);
|
||||||
data.set("creator", creator);
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.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.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete Server Packet
|
||||||
|
*/
|
||||||
|
public class PacketDeleteServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
|
private UUID player;
|
||||||
|
private String server;
|
||||||
|
private boolean recycle;
|
||||||
|
private boolean force;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketDeleteServer (In)
|
||||||
|
*/
|
||||||
|
public PacketDeleteServer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketDeleteServer (Out)
|
||||||
|
*
|
||||||
|
* @param player Player Deleting
|
||||||
|
* @param server Server
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketDeleteServer(UUID player, String server, boolean recycle, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||||
|
this.player = player;
|
||||||
|
this.server = server;
|
||||||
|
this.recycle = recycle;
|
||||||
|
this.force = force;
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, server);
|
||||||
|
data.set(0x0002, recycle);
|
||||||
|
data.set(0x0003, force);
|
||||||
|
if (player != null) data.set(0x0004, player.toString());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,23 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Group Info Packet
|
* Download Group Info Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
public class PacketDownloadGroupInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||||
private String group;
|
private String group;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadGroupInfo (In)
|
* New PacketDownloadGroupInfo (In)
|
||||||
@ -30,29 +31,30 @@ public class PacketDownloadGroupInfo implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketDownloadGroupInfo(String group, Callback<YAMLSection>... callback) {
|
public PacketDownloadGroupInfo(String group, Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection json = new YAMLSection();
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
json.set("id", id);
|
json.set(0x0000, tracker);
|
||||||
if (group != null) json.set("group", group);
|
if (group != null) json.set(0x0001, group);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Host Info Packet
|
* Download Host Info Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
public class PacketDownloadHostInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||||
private String host;
|
private String group;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadHostInfo (In)
|
* New PacketDownloadHostInfo (In)
|
||||||
@ -26,33 +27,34 @@ public class PacketDownloadHostInfo implements PacketIn, PacketOut {
|
|||||||
/**
|
/**
|
||||||
* New PacketDownloadHostInfo (Out)
|
* New PacketDownloadHostInfo (Out)
|
||||||
*
|
*
|
||||||
* @param host Host name (or null for all)
|
* @param group Host name (or null for all)
|
||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketDownloadHostInfo(String host, Callback<YAMLSection>... callback) {
|
public PacketDownloadHostInfo(String group, Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.host = host;
|
this.group = group;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection json = new YAMLSection();
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
json.set("id", id);
|
json.set(0x0000, tracker);
|
||||||
if (host != null) json.set("host", host);
|
if (group != null) json.set(0x0001, group);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,21 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Lang Packet
|
* Download Lang Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadLang implements PacketIn, PacketOut {
|
public class PacketDownloadLang implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private SubPlugin plugin;
|
private SubPlugin plugin;
|
||||||
private Logger log = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadLang (In)
|
* New PacketDownloadLang (In)
|
||||||
@ -28,7 +25,6 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
|||||||
public PacketDownloadLang(SubPlugin plugin) {
|
public PacketDownloadLang(SubPlugin plugin) {
|
||||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,14 +33,15 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
|||||||
public PacketDownloadLang() {}
|
public PacketDownloadLang() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient subDataClient) throws Throwable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||||
try {
|
try {
|
||||||
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getSection("Lang").get()));
|
Util.reflect(SubPlugin.class.getDeclaredField("lang"), plugin, new NamedContainer<>(Calendar.getInstance().getTime().getTime(), data.getObject(0x0001)));
|
||||||
log.info("Lang Settings Downloaded");
|
log.info("Lang Settings Downloaded");
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -52,7 +49,7 @@ public class PacketDownloadLang implements PacketIn, PacketOut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download Network List Packet
|
|
||||||
*/
|
|
||||||
public class PacketDownloadNetworkList implements PacketIn, PacketOut {
|
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New PacketDownloadNetworkList (In)
|
|
||||||
*/
|
|
||||||
public PacketDownloadNetworkList() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New PacketDownloadNetworkList (Out)
|
|
||||||
*
|
|
||||||
* @param callback Callbacks
|
|
||||||
*/
|
|
||||||
@SafeVarargs
|
|
||||||
public PacketDownloadNetworkList(Callback<YAMLSection>... callback) {
|
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
|
||||||
callbacks.put(id, callback);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public YAMLSection generate() {
|
|
||||||
if (id != null) {
|
|
||||||
YAMLSection data = new YAMLSection();
|
|
||||||
data.set("id", id);
|
|
||||||
return data;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(YAMLSection data) {
|
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
|
||||||
callbacks.remove(data.getRawString("id"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Version getVersion() {
|
|
||||||
return new Version("2.11.0a");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +1,50 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Platform Info Packet
|
* Download Proxy Info Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadPlatformInfo implements PacketIn, PacketOut {
|
public class PacketDownloadPlatformInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||||
private String id;
|
private UUID tracker;
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadPlatformInfo
|
* New PacketDownloadPlatformInfo
|
||||||
*
|
*
|
||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketDownloadPlatformInfo(Callback<YAMLSection>... callback) {
|
public PacketDownloadPlatformInfo(Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, tracker);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,56 +1,51 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Player List Packet
|
* Download Player List Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadPlayerList implements PacketIn, PacketOut {
|
public class PacketDownloadPlayerList implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadPlayerList (In)
|
* New PacketDownloadPlayerList
|
||||||
*/
|
|
||||||
public PacketDownloadPlayerList() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New PacketDownloadPlayerList (Out)
|
|
||||||
*
|
*
|
||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
public PacketDownloadPlayerList(Callback<YAMLSection>... callback) {
|
@SafeVarargs
|
||||||
|
public PacketDownloadPlayerList(Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public YAMLSection generate() {
|
|
||||||
if (id != null) {
|
|
||||||
YAMLSection json = new YAMLSection();
|
|
||||||
json.set("id", id);
|
|
||||||
return json;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
callbacks.remove(data.getRawString("id"));
|
json.set(0x0000, tracker);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Proxy Info Packet
|
* Download Proxy Info Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
public class PacketDownloadProxyInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>> callbacks = new HashMap<UUID, NamedContainer<Boolean, Callback<ObjectMap<String>>[]>>();
|
||||||
private String proxy;
|
private String proxy;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadProxyInfo (In)
|
* New PacketDownloadProxyInfo (In)
|
||||||
@ -30,29 +32,35 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketDownloadProxyInfo(String proxy, Callback<YAMLSection>... callback) {
|
public PacketDownloadProxyInfo(String proxy, Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, new NamedContainer<>(proxy != null && proxy.length() <= 0, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection json = new YAMLSection();
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
json.set("id", id);
|
json.set(0x0000, tracker);
|
||||||
if (proxy != null) json.set("proxy", proxy);
|
if (proxy != null) json.set(0x0001, proxy);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
boolean mode = callbacks.get(data.getUUID(0x0000)).name();
|
||||||
callbacks.remove(data.getRawString("id"));
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000)).get()) {
|
||||||
|
if (mode) {
|
||||||
|
callback.run((data.contains(0x0002))?new ObjectMap<String>((Map<String, ?>) data.getObject(0x0002)):null);
|
||||||
|
} else callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
|
}
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download Server Info Packet
|
* Download Server Info Packet
|
||||||
*/
|
*/
|
||||||
public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
public class PacketDownloadServerInfo implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<String>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<String>>[]>();
|
||||||
private String server;
|
private String server;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketDownloadServerInfo (In)
|
* New PacketDownloadServerInfo (In)
|
||||||
@ -30,29 +31,30 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketDownloadServerInfo(String server, Callback<YAMLSection>... callback) {
|
public PacketDownloadServerInfo(String server, Callback<ObjectMap<String>>... callback) {
|
||||||
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
if (Util.isNull((Object) callback)) throw new NullPointerException();
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection json = new YAMLSection();
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
json.set("id", id);
|
json.set(0x0000, tracker);
|
||||||
if (server != null) json.set("server", server);
|
if (server != null) json.set(0x0001, server);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<String>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(new ObjectMap<String>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.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.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit Server Packet
|
||||||
|
*/
|
||||||
|
public class PacketEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
|
private UUID player;
|
||||||
|
private String server;
|
||||||
|
private ObjectMap<String> edit;
|
||||||
|
private boolean perma;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketEditServer (In)
|
||||||
|
*/
|
||||||
|
public PacketEditServer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketEditServer (Out)
|
||||||
|
*
|
||||||
|
* @param player Player Editing
|
||||||
|
* @param server Server
|
||||||
|
* @param edit Edits
|
||||||
|
* @param perma Save Changes
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketEditServer(UUID player, String server, ObjectMap<String> edit, boolean perma, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||||
|
this.player = player;
|
||||||
|
this.server = server;
|
||||||
|
this.edit = edit;
|
||||||
|
this.perma = perma;
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, server);
|
||||||
|
data.set(0x0002, edit);
|
||||||
|
data.set(0x0003, perma);
|
||||||
|
if (player != null) data.set(0x0004, player.toString());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External Check Permission Packet
|
||||||
|
*/
|
||||||
|
public class PacketExCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private UUID player;
|
||||||
|
private String permission;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketExCheckPermission (In)
|
||||||
|
*/
|
||||||
|
public PacketExCheckPermission() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketExCheckPermission (Out)
|
||||||
|
*
|
||||||
|
* @param player Player to check on
|
||||||
|
* @param permission Permission to check
|
||||||
|
* @param tracker Receiver ID
|
||||||
|
*/
|
||||||
|
public PacketExCheckPermission(UUID player, String permission, UUID tracker) {
|
||||||
|
this.player = player;
|
||||||
|
this.permission = permission;
|
||||||
|
this.tracker = tracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, Util.getDespiteException(() -> Sponge.getServer().getPlayer(player).get().hasPermission(permission), false));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
|
||||||
|
client.sendPacket(new PacketExCheckPermission(data.getUUID(0x0001), data.getRawString(0x0002), (data.contains(0x0000))?data.getUUID(0x0000):null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload Packet
|
||||||
|
*/
|
||||||
|
public class PacketInExReload implements PacketObjectIn<Integer> {
|
||||||
|
private SubPlugin plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketInExReload
|
||||||
|
*
|
||||||
|
* @param plugin Plugin
|
||||||
|
*/
|
||||||
|
public PacketInExReload(SubPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||||
|
if (data != null && data.contains(0x0000)) log.warning("Received request for a plugin reload: " + data.getString(0x0000));
|
||||||
|
else log.warning("Received request for a plugin reload");
|
||||||
|
Sponge.getScheduler().createTaskBuilder().async().execute(() -> {
|
||||||
|
try {
|
||||||
|
plugin.reload(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}).submit(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset Packet
|
||||||
|
*/
|
||||||
|
public class PacketInExReset implements PacketObjectIn<Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||||
|
if (data != null && data.contains(0x0000)) log.warning("Received shutdown signal: " + data.getString(0x0000));
|
||||||
|
else log.warning("Received shutdown signal");
|
||||||
|
Sponge.getServer().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -1,135 +1,137 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Event.*;
|
import net.ME1312.SubServers.Client.Sponge.Event.*;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run Event Packet
|
* Run Event Packet
|
||||||
*/
|
*/
|
||||||
public class PacketInRunEvent implements PacketIn {
|
public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||||
private static HashMap<String, List<Callback<YAMLSection>>> callbacks = new HashMap<String, List<Callback<YAMLSection>>>();
|
private static HashMap<String, List<Callback<ObjectMap<String>>>> callbacks = new HashMap<String, List<Callback<ObjectMap<String>>>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketInRunEvent
|
* New PacketInRunEvent
|
||||||
*/
|
*/
|
||||||
public PacketInRunEvent(SubPlugin plugin) {
|
public PacketInExRunEvent(SubPlugin plugin) {
|
||||||
callback("SubAddHostEvent", new Callback<YAMLSection>() {
|
callback("SubAddHostEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubAddHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host")));
|
Sponge.getEventManager().post(new SubAddHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host")));
|
||||||
callback("SubAddHostEvent", this);
|
callback("SubAddHostEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubAddProxyEvent", new Callback<YAMLSection>() {
|
callback("SubAddProxyEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubAddProxyEvent(data.getString("proxy")));
|
Sponge.getEventManager().post(new SubAddProxyEvent(data.getString("proxy")));
|
||||||
callback("SubAddProxyEvent", this);
|
callback("SubAddProxyEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubAddServerEvent", new Callback<YAMLSection>() {
|
callback("SubAddServerEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubAddServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getString("server")));
|
Sponge.getEventManager().post(new SubAddServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getString("server")));
|
||||||
callback("SubAddServerEvent", this);
|
callback("SubAddServerEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubCreateEvent", new Callback<YAMLSection>() {
|
callback("SubCreateEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
Sponge.getEventManager().post(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
||||||
data.getString("template"), new Version(data.getString("version")), data.getInt("port")));
|
data.getString("template"), new Version(data.getString("version")), data.getInt("port")));
|
||||||
callback("SubCreateEvent", this);
|
callback("SubCreateEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubSendCommandEvent", new Callback<YAMLSection>() {
|
callback("SubSendCommandEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command")));
|
Sponge.getEventManager().post(new SubSendCommandEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getString("command")));
|
||||||
callback("SubSendCommandEvent", this);
|
callback("SubSendCommandEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubEditServerEvent", new Callback<YAMLSection>() {
|
callback("SubEditServerEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new NamedContainer<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
|
Sponge.getEventManager().post(new SubEditServerEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), new NamedContainer<String, Object>(data.getString("edit"), data.get("value")), data.getBoolean("perm")));
|
||||||
callback("SubEditServerEvent", this);
|
callback("SubEditServerEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubStartEvent", new Callback<YAMLSection>() {
|
callback("SubStartEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubStartEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server")));
|
Sponge.getEventManager().post(new SubStartEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server")));
|
||||||
callback("SubStartEvent", this);
|
callback("SubStartEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubStopEvent", new Callback<YAMLSection>() {
|
callback("SubStopEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubStopEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getBoolean("force")));
|
Sponge.getEventManager().post(new SubStopEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("server"), data.getBoolean("force")));
|
||||||
callback("SubStopEvent", this);
|
callback("SubStopEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubStoppedEvent", new Callback<YAMLSection>() {
|
callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubStoppedEvent(data.getString("server")));
|
Sponge.getEventManager().post(new SubStoppedEvent(data.getString("server")));
|
||||||
callback("SubStoppedEvent", this);
|
callback("SubStoppedEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubRemoveServerEvent", new Callback<YAMLSection>() {
|
callback("SubRemoveServerEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubRemoveServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getString("server")));
|
Sponge.getEventManager().post(new SubRemoveServerEvent((data.contains("player"))?data.getUUID("player"):null, (data.contains("host"))?data.getRawString("host"):null, data.getString("server")));
|
||||||
callback("SubRemoveServerEvent", this);
|
callback("SubRemoveServerEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubRemoveProxyEvent", new Callback<YAMLSection>() {
|
callback("SubRemoveProxyEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubRemoveProxyEvent(data.getString("proxy")));
|
Sponge.getEventManager().post(new SubRemoveProxyEvent(data.getString("proxy")));
|
||||||
callback("SubRemoveProxyEvent", this);
|
callback("SubRemoveProxyEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback("SubRemoveHostEvent", new Callback<YAMLSection>() {
|
callback("SubRemoveHostEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection data) {
|
public void run(ObjectMap<String> data) {
|
||||||
Sponge.getEventManager().post(new SubRemoveHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host")));
|
Sponge.getEventManager().post(new SubRemoveHostEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host")));
|
||||||
callback("SubRemoveHostEvent", this);
|
callback("SubRemoveHostEvent", this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
if (callbacks.keySet().contains(data.getString("type"))) {
|
if (callbacks.keySet().contains(data.getString(0x0000))) {
|
||||||
List<Callback<YAMLSection>> callbacks = PacketInRunEvent.callbacks.get(data.getString("type"));
|
List<Callback<ObjectMap<String>>> callbacks = PacketInExRunEvent.callbacks.get(data.getString(0x0000));
|
||||||
PacketInRunEvent.callbacks.remove(data.getString("type"));
|
PacketInExRunEvent.callbacks.remove(data.getString(0x0000));
|
||||||
for (Callback callback : callbacks) {
|
for (Callback<ObjectMap<String>> callback : callbacks) {
|
||||||
callback.run(data.getSection("args"));
|
callback.run(new ObjectMap<>((Map<String, ?>) data.getObject(0x0001)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callback(String event, Callback<YAMLSection> callback) {
|
public static void callback(String event, Callback<ObjectMap<String>> callback) {
|
||||||
List<Callback<YAMLSection>> callbacks = (PacketInRunEvent.callbacks.keySet().contains(event))?PacketInRunEvent.callbacks.get(event):new ArrayList<Callback<YAMLSection>>();
|
List<Callback<ObjectMap<String>>> callbacks = (PacketInExRunEvent.callbacks.keySet().contains(event))? PacketInExRunEvent.callbacks.get(event):new ArrayList<Callback<ObjectMap<String>>>();
|
||||||
callbacks.add(callback);
|
callbacks.add(callback);
|
||||||
PacketInRunEvent.callbacks.put(event, callbacks);
|
PacketInExRunEvent.callbacks.put(event, callbacks);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,45 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reload Packet
|
|
||||||
*/
|
|
||||||
public class PacketInReload implements PacketIn {
|
|
||||||
private SubPlugin plugin;
|
|
||||||
private Logger log = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New PacketOutReload
|
|
||||||
*
|
|
||||||
* @param plugin Plugin
|
|
||||||
*/
|
|
||||||
public PacketInReload(SubPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(YAMLSection data) {
|
|
||||||
if (data != null && data.contains("m")) log.warn("Received request for a plugin reload: " + data.getString("m"));
|
|
||||||
else log.warn("Received request for a plugin reload");
|
|
||||||
try {
|
|
||||||
plugin.reload(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Version getVersion() {
|
|
||||||
return new Version("2.11.0a");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset Packet
|
|
||||||
*/
|
|
||||||
public class PacketInReset implements PacketIn {
|
|
||||||
private Logger log = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New PacketInReset
|
|
||||||
*/
|
|
||||||
public PacketInReset() {
|
|
||||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(YAMLSection data) {
|
|
||||||
if (data != null && data.contains("m")) log.warn("Received shutdown signal: " + data.getString("m"));
|
|
||||||
else log.warn("Received shutdown signal");
|
|
||||||
Sponge.getServer().shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Version getVersion() {
|
|
||||||
return new Version("2.11.0a");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +1,84 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.util.logging.Logger;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link Server Packet
|
* Link Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketLinkServer implements PacketIn, PacketOut {
|
public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private SubPlugin plugin;
|
private SubPlugin plugin;
|
||||||
private Logger log = null;
|
private int channel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketLinkServer
|
* New PacketLinkServer (In)
|
||||||
*
|
*
|
||||||
* @param plugin SubServers.Client
|
* @param plugin SubServers.Client
|
||||||
*/
|
*/
|
||||||
public PacketLinkServer(SubPlugin plugin) {
|
public PacketLinkServer(SubPlugin plugin) {
|
||||||
if (Util.isNull(plugin)) throw new NullPointerException();
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
Util.isException(() -> this.log = Util.reflect(SubDataClient.class.getDeclaredField("log"), null));
|
}
|
||||||
|
/**
|
||||||
|
* New PacketLinkServer (Out)
|
||||||
|
*
|
||||||
|
* @param plugin SubServers.Client
|
||||||
|
* @param channel Channel ID
|
||||||
|
*/
|
||||||
|
public PacketLinkServer(SubPlugin plugin, int channel) {
|
||||||
|
if (Util.isNull(plugin)) throw new NullPointerException();
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection json = new YAMLSection();
|
ObjectMap<Integer> json = new ObjectMap<Integer>();
|
||||||
if (plugin.subdata.getName() != null) json.set("name", plugin.subdata.getName());
|
if (plugin.api.getName() != null) json.set(0x0000, plugin.api.getName());
|
||||||
if (plugin.game.getServer().getBoundAddress().isPresent()) json.set("port", plugin.game.getServer().getBoundAddress().get());
|
if (plugin.game.getServer().getBoundAddress().isPresent()) json.set(0x0001, plugin.game.getServer().getBoundAddress().get());
|
||||||
|
json.set(0x0002, channel);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
if (data.getInt("r") == 0) {
|
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client), null);
|
||||||
|
if (data.getInt(0x0001) == 0) {
|
||||||
try {
|
try {
|
||||||
if (data.contains("n")) {
|
if (data.contains(0x0000)) {
|
||||||
Util.reflect(SubDataClient.class.getDeclaredField("name"), plugin.subdata, data.getRawString("n"));
|
Util.reflect(SubAPI.class.getDeclaredField("name"), plugin.api, data.getRawString(0x0000));
|
||||||
|
setReady(client, true);
|
||||||
}
|
}
|
||||||
Util.reflect(SubDataClient.class.getDeclaredMethod("init"), plugin.subdata);
|
} catch (Throwable e) {
|
||||||
} catch (Exception e) {}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("Could not link name with server: " + data.getRawString("m"));
|
log.info("Could not link name with server" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
|
||||||
try {
|
try {
|
||||||
if (data.getInt("r") == 2) {
|
if (data.getInt(0x0001) == 2) {
|
||||||
if (!plugin.config.get().getSection("Settings").getSection("SubData").contains("Name")) {
|
if (!plugin.config.get().getMap("Settings").getMap("SubData").contains("Name")) {
|
||||||
plugin.config.get().getSection("Settings").getSection("SubData").set("Name", "");
|
plugin.config.get().getMap("Settings").getMap("SubData").set("Name", "");
|
||||||
plugin.config.save();
|
plugin.config.save();
|
||||||
}
|
}
|
||||||
if (plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Name").length() <= 0)
|
if (plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Name").length() <= 0)
|
||||||
log.info("Use the server \"Name\" option to override auto-linking");
|
log.info("Use the server \"Name\" option to override auto-linking");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
|
new IllegalStateException().printStackTrace();
|
||||||
plugin.disable(null);
|
plugin.disable(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.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.Client.Protocol.PacketObjectIn;
|
||||||
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove Server Packet
|
||||||
|
*/
|
||||||
|
public class PacketRemoveServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
|
private UUID player;
|
||||||
|
private String server;
|
||||||
|
private boolean force;
|
||||||
|
private UUID tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketRemoveServer (In)
|
||||||
|
*/
|
||||||
|
public PacketRemoveServer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New PacketRemoveServer (Out)
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param server Server
|
||||||
|
* @param callback Callbacks
|
||||||
|
*/
|
||||||
|
@SafeVarargs
|
||||||
|
public PacketRemoveServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||||
|
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||||
|
this.player = player;
|
||||||
|
this.server = server;
|
||||||
|
this.force = force;
|
||||||
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
|
callbacks.put(tracker, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
|
data.set(0x0000, tracker);
|
||||||
|
data.set(0x0001, server);
|
||||||
|
data.set(0x0002, force);
|
||||||
|
if (player != null) data.set(0x0003, player.toString());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int version() {
|
||||||
|
return 0x0001;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Restart Server Packet
|
* Restart Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketRestartServer implements PacketIn, PacketOut {
|
public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private String server;
|
private String server;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketRestartServer (In)
|
* New PacketRestartServer (In)
|
||||||
@ -32,31 +32,31 @@ public class PacketRestartServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketRestartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
public PacketRestartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, tracker);
|
||||||
if (player != null) data.set("player", player.toString());
|
data.set(0x0001, server);
|
||||||
data.set("server", server);
|
if (player != null) data.set(0x0002, player.toString());
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -13,11 +13,11 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Start Server Packet
|
* Start Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketStartServer implements PacketIn, PacketOut {
|
public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private String server;
|
private String server;
|
||||||
private String id;
|
private UUID tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketStartServer (In)
|
* New PacketStartServer (In)
|
||||||
@ -32,31 +32,31 @@ public class PacketStartServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketStartServer(UUID player, String server, Callback<YAMLSection>... callback) {
|
public PacketStartServer(UUID player, String server, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(server, callback)) throw new NullPointerException();
|
if (Util.isNull(server, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(tracker, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, tracker);
|
||||||
if (player != null) data.set("player", player.toString());
|
data.set(0x0001, server);
|
||||||
data.set("server", server);
|
if (player != null) data.set(0x0002, player.toString());
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.13b");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketIn;
|
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.PacketOut;
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -13,12 +13,12 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* Stop Server Packet
|
* Stop Server Packet
|
||||||
*/
|
*/
|
||||||
public class PacketStopServer implements PacketIn, PacketOut {
|
public class PacketStopServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||||
private static HashMap<String, Callback<YAMLSection>[]> callbacks = new HashMap<String, Callback<YAMLSection>[]>();
|
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||||
private UUID player;
|
private UUID player;
|
||||||
private boolean force;
|
private boolean force;
|
||||||
private String server;
|
private String server;
|
||||||
private String id;
|
private UUID id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New PacketStopServer (In)
|
* New PacketStopServer (In)
|
||||||
@ -34,33 +34,33 @@ public class PacketStopServer implements PacketIn, PacketOut {
|
|||||||
* @param callback Callbacks
|
* @param callback Callbacks
|
||||||
*/
|
*/
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public PacketStopServer(UUID player, String server, boolean force, Callback<YAMLSection>... callback) {
|
public PacketStopServer(UUID player, String server, boolean force, Callback<ObjectMap<Integer>>... callback) {
|
||||||
if (Util.isNull(server, force, callback)) throw new NullPointerException();
|
if (Util.isNull(server, force, callback)) throw new NullPointerException();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.force = force;
|
this.force = force;
|
||||||
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString();
|
this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||||
callbacks.put(id, callback);
|
callbacks.put(id, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YAMLSection generate() {
|
public ObjectMap<Integer> send(SubDataClient client) {
|
||||||
YAMLSection data = new YAMLSection();
|
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||||
data.set("id", id);
|
data.set(0x0000, id);
|
||||||
if (player != null) data.set("player", player.toString());
|
data.set(0x0001, server);
|
||||||
data.set("server", server);
|
data.set(0x0002, force);
|
||||||
data.set("force", force);
|
if (player != null) data.set(0x0003, player.toString());
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(YAMLSection data) {
|
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||||
for (Callback<YAMLSection> callback : callbacks.get(data.getRawString("id"))) callback.run(data);
|
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||||
callbacks.remove(data.getRawString("id"));
|
callbacks.remove(data.getUUID(0x0000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Version getVersion() {
|
public int version() {
|
||||||
return new Version("2.11.0a");
|
return 0x0001;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PacketIn Layout Class
|
|
||||||
*/
|
|
||||||
public interface PacketIn {
|
|
||||||
/**
|
|
||||||
* Execute Incoming Packet
|
|
||||||
*
|
|
||||||
* @param data Incoming Data
|
|
||||||
*/
|
|
||||||
void execute(YAMLSection data) throws Throwable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Packet Version
|
|
||||||
*
|
|
||||||
* @return Packet Version
|
|
||||||
*/
|
|
||||||
Version getVersion();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check Compatibility with oncoming packet
|
|
||||||
*
|
|
||||||
* @param version Version of oncoming packet
|
|
||||||
* @return Compatibility Status
|
|
||||||
*/
|
|
||||||
default boolean isCompatible(Version version) {
|
|
||||||
return getVersion().equals(version);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PacketOut Layout Class
|
|
||||||
*/
|
|
||||||
public interface PacketOut {
|
|
||||||
/**
|
|
||||||
* Generate JSON Packet Contents
|
|
||||||
*
|
|
||||||
* @return Packet Contents
|
|
||||||
*/
|
|
||||||
YAMLSection generate() throws Throwable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Packet Version
|
|
||||||
*
|
|
||||||
* @return Packet Version
|
|
||||||
*/
|
|
||||||
Version getVersion();
|
|
||||||
}
|
|
@ -1,457 +0,0 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge.Network;
|
|
||||||
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Event.SubNetworkConnectEvent;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Event.SubNetworkDisconnectEvent;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Exception.IllegalPacketException;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Encryption.AES;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
|
||||||
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
|
||||||
import org.msgpack.core.MessageInsufficientBufferException;
|
|
||||||
import org.msgpack.core.MessagePack;
|
|
||||||
import org.msgpack.core.MessagePacker;
|
|
||||||
import org.msgpack.core.MessageUnpacker;
|
|
||||||
import org.msgpack.value.Value;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.spongepowered.api.Sponge;
|
|
||||||
import org.yaml.snakeyaml.error.YAMLException;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubData Direct Client Class
|
|
||||||
*/
|
|
||||||
public final class SubDataClient {
|
|
||||||
private static HashMap<Class<? extends PacketOut>, NamedContainer<String, String>> pOut = new HashMap<Class<? extends PacketOut>, NamedContainer<String, String>>();
|
|
||||||
private static HashMap<String, HashMap<String, List<PacketIn>>> pIn = new HashMap<String, HashMap<String, List<PacketIn>>>();
|
|
||||||
private static HashMap<String, Cipher> ciphers = new HashMap<String, Cipher>();
|
|
||||||
private static boolean defaults = false;
|
|
||||||
protected static Logger log = LoggerFactory.getLogger("SubData");
|
|
||||||
private MessagePacker out;
|
|
||||||
private NamedContainer<Boolean, Socket> socket;
|
|
||||||
private String name;
|
|
||||||
private Cipher cipher;
|
|
||||||
private SubPlugin plugin;
|
|
||||||
private LinkedList<NamedContainer<String, PacketOut>> queue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubServers Client Instance
|
|
||||||
*
|
|
||||||
* @param plugin SubPlugin
|
|
||||||
* @param name Server Name
|
|
||||||
* @param address Address
|
|
||||||
* @param port Port
|
|
||||||
* @param cipher Cipher
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public SubDataClient(SubPlugin plugin, String name, InetAddress address, int port, Cipher cipher) throws IOException {
|
|
||||||
if (Util.isNull(plugin, address, port)) throw new NullPointerException();
|
|
||||||
socket = new NamedContainer<>(false, new Socket(address, port));
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.name = (name == null || name.length() > 0)?name:null;
|
|
||||||
this.out = MessagePack.newDefaultPacker(socket.get().getOutputStream());
|
|
||||||
this.queue = new LinkedList<NamedContainer<String, PacketOut>>();
|
|
||||||
this.cipher = (cipher != null)?cipher:new Cipher() {
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "NONE";
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Value encrypt(String key, YAMLSection data) {
|
|
||||||
return data.msgPack();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public YAMLSection decrypt(String key, Value data) {
|
|
||||||
return new YAMLSection(data.asMapValue());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!defaults) loadDefaults();
|
|
||||||
loop();
|
|
||||||
|
|
||||||
sendPacket(new NamedContainer<>(null, new PacketAuthorization(plugin)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
sendPacket(new PacketDownloadLang());
|
|
||||||
while (queue.size() != 0) {
|
|
||||||
sendPacket(queue.get(0));
|
|
||||||
queue.remove(0);
|
|
||||||
}
|
|
||||||
socket.rename(true);
|
|
||||||
Sponge.getEventManager().post(new SubNetworkConnectEvent(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
addCipher("AES", new AES(128));
|
|
||||||
addCipher("AES_128", new AES(128));
|
|
||||||
addCipher("AES_192", new AES(192));
|
|
||||||
addCipher("AES_256", new AES(256));
|
|
||||||
} private void loadDefaults() {
|
|
||||||
defaults = true;
|
|
||||||
log = LoggerFactory.getLogger("SubData");
|
|
||||||
|
|
||||||
registerPacket(new PacketAuthorization(plugin), "SubData", "Authorization");
|
|
||||||
registerPacket(new PacketCommandServer(), "SubServers", "CommandServer");
|
|
||||||
registerPacket(new PacketCreateServer(), "SubServers", "CreateServer");
|
|
||||||
registerPacket(new PacketDownloadGroupInfo(), "SubServers", "DownloadGroupInfo");
|
|
||||||
registerPacket(new PacketDownloadHostInfo(), "SubServers", "DownloadHostInfo");
|
|
||||||
registerPacket(new PacketDownloadLang(plugin), "SubServers", "DownloadLang");
|
|
||||||
registerPacket(new PacketDownloadNetworkList(), "SubServers", "DownloadNetworkList");
|
|
||||||
registerPacket(new PacketDownloadPlatformInfo(), "SubServers", "DownloadPlatformInfo");
|
|
||||||
registerPacket(new PacketDownloadPlayerList(), "SubServers", "DownloadPlayerList");
|
|
||||||
registerPacket(new PacketDownloadProxyInfo(), "SubServers", "DownloadProxyInfo");
|
|
||||||
registerPacket(new PacketDownloadServerInfo(), "SubServers", "DownloadServerInfo");
|
|
||||||
registerPacket(new PacketInRunEvent(plugin), "SubServers", "RunEvent");
|
|
||||||
registerPacket(new PacketInReload(plugin), "SubServers", "Reload");
|
|
||||||
registerPacket(new PacketInReset(), "SubServers", "Reset");
|
|
||||||
registerPacket(new PacketLinkServer(plugin), "SubServers", "LinkServer");
|
|
||||||
registerPacket(new PacketRestartServer(), "SubServers", "RestartServer");
|
|
||||||
registerPacket(new PacketStartServer(), "SubServers", "StartServer");
|
|
||||||
registerPacket(new PacketStopServer(), "SubServers", "StopServer");
|
|
||||||
|
|
||||||
registerPacket(PacketAuthorization.class, "SubData", "Authorization");
|
|
||||||
registerPacket(PacketCommandServer.class, "SubServers", "CommandServer");
|
|
||||||
registerPacket(PacketCreateServer.class, "SubServers", "CreateServer");
|
|
||||||
registerPacket(PacketDownloadGroupInfo.class, "SubServers", "DownloadGroupInfo");
|
|
||||||
registerPacket(PacketDownloadHostInfo.class, "SubServers", "DownloadHostInfo");
|
|
||||||
registerPacket(PacketDownloadLang.class, "SubServers", "DownloadLang");
|
|
||||||
registerPacket(PacketDownloadNetworkList.class, "SubServers", "DownloadNetworkList");
|
|
||||||
registerPacket(PacketDownloadPlatformInfo.class, "SubServers", "DownloadPlatformInfo");
|
|
||||||
registerPacket(PacketDownloadPlayerList.class, "SubServers", "DownloadPlayerList");
|
|
||||||
registerPacket(PacketDownloadProxyInfo.class, "SubServers", "DownloadProxyInfo");
|
|
||||||
registerPacket(PacketDownloadServerInfo.class, "SubServers", "DownloadServerInfo");
|
|
||||||
registerPacket(PacketLinkServer.class, "SubServers", "LinkServer");
|
|
||||||
registerPacket(PacketRestartServer.class, "SubServers", "RestartServer");
|
|
||||||
registerPacket(PacketStartServer.class, "SubServers", "StartServer");
|
|
||||||
registerPacket(PacketStopServer.class, "SubServers", "StopServer");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loop() {
|
|
||||||
Sponge.getScheduler().createTaskBuilder().async().execute(() -> {
|
|
||||||
try {
|
|
||||||
MessageUnpacker in = MessagePack.newDefaultUnpacker(socket.get().getInputStream());
|
|
||||||
Value input;
|
|
||||||
while ((input = in.unpackValue()) != null) {
|
|
||||||
recieve(input);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (!(e instanceof SocketException || e instanceof MessageInsufficientBufferException)) e.printStackTrace();
|
|
||||||
try {
|
|
||||||
destroy(plugin.config.get().getSection("Settings").getSection("SubData").getInt("Reconnect", 30));
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).submit(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void recieve(Value input) {
|
|
||||||
try {
|
|
||||||
YAMLSection data = getCipher().decrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), input);
|
|
||||||
for (PacketIn packet : decodePacket(data)) {
|
|
||||||
Sponge.getScheduler().createTaskBuilder().execute(() -> {
|
|
||||||
try {
|
|
||||||
packet.execute((data.contains("c")) ? data.getSection("c") : null);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
new InvocationTargetException(e, "Exception while executing PacketIn").printStackTrace();
|
|
||||||
}
|
|
||||||
}).submit(plugin);
|
|
||||||
}
|
|
||||||
} catch (YAMLException e) {
|
|
||||||
new IllegalPacketException("Unknown Packet Format: " + input).printStackTrace();
|
|
||||||
} catch (IllegalPacketException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (Exception e) {
|
|
||||||
new InvocationTargetException(e, "Exception while decoding packet").printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Assigned Server Name
|
|
||||||
*
|
|
||||||
* @return Server Name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Client Socket
|
|
||||||
*
|
|
||||||
* @return Client Socket
|
|
||||||
*/
|
|
||||||
public Socket getClient() {
|
|
||||||
return socket.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a Cipher for use by SubData
|
|
||||||
*
|
|
||||||
* @param cipher Cipher to Add
|
|
||||||
* @param handle Handle to Bind
|
|
||||||
*/
|
|
||||||
public static void addCipher(String handle, Cipher cipher) {
|
|
||||||
if (Util.isNull(cipher)) throw new NullPointerException();
|
|
||||||
if (ciphers.keySet().contains(handle.toUpperCase().replace('-', '_').replace(' ', '_'))) throw new IllegalStateException("Cipher already exists: " + handle);
|
|
||||||
ciphers.put(handle.toUpperCase().replace('-', '_').replace(' ', '_'), cipher);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Ciphers
|
|
||||||
*
|
|
||||||
* @return Cipher Map
|
|
||||||
*/
|
|
||||||
public static Map<String, Cipher> getCiphers() {
|
|
||||||
return new TreeMap<>(ciphers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Client's Cipher
|
|
||||||
*
|
|
||||||
* @return Cipher
|
|
||||||
*/
|
|
||||||
public Cipher getCipher() {
|
|
||||||
return cipher;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a Cipher by Handle
|
|
||||||
*
|
|
||||||
* @param handle Handle
|
|
||||||
* @return Cipher
|
|
||||||
*/
|
|
||||||
public static Cipher getCipher(String handle) {
|
|
||||||
return getCiphers().get(handle.toUpperCase().replace('-', '_').replace(' ', '_'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register PacketIn to the Network
|
|
||||||
*
|
|
||||||
* @param packet PacketIn to register
|
|
||||||
* @param channel Packet Channel
|
|
||||||
* @param handle Handle to Bind
|
|
||||||
*/
|
|
||||||
public static void registerPacket(PacketIn packet, String channel, String handle) {
|
|
||||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
|
||||||
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
|
|
||||||
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
|
|
||||||
if (!list.contains(packet)) {
|
|
||||||
list.add(packet);
|
|
||||||
map.put(handle, list);
|
|
||||||
pIn.put(channel.toLowerCase(), map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregister PacketIn from the Network
|
|
||||||
*
|
|
||||||
* @param channel Packet Channel
|
|
||||||
* @param packet PacketIn to unregister
|
|
||||||
*/
|
|
||||||
public static void unregisterPacket(String channel, PacketIn packet) {
|
|
||||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
|
||||||
if (pIn.keySet().contains(channel.toLowerCase())) {
|
|
||||||
List<String> search = new ArrayList<String>();
|
|
||||||
search.addAll(pIn.get(channel.toLowerCase()).keySet());
|
|
||||||
for (String handle : search) if (pIn.get(channel.toLowerCase()).get(handle).contains(packet)) {
|
|
||||||
List<PacketIn> list = pIn.get(channel.toLowerCase()).get(handle);
|
|
||||||
list.remove(packet);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
pIn.get(channel.toLowerCase()).remove(handle);
|
|
||||||
if (pIn.get(channel.toLowerCase()).isEmpty()) pIn.remove(channel.toLowerCase());
|
|
||||||
} else {
|
|
||||||
pIn.get(channel.toLowerCase()).put(handle, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register PacketOut to the Network
|
|
||||||
*
|
|
||||||
* @param packet PacketOut to register
|
|
||||||
* @param channel Packet Channel
|
|
||||||
* @param handle Handle to bind
|
|
||||||
*/
|
|
||||||
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
|
|
||||||
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
|
|
||||||
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregister PacketOut to the Network
|
|
||||||
*
|
|
||||||
* @param channel Packet Channel
|
|
||||||
* @param packet PacketOut to unregister
|
|
||||||
*/
|
|
||||||
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
|
|
||||||
if (Util.isNull(channel, packet)) throw new NullPointerException();
|
|
||||||
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab PacketIn Instances via handle
|
|
||||||
*
|
|
||||||
* @param channel Packet Channel
|
|
||||||
* @param handle Handle
|
|
||||||
* @return PacketIn
|
|
||||||
*/
|
|
||||||
public static List<? extends PacketIn> getPacket(String channel, String handle) {
|
|
||||||
if (Util.isNull(channel, handle)) throw new NullPointerException();
|
|
||||||
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send Packet to Server
|
|
||||||
*
|
|
||||||
* @param packet Packet to send
|
|
||||||
*/
|
|
||||||
public void sendPacket(PacketOut packet) {
|
|
||||||
if (Util.isNull(packet)) throw new NullPointerException();
|
|
||||||
if (socket == null || !socket.name()) {
|
|
||||||
queue.add(new NamedContainer<>(null, packet));
|
|
||||||
} else {
|
|
||||||
sendPacket(new NamedContainer<>(null, packet));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendPacket(NamedContainer<String, PacketOut> packet) {
|
|
||||||
try {
|
|
||||||
YAMLSection data = encodePacket(packet.get());
|
|
||||||
if (packet.name() != null) data.set("f", packet.name());
|
|
||||||
out.packValue(getCipher().encrypt(plugin.config.get().getSection("Settings").getSection("SubData").getRawString("Password"), data));
|
|
||||||
out.flush();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forward Packet to Client
|
|
||||||
*
|
|
||||||
* @param packet Packet to send
|
|
||||||
* @param location Where to send
|
|
||||||
*/
|
|
||||||
public void forwardPacket(PacketOut packet, String location) {
|
|
||||||
if (Util.isNull(packet, location)) throw new NullPointerException();
|
|
||||||
if (socket.get() == null || !socket.name()) {
|
|
||||||
queue.add(new NamedContainer<>(location, packet));
|
|
||||||
} else {
|
|
||||||
sendPacket(new NamedContainer<>(location, packet));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast packet to all Clients
|
|
||||||
*
|
|
||||||
* @param packet Packet to send
|
|
||||||
*/
|
|
||||||
public void broadcastPacket(PacketOut packet) {
|
|
||||||
forwardPacket(packet, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode PacketOut
|
|
||||||
*
|
|
||||||
* @param packet PacketOut
|
|
||||||
* @return JSON Formatted Packet
|
|
||||||
* @throws IllegalPacketException
|
|
||||||
*/
|
|
||||||
private static YAMLSection encodePacket(PacketOut packet) throws IllegalPacketException, InvocationTargetException {
|
|
||||||
YAMLSection data = new YAMLSection();
|
|
||||||
|
|
||||||
if (!pOut.keySet().contains(packet.getClass())) throw new IllegalPacketException("Unknown PacketOut Channel: " + packet.getClass().getCanonicalName());
|
|
||||||
if (packet.getVersion() == null) throw new NullPointerException("PacketOut Version cannot be null: " + packet.getClass().getCanonicalName());
|
|
||||||
|
|
||||||
try {
|
|
||||||
YAMLSection contents = packet.generate();
|
|
||||||
data.set("n", pOut.get(packet.getClass()).name());
|
|
||||||
data.set("h", pOut.get(packet.getClass()).get());
|
|
||||||
data.set("v", packet.getVersion());
|
|
||||||
if (contents != null) data.set("c", contents);
|
|
||||||
return data;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new InvocationTargetException(e, "Exception while encoding packet");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode PacketIn
|
|
||||||
*
|
|
||||||
* @param data Data to Decode
|
|
||||||
* @return PacketIn
|
|
||||||
* @throws IllegalPacketException
|
|
||||||
* @throws InvocationTargetException
|
|
||||||
*/
|
|
||||||
private static List<PacketIn> decodePacket(YAMLSection data) throws IllegalPacketException, InvocationTargetException {
|
|
||||||
if (!data.contains("n") || !data.contains("h") || !data.contains("v")) throw new IllegalPacketException("Unknown Packet Format: " + data.toString());
|
|
||||||
if (!pIn.keySet().contains(data.getRawString("n")) || !pIn.get(data.getRawString("n")).keySet().contains(data.getRawString("h"))) throw new IllegalPacketException("Unknown PacketIn Channel: " + data.getRawString("n") + ':' + data.getRawString("h"));
|
|
||||||
|
|
||||||
List<PacketIn> list = new ArrayList<PacketIn>();
|
|
||||||
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
|
|
||||||
if (packet.isCompatible(data.getVersion("v"))) {
|
|
||||||
list.add(packet);
|
|
||||||
} else {
|
|
||||||
new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion()).printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drops All Connections and Stops the SubData Listener
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void destroy(int reconnect) throws IOException {
|
|
||||||
if (Util.isNull(reconnect)) throw new NullPointerException();
|
|
||||||
if (socket.get() != null) {
|
|
||||||
final Socket socket = this.socket.get();
|
|
||||||
this.socket.set(null);
|
|
||||||
if (!socket.isClosed()) socket.close();
|
|
||||||
Sponge.getEventManager().post(new SubNetworkDisconnectEvent());
|
|
||||||
log.info("The SubData Connection was closed");
|
|
||||||
if (reconnect > 0) {
|
|
||||||
|
|
||||||
log.info("SubServers > Attempting to reconnect in " + reconnect + " seconds");
|
|
||||||
Sponge.getScheduler().createTaskBuilder().async().execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
plugin.subdata = new SubDataClient(plugin, name, socket.getInetAddress(), socket.getPort(), cipher);
|
|
||||||
while (queue.size() != 0) {
|
|
||||||
if (queue.get(0).name() != null) {
|
|
||||||
plugin.subdata.forwardPacket(queue.get(0).get(), queue.get(0).name());
|
|
||||||
} else {
|
|
||||||
plugin.subdata.sendPacket(queue.get(0).get());
|
|
||||||
}
|
|
||||||
queue.remove(0);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.info("SubServers > Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
|
||||||
Sponge.getScheduler().createTaskBuilder().async().execute(this).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,210 @@
|
|||||||
|
package net.ME1312.SubServers.Client.Sponge.Network;
|
||||||
|
|
||||||
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
|
import net.ME1312.SubData.Client.Library.DisconnectReason;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
|
import net.ME1312.SubData.Client.SubDataProtocol;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Event.SubNetworkConnectEvent;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Event.SubNetworkDisconnectEvent;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||||
|
import net.ME1312.SubServers.Client.Sponge.SubPlugin;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.spongepowered.api.GameState;
|
||||||
|
import org.spongepowered.api.Sponge;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.*;
|
||||||
|
|
||||||
|
public class SubProtocol extends SubDataProtocol {
|
||||||
|
private static SubProtocol instance;
|
||||||
|
private static Logger log;
|
||||||
|
private SubProtocol() {}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static SubProtocol get() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new SubProtocol();
|
||||||
|
|
||||||
|
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||||
|
|
||||||
|
log = Logger.getAnonymousLogger();
|
||||||
|
log.setUseParentHandlers(false);
|
||||||
|
log.addHandler(new Handler() {
|
||||||
|
private org.slf4j.Logger log = LoggerFactory.getLogger("SubData");
|
||||||
|
private boolean open = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void publish(LogRecord record) {
|
||||||
|
if (open) {
|
||||||
|
if (record.getLevel().intValue() == OFF.intValue()) {
|
||||||
|
// do nothing
|
||||||
|
} else if (record.getLevel().intValue() == FINE.intValue() || record.getLevel().intValue() == FINER.intValue() || record.getLevel().intValue() == FINEST.intValue()) {
|
||||||
|
log.debug(record.getMessage());
|
||||||
|
} else if (record.getLevel().intValue() == ALL.intValue() || record.getLevel().intValue() == CONFIG.intValue() || record.getLevel().intValue() == INFO.intValue()) {
|
||||||
|
log.info(record.getMessage());
|
||||||
|
} else if (record.getLevel().intValue() == WARNING.intValue()) {
|
||||||
|
log.warn(record.getMessage());
|
||||||
|
} else if (record.getLevel().intValue() == SEVERE.intValue()) {
|
||||||
|
log.error(record.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SecurityException {
|
||||||
|
open = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.setName("SubServers 2");
|
||||||
|
instance.addVersion(new Version("2.14a+"));
|
||||||
|
|
||||||
|
|
||||||
|
// 00-09: Object Link Packets
|
||||||
|
instance.registerPacket(0x0002, PacketLinkServer.class);
|
||||||
|
instance.registerPacket(0x0002, new PacketLinkServer(plugin));
|
||||||
|
|
||||||
|
|
||||||
|
// 10-29: Download Packets
|
||||||
|
instance.registerPacket(0x0010, PacketDownloadLang.class);
|
||||||
|
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
|
||||||
|
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
|
||||||
|
instance.registerPacket(0x0013, PacketDownloadHostInfo.class);
|
||||||
|
instance.registerPacket(0x0014, PacketDownloadGroupInfo.class);
|
||||||
|
instance.registerPacket(0x0015, PacketDownloadServerInfo.class);
|
||||||
|
instance.registerPacket(0x0016, PacketDownloadPlayerList.class);
|
||||||
|
instance.registerPacket(0x0017, PacketCheckPermission.class);
|
||||||
|
|
||||||
|
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
|
||||||
|
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo());
|
||||||
|
instance.registerPacket(0x0012, new PacketDownloadProxyInfo());
|
||||||
|
instance.registerPacket(0x0013, new PacketDownloadHostInfo());
|
||||||
|
instance.registerPacket(0x0014, new PacketDownloadGroupInfo());
|
||||||
|
instance.registerPacket(0x0015, new PacketDownloadServerInfo());
|
||||||
|
instance.registerPacket(0x0016, new PacketDownloadPlayerList());
|
||||||
|
instance.registerPacket(0x0017, new PacketCheckPermission());
|
||||||
|
|
||||||
|
|
||||||
|
// 30-49: Control Packets
|
||||||
|
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||||
|
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||||
|
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||||
|
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||||
|
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||||
|
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||||
|
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||||
|
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||||
|
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||||
|
|
||||||
|
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||||
|
instance.registerPacket(0x0031, new PacketAddServer());
|
||||||
|
instance.registerPacket(0x0032, new PacketStartServer());
|
||||||
|
instance.registerPacket(0x0033, new PacketEditServer());
|
||||||
|
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||||
|
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||||
|
instance.registerPacket(0x0036, new PacketStopServer());
|
||||||
|
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||||
|
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||||
|
|
||||||
|
|
||||||
|
// 70-79: External Misc Packets
|
||||||
|
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
|
||||||
|
//instance.registerPacket(0x0071, PacketInExReset.class);
|
||||||
|
//instance.registerPacket(0x0072, PacketInExReload.class);
|
||||||
|
instance.registerPacket(0x0074, PacketExCheckPermission.class);
|
||||||
|
|
||||||
|
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
|
||||||
|
instance.registerPacket(0x0071, new PacketInExReset());
|
||||||
|
instance.registerPacket(0x0072, new PacketInExReload(plugin));
|
||||||
|
instance.registerPacket(0x0074, new PacketExCheckPermission());
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SubDataClient sub(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||||
|
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||||
|
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||||
|
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||||
|
|
||||||
|
int channel = 1;
|
||||||
|
while (map.keySet().contains(channel)) channel++;
|
||||||
|
final int fc = channel;
|
||||||
|
|
||||||
|
map.put(fc, subdata);
|
||||||
|
subdata.sendPacket(new PacketLinkServer(plugin, fc));
|
||||||
|
subdata.on.closed(client -> map.remove(fc));
|
||||||
|
|
||||||
|
return subdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||||
|
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||||
|
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||||
|
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
|
||||||
|
|
||||||
|
subdata.sendPacket(new PacketLinkServer(plugin, 0));
|
||||||
|
subdata.sendPacket(new PacketDownloadLang());
|
||||||
|
subdata.on.ready(client -> Sponge.getEventManager().post(new SubNetworkConnectEvent((SubDataClient) client)));
|
||||||
|
subdata.on.closed(client -> {
|
||||||
|
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
|
||||||
|
Sponge.getEventManager().post(event);
|
||||||
|
map.put(0, null);
|
||||||
|
|
||||||
|
Logger log = Util.getDespiteException(() -> Util.reflect(SubDataClient.class.getDeclaredField("log"), client.get()), null);
|
||||||
|
int reconnect = plugin.config.get().getMap("Settings").getMap("SubData").getInt("Reconnect", 30);
|
||||||
|
if (Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("reconnect"), plugin), false) && reconnect > 0
|
||||||
|
&& client.name() != DisconnectReason.PROTOCOL_MISMATCH && client.name() != DisconnectReason.ENCRYPTION_MISMATCH) {
|
||||||
|
log.info("Attempting reconnect in " + reconnect + " seconds");
|
||||||
|
Sponge.getScheduler().createTaskBuilder().async().execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Util.reflect(SubPlugin.class.getDeclaredMethod("connect"), plugin);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
if (e.getTargetException() instanceof IOException) {
|
||||||
|
log.info("Connection was unsuccessful, retrying in " + reconnect + " seconds");
|
||||||
|
|
||||||
|
Sponge.getScheduler().createTaskBuilder().async().execute(this).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
|
||||||
|
} else e.printStackTrace();
|
||||||
|
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).delay(reconnect, TimeUnit.SECONDS).submit(plugin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return subdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public SubDataClient open(Logger logger, InetAddress address, int port) throws IOException {
|
||||||
|
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||||
|
return open(event -> Sponge.getScheduler().createTaskBuilder().async().execute(event).submit(plugin), logger, address, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||||
|
return open(log, address, port);
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,23 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge;
|
package net.ME1312.SubServers.Client.Sponge;
|
||||||
|
|
||||||
|
import net.ME1312.SubData.Client.DataClient;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
|
import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.Host;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Proxy;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.Proxy;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.Server;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.Server;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import org.spongepowered.api.Platform;
|
import org.spongepowered.api.Platform;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +27,7 @@ public final class SubAPI {
|
|||||||
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
|
LinkedList<Runnable> reloadListeners = new LinkedList<Runnable>();
|
||||||
private final SubPlugin plugin;
|
private final SubPlugin plugin;
|
||||||
private static SubAPI api;
|
private static SubAPI api;
|
||||||
|
String name;
|
||||||
|
|
||||||
protected SubAPI(SubPlugin plugin) {
|
protected SubAPI(SubPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -61,6 +64,15 @@ public final class SubAPI {
|
|||||||
if (reload != null) reloadListeners.add(reload);
|
if (reload != null) reloadListeners.add(reload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Server Name
|
||||||
|
*
|
||||||
|
* @return Server Name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the Hosts
|
* Gets the Hosts
|
||||||
*
|
*
|
||||||
@ -69,10 +81,10 @@ public final class SubAPI {
|
|||||||
public void getHosts(Callback<Map<String, Host>> callback) {
|
public void getHosts(Callback<Map<String, Host>> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(null, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(null, data -> {
|
||||||
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
TreeMap<String, Host> hosts = new TreeMap<String, Host>();
|
||||||
for (String host : data.getSection("hosts").getKeys()) {
|
for (String host : data.getKeys()) {
|
||||||
hosts.put(host.toLowerCase(), new Host(data.getSection("hosts").getSection(host)));
|
hosts.put(host.toLowerCase(), new Host(data.getMap(host)));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -94,10 +106,10 @@ public final class SubAPI {
|
|||||||
public void getHost(String name, Callback<Host> callback) {
|
public void getHost(String name, Callback<Host> callback) {
|
||||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadHostInfo(name, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadHostInfo(name, data -> {
|
||||||
Host host = null;
|
Host host = null;
|
||||||
if (data.getSection("hosts").getKeys().size() > 0) {
|
if (data.getKeys().size() > 0) {
|
||||||
host = new Host(data.getSection("hosts").getSection(new LinkedList<String>(data.getSection("hosts").getKeys()).getFirst()));
|
host = new Host(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -118,15 +130,15 @@ public final class SubAPI {
|
|||||||
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
public void getGroups(Callback<Map<String, List<Server>>> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(null, data -> {
|
||||||
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
TreeMap<String, List<Server>> groups = new TreeMap<String, List<Server>>();
|
||||||
for (String group : data.getSection("groups").getKeys()) {
|
for (String group : data.getKeys()) {
|
||||||
ArrayList<Server> servers = new ArrayList<Server>();
|
ArrayList<Server> servers = new ArrayList<Server>();
|
||||||
for (String server : data.getSection("groups").getSection(group).getKeys()) {
|
for (String server : data.getMap(group).getKeys()) {
|
||||||
if (data.getSection("groups").getSection(group).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
if (data.getMap(group).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||||
servers.add(new SubServer(data.getSection("groups").getSection(group).getSection(server)));
|
servers.add(new SubServer(data.getMap(group).getMap(server)));
|
||||||
} else {
|
} else {
|
||||||
servers.add(new Server(data.getSection("groups").getSection(group).getSection(server)));
|
servers.add(new Server(data.getMap(group).getMap(server)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (servers.size() > 0) groups.put(group, servers);
|
if (servers.size() > 0) groups.put(group, servers);
|
||||||
@ -167,16 +179,16 @@ public final class SubAPI {
|
|||||||
public void getGroup(String name, Callback<List<Server>> callback) {
|
public void getGroup(String name, Callback<List<Server>> callback) {
|
||||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadGroupInfo(name, data -> {
|
||||||
List<Server> servers = null;
|
List<Server> servers = null;
|
||||||
if (data.getSection("groups").getKeys().size() > 0) {
|
if (data.getKeys().size() > 0) {
|
||||||
String key = new LinkedList<String>(data.getSection("groups").getKeys()).getFirst();
|
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||||
servers = new ArrayList<Server>();
|
servers = new ArrayList<Server>();
|
||||||
for (String server : data.getSection("groups").getSection(key).getKeys()) {
|
for (String server : data.getMap(key).getKeys()) {
|
||||||
if (data.getSection("groups").getSection(key).getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
if (data.getMap(key).getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||||
servers.add(new SubServer(data.getSection("groups").getSection(key).getSection(server)));
|
servers.add(new SubServer(data.getMap(key).getMap(server)));
|
||||||
} else {
|
} else {
|
||||||
servers.add(new Server(data.getSection("groups").getSection(key).getSection(server)));
|
servers.add(new Server(data.getMap(key).getMap(server)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,13 +211,13 @@ public final class SubAPI {
|
|||||||
public void getServers(Callback<Map<String, Server>> callback) {
|
public void getServers(Callback<Map<String, Server>> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(null, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(null, data -> {
|
||||||
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
TreeMap<String, Server> servers = new TreeMap<String, Server>();
|
||||||
for (String server : data.getSection("servers").getKeys()) {
|
for (String server : data.getKeys()) {
|
||||||
if (data.getSection("servers").getSection(server).getRawString("type", "Server").equals("SubServer")) {
|
if (data.getMap(server).getRawString("type", "Server").equals("SubServer")) {
|
||||||
servers.put(server.toLowerCase(), new SubServer(data.getSection("servers").getSection(server)));
|
servers.put(server.toLowerCase(), new SubServer(data.getMap(server)));
|
||||||
} else {
|
} else {
|
||||||
servers.put(server.toLowerCase(), new Server(data.getSection("servers").getSection(server)));
|
servers.put(server.toLowerCase(), new Server(data.getMap(server)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,14 +240,14 @@ public final class SubAPI {
|
|||||||
public void getServer(String name, Callback<Server> callback) {
|
public void getServer(String name, Callback<Server> callback) {
|
||||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadServerInfo(name, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadServerInfo(name, data -> {
|
||||||
Server server = null;
|
Server server = null;
|
||||||
if (data.getSection("servers").getKeys().size() > 0) {
|
if (data.getKeys().size() > 0) {
|
||||||
String key = new LinkedList<String>(data.getSection("servers").getKeys()).getFirst();
|
String key = new LinkedList<String>(data.getKeys()).getFirst();
|
||||||
if (data.getSection("servers").getSection(key).getRawString("type", "Server").equals("SubServer")) {
|
if (data.getMap(key).getRawString("type", "Server").equals("SubServer")) {
|
||||||
server = new SubServer(data.getSection("servers").getSection(key));
|
server = new SubServer(data.getMap(key));
|
||||||
} else {
|
} else {
|
||||||
server = new Server(data.getSection("servers").getSection(key));
|
server = new Server(data.getMap(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,6 +261,174 @@ public final class SubAPI {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a Server to the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param ip IP of the Server
|
||||||
|
* @param port Port of the Server
|
||||||
|
* @param motd MOTD of the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||||
|
addServer(null, name, ip, port, motd, hidden, restricted, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a Server to the Network
|
||||||
|
*
|
||||||
|
* @param player Player who added
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param ip IP of the Server
|
||||||
|
* @param port Port of the Server
|
||||||
|
* @param motd MOTD of the Server
|
||||||
|
* @param hidden If the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketAddServer(player, name, ip, port, motd, hidden, restricted, data -> {
|
||||||
|
try {
|
||||||
|
response.run(data.getInt(0x0001));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a Server to the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param ip IP of the Server
|
||||||
|
* @param port Port of the Server
|
||||||
|
* @param motd MOTD of the Server
|
||||||
|
* @param hidden if the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
*/
|
||||||
|
public void addServer(String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||||
|
addServer(null, name, ip, port, motd, hidden, restricted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a Server to the Network
|
||||||
|
*
|
||||||
|
* @param player Player who added
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param ip IP of the Server
|
||||||
|
* @param port Port of the Server
|
||||||
|
* @param motd MOTD of the Server
|
||||||
|
* @param hidden If the server should be hidden from players
|
||||||
|
* @param restricted Players will need a permission to join if true
|
||||||
|
*/
|
||||||
|
public void addServer(UUID player, String name, InetAddress ip, int port, String motd, boolean hidden, boolean restricted) {
|
||||||
|
addServer(player, name, ip, port, motd, hidden, restricted, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void removeServer(String name, Callback<Integer> response) {
|
||||||
|
removeServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void removeServer(UUID player, String name, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeServer(player, name, false, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
*/
|
||||||
|
public void removeServer(String name) {
|
||||||
|
removeServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name Name of the Server
|
||||||
|
*/
|
||||||
|
public void removeServer(UUID player, String name) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeServer(player, name, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRemoveServer(String name, Callback<Integer> response) {
|
||||||
|
forceRemoveServer(null, name, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name Name of the Server
|
||||||
|
* @param response Response Code
|
||||||
|
*/
|
||||||
|
public void forceRemoveServer(UUID player, String name, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
removeServer(player, name, true, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param name Name of the Server
|
||||||
|
*/
|
||||||
|
public void forceRemoveServer(String name) {
|
||||||
|
forceRemoveServer(null, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force Remove a Server from the Network
|
||||||
|
*
|
||||||
|
* @param player Player Removing
|
||||||
|
* @param name Name of the Server
|
||||||
|
*/
|
||||||
|
public void forceRemoveServer(UUID player, String name) {
|
||||||
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
|
forceRemoveServer(player, name, i -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeServer(UUID player, String name, boolean force, Callback<Integer> response) {
|
||||||
|
if (Util.isNull(response)) throw new NullPointerException();
|
||||||
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRemoveServer(player, name, force, data -> {
|
||||||
|
try {
|
||||||
|
response.run(data.getInt(0x0001));
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Throwable ew = new InvocationTargetException(e);
|
||||||
|
ew.setStackTrace(origin);
|
||||||
|
ew.printStackTrace();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the SubServers
|
* Gets the SubServers
|
||||||
*
|
*
|
||||||
@ -284,10 +464,10 @@ public final class SubAPI {
|
|||||||
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
public void getProxies(Callback<Map<String, Proxy>> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(null, data -> {
|
||||||
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
TreeMap<String, Proxy> proxies = new TreeMap<String, Proxy>();
|
||||||
for (String proxy : data.getSection("proxies").getKeys()) {
|
for (String proxy : data.getKeys()) {
|
||||||
proxies.put(proxy.toLowerCase(), new Proxy(data.getSection("proxies").getSection(proxy)));
|
proxies.put(proxy.toLowerCase(), new Proxy(data.getMap(proxy)));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -309,10 +489,10 @@ public final class SubAPI {
|
|||||||
public void getProxy(String name, Callback<Proxy> callback) {
|
public void getProxy(String name, Callback<Proxy> callback) {
|
||||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo(name, data -> {
|
||||||
Proxy proxy = null;
|
Proxy proxy = null;
|
||||||
if (data.getSection("proxies").getKeys().size() > 0) {
|
if (data.getKeys().size() > 0) {
|
||||||
proxy = new Proxy(data.getSection("proxies").getSection(new LinkedList<String>(data.getSection("proxies").getKeys()).getFirst()));
|
proxy = new Proxy(data.getMap(new LinkedList<String>(data.getKeys()).getFirst()));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -333,10 +513,10 @@ public final class SubAPI {
|
|||||||
public void getMasterProxy(Callback<Proxy> callback) {
|
public void getMasterProxy(Callback<Proxy> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadProxyInfo("", data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadProxyInfo("", data -> {
|
||||||
Proxy proxy = null;
|
Proxy proxy = null;
|
||||||
if (data.getKeys().contains("master")) {
|
if (data != null) {
|
||||||
proxy = new Proxy(data.getSection("master"));
|
proxy = new Proxy(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -358,10 +538,10 @@ public final class SubAPI {
|
|||||||
public void getGlobalPlayers(Callback<Collection<NamedContainer<String, UUID>>> callback) {
|
public void getGlobalPlayers(Callback<Collection<NamedContainer<String, UUID>>> callback) {
|
||||||
if (Util.isNull(callback)) throw new NullPointerException();
|
if (Util.isNull(callback)) throw new NullPointerException();
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
plugin.subdata.sendPacket(new PacketDownloadPlayerList(data -> {
|
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketDownloadPlayerList(data -> {
|
||||||
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
List<NamedContainer<String, UUID>> players = new ArrayList<NamedContainer<String, UUID>>();
|
||||||
for (String id : data.getSection("players").getKeys()) {
|
for (String id : data.getKeys()) {
|
||||||
players.add(new NamedContainer<String, UUID>(data.getSection("players").getSection(id).getRawString("name"), UUID.fromString(id)));
|
players.add(new NamedContainer<String, UUID>(data.getMap(id).getRawString("name"), UUID.fromString(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -379,8 +559,12 @@ public final class SubAPI {
|
|||||||
*
|
*
|
||||||
* @return SubData Network Manager
|
* @return SubData Network Manager
|
||||||
*/
|
*/
|
||||||
public SubDataClient getSubDataNetwork() {
|
public DataClient[] getSubDataNetwork() {
|
||||||
return plugin.subdata;
|
LinkedList<Integer> keys = new LinkedList<Integer>(plugin.subdata.keySet());
|
||||||
|
LinkedList<SubDataClient> channels = new LinkedList<SubDataClient>();
|
||||||
|
Collections.sort(keys);
|
||||||
|
for (Integer channel : keys) channels.add(plugin.subdata.get(channel));
|
||||||
|
return channels.toArray(new DataClient[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package net.ME1312.SubServers.Client.Sponge;
|
package net.ME1312.SubServers.Client.Sponge;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
|
import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Callback;
|
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
|
import net.ME1312.SubServers.Client.Sponge.Library.ChatColor;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Container;
|
import net.ME1312.Galaxi.Library.Container;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.API.*;
|
import net.ME1312.SubServers.Client.Sponge.Network.API.*;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
import net.ME1312.SubServers.Client.Sponge.Network.Packet.*;
|
||||||
import org.spongepowered.api.Platform;
|
import org.spongepowered.api.Platform;
|
||||||
@ -110,7 +111,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean canRun(CommandSource sender) throws CommandException {
|
private boolean canRun(CommandSource sender) throws CommandException {
|
||||||
if (plugin.subdata == null) {
|
if (SubAPI.getInstance().getSubDataNetwork()[0] == null) {
|
||||||
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("SubData is not connected"), false);
|
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("SubData is not connected"), false);
|
||||||
} else if (plugin.lang == null) {
|
} else if (plugin.lang == null) {
|
||||||
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("There are no lang options available at this time"), false);
|
throw new CommandException(Text.builder("An exception has occurred while running this command").color(TextColors.RED).build(), new IllegalStateException("There are no lang options available at this time"), false);
|
||||||
@ -194,12 +195,12 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(Text.EMPTY);
|
sender.sendMessage(Text.EMPTY);
|
||||||
plugin.game.getScheduler().createTaskBuilder().async().execute(() -> {
|
plugin.game.getScheduler().createTaskBuilder().async().execute(() -> {
|
||||||
try {
|
try {
|
||||||
YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
ObjectMap<String> tags = new ObjectMap<String>(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||||
List<Version> versions = new LinkedList<Version>();
|
List<Version> versions = new LinkedList<Version>();
|
||||||
|
|
||||||
Version updversion = plugin.version;
|
Version updversion = plugin.version;
|
||||||
int updcount = 0;
|
int updcount = 0;
|
||||||
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||||
Collections.sort(versions);
|
Collections.sort(versions);
|
||||||
for (Version version : versions) {
|
for (Version version : versions) {
|
||||||
if (version.compareTo(updversion) > 0) {
|
if (version.compareTo(updversion) > 0) {
|
||||||
@ -249,7 +250,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
if (!server.getName().equals(server.getDisplayName())) {
|
if (!server.getName().equals(server.getDisplayName())) {
|
||||||
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
hover.append(Text.builder(server.getName() + '\n').color(TextColors.GRAY).build());
|
||||||
}
|
}
|
||||||
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
if (((SubServer) server).getStopAction() == SubServer.StopAction.REMOVE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.RECYCLE_SERVER || ((SubServer) server).getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||||
message.color(TextColors.AQUA);
|
message.color(TextColors.AQUA);
|
||||||
hover.color(TextColors.AQUA);
|
hover.color(TextColors.AQUA);
|
||||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'));
|
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'));
|
||||||
@ -284,7 +285,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
} else {
|
} else {
|
||||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
@ -300,7 +301,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
|
||||||
);
|
);
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
} else {
|
} else {
|
||||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
@ -339,7 +340,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
if (!host.isAvailable()) hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Unavailable")));
|
if (!host.isAvailable()) hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Unavailable")));
|
||||||
else hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Disabled")));
|
else hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Host-Menu.Host-Disabled")));
|
||||||
}
|
}
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||||
hover.append(Text.builder('\n' + host.getAddress().getHostAddress()).color(TextColors.WHITE).build());
|
hover.append(Text.builder('\n' + host.getAddress().getHostAddress()).color(TextColors.WHITE).build());
|
||||||
}
|
}
|
||||||
msg.onClick(TextActions.runCommand("/subservers open Host/ " + host.getName()));
|
msg.onClick(TextActions.runCommand("/subservers open Host/ " + host.getName()));
|
||||||
@ -355,7 +356,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||||
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
hover.append(Text.builder(subserver.getName() + '\n').color(TextColors.GRAY).build());
|
||||||
}
|
}
|
||||||
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
if (subserver.getStopAction() == SubServer.StopAction.REMOVE_SERVER || subserver.getStopAction() == SubServer.StopAction.RECYCLE_SERVER || subserver.getStopAction() == SubServer.StopAction.DELETE_SERVER) {
|
||||||
message.color(TextColors.AQUA);
|
message.color(TextColors.AQUA);
|
||||||
hover.color(TextColors.AQUA);
|
hover.color(TextColors.AQUA);
|
||||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'));
|
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'));
|
||||||
@ -386,7 +387,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||||
hover.append(Text.builder('\n' + subserver.getAddress().getAddress().getHostAddress()+':'+subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder('\n' + subserver.getAddress().getAddress().getHostAddress()+':'+subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
} else {
|
} else {
|
||||||
hover.append(Text.builder("\n" + subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder("\n" + subserver.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
@ -416,7 +417,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
hover.append(
|
hover.append(
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-External") + '\n'),
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size()))));
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size()))));
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) {
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||||
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder('\n' + server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
} else {
|
} else {
|
||||||
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
hover.append(Text.builder("\n" + server.getAddress().getPort()).color(TextColors.WHITE).build());
|
||||||
@ -447,14 +448,14 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
for (Proxy proxy : proxies.values()) {
|
for (Proxy proxy : proxies.values()) {
|
||||||
message = Text.builder(proxy.getDisplayName());
|
message = Text.builder(proxy.getDisplayName());
|
||||||
hover = Text.builder(proxy.getDisplayName());
|
hover = Text.builder(proxy.getDisplayName());
|
||||||
if (proxy.getSubData() != null && proxy.isRedis()) {
|
if (proxy.getSubData()[0] != null && proxy.isRedis()) {
|
||||||
message.color(TextColors.GREEN);
|
message.color(TextColors.GREEN);
|
||||||
hover.color(TextColors.GREEN);
|
hover.color(TextColors.GREEN);
|
||||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||||
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
hover.append(Text.builder('\n' + proxy.getName()).color(TextColors.GRAY).build());
|
||||||
}
|
}
|
||||||
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
|
hover.append(ChatColor.convertColor('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Player-Count").replace("$int$", new DecimalFormat("#,###").format(proxy.getPlayers().size()))));
|
||||||
} else if (proxy.getSubData() != null) {
|
} else if (proxy.getSubData()[0] != null) {
|
||||||
message.color(TextColors.AQUA);
|
message.color(TextColors.AQUA);
|
||||||
hover.color(TextColors.AQUA);
|
hover.color(TextColors.AQUA);
|
||||||
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
if (!proxy.getName().equals(proxy.getDisplayName())) {
|
||||||
@ -521,11 +522,11 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
if (server.getGroups().size() > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":""))).toBuilder().append(Text.builder((server.getGroups().size() > 1)?"":server.getGroups().get(0)).color(TextColors.WHITE).build()).build());
|
if (server.getGroups().size() > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":""))).toBuilder().append(Text.builder((server.getGroups().size() > 1)?"":server.getGroups().get(0)).color(TextColors.WHITE).build()).build());
|
||||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(group).color(TextColors.WHITE).build()).build());
|
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(group).color(TextColors.WHITE).build()).build());
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build()).build());
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(server.getAddress().getAddress().getHostAddress()+':'+server.getAddress().getPort()).color(TextColors.WHITE).build()).build());
|
||||||
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).toBuilder().append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
|
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Port")).toBuilder().append(Text.builder(Integer.toString(server.getAddress().getPort())).color(TextColors.AQUA).build()).build());
|
||||||
if (server instanceof SubServer) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).toBuilder().append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.RED).build()).build());
|
if (server instanceof SubServer) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Running")).toBuilder().append(Text.builder((((SubServer) server).isRunning())?"yes":"no").color((((SubServer) server).isRunning())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||||
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
if (!(server instanceof SubServer) || ((SubServer) server).isRunning()) {
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((server.getSubData() != null)?"yes":"no").color((server.getSubData() != null)?TextColors.GREEN:TextColors.RED).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((server.getSubData()[0] != null)?"yes":"no").color((server.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((server.getSubData().length > 1)?" +"+(server.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(server.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(server.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||||
}
|
}
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD")).toBuilder().append(Text.builder(server.getMotd().replaceAll("\\u00A7[0-9a-fA-Fk-oK-ORr]", "")).color(TextColors.WHITE).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "MOTD")).toBuilder().append(Text.builder(server.getMotd().replaceAll("\\u00A7[0-9a-fA-Fk-oK-ORr]", "")).color(TextColors.WHITE).build()).build());
|
||||||
@ -567,8 +568,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(host.getName()).color(TextColors.WHITE).build()).build());
|
if (!host.getName().equals(host.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(host.getName()).color(TextColors.WHITE).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available")).toBuilder().append(Text.builder((host.isAvailable())?"yes":"no").color((host.isAvailable())?TextColors.GREEN:TextColors.RED).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available")).toBuilder().append(Text.builder((host.isAvailable())?"yes":"no").color((host.isAvailable())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((host.isEnabled())?"yes":"no").color((host.isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((host.isEnabled())?"yes":"no").color((host.isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||||
if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(host.getAddress().getHostAddress()).color(TextColors.WHITE).build()).build());
|
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Address")).toBuilder().append(Text.builder(host.getAddress().getHostAddress()).color(TextColors.WHITE).build()).build());
|
||||||
if (host.getSubData() != null) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder("yes").color(TextColors.GREEN).build()).build());
|
if (host.getSubData().length > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((host.getSubData()[0] != null)?"yes":"no").color((host.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((host.getSubData().length > 1)?" +"+(host.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers")).toBuilder().append(Text.builder((host.getSubServers().keySet().size() <= 0)?"(none)":Integer.toString(host.getSubServers().keySet().size())).color((host.getSubServers().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "SubServers")).toBuilder().append(Text.builder((host.getSubServers().keySet().size() <= 0)?"(none)":Integer.toString(host.getSubServers().keySet().size())).color((host.getSubServers().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
||||||
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')')).color((subserver.isEnabled())?TextColors.WHITE:TextColors.GRAY).build()).build());
|
for (SubServer subserver : host.getSubServers().values()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(subserver.getDisplayName() + ((subserver.getName().equals(subserver.getDisplayName()))?"":" ("+subserver.getName()+')')).color((subserver.isEnabled())?TextColors.WHITE:TextColors.GRAY).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates")).toBuilder().append(Text.builder((host.getCreator().getTemplates().keySet().size() <= 0)?"(none)":Integer.toString(host.getCreator().getTemplates().keySet().size())).color((host.getCreator().getTemplates().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Templates")).toBuilder().append(Text.builder((host.getCreator().getTemplates().keySet().size() <= 0)?"(none)":Integer.toString(host.getCreator().getTemplates().keySet().size())).color((host.getCreator().getTemplates().keySet().size() <= 0)?TextColors.GRAY:TextColors.AQUA).build()).build());
|
||||||
@ -586,7 +587,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
if (proxy != null) {
|
if (proxy != null) {
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy")).toBuilder().append(Text.builder(proxy.getDisplayName()).color(TextColors.WHITE).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", "Proxy")).toBuilder().append(Text.builder(proxy.getDisplayName()).color(TextColors.WHITE).build()).build());
|
||||||
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(proxy.getName()).color(TextColors.WHITE ).build()).build());
|
if (!proxy.getName().equals(proxy.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(proxy.getName()).color(TextColors.WHITE ).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData() != null)?"yes":"no").color((proxy.getSubData() != null)?TextColors.GREEN:TextColors.RED).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Connected")).toBuilder().append(Text.builder((proxy.getSubData()[0] != null)?"yes":"no").color((proxy.getSubData()[0] != null)?TextColors.GREEN:TextColors.RED).build(), Text.builder((proxy.getSubData().length > 1)?" +"+(proxy.getSubData().length-1):"").color(TextColors.AQUA).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") ).toBuilder().append(Text.builder(((proxy.isRedis())?"":"un") + "available").color((proxy.isRedis())?TextColors.GREEN:TextColors.RED).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Redis") ).toBuilder().append(Text.builder(((proxy.isRedis())?"":"un") + "available").color((proxy.isRedis())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||||
if (proxy.isRedis()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
if (proxy.isRedis()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Players")).toBuilder().append(Text.builder(proxy.getPlayers().size() + " online").color(TextColors.AQUA).build()).build());
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(proxy.getSignature()).color(TextColors.AQUA).build()).build());
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Signature")).toBuilder().append(Text.builder(proxy.getSignature()).color(TextColors.AQUA).build()).build());
|
||||||
@ -642,8 +643,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||||
if (subserver.isPresent()) {
|
if (subserver.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.subserver.start." + subserver.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.subserver.start." + subserver.get().toLowerCase())) {
|
||||||
plugin.subdata.sendPacket(new PacketStartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Unknown")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Unknown")));
|
||||||
break;
|
break;
|
||||||
@ -663,10 +664,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Running")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Running")));
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1])));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002))));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketStartServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ") responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start")));
|
||||||
@ -695,8 +694,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||||
if (subserver.isPresent()) {
|
if (subserver.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase()) && sender.hasPermission("subservers.subserver.start." + subserver.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase()) && sender.hasPermission("subservers.subserver.start." + subserver.get().toLowerCase())) {
|
||||||
Runnable starter = () -> plugin.subdata.sendPacket(new PacketStartServer(null, subserver.get(), data -> {
|
Runnable starter = () -> ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStartServer(null, subserver.get(), data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Disappeared")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Disappeared")));
|
||||||
@ -711,10 +710,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Server-Disabled")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Server-Disabled")));
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString("m").split(":\\s")[1])));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002))));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketStartServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ") responded with: " + data.getString("m"));
|
|
||||||
case 8:
|
case 8:
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@ -724,12 +721,12 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
final Container<Boolean> listening = new Container<Boolean>(true);
|
final Container<Boolean> listening = new Container<Boolean>(true);
|
||||||
PacketInRunEvent.callback("SubStoppedEvent", new Callback<YAMLSection>() {
|
PacketInExRunEvent.callback("SubStoppedEvent", new Callback<ObjectMap<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(YAMLSection json) {
|
public void run(ObjectMap<String> json) {
|
||||||
try {
|
try {
|
||||||
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(subserver.get())) {
|
if (listening.get()) if (!json.getString("server").equalsIgnoreCase(subserver.get())) {
|
||||||
PacketInRunEvent.callback("SubStoppedEvent", this);
|
PacketInExRunEvent.callback("SubStoppedEvent", this);
|
||||||
} else {
|
} else {
|
||||||
plugin.game.getScheduler().createTaskBuilder().execute(starter).delay(100, TimeUnit.MILLISECONDS).submit(plugin);
|
plugin.game.getScheduler().createTaskBuilder().execute(starter).delay(100, TimeUnit.MILLISECONDS).submit(plugin);
|
||||||
}
|
}
|
||||||
@ -737,9 +734,9 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Callback<YAMLSection> stopper = data -> {
|
Callback<ObjectMap<Integer>> stopper = data -> {
|
||||||
if (data.getInt("r") != 0) listening.set(false);
|
if (data.getInt(0x0001) != 0) listening.set(false);
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Unknown")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Unknown")));
|
||||||
break;
|
break;
|
||||||
@ -749,8 +746,6 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
case 5:
|
case 5:
|
||||||
starter.run();
|
starter.run();
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketStopServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", false) responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart")));
|
||||||
@ -758,11 +753,11 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (plugin.subdata.getName().equalsIgnoreCase(subserver.get())) {
|
if (SubAPI.getInstance().getName().equalsIgnoreCase(subserver.get())) {
|
||||||
listening.set(false);
|
listening.set(false);
|
||||||
plugin.subdata.sendPacket(new PacketRestartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), stopper));
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketRestartServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), stopper));
|
||||||
} else {
|
} else {
|
||||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), false, stopper));
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), false, stopper));
|
||||||
}
|
}
|
||||||
return CommandResult.builder().successCount(1).build();
|
return CommandResult.builder().successCount(1).build();
|
||||||
} else if (!sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase())) {
|
} else if (!sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase())) {
|
||||||
@ -789,8 +784,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||||
if (subserver.isPresent()) {
|
if (subserver.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.subserver.stop." + subserver.get().toLowerCase())) {
|
||||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player) ? ((Player) sender).getUniqueId():null, subserver.get(), false, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player) ? ((Player) sender).getUniqueId():null, subserver.get(), false, data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Unknown")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Unknown")));
|
||||||
break;
|
break;
|
||||||
@ -800,8 +795,6 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
case 5:
|
case 5:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Not-Running")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop.Not-Running")));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketStopServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", false) responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Stop")));
|
||||||
@ -830,8 +823,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||||
if (subserver.isPresent()) {
|
if (subserver.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.subserver.terminate." + subserver.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.subserver.terminate." + subserver.get().toLowerCase())) {
|
||||||
plugin.subdata.sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), true, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketStopServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), true, data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Unknown")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Unknown")));
|
||||||
break;
|
break;
|
||||||
@ -841,8 +834,6 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
case 5:
|
case 5:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Not-Running")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate.Not-Running")));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketStopServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", true) responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Terminate")));
|
||||||
@ -872,8 +863,8 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> command = args.getOne(Text.of("Command"));
|
Optional<String> command = args.getOne(Text.of("Command"));
|
||||||
if (subserver.isPresent() && command.isPresent()) {
|
if (subserver.isPresent() && command.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.subserver.command." + subserver.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.subserver.command." + subserver.get().toLowerCase())) {
|
||||||
plugin.subdata.sendPacket(new PacketCommandServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), command.get(), data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCommandServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), command.get(), data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Unknown")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Unknown")));
|
||||||
break;
|
break;
|
||||||
@ -883,8 +874,6 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
case 5:
|
case 5:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Not-Running")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command.Not-Running")));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketCommandServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + subserver.get() + ", /" + command.get() + ") responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Command")));
|
||||||
@ -915,14 +904,14 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
Optional<String> template = args.getOne(Text.of("Template"));
|
Optional<String> template = args.getOne(Text.of("Template"));
|
||||||
Optional<String> version = args.getOne(Text.of("Version"));
|
Optional<String> version = args.getOne(Text.of("Version"));
|
||||||
Optional<String> port = args.getOne(Text.of("Port"));
|
Optional<String> port = args.getOne(Text.of("Port"));
|
||||||
if (name.isPresent() && host.isPresent() && template.isPresent() && version.isPresent()) {
|
if (name.isPresent() && host.isPresent() && template.isPresent()) {
|
||||||
if (sender.hasPermission("subservers.host.create." + host.get().toLowerCase())) {
|
if (sender.hasPermission("subservers.host.create." + host.get().toLowerCase())) {
|
||||||
if (port.isPresent() && Util.isException(() -> Integer.parseInt(port.get()))) {
|
if (port.isPresent() && Util.isException(() -> Integer.parseInt(port.get()))) {
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
|
||||||
return CommandResult.builder().successCount(0).build();
|
return CommandResult.builder().successCount(0).build();
|
||||||
} else {
|
} else {
|
||||||
plugin.subdata.sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, name.get(), host.get(), template.get(), new Version(version.get()), (port.isPresent())?Integer.parseInt(port.get()):null, data -> {
|
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, name.get(), host.get(), template.get(), (version.isPresent() && version.get().length() > 0)?new Version(version.get()):null, (port.isPresent())?Integer.parseInt(port.get()):null, data -> {
|
||||||
switch (data.getInt("r")) {
|
switch (data.getInt(0x0001)) {
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Exists")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Exists")));
|
||||||
@ -943,13 +932,11 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Template-Disabled")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Template-Disabled")));
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Version")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Version-Required")));
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator.Invalid-Port")));
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
plugin.logger.warn("PacketCreateServer(" + ((sender instanceof Player)?((Player) sender).getUniqueId().toString():"null") + ", " + name.get() + ", " + host.get() + ", " + template.get() + ", " + version.get() + ", " + (port.orElse("null")) + ") responded with: " + data.getString("m"));
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator")));
|
||||||
@ -963,7 +950,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
return CommandResult.builder().successCount(0).build();
|
return CommandResult.builder().successCount(0).build();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")));
|
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub create <Name> <Host> <Template> [Version] [Port]")));
|
||||||
return CommandResult.builder().successCount(0).build();
|
return CommandResult.builder().successCount(0).build();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1048,7 +1035,7 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Stop").replace("$str$", "/sub stop <SubServer>")),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Stop").replace("$str$", "/sub stop <SubServer>")),
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <SubServer>")),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <SubServer>")),
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <SubServer> <Command> [Args...]")),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <SubServer> <Command> [Args...]")),
|
||||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> <Version> <Port>")),
|
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> [Version] [Port]")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,17 +2,19 @@ package net.ME1312.SubServers.Client.Sponge;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import net.ME1312.SubData.Client.Encryption.AES;
|
||||||
|
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||||
|
import net.ME1312.SubData.Client.SubDataClient;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
|
import net.ME1312.SubServers.Client.Sponge.Graphic.UIHandler;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLConfig;
|
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection;
|
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Metrics;
|
import net.ME1312.SubServers.Client.Sponge.Library.Metrics;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.NamedContainer;
|
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.UniversalFile;
|
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Util;
|
import net.ME1312.Galaxi.Library.Util;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
|
import net.ME1312.Galaxi.Library.Version.Version;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Library.Version.VersionType;
|
import net.ME1312.SubServers.Client.Sponge.Library.Updates.ConfigUpdater;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.Cipher;
|
import net.ME1312.SubServers.Client.Sponge.Network.SubProtocol;
|
||||||
import net.ME1312.SubServers.Client.Sponge.Network.SubDataClient;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongepowered.api.Game;
|
import org.spongepowered.api.Game;
|
||||||
@ -24,12 +26,7 @@ import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
|||||||
import org.spongepowered.api.event.game.state.GameStoppingEvent;
|
import org.spongepowered.api.event.game.state.GameStoppingEvent;
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -37,10 +34,7 @@ import java.net.URL;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,24 +42,29 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
||||||
public final class SubPlugin {
|
public final class SubPlugin {
|
||||||
|
protected HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||||
public YAMLConfig config;
|
public YAMLConfig config;
|
||||||
public SubDataClient subdata = null;
|
public SubProtocol subprotocol;
|
||||||
|
|
||||||
@ConfigDir(sharedRoot = false)
|
@ConfigDir(sharedRoot = false)
|
||||||
@Inject public File dir;
|
@Inject public File dir;
|
||||||
public Logger logger = LoggerFactory.getLogger("SubServers");
|
public Logger log = LoggerFactory.getLogger("SubServers");
|
||||||
public UIHandler gui = null;
|
public UIHandler gui = null;
|
||||||
public Version version;
|
public Version version;
|
||||||
public SubAPI api;
|
public SubAPI api;
|
||||||
@Inject public PluginContainer plugin;
|
@Inject public PluginContainer plugin;
|
||||||
@Inject public Game game;
|
@Inject public Game game;
|
||||||
|
|
||||||
|
private boolean reconnect = false;
|
||||||
|
private boolean scheduling = false;
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void setup(GamePreInitializationEvent event) {
|
public void setup(GamePreInitializationEvent event) {
|
||||||
if (plugin.getVersion().isPresent()) {
|
if (plugin.getVersion().isPresent()) {
|
||||||
version = Version.fromString(plugin.getVersion().get());
|
version = Version.fromString(plugin.getVersion().get());
|
||||||
} else version = new Version("Custom");
|
} else version = new Version("Custom");
|
||||||
|
subdata.put(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,33 +75,30 @@ public final class SubPlugin {
|
|||||||
public void enable(GameInitializationEvent event) {
|
public void enable(GameInitializationEvent event) {
|
||||||
api = new SubAPI(this);
|
api = new SubAPI(this);
|
||||||
try {
|
try {
|
||||||
logger.info("Loading SubServers.Client.Sponge v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion() + ")");
|
log.info("Loading SubServers.Client.Sponge v" + version.toString() + " Libraries (for Minecraft " + api.getGameVersion() + ")");
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
if (new UniversalFile(dir.getParentFile(), "SubServers-Client:config.yml").exists()) {
|
if (new UniversalFile(dir.getParentFile(), "SubServers-Client:config.yml").exists()) {
|
||||||
Files.move(new UniversalFile(dir.getParentFile(), "SubServers-Client:config.yml").toPath(), new UniversalFile(dir, "config.yml").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.move(new UniversalFile(dir.getParentFile(), "SubServers-Client:config.yml").toPath(), new UniversalFile(dir, "config.yml").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
Util.deleteDirectory(new UniversalFile(dir.getParentFile(), "SubServers-Client"));
|
Util.deleteDirectory(new UniversalFile(dir.getParentFile(), "SubServers-Client"));
|
||||||
}
|
}
|
||||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
ConfigUpdater.updateConfig(new UniversalFile(dir, "config.yml"));
|
||||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(dir, "config.yml").getPath());
|
|
||||||
logger.info("Created ./config/subservers-client-sponge/config.yml");
|
|
||||||
} else if (((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
|
||||||
Files.move(new UniversalFile(dir, "config.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
|
||||||
|
|
||||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(dir, "config.yml").getPath());
|
|
||||||
logger.info("Updated ./config/subservers-client-sponge/config.yml");
|
|
||||||
}
|
|
||||||
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
||||||
if (new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client").exists()) {
|
if (new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
|
||||||
FileReader reader = new FileReader(new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client"));
|
FileReader reader = new FileReader(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json"));
|
||||||
config.get().getSection("Settings").set("SubData", new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class)));
|
config.get().getMap("Settings").set("SubData", new ObjectMap<String>(new Gson().fromJson(Util.readAll(reader), Map.class)));
|
||||||
config.save();
|
config.save();
|
||||||
reader.close();
|
reader.close();
|
||||||
new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client").delete();
|
new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json").delete();
|
||||||
|
}
|
||||||
|
if (new UniversalFile(new File(System.getProperty("user.dir")), "subdata.rsa.key").exists()) {
|
||||||
|
Files.move(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheduling = true;
|
||||||
|
subprotocol = SubProtocol.get();
|
||||||
reload(false);
|
reload(false);
|
||||||
|
|
||||||
if (config.get().getSection("Settings").getBoolean("Ingame-Access", true)) {
|
if (!config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
|
||||||
//gui = new InternalUIHandler(this);
|
//gui = new InternalUIHandler(this);
|
||||||
Sponge.getCommandManager().register(plugin, new SubCommand(this).spec(), "sub", "subserver", "subservers");
|
Sponge.getCommandManager().register(plugin, new SubCommand(this).spec(), "sub", "subserver", "subservers");
|
||||||
}
|
}
|
||||||
@ -110,12 +106,12 @@ public final class SubPlugin {
|
|||||||
new Metrics(this);
|
new Metrics(this);
|
||||||
game.getScheduler().createTaskBuilder().async().execute(() -> {
|
game.getScheduler().createTaskBuilder().async().execute(() -> {
|
||||||
try {
|
try {
|
||||||
YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
ObjectMap<String> tags = new ObjectMap<String>(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||||
List<Version> versions = new LinkedList<Version>();
|
List<Version> versions = new LinkedList<Version>();
|
||||||
|
|
||||||
Version updversion = version;
|
Version updversion = version;
|
||||||
int updcount = 0;
|
int updcount = 0;
|
||||||
for (YAMLSection tag : tags.getSectionList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
for (ObjectMap<String> tag : tags.getMapList("tags")) versions.add(Version.fromString(tag.getString("ref").substring(10)));
|
||||||
Collections.sort(versions);
|
Collections.sort(versions);
|
||||||
for (Version version : versions) {
|
for (Version version : versions) {
|
||||||
if (version.compareTo(updversion) > 0) {
|
if (version.compareTo(updversion) > 0) {
|
||||||
@ -123,7 +119,7 @@ public final class SubPlugin {
|
|||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updcount > 0) logger.info("SubServers.Client.Sponge v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
if (updcount > 0) log.info("SubServers.Client.Sponge v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}).delay(0, TimeUnit.MILLISECONDS).interval(2, TimeUnit.DAYS).submit(plugin);
|
}).delay(0, TimeUnit.MILLISECONDS).interval(2, TimeUnit.DAYS).submit(plugin);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -131,25 +127,50 @@ public final class SubPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload(boolean notifyPlugins) throws IOException {
|
|
||||||
if (subdata != null)
|
|
||||||
subdata.destroy(0);
|
|
||||||
|
|
||||||
|
|
||||||
|
public void reload(boolean notifyPlugins) throws IOException {
|
||||||
|
reconnect = false;
|
||||||
|
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
|
||||||
|
tmp.addAll(subdata.values());
|
||||||
|
for (SubDataClient client : tmp) if (client != null) {
|
||||||
|
client.close();
|
||||||
|
Util.isException(client::waitFor);
|
||||||
|
}
|
||||||
|
subdata.clear();
|
||||||
|
subdata.put(0, null);
|
||||||
|
|
||||||
|
ConfigUpdater.updateConfig(new UniversalFile(dir, "config.yml"));
|
||||||
config.reload();
|
config.reload();
|
||||||
|
|
||||||
Cipher cipher = null;
|
subprotocol.unregisterCipher("AES");
|
||||||
if (!config.get().getSection("Settings").getSection("SubData").getRawString("Encryption", "NONE").equalsIgnoreCase("NONE")) {
|
subprotocol.unregisterCipher("AES-128");
|
||||||
if (config.get().getSection("Settings").getSection("SubData").getString("Password", "").length() == 0) {
|
subprotocol.unregisterCipher("AES-192");
|
||||||
logger.info("Cannot encrypt connection without a password");
|
subprotocol.unregisterCipher("AES-256");
|
||||||
} else if (!SubDataClient.getCiphers().keySet().contains(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption").toUpperCase().replace('-', '_').replace(' ', '_'))) {
|
subprotocol.unregisterCipher("RSA");
|
||||||
logger.info("Unknown encryption type: " + config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
api.name = config.get().getMap("Settings").getMap("SubData").getString("Name", null);
|
||||||
} else {
|
Logger log = LoggerFactory.getLogger("SubData");
|
||||||
cipher = SubDataClient.getCipher(config.get().getSection("Settings").getSection("SubData").getRawString("Encryption"));
|
|
||||||
|
if (config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) {
|
||||||
|
subprotocol.registerCipher("AES", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||||
|
subprotocol.registerCipher("AES-128", new AES(128, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||||
|
subprotocol.registerCipher("AES-192", new AES(192, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||||
|
subprotocol.registerCipher("AES-256", new AES(256, config.get().getMap("Settings").getMap("SubData").getRawString("Password")));
|
||||||
|
|
||||||
|
log.info("AES Encryption Available");
|
||||||
|
}
|
||||||
|
if (new UniversalFile(dir, "subdata.rsa.key").exists()) {
|
||||||
|
try {
|
||||||
|
subprotocol.registerCipher("RSA", new RSA(new UniversalFile(dir, "subdata.rsa.key")));
|
||||||
|
log.info("RSA Encryption Available");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subdata = new SubDataClient(this, config.get().getSection("Settings").getSection("SubData").getString("Name", null),
|
|
||||||
InetAddress.getByName(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
|
reconnect = true;
|
||||||
Integer.parseInt(config.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]), cipher);
|
log.info(" ");
|
||||||
|
connect();
|
||||||
|
|
||||||
if (notifyPlugins) {
|
if (notifyPlugins) {
|
||||||
List<Runnable> listeners = api.reloadListeners;
|
List<Runnable> listeners = api.reloadListeners;
|
||||||
@ -165,14 +186,29 @@ public final class SubPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void connect() throws IOException {
|
||||||
|
subdata.put(0, subprotocol.open((config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0].equals("0.0.0.0"))?null:InetAddress.getByName(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[0]),
|
||||||
|
Integer.parseInt(config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").split(":")[1])));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable Plugin
|
* Disable Plugin
|
||||||
*/
|
*/
|
||||||
@Listener
|
@Listener
|
||||||
public void disable(GameStoppingEvent event) {
|
public void disable(GameStoppingEvent event) {
|
||||||
|
scheduling = false;
|
||||||
if (subdata != null) try {
|
if (subdata != null) try {
|
||||||
subdata.destroy(0);
|
reconnect = false;
|
||||||
} catch (IOException e) {
|
|
||||||
|
ArrayList<SubDataClient> temp = new ArrayList<SubDataClient>();
|
||||||
|
temp.addAll(subdata.values());
|
||||||
|
for (SubDataClient client : temp) if (client != null) {
|
||||||
|
client.close();
|
||||||
|
client.waitFor();
|
||||||
|
}
|
||||||
|
subdata.clear();
|
||||||
|
subdata.put(0, null);
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
pom.xml
2
pom.xml
@ -10,9 +10,9 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>SubServers.Client</module>
|
<module>SubServers.Client</module>
|
||||||
<module>SubServers.Bungee</module>
|
<module>SubServers.Bungee</module>
|
||||||
|
<module>SubServers.Console</module>
|
||||||
<module>SubServers.Host</module>
|
<module>SubServers.Host</module>
|
||||||
<module>SubServers.Sync</module>
|
<module>SubServers.Sync</module>
|
||||||
<module>SubServers.Console</module>
|
|
||||||
<module>SubServers.Test</module>
|
<module>SubServers.Test</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
Loading…
Reference in New Issue
Block a user