General Fixes & Module Updates

This commit is contained in:
ME1312 2019-05-11 17:23:31 -04:00
parent 2a939117ac
commit 7059b5cad7
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
20 changed files with 441 additions and 60 deletions

View File

@ -36,7 +36,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Server</artifactId>
<version>19w19d</version>
<version>19w19f</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -469,7 +469,7 @@ public class InternalSubCreator extends SubCreator {
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
config.set("Name", name);
config.set("Address", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1").replace("0.0.0.0", "127.0.0.1"));
config.set("Password", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password", ""));
if (host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password", "").length() > 0) config.set("Password", host.plugin.config.get().getMap("Settings").getMap("SubData").getRawString("Password"));
writer.write(config.toJSON().toString());
writer.close();

View File

@ -25,15 +25,16 @@ public class ConfigUpdater {
*/
public static void updateConfig(File file) throws IOException {
YAMLConfig config = new YAMLConfig(file);
YAMLSection updated = config.get().clone();
YAMLSection existing = config.get().clone();
YAMLSection updated = existing.clone();
YAMLSection rewritten = new YAMLSection();
Version was = updated.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version now = SubAPI.getInstance().getWrapperBuild();
int i = 0;
if (now == null) now = UNSIGNED;
if (!updated.contains("Settings") || !updated.getMap("Settings").contains("Version")) {
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
YAMLSection hosts = new YAMLSection();
YAMLSection host = new YAMLSection();
host.set("Enabled", true);
@ -45,27 +46,29 @@ public class ConfigUpdater {
System.out.println("SubServers > Created ./SubServers/config.yml");
} else {
if (was.compareTo(new Version("19w17a")) <= 0) {
if (updated.getMap("Settings", new YAMLSection()).contains("Log-Creator")) for (String name : updated.getMap("Hosts", new YAMLSection()).getKeys())
updated.getMap("Hosts").getMap(name).safeSet("Log-Creator", updated.getMap("Settings").getBoolean("Log-Creator"));
if (existing.getMap("Settings", new YAMLSection()).contains("Log-Creator")) for (String name : existing.getMap("Hosts", new YAMLSection()).getKeys())
updated.getMap("Hosts").getMap(name).safeSet("Log-Creator", existing.getMap("Settings").getBoolean("Log-Creator"));
if (updated.getMap("Settings", new YAMLSection()).contains("SubData") && !updated.getMap("Settings", new YAMLSection()).getMap("SubData").contains("Encryption"))
if (existing.getMap("Settings", new YAMLSection()).contains("SubData") && !existing.getMap("Settings", new YAMLSection()).getMap("SubData").contains("Encryption"))
updated.getMap("Settings").getMap("SubData").set("Encryption", "NONE");
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Allowed-Connections"))
updated.getMap("Settings").getMap("SubData").safeSet("Whitelist", updated.getMap("Settings").getMap("SubData").getRawStringList("Allowed-Connections"));
if (existing.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Allowed-Connections"))
updated.getMap("Settings").getMap("SubData").safeSet("Whitelist", existing.getMap("Settings").getMap("SubData").getRawStringList("Allowed-Connections"));
if (updated.contains("Servers")) {
if (existing.contains("Servers")) {
YAMLConfig sc = new YAMLConfig(new File(file.getParentFile(), "servers.yml"));
YAMLSection settings = new YAMLSection();
settings.set("Version", was.toString());
settings.set("Run-On-Launch-Timeout", (updated.getMap("Settings", new YAMLSection()).contains("Run-On-Launch-Timeout"))?updated.getMap("Settings").getInt("Run-On-Launch-Timeout"):0);
settings.set("Run-On-Launch-Timeout", (existing.getMap("Settings", new YAMLSection()).contains("Run-On-Launch-Timeout"))?existing.getMap("Settings").getInt("Run-On-Launch-Timeout"):0);
sc.get().safeSet("Settings", settings);
sc.get().safeSet("Servers", new YAMLSection());
sc.get().getMap("Servers").safeSetAll(updated.getMap("Servers"));
sc.get().getMap("Servers").safeSetAll(existing.getMap("Servers"));
System.out.println("SubServers > Created ./SubServers/servers.yml (using existing data)");
sc.save();
}
existing = updated.clone();
i++;
}// if (was.compareTo(new Version("99w99a")) <= 0) {
// // do something
@ -88,7 +91,7 @@ public class ConfigUpdater {
YAMLSection subdata = new YAMLSection();
subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Address", "127.0.0.1:4391"));
subdata.set("Password", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Password", ""));
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Password")) subdata.set("Password", updated.getMap("Settings").getMap("SubData").getRawString("Password"));
subdata.set("Encryption", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Encryption", "RSA/AES"));
subdata.set("Whitelist", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawStringList("Whitelist", Collections.emptyList()));
settings.set("SubData", subdata);
@ -124,15 +127,16 @@ public class ConfigUpdater {
*/
public static void updateServers(File file) throws IOException {
YAMLConfig config = new YAMLConfig(file);
YAMLSection updated = config.get().clone();
YAMLSection existing = config.get().clone();
YAMLSection updated = existing.clone();
YAMLSection rewritten = new YAMLSection();
Version was = updated.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version now = SubAPI.getInstance().getWrapperBuild();
int i = 0;
if (now == null) now = UNSIGNED;
if (!updated.contains("Settings") || !updated.getMap("Settings").contains("Version")) {
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
YAMLSection servers = new YAMLSection();
servers.set("Example", new YAMLSection());
updated.set("Servers", servers);
@ -141,11 +145,11 @@ public class ConfigUpdater {
System.out.println("SubServers > Created ./SubServers/servers.yml");
} else {
if (was.compareTo(new Version("19w17a")) <= 0) {
for (String name : updated.getMap("Servers", new YAMLSection()).getKeys()) {
if (updated.getMap("Servers").getMap(name).getBoolean("Auto-Restart", true))
for (String name : existing.getMap("Servers", new YAMLSection()).getKeys()) {
if (existing.getMap("Servers").getMap(name).getBoolean("Auto-Restart", true))
updated.getMap("Servers").getMap(name).safeSet("Stop-Action", "RESTART");
if (updated.getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").equalsIgnoreCase("DELETE_SERVER"))
if (existing.getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").equalsIgnoreCase("DELETE_SERVER"))
updated.getMap("Servers").getMap(name).set("Stop-Action", "RECYCLE_SERVER");
}
i++;
@ -201,15 +205,16 @@ public class ConfigUpdater {
*/
public static void updateLang(File file) throws IOException {
YAMLConfig config = new YAMLConfig(file);
YAMLSection updated = config.get().clone();
YAMLSection existing = config.get().clone();
YAMLSection updated = existing.clone();
YAMLSection rewritten = new YAMLSection();
Version was = updated.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version was = existing.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
Version now = SubAPI.getInstance().getWrapperBuild();
int i = 0;
if (now == null) now = UNSIGNED;
if (!updated.contains("Settings") || !updated.getMap("Settings").contains("Version")) {
if (!existing.contains("Settings") || !existing.getMap("Settings").contains("Version")) {
i++;
System.out.println("SubServers > Created ./SubServers/lang.yml");

View File

@ -0,0 +1,66 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.ProxyServer;
import java.util.UUID;
/**
* Check Permission Packet
*/
public class PacketCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private boolean result;
private UUID tracker;
/**
* New PacketCheckPermission (In)
*/
public PacketCheckPermission() {}
/**
* New PacketCheckPermission (Out)
*
* @param player Player to check on
* @param permission Permission to check
* @param tracker Receiver ID
*/
public PacketCheckPermission(UUID player, String permission, UUID tracker) {
this(Util.getDespiteException(() -> ProxyServer.getInstance().getPlayer(player).hasPermission(permission), false), tracker);
}
PacketCheckPermission(boolean result, UUID tracker) {
this.result = result;
this.tracker = tracker;
}
@Override
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, result);
return data;
}
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
Server server = data.contains(0x0003)?SubAPI.getInstance().getServer(data.getRawString(0x0003)):null;
if (server != null && server.getSubData()[0] != null) {
((SubDataClient) server.getSubData()[0]).sendPacket(new PacketExCheckPermission(data.getUUID(0x0001), data.getRawString(0x0002), result -> {
client.sendPacket(new PacketCheckPermission(result, (data.contains(0x0000))?data.getUUID(0x0000):null));
}));
} else {
client.sendPacket(new PacketCheckPermission(data.getUUID(0x0001), data.getRawString(0x0002), (data.contains(0x0000))?data.getUUID(0x0000):null));
}
}
@Override
public int version() {
return 0x0001;
}
}

View File

@ -0,0 +1,61 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.UUID;
/**
* Packet Check Permission
*/
public class PacketExCheckPermission implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private static HashMap<UUID, Callback<Boolean>[]> callbacks = new HashMap<UUID, Callback<Boolean>[]>();
private UUID player;
private String permission;
private UUID tracker;
/**
* New PacketCheckPermission (In)
*/
public PacketExCheckPermission() {}
/**
* New PacketCheckPermission (Out)
*
* @param player Player to check on
* @param permission Permission to check
* @param callback Callbacks
*/
@SafeVarargs
public PacketExCheckPermission(UUID player, String permission, Callback<Boolean>... callback) {
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);
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;
}
}

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.External.ExternalHost;
import net.ME1312.SubServers.Bungee.Host.Host;
@ -17,7 +18,7 @@ import java.util.Map;
/**
* Link External Host Packet
*/
public class PacketLinkExHost implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
public class PacketLinkExHost implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubPlugin plugin;
private int response;
@ -60,6 +61,7 @@ public class PacketLinkExHost implements PacketObjectIn<Integer>, PacketObjectOu
((ExternalHost) host).setSubData(client, channel);
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Host: " + host.getName() + ((channel > 0)?" (Sub "+channel+")":""));
client.sendPacket(new PacketLinkExHost(0));
setReady(client, true);
} else {
client.sendPacket(new PacketLinkExHost(3));
}
@ -69,7 +71,7 @@ public class PacketLinkExHost implements PacketObjectIn<Integer>, PacketObjectOu
} else {
client.sendPacket(new PacketLinkExHost(2));
}
} catch (Exception e) {
} catch (Throwable e) {
client.sendPacket(new PacketLinkExHost(1));
e.printStackTrace();
}

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
import net.ME1312.SubServers.Bungee.Event.SubAddProxyEvent;
import net.ME1312.SubServers.Bungee.Host.Proxy;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
@ -17,7 +18,7 @@ import java.util.Map;
/**
* Link Proxy Packet
*/
public class PacketLinkProxy implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
public class PacketLinkProxy implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubPlugin plugin;
private int response;
private String name;
@ -70,11 +71,12 @@ public class PacketLinkProxy implements PacketObjectIn<Integer>, PacketObjectOut
proxy.setSubData(client, channel);
System.out.println("SubData > " + client.getAddress().toString() + " has been defined as Proxy: " + proxy.getName() + ((channel > 0)?" (Sub "+channel+")":""));
client.sendPacket(new PacketLinkProxy(proxy.getName(), 0));
setReady(client, true);
} else {
client.sendPacket(new PacketLinkProxy(proxy.getName(), 2));
}
} catch (Exception e) {
} catch (Throwable e) {
client.sendPacket(new PacketLinkProxy(null, 1));
e.printStackTrace();
}

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Network.Packet;
import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.Server;
import net.ME1312.SubServers.Bungee.Host.ServerContainer;
@ -18,7 +19,7 @@ import java.util.Map;
/**
* Link Server Packet
*/
public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubPlugin plugin;
private int response;
private String message;
@ -89,13 +90,13 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
} else {
client.sendPacket(new PacketLinkServer(null, 2, e.getMessage()));
}
} catch (Exception e) {
} catch (Throwable e) {
client.sendPacket(new PacketLinkServer(null, 1, null));
e.printStackTrace();
}
}
private void link(SubDataClient client, Server server, int channel) {
private void link(SubDataClient client, Server server, int channel) throws Throwable {
HashMap<Integer, SubDataClient> subdata = Util.getDespiteException(() -> Util.reflect(ServerContainer.class.getDeclaredField("subdata"), server), null);
if (!subdata.keySet().contains(channel) || (channel == 0 && subdata.get(0) == null)) {
server.setSubData(client, channel);
@ -106,6 +107,7 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
} else {
client.sendPacket(new PacketLinkServer(server.getName(), 0, null));
}
setReady(client, true);
} else {
client.sendPacket(new PacketLinkServer(null, 4, "Server already linked"));
}

View File

@ -72,6 +72,7 @@ public class SubProtocol extends SubDataProtocol {
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(plugin));
@ -80,6 +81,7 @@ public class SubProtocol extends SubDataProtocol {
instance.registerPacket(0x0014, new PacketDownloadGroupInfo(plugin));
instance.registerPacket(0x0015, new PacketDownloadServerInfo(plugin));
instance.registerPacket(0x0016, new PacketDownloadPlayerList(plugin));
instance.registerPacket(0x0017, new PacketCheckPermission());
// 30-49: Control Packets
@ -131,11 +133,13 @@ public class SubProtocol extends SubDataProtocol {
instance.registerPacket(0x0071, PacketOutExReset.class);
instance.registerPacket(0x0072, PacketOutExReload.class);
instance.registerPacket(0x0073, PacketOutExUpdateWhitelist.class);
instance.registerPacket(0x0074, PacketExCheckPermission.class);
//instance.registerPacket(0x0070, new PacketOutRunEvent());
//instance.registerPacket(0x0071, new PacketOutReset());
//instance.registerPacket(0x0072, new PacketOutReload());
//instance.registerPacket(0x0073, new PacketOutExUpdateWhitelist());
instance.registerPacket(0x0074, new PacketExCheckPermission());
}
return instance;

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee;
import com.google.gson.Gson;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.SubServers.Bungee.Library.Compatibility.CommandX;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
@ -8,11 +9,13 @@ import net.ME1312.Galaxi.Library.NamedContainer;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExCheckPermission;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.command.ConsoleCommandSender;
@ -23,12 +26,14 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* Plugin Command Class
*/
@SuppressWarnings("deprecation")
public final class SubCommand extends CommandX {
static HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>> players = new HashMap<UUID, HashMap<ServerInfo, NamedContainer<Long, Boolean>>>();
private SubPlugin plugin;
private String label;
@ -637,7 +642,29 @@ public final class SubCommand extends CommandX {
*/
public NamedContainer<String, List<String>> suggestArguments(CommandSender sender, String[] args) {
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
if (args.length <= 1) {
if (sender instanceof ProxiedPlayer && (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| !players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).get())) {
if (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) && players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
&& players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() == null) {
// do nothing
} else if (!players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()) || !players.get(((ProxiedPlayer) sender).getUniqueId()).keySet().contains(((ProxiedPlayer) sender).getServer().getInfo())
|| Calendar.getInstance().getTime().getTime() - players.get(((ProxiedPlayer) sender).getUniqueId()).get(((ProxiedPlayer) sender).getServer().getInfo()).name() >= TimeUnit.MINUTES.toMillis(1)) {
if (!(((ProxiedPlayer) sender).getServer().getInfo() instanceof Server) || ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0] == null) {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
} else {
HashMap<ServerInfo, NamedContainer<Long, Boolean>> map = (players.keySet().contains(((ProxiedPlayer) sender).getUniqueId()))?players.get(((ProxiedPlayer) sender).getUniqueId()):new HashMap<ServerInfo, NamedContainer<Long, Boolean>>();
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(null, false));
players.put(((ProxiedPlayer) sender).getUniqueId(), map);
((SubDataClient) ((Server) ((ProxiedPlayer) sender).getServer().getInfo()).getSubData()[0]).sendPacket(new PacketExCheckPermission(((ProxiedPlayer) sender).getUniqueId(), "subservers.command", result -> {
map.put(((ProxiedPlayer) sender).getServer().getInfo(), new NamedContainer<>(Calendar.getInstance().getTime().getTime(), result));
}));
}
}
return new NamedContainer<>(null, Collections.emptyList());
} else if (args.length <= 1) {
List<String> cmds = new ArrayList<>();
cmds.addAll(Arrays.asList("help", "list", "info", "status", "version", "start", "stop", "restart", "kill", "terminate", "cmd", "command", "create"));
if (!(sender instanceof ProxiedPlayer)) cmds.addAll(Arrays.asList("reload", "sudo", "screen", "delete"));

View File

@ -869,6 +869,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
@EventHandler(priority = Byte.MIN_VALUE)
public void resetLimbo(PlayerDisconnectEvent e) {
fallbackLimbo.remove(e.getPlayer().getUniqueId());
SubCommand.players.remove(e.getPlayer().getUniqueId());
}
@EventHandler(priority = Byte.MIN_VALUE)

View File

@ -54,7 +54,7 @@
<dependency>
<groupId>net.ME1312.SubData</groupId>
<artifactId>Client</artifactId>
<version>19w19d</version>
<version>19w19f</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -104,7 +104,6 @@
<configuration>
<tasks>
<mkdir dir="${project.build.directory}" />
<copy file="${basedir}/../config.yml" todir="${project.build.directory}/classes" />
<copy file="${basedir}/../../LICENSE" todir="${project.build.directory}/classes" />
</tasks>
</configuration>

View File

@ -0,0 +1,75 @@
package net.ME1312.SubServers.Client.Bukkit.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.Bukkit.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 ./plugins/SubServers-Client-Bukkit/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 ./plugins/SubServers-Client-Bukkit/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();
}
}
}

View File

@ -0,0 +1,77 @@
package net.ME1312.SubServers.Client.Bukkit.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;
}
}

View File

@ -0,0 +1,55 @@
package net.ME1312.SubServers.Client.Bukkit.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.bukkit.Bukkit;
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;
}
@Override
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, Util.getDespiteException(() -> Bukkit.getServer().getPlayer(player).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;
}
}

View File

@ -26,11 +26,13 @@ public class PacketInExReload implements PacketObjectIn<Integer> {
public void receive(SubDataClient client, ObjectMap<Integer> data) {
if (data != null && data.contains(0x0000)) Bukkit.getLogger().warning("SubData > Received request for a plugin reload: " + data.getString(0x0000));
else Bukkit.getLogger().warning("SubData > Received request for a plugin reload");
try {
plugin.reload(true);
} catch (Exception e) {
e.printStackTrace();
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try {
plugin.reload(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
@Override

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Client.Protocol.Initial.InitialPacket;
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
import net.ME1312.SubData.Client.SubDataClient;
@ -13,7 +14,7 @@ import org.bukkit.Bukkit;
/**
* Link Server Packet
*/
public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
public class PacketLinkServer implements InitialPacket, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
private SubPlugin plugin;
private int channel;
@ -53,12 +54,11 @@ public class PacketLinkServer implements PacketObjectIn<Integer>, PacketObjectOu
try {
if (data.contains(0x0000)) {
Util.reflect(SubAPI.class.getDeclaredField("name"), plugin.api, data.getRawString(0x0000));
setReady(client, true);
}
if (SubAPI.getInstance().getSubDataNetwork()[0] == client) {
client.sendPacket(new PacketDownloadLang());
Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent(client));
}
} catch (Exception e) {}
} catch (Throwable e) {
e.printStackTrace();
}
} else {
Bukkit.getLogger().info("SubData > Could not link name with server" + ((data.contains(0x0002))?": "+data.getRawString(0x0002):'.'));
try {

View File

@ -6,6 +6,7 @@ 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.Bukkit.Event.SubNetworkConnectEvent;
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkDisconnectEvent;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
@ -75,6 +76,7 @@ public class SubProtocol extends SubDataProtocol {
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());
@ -83,6 +85,7 @@ public class SubProtocol extends SubDataProtocol {
instance.registerPacket(0x0014, new PacketDownloadGroupInfo());
instance.registerPacket(0x0015, new PacketDownloadServerInfo());
instance.registerPacket(0x0016, new PacketDownloadPlayerList());
instance.registerPacket(0x0017, new PacketCheckPermission());
// 30-49: Control Packets
@ -111,17 +114,19 @@ public class SubProtocol extends SubDataProtocol {
//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 openChannel(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
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);
@ -131,7 +136,7 @@ public class SubProtocol extends SubDataProtocol {
final int fc = channel;
map.put(fc, subdata);
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin, fc)));
subdata.sendPacket(new PacketLinkServer(plugin, fc));
subdata.on.closed(client -> map.remove(fc));
return subdata;
@ -144,7 +149,9 @@ public class SubProtocol extends SubDataProtocol {
SubDataClient subdata = super.open(scheduler, logger, address, port);
HashMap<Integer, SubDataClient> map = Util.getDespiteException(() -> Util.reflect(SubPlugin.class.getDeclaredField("subdata"), plugin), null);
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin, 0)));
subdata.sendPacket(new PacketLinkServer(plugin, 0));
subdata.sendPacket(new PacketDownloadLang());
subdata.on.ready(client -> Bukkit.getPluginManager().callEvent(new SubNetworkConnectEvent((SubDataClient) client)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);

View File

@ -584,7 +584,7 @@ public final class SubCommand extends BukkitCommand {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + args[2].toLowerCase()));
}
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] <Port>"));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]"));
}
} else if ((args[0].equalsIgnoreCase("view") || args[0].equalsIgnoreCase("open")) && sender instanceof Player) {
if (plugin.gui != null) {

View File

@ -14,6 +14,7 @@ import net.ME1312.Galaxi.Library.UniversalFile;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubServers.Client.Bukkit.Library.Updates.ConfigUpdater;
import net.ME1312.SubServers.Client.Bukkit.Network.SubProtocol;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandMap;
@ -63,15 +64,7 @@ public final class SubPlugin extends JavaPlugin {
Files.move(new UniversalFile(getDataFolder().getParentFile(), "SubServers-Client:config.yml").toPath(), new UniversalFile(getDataFolder(), "config.yml").toPath(), StandardCopyOption.REPLACE_EXISTING);
Util.deleteDirectory(new UniversalFile(getDataFolder().getParentFile(), "SubServers-Client"));
}
if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
Bukkit.getLogger().info("SubServers > Created ./plugins/SubServers-Client-Bukkit/config.yml");
} else if (((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getMap("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
Bukkit.getLogger().info("SubServers > Updated .plugins/SubServers-Client-Bukkit/config.yml");
}
ConfigUpdater.updateConfig(new UniversalFile(getDataFolder(), "config.yml"));
config = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
if (new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
FileReader reader = new FileReader(new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json"));
@ -87,7 +80,7 @@ public final class SubPlugin extends JavaPlugin {
subprotocol = SubProtocol.get();
reload(false);
if (config.get().getMap("Settings").getBoolean("Ingame-Access", true)) {
if (!config.get().getMap("Settings").getBoolean("API-Only-Mode", false)) {
CommandMap cmd = Util.reflect(Bukkit.getServer().getClass().getDeclaredField("commandMap"), Bukkit.getServer());
gui = new DefaultUIHandler(this);
@ -124,12 +117,14 @@ public final class SubPlugin extends JavaPlugin {
reconnect = false;
ArrayList<SubDataClient> tmp = new ArrayList<SubDataClient>();
tmp.addAll(subdata.values());
for (SubDataClient client : tmp) {
for (SubDataClient client : tmp) if (client != null) {
client.close();
Util.isException(client::waitFor);
}
subdata.clear();
subdata.put(0, null);
ConfigUpdater.updateConfig(new UniversalFile(getDataFolder(), "config.yml"));
config.reload();
subprotocol.unregisterCipher("AES");
@ -190,11 +185,12 @@ public final class SubPlugin extends JavaPlugin {
ArrayList<SubDataClient> temp = new ArrayList<SubDataClient>();
temp.addAll(subdata.values());
for (SubDataClient client : temp) {
for (SubDataClient client : temp) if (client != null) {
client.close();
client.waitFor();
}
subdata.clear();
subdata.put(0, null);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}