Skip to content

Commit

Permalink
Send actual data packet on ExCreator reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Feb 17, 2020
1 parent d2c7512 commit 65a5b7d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -13,7 +14,6 @@
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;
Expand All @@ -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;

Expand All @@ -61,7 +61,7 @@ public ExternalHost(SubProxy plugin, String name, boolean enabled, Range<Integer
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);
Expand Down Expand Up @@ -93,8 +93,8 @@ public void removeSubData(DataClient client) {
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);
Expand Down
Expand Up @@ -14,6 +14,7 @@
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;

Expand Down Expand Up @@ -55,21 +56,25 @@ public ExternalSubCreator(ExternalHost host, Range<Integer> ports, boolean log,

@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
Expand Down
Expand Up @@ -15,6 +15,7 @@
* External Host Template Download Packet
*/
public class PacketExDownloadTemplates implements PacketOut, PacketStreamIn {
private static boolean first = false;
private ExHost host;

/**
Expand All @@ -26,20 +27,27 @@ public PacketExDownloadTemplates(ExHost host) {

@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 {
if (dir.exists()) Util.deleteDirectory(dir);
} catch (Exception e) {
SubAPI.getInstance().getAppInfo().getLogger().error.println(e);
}

try {
Util.unzip(stream, new UniversalFile(GalaxiEngine.getInstance().getRuntimeDirectory(), "Templates"));
host.log.info.println("Template Files Downloaded");
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
Expand Down

0 comments on commit 65a5b7d

Please sign in to comment.