Add Version support to YAMLConfig

This commit is contained in:
ME1312 2019-01-17 12:44:47 -05:00
parent 8b77434ccf
commit fcde0bc845
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
30 changed files with 326 additions and 40 deletions

View File

@ -101,7 +101,10 @@ public class ExternalSubCreator extends SubCreator {
YAMLSection server = new YAMLSection();
YAMLSection config = new YAMLSection((Map<String, ?>) convert(data.getSection("c").get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")), new NamedContainer<>("$port$", Integer.toString(fport))));
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
new NamedContainer<>("$address$", data.getSection("c").getRawString("\033address", "null")), new NamedContainer<>("$port$", Integer.toString(fport))));
config.remove("\033address");
server.set("Enabled", true);
server.set("Display", "");

View File

@ -192,8 +192,9 @@ public class InternalSubCreator extends SubCreator {
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
host.plugin.exServers.remove(name.toLowerCase());
config = new YAMLSection((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name), new NamedContainer<>("$template$", template.getName()),
new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")), new NamedContainer<>("$port$", Integer.toString(port))));
config = new YAMLSection((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
new NamedContainer<>("$address$", host.getAddress().getHostAddress()), new NamedContainer<>("$port$", Integer.toString(port))));
server.set("Enabled", true);
server.set("Display", "");

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Bungee.Library.Config;
import com.google.gson.Gson;
import net.ME1312.SubServers.Bungee.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Version.Version;
import org.msgpack.value.MapValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
@ -211,6 +212,8 @@ public class YAMLSection {
return list;
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof Version) {
return ((Version) value).toFullString();
} else {
return value;
}
@ -958,6 +961,48 @@ public class YAMLSection {
return get(handle, def).asUUIDList();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @return Version
*/
public Version getVersion(String handle) {
return get(handle).asVersion();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @param def Default
* @return Version
*/
public Version getVersion(String handle, Version def) {
return get(handle, def).asVersion();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @return Version List
*/
public List<Version> getVersionList(String handle) {
return get(handle).asVersionList();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @param def Default
* @return Version List
*/
public List<Version> getVersionList(String handle, List<Version> def) {
return get(handle, def).asVersionList();
}
/**
* Check if object is Null by Handle
*

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Bungee.Library.Config;
import net.ME1312.SubServers.Bungee.Library.Util;
import net.ME1312.SubServers.Bungee.Library.Version.Version;
import net.md_5.bungee.api.ChatColor;
import org.yaml.snakeyaml.Yaml;
@ -268,7 +269,7 @@ public class YAMLValue {
* @return UUID
*/
public UUID asUUID() {
if (obj != null) return UUID.fromString((String) obj);
if (obj != null) return UUID.fromString(asRawString());
else return null;
}
@ -287,6 +288,30 @@ public class YAMLValue {
} 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
@ -348,7 +373,7 @@ public class YAMLValue {
* @return UUID Status
*/
public boolean isUUID() {
return (obj instanceof String && !Util.isException(() -> UUID.fromString((String) obj)));
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
}
@Override

View File

@ -68,12 +68,12 @@ public class PacketCreateServer implements PacketIn, PacketOut {
client.sendPacket(new PacketCreateServer(8, "There is no template with that name", (data.contains("id")) ? data.getRawString("id") : null));
} else if (!plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")).isEnabled()) {
client.sendPacket(new PacketCreateServer(8, "That Template is not enabled", (data.contains("id")) ? data.getRawString("id") : null));
} else if (new Version("1.8").compareTo(new Version(data.getSection("creator").getString("version"))) > 0) {
} else if (new Version("1.8").compareTo(data.getSection("creator").getVersion("version")) > 0) {
client.sendPacket(new PacketCreateServer(10, "SubCreator cannot create servers before Minecraft 1.8", (data.contains("id")) ? data.getRawString("id") : null));
} else if (data.getSection("creator").contains("port") && (data.getSection("creator").getInt("port") <= 0 || data.getSection("creator").getInt("port") > 65535)) {
client.sendPacket(new PacketCreateServer(11, "Invalid Port Number", (data.contains("id")) ? data.getRawString("id") : null));
} else {
if (plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().create((data.contains("player"))?data.getUUID("player"):null, data.getSection("creator").getString("name"), plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")), new Version(data.getSection("creator").getString("version")), (data.getSection("creator").contains("port"))?data.getSection("creator").getInt("port"):null)) {
if (plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().create((data.contains("player"))?data.getUUID("player"):null, data.getSection("creator").getString("name"), plugin.hosts.get(data.getSection("creator").getString("host").toLowerCase()).getCreator().getTemplate(data.getSection("creator").getString("template")), data.getSection("creator").getVersion("version"), (data.getSection("creator").contains("port"))?data.getSection("creator").getInt("port"):null)) {
if (data.contains("wait") && data.getBoolean("wait")) {
new Thread(() -> {
try {

View File

@ -65,7 +65,7 @@ public class PacketExCreateServer implements PacketIn, PacketOut {
YAMLSection creator = new YAMLSection();
creator.set("name", name);
creator.set("template", template.getName());
creator.set("version", version.toString());
creator.set("version", version);
creator.set("port", port);
creator.set("log", log.toString());
data.set("creator", creator);

View File

@ -457,7 +457,7 @@ public final class SubDataServer {
List<PacketIn> list = new ArrayList<PacketIn>();
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
if (packet.isCompatible(new Version(data.getRawString("v")))) {
if (packet.isCompatible(data.getVersion("v"))) {
list.add(packet);
} else {
new IllegalPacketException(client.getAddress().toString() + ": Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " =/= " + packet.getVersion().toString()).printStackTrace();

View File

@ -88,7 +88,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
if (!(new UniversalFile(dir, "config.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
System.out.println("SubServers > Created ~/SubServers/config.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
} 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(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
@ -99,7 +99,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
if (!(new UniversalFile(dir, "lang.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
System.out.println("SubServers > Created ~/SubServers/lang.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.2c+"))) != 0) {
} else if (((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getVersion("Version", new Version(9))).compareTo(new Version("2.13.2c+")) != 0) {
Files.move(new UniversalFile(dir, "lang.yml").toPath(), new UniversalFile(dir, "lang.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
System.out.println("SubServers > Updated ~/SubServers/lang.yml");
@ -121,22 +121,22 @@ public final class SubPlugin extends BungeeCord implements Listener {
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
System.out.println("SubServers > Created ~/SubServers/Templates/Sponge");
} else {
if (new UniversalFile(dir, "Templates:Vanilla:template.yml").exists() && (new Version((new YAMLConfig(new UniversalFile(dir, "Templates:Vanilla:template.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.2c+"))) != 0) {
if (new UniversalFile(dir, "Templates:Vanilla:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Vanilla:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
Files.move(new UniversalFile(dir, "Templates:Vanilla").toPath(), new UniversalFile(dir, "Templates:Vanilla.old" + Math.round(Math.random() * 100000) + ".x").toPath());
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new UniversalFile(dir, "Templates"));
System.out.println("SubServers > Updated ~/SubServers/Templates/Vanilla");
}
if (new UniversalFile(dir, "Templates:Spigot:template.yml").exists() && (new Version((new YAMLConfig(new UniversalFile(dir, "Templates:Spigot:template.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.2c+"))) != 0) {
if (new UniversalFile(dir, "Templates:Spigot:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Spigot:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
Files.move(new UniversalFile(dir, "Templates:Spigot").toPath(), new UniversalFile(dir, "Templates:Spigot.old" + Math.round(Math.random() * 100000) + ".x").toPath());
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new UniversalFile(dir, "Templates"));
System.out.println("SubServers > Updated ~/SubServers/Templates/Spigot");
}
if (new UniversalFile(dir, "Templates:Forge:template.yml").exists() && (new Version((new YAMLConfig(new UniversalFile(dir, "Templates:Forge:template.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.2c+"))) != 0) {
if (new UniversalFile(dir, "Templates:Forge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Forge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
Files.move(new UniversalFile(dir, "Templates:Forge").toPath(), new UniversalFile(dir, "Templates:Forge.old" + Math.round(Math.random() * 100000) + ".x").toPath());
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new UniversalFile(dir, "Templates"));
System.out.println("SubServers > Updated ~/SubServers/Templates/Forge");
}
if (new UniversalFile(dir, "Templates:Sponge:template.yml").exists() && (new Version((new YAMLConfig(new UniversalFile(dir, "Templates:Sponge:template.yml"))).get().getString("Version", "0")).compareTo(new Version("2.13.2c+"))) != 0) {
if (new UniversalFile(dir, "Templates:Sponge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Sponge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
Files.move(new UniversalFile(dir, "Templates:Sponge").toPath(), new UniversalFile(dir, "Templates:Sponge.old" + Math.round(Math.random() * 100000) + ".x").toPath());
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
System.out.println("SubServers > Updated ~/SubServers/Templates/Sponge");

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
import org.msgpack.value.MapValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
@ -213,6 +214,8 @@ public class YAMLSection {
return list;
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof Version) {
return ((Version) value).toFullString();
} else {
return value;
}
@ -960,6 +963,48 @@ public class YAMLSection {
return get(handle, def).asUUIDList();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @return Version
*/
public Version getVersion(String handle) {
return get(handle).asVersion();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @param def Default
* @return Version
*/
public Version getVersion(String handle, Version def) {
return get(handle, def).asVersion();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @return Version List
*/
public List<Version> getVersionList(String handle) {
return get(handle).asVersionList();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @param def Default
* @return Version List
*/
public List<Version> getVersionList(String handle, List<Version> def) {
return get(handle, def).asVersionList();
}
/**
* Check if object is Null by Handle
*

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Client.Bukkit.Library.Config;
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
import org.bukkit.ChatColor;
import org.yaml.snakeyaml.Yaml;
@ -290,6 +291,30 @@ public class YAMLValue {
} 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

View File

@ -83,7 +83,7 @@ public class PacketCreateServer implements PacketIn, PacketOut {
creator.set("name", name);
creator.set("host", host);
creator.set("template", template);
creator.set("version", version.toString());
creator.set("version", version);
if (port != null) creator.set("port", port);
data.set("creator", creator);
return data;

View File

@ -378,7 +378,7 @@ public final class SubDataClient {
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().toString());
data.set("v", packet.getVersion());
if (contents != null) data.set("c", contents);
return data;
} catch (Throwable e) {
@ -400,7 +400,7 @@ public final class SubDataClient {
List<PacketIn> list = new ArrayList<PacketIn>();
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
if (packet.isCompatible(new Version(data.getRawString("v")))) {
if (packet.isCompatible(data.getVersion("v"))) {
list.add(packet);
} else {
new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toString()).printStackTrace();

View File

@ -60,7 +60,7 @@ public final class SubPlugin extends JavaPlugin {
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 Version((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
} else if (((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("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());

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Client.Sponge.Library.Config;
import com.google.gson.Gson;
import net.ME1312.SubServers.Client.Sponge.Library.Util;
import net.ME1312.SubServers.Client.Sponge.Library.Version.Version;
import org.msgpack.value.MapValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
@ -213,6 +214,8 @@ public class YAMLSection {
return list;
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof Version) {
return ((Version) value).toFullString();
} else {
return value;
}
@ -960,6 +963,48 @@ public class YAMLSection {
return get(handle, def).asUUIDList();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @return Version
*/
public Version getVersion(String handle) {
return get(handle).asVersion();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @param def Default
* @return Version
*/
public Version getVersion(String handle, Version def) {
return get(handle, def).asVersion();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @return Version List
*/
public List<Version> getVersionList(String handle) {
return get(handle).asVersionList();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @param def Default
* @return Version List
*/
public List<Version> getVersionList(String handle, List<Version> def) {
return get(handle, def).asVersionList();
}
/**
* Check if object is Null by Handle
*

View File

@ -2,6 +2,7 @@ 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;
@ -272,7 +273,7 @@ public class YAMLValue {
* @return UUID
*/
public UUID asUUID() {
if (obj != null) return UUID.fromString((String) obj);
if (obj != null) return UUID.fromString(asRawString());
else return null;
}
@ -291,6 +292,31 @@ public class YAMLValue {
} 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
@ -352,7 +378,7 @@ public class YAMLValue {
* @return UUID Status
*/
public boolean isUUID() {
return (obj instanceof String && !Util.isException(() -> UUID.fromString((String) obj)));
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
}
@Override

View File

@ -83,7 +83,7 @@ public class PacketCreateServer implements PacketIn, PacketOut {
creator.set("name", name);
creator.set("host", host);
creator.set("template", template);
creator.set("version", version.toString());
creator.set("version", version);
if (port != null) creator.set("port", port);
data.set("creator", creator);
return data;

View File

@ -382,7 +382,7 @@ public final class SubDataClient {
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().toString());
data.set("v", packet.getVersion());
if (contents != null) data.set("c", contents);
return data;
} catch (Throwable e) {
@ -404,7 +404,7 @@ public final class SubDataClient {
List<PacketIn> list = new ArrayList<PacketIn>();
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
if (packet.isCompatible(new Version(data.getRawString("v")))) {
if (packet.isCompatible(data.getVersion("v"))) {
list.add(packet);
} else {
new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toString()).printStackTrace();

View File

@ -85,7 +85,7 @@ public final class SubPlugin {
if (!(new UniversalFile(dir, "config.yml").exists())) {
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 Version((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
} 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());

View File

@ -20,7 +20,7 @@
<dependency>
<groupId>net.ME1312.Galaxi</groupId>
<artifactId>GalaxiEngine</artifactId>
<version>19w03b</version>
<version>19w03d</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -138,7 +138,7 @@ public final class ExHost {
if (!(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").exists())) {
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
log.info.println("Created ~/config.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
} else if (((new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0)).compareTo(new Version("2.11.2a+"))) != 0) {
Files.move(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").toPath(), new UniversalFile(engine.getRuntimeDirectory(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());

View File

@ -271,7 +271,7 @@ public class SubCreator {
log.logger.error.println(e);
}
if (template.getBuildOptions().contains("Shell-Location")) {
if (template.getBuildOptions().contains("Executable")) {
File cache;
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
cache = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Cache:Templates:" + template.getName());
@ -333,12 +333,13 @@ public class SubCreator {
server = null;
log.logger.error.println(e);
}
YAMLSection config = template.getConfigOptions().clone();
config.set("\033address", host.config.get().getSection("Settings").getRawString("Server-Bind"));
if (server != null) {
host.subdata.sendPacket(new PacketExCreateServer(0, "Created Server Successfully", template.getConfigOptions(), id));
host.subdata.sendPacket(new PacketExCreateServer(0, "Created Server Successfully", config, id));
} else {
log.logger.info.println("Couldn't build the server jar. Check the SubCreator logs for more detail.");
host.subdata.sendPacket(new PacketExCreateServer(-1, "Couldn't build the server jar. Check the SubCreator logs for more detail.", template.getConfigOptions(), id));
host.subdata.sendPacket(new PacketExCreateServer(-1, "Couldn't build the server jar. Check the SubCreator logs for more detail.", config, id));
}
SubCreator.this.thread.remove(name.toLowerCase());
}

View File

@ -61,7 +61,7 @@ public class PacketCreateServer implements PacketIn, PacketOut {
creator.set("name", name);
creator.set("host", host);
creator.set("template", template);
creator.set("version", version.toString());
creator.set("version", version);
if (port != null) creator.set("port", port);
data.set("creator", creator);
return data;

View File

@ -58,7 +58,7 @@ public class PacketExCreateServer implements PacketIn, PacketOut {
@Override
public void execute(YAMLSection data) {
try {
host.creator.create(data.getSection("creator").getRawString("name"), host.templates.get(data.getSection("creator").getRawString("template").toLowerCase()), new Version(data.getSection("creator").getRawString("version")),
host.creator.create(data.getSection("creator").getRawString("name"), host.templates.get(data.getSection("creator").getRawString("template").toLowerCase()), data.getSection("creator").getVersion("version"),
data.getSection("creator").getInt("port"), data.getSection("creator").getUUID("log"), (data.contains("id"))?data.getRawString("id"):null);
} catch (Throwable e) {
if (data.contains("thread")) {

View File

@ -49,7 +49,7 @@ public class PacketInRunEvent implements PacketIn {
@Override
public void run(YAMLSection data) {
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
data.getRawString("template"), new Version(data.getRawString("version")), data.getInt("port")));
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
callback("SubCreateEvent", this);
}
});

View File

@ -525,7 +525,7 @@ public final class SubDataClient {
List<PacketIn> list = new ArrayList<PacketIn>();
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
if (packet.isCompatible(new Version(data.getRawString("v")))) {
if (packet.isCompatible(data.getVersion("v"))) {
list.add(packet);
} else {
SubAPI.getInstance().getInternals().log.error.println(new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toString()));

View File

@ -2,6 +2,7 @@ package net.ME1312.SubServers.Sync.Library.Config;
import com.google.gson.Gson;
import net.ME1312.SubServers.Sync.Library.Util;
import net.ME1312.SubServers.Sync.Library.Version.Version;
import org.msgpack.value.MapValue;
import org.msgpack.value.Value;
import org.msgpack.value.ValueFactory;
@ -213,6 +214,8 @@ public class YAMLSection {
return list;
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof Version) {
return ((Version) value).toFullString();
} else {
return value;
}
@ -1030,6 +1033,48 @@ public class YAMLSection {
return get(handle).isUUID();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @return Version
*/
public Version getVersion(String handle) {
return get(handle).asVersion();
}
/**
* Get a Version by Handle
*
* @param handle Handle
* @param def Default
* @return Version
*/
public Version getVersion(String handle, Version def) {
return get(handle, def).asVersion();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @return Version List
*/
public List<Version> getVersionList(String handle) {
return get(handle).asVersionList();
}
/**
* Get a Version List by Handle
*
* @param handle Handle
* @param def Default
* @return Version List
*/
public List<Version> getVersionList(String handle, List<Version> def) {
return get(handle, def).asVersionList();
}
@Override
public boolean equals(Object object) {
if (object instanceof YAMLSection) {

View File

@ -1,6 +1,7 @@
package net.ME1312.SubServers.Sync.Library.Config;
import net.ME1312.SubServers.Sync.Library.Util;
import net.ME1312.SubServers.Sync.Library.Version.Version;
import net.md_5.bungee.api.ChatColor;
import org.yaml.snakeyaml.Yaml;
@ -271,7 +272,7 @@ public class YAMLValue {
* @return UUID
*/
public UUID asUUID() {
if (obj != null) return UUID.fromString((String) obj);
if (obj != null) return UUID.fromString(asRawString());
else return null;
}
@ -290,6 +291,30 @@ public class YAMLValue {
} 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
@ -351,7 +376,7 @@ public class YAMLValue {
* @return UUID Status
*/
public boolean isUUID() {
return (obj instanceof String && !Util.isException(() -> UUID.fromString((String) obj)));
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
}
@Override

View File

@ -49,7 +49,7 @@ public class PacketInRunEvent implements PacketIn {
@Override
public void run(YAMLSection data) {
ProxyServer.getInstance().getPluginManager().callEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
data.getRawString("template"), new Version(data.getRawString("version")), data.getInt("port")));
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
callback("SubCreateEvent", this);
}
});

View File

@ -442,7 +442,7 @@ public final class SubDataClient {
List<PacketIn> list = new ArrayList<PacketIn>();
for (PacketIn packet : pIn.get(data.getRawString("n")).get(data.getRawString("h"))) {
if (packet.isCompatible(new Version(data.getRawString("v")))) {
if (packet.isCompatible(data.getVersion("v"))) {
list.add(packet);
} else {
new IllegalPacketException("Packet Version Mismatch in " + data.getRawString("h") + ": " + data.getRawString("v") + " -> " + packet.getVersion().toString()).printStackTrace();

View File

@ -67,7 +67,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
if (!(new UniversalFile(dir, "sync.yml").exists())) {
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());
System.out.println("SubServers > Created ~/SubServers/sync.yml");
} else if ((new Version((new YAMLConfig(new UniversalFile(dir, "sync.yml"))).get().getSection("Settings").getRawString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
} else if (((new YAMLConfig(new UniversalFile(dir, "sync.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
Files.move(new UniversalFile(dir, "sync.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());