Send actual data packet on ExCreator reload

This commit is contained in:
ME1312 2020-02-16 22:25:15 -05:00
parent d2c7512257
commit 65a5b7d0c9
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 34 additions and 21 deletions

View File

@ -3,6 +3,7 @@ package net.ME1312.SubServers.Bungee.Host.External;
import com.google.common.collect.Range;
import net.ME1312.SubData.Server.ClientHandler;
import net.ME1312.SubData.Server.DataClient;
import net.ME1312.SubData.Server.Protocol.PacketOut;
import net.ME1312.SubData.Server.SubDataClient;
import net.ME1312.SubServers.Bungee.Event.SubAddServerEvent;
import net.ME1312.SubServers.Bungee.Event.SubRemoveServerEvent;
@ -13,7 +14,6 @@ import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExAddServer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExDeleteServer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExRemoveServer;
@ -36,7 +36,7 @@ public class ExternalHost extends Host implements ClientHandler {
private InetAddress address;
private SubCreator creator;
private String directory;
private LinkedList<PacketObjectOut> queue;
private LinkedList<PacketOut> queue;
private boolean clean;
protected SubProxy plugin;
@ -61,7 +61,7 @@ public class ExternalHost extends Host implements ClientHandler {
this.address = address;
this.creator = new ExternalSubCreator(this, ports, log, gitBash);
this.directory = directory;
this.queue = new LinkedList<PacketObjectOut>();
this.queue = new LinkedList<PacketOut>();
this.clean = false;
subdata.put(0, null);
@ -93,8 +93,8 @@ public class ExternalHost extends Host implements ClientHandler {
for (Integer channel : Util.getBackwards(subdata, (SubDataClient) client)) setSubData(null, channel);
}
protected void queue(PacketObjectOut... packet) {
for (PacketObjectOut p : packet) if (getSubData()[0] == null || !available) {
protected void queue(PacketOut... packet) {
for (PacketOut p : packet) if (getSubData()[0] == null || !available) {
queue.add(p);
} else {
((SubDataClient) getSubData()[0]).sendPacket(p);

View File

@ -14,6 +14,7 @@ import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExConfigureHost;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExCreateServer;
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExDownloadTemplates;
import net.ME1312.SubServers.Bungee.SubAPI;
import net.md_5.bungee.api.ChatColor;
@ -55,21 +56,25 @@ public class ExternalSubCreator extends SubCreator {
@Override
public void reload() {
templates.clear();
if (new UniversalFile(host.plugin.dir, "SubServers:Templates").exists()) for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
try {
if (file.isDirectory() && !file.getName().endsWith(".x")) {
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()):new ObjectMap<String>();
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
templates.put(file.getName().toLowerCase(), template);
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
if (host.available) {
templates.clear();
if (new UniversalFile(host.plugin.dir, "SubServers:Templates").exists()) for (File file : new UniversalFile(host.plugin.dir, "SubServers:Templates").listFiles()) {
try {
if (file.isDirectory() && !file.getName().endsWith(".x")) {
ObjectMap<String> config = (new UniversalFile(file, "template.yml").exists())?new YAMLConfig(new UniversalFile(file, "template.yml")).get().getMap("Template", new ObjectMap<String>()):new ObjectMap<String>();
ServerTemplate template = new ServerTemplate(file.getName(), config.getBoolean("Enabled", true), config.getRawString("Icon", "::NULL::"), file, config.getMap("Build", new ObjectMap<String>()), config.getMap("Settings", new ObjectMap<String>()));
templates.put(file.getName().toLowerCase(), template);
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
}
} catch (Exception e) {
System.out.println(host.getName() + "/Creator > Couldn't load template: " + file.getName());
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(host.getName() + "/Creator > Couldn't load template: " + file.getName());
e.printStackTrace();
}
host.queue(new PacketExConfigureHost(host.plugin, host));
host.queue(new PacketExDownloadTemplates(host.plugin, host));
}
if (host.available) host.queue(new PacketExConfigureHost(host.plugin, host));
}
@Override

View File

@ -15,6 +15,7 @@ import java.io.InputStream;
* External Host Template Download Packet
*/
public class PacketExDownloadTemplates implements PacketOut, PacketStreamIn {
private static boolean first = false;
private ExHost host;
/**
@ -26,20 +27,27 @@ public class PacketExDownloadTemplates implements PacketOut, PacketStreamIn {
@Override
public void sending(SubDataSender client) throws Throwable {
UniversalFile dir = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
if (dir.exists()) Util.deleteDirectory(dir);
host.log.info.println("Downloading Template Files...");
first = true;
}
@Override
public void receive(SubDataSender client, InputStream stream) {
UniversalFile dir = new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates");
try {
Util.unzip(stream, new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates"));
host.log.info.println("Template Files Downloaded");
if (dir.exists()) Util.deleteDirectory(dir);
} catch (Exception e) {
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
}
try {
Util.unzip(stream, dir);
host.log.info.println(((first)?"":"New ") + "Template Files Downloaded");
} catch (Exception e) {
SubAPI.getInstance().getAppInfo().getLogger().error.println("Problem decoding template files");
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
}
first = false;
}
@Override