mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 11:46:50 +01:00
Reset servers to unregistered after removal
This commit is contained in:
parent
ee59429e1d
commit
ba6af4d66d
@ -20,7 +20,6 @@ import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReset;
|
|||||||
import net.ME1312.SubServers.Bungee.SubProxy;
|
import net.ME1312.SubServers.Bungee.SubProxy;
|
||||||
|
|
||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
import net.md_5.bungee.BungeeCord;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -180,7 +179,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
|
queue(new PacketExAddServer(((ExternalSubServer) server), (server.isRunning())?((ExternalSubLogger) server.getLogger()).getExternalAddress():null, data -> {
|
||||||
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
|
if (data.contains(0x0002)) ((ExternalSubServer) server).started(data.getUUID(0x0002));
|
||||||
}));
|
}));
|
||||||
((ExternalSubServer) server).register();
|
((ExternalSubServer) server).registered(true);
|
||||||
servers.put(server.getName().toLowerCase(), server);
|
servers.put(server.getName().toLowerCase(), server);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -191,18 +190,21 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
||||||
if (Util.isNull(name)) throw new NullPointerException();
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
SubServer server = servers.get(name.toLowerCase());
|
ExternalSubServer server = (ExternalSubServer) servers.get(name.toLowerCase());
|
||||||
|
|
||||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (forced || !event.isCancelled()) {
|
if (forced || !event.isCancelled()) {
|
||||||
|
server.registered(false);
|
||||||
if (server.isRunning()) {
|
if (server.isRunning()) {
|
||||||
server.stop();
|
server.stop();
|
||||||
server.waitFor();
|
server.waitFor();
|
||||||
}
|
}
|
||||||
|
|
||||||
servers.remove(name.toLowerCase());
|
servers.remove(name.toLowerCase());
|
||||||
queue(new PacketExRemoveServer(name.toLowerCase(), data -> {
|
queue(new PacketExRemoveServer(name.toLowerCase(), data -> {
|
||||||
if (data.getInt(0x0001) != 0 && data.getInt(0x0001) != 1) {
|
if (data.getInt(0x0001) != 0 && data.getInt(0x0001) != 1) {
|
||||||
|
server.registered(true);
|
||||||
servers.put(name.toLowerCase(), server);
|
servers.put(name.toLowerCase(), server);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -213,12 +215,13 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean recycleSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
protected boolean recycleSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
||||||
if (Util.isNull(name)) throw new NullPointerException();
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
SubServer s = servers.get(name.toLowerCase());
|
ExternalSubServer s = (ExternalSubServer) servers.get(name.toLowerCase());
|
||||||
String server = s.getName();
|
String server = s.getName();
|
||||||
|
|
||||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, s);
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, s);
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (forced || !event.isCancelled()) {
|
if (forced || !event.isCancelled()) {
|
||||||
|
s.registered(false);
|
||||||
if (s.isRunning()) {
|
if (s.isRunning()) {
|
||||||
s.stop();
|
s.stop();
|
||||||
s.waitFor();
|
s.waitFor();
|
||||||
@ -243,6 +246,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
servers.remove(server.toLowerCase());
|
servers.remove(server.toLowerCase());
|
||||||
Logger.get("SubServers").info("Deleted SubServer: " + server);
|
Logger.get("SubServers").info("Deleted SubServer: " + server);
|
||||||
} else {
|
} else {
|
||||||
|
s.registered(true);
|
||||||
Logger.get("SubServers").info("Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
Logger.get("SubServers").info("Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -253,12 +257,13 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean deleteSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
protected boolean deleteSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
||||||
if (Util.isNull(name)) throw new NullPointerException();
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
SubServer s = servers.get(name.toLowerCase());
|
ExternalSubServer s = (ExternalSubServer) servers.get(name.toLowerCase());
|
||||||
String server = s.getName();
|
String server = s.getName();
|
||||||
|
|
||||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (forced || !event.isCancelled()) {
|
if (forced || !event.isCancelled()) {
|
||||||
|
s.registered(false);
|
||||||
if (s.isRunning()) {
|
if (s.isRunning()) {
|
||||||
s.stop();
|
s.stop();
|
||||||
s.waitFor();
|
s.waitFor();
|
||||||
@ -283,6 +288,7 @@ public class ExternalHost extends Host implements ClientHandler {
|
|||||||
servers.remove(server.toLowerCase());
|
servers.remove(server.toLowerCase());
|
||||||
Logger.get("SubServers").info("Deleted SubServer: " + server);
|
Logger.get("SubServers").info("Deleted SubServer: " + server);
|
||||||
} else {
|
} else {
|
||||||
|
s.registered(true);
|
||||||
Logger.get("SubServers").info("Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
Logger.get("SubServers").info("Couldn't remove " + server + " from memory. See " + getName() + " console for more details");
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -143,7 +143,7 @@ public class ExternalSubCreator extends SubCreator {
|
|||||||
|
|
||||||
String name = server.getName();
|
String name = server.getName();
|
||||||
String prefix = name + File.separator + "Updater";
|
String prefix = name + File.separator + "Updater";
|
||||||
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, true));
|
((ExternalSubServer) server).updating(true);
|
||||||
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
|
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
|
||||||
thread.put(name.toLowerCase(), new ContainedPair<>(server.getAddress().getPort(), logger));
|
thread.put(name.toLowerCase(), new ContainedPair<>(server.getAddress().getPort(), logger));
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ public class ExternalSubCreator extends SubCreator {
|
|||||||
logger.start();
|
logger.start();
|
||||||
host.queue(new PacketExCreateServer(player, server, ft, version, logger.getExternalAddress(), data -> {
|
host.queue(new PacketExCreateServer(player, server, ft, version, logger.getExternalAddress(), data -> {
|
||||||
finish(player, server, server.getName(), ft, version, server.getAddress().getPort(), prefix, origin, data, s -> {
|
finish(player, server, server.getName(), ft, version, server.getAddress().getPort(), prefix, origin, data, s -> {
|
||||||
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, false));
|
((ExternalSubServer) server).updating(false);
|
||||||
if (callback != null) callback.run(s != null);
|
if (callback != null) callback.run(s != null);
|
||||||
});
|
});
|
||||||
logger.stop();
|
logger.stop();
|
||||||
|
@ -97,8 +97,12 @@ public class ExternalSubServer extends SubServerImpl {
|
|||||||
this.lock = false;
|
this.lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register() {
|
void registered(boolean value) {
|
||||||
registered = true;
|
registered = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updating(boolean value) {
|
||||||
|
updating = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,7 +110,7 @@ public class InternalHost extends Host {
|
|||||||
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
SubAddServerEvent event = new SubAddServerEvent(player, this, server);
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
((InternalSubServer) server).register();
|
((InternalSubServer) server).registered(true);
|
||||||
servers.put(server.getName().toLowerCase(), server);
|
servers.put(server.getName().toLowerCase(), server);
|
||||||
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getAddress().getPort());
|
if (UPnP.isUPnPAvailable() && plugin.config.get().getMap("Settings").getMap("UPnP", new ObjectMap<String>()).getBoolean("Forward-Servers", false)) UPnP.openPortTCP(server.getAddress().getPort());
|
||||||
return true;
|
return true;
|
||||||
@ -122,10 +122,11 @@ public class InternalHost extends Host {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
protected boolean removeSubServer(UUID player, String name, boolean forced) throws InterruptedException {
|
||||||
if (Util.isNull(name)) throw new NullPointerException();
|
if (Util.isNull(name)) throw new NullPointerException();
|
||||||
SubServer server = servers.get(name.toLowerCase());
|
InternalSubServer server = (InternalSubServer) servers.get(name.toLowerCase());
|
||||||
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
|
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, server);
|
||||||
plugin.getPluginManager().callEvent(event);
|
plugin.getPluginManager().callEvent(event);
|
||||||
if (forced || !event.isCancelled()) {
|
if (forced || !event.isCancelled()) {
|
||||||
|
server.registered(false);
|
||||||
if (server.isRunning()) {
|
if (server.isRunning()) {
|
||||||
server.stop();
|
server.stop();
|
||||||
server.waitFor();
|
server.waitFor();
|
||||||
|
@ -430,10 +430,9 @@ public class InternalSubCreator extends SubCreator {
|
|||||||
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) {
|
if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) {
|
||||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||||
|
|
||||||
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, true));
|
((InternalSubServer) server).updating(true);
|
||||||
|
|
||||||
CreatorTask task = new CreatorTask(player, server, ft, version, x -> {
|
CreatorTask task = new CreatorTask(player, server, ft, version, x -> {
|
||||||
Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, false));
|
((InternalSubServer) server).updating(false);
|
||||||
if (callback != null) try {
|
if (callback != null) try {
|
||||||
callback.run(x != null);
|
callback.run(x != null);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -136,8 +136,12 @@ public class InternalSubServer extends SubServerImpl {
|
|||||||
this.lock = false;
|
this.lock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register() {
|
void registered(boolean value) {
|
||||||
registered = true;
|
registered = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updating(boolean value) {
|
||||||
|
updating = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void run() {
|
private void run() {
|
||||||
|
@ -20,9 +20,7 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer {
|
|||||||
private List<Pair<String, String>> incompatibilities = new ArrayList<Pair<String, String>>();
|
private List<Pair<String, String>> incompatibilities = new ArrayList<Pair<String, String>>();
|
||||||
private SubCreator.ServerTemplate templateV = null;
|
private SubCreator.ServerTemplate templateV = null;
|
||||||
private String templateS = null;
|
private String templateS = null;
|
||||||
protected boolean registered;
|
protected boolean registered, started, updating;
|
||||||
protected boolean started;
|
|
||||||
private boolean updating;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SubServer
|
* Creates a SubServer
|
||||||
|
Loading…
Reference in New Issue
Block a user