Lock the start method for event usage

This commit is contained in:
ME1312 2018-07-29 19:01:36 -04:00
parent 97c73bf738
commit d69840f439
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
7 changed files with 38 additions and 31 deletions

View File

@ -35,6 +35,7 @@ public class ExternalSubServer extends SubServerContainer {
private boolean restart;
private boolean temporary;
private boolean running;
private boolean lock;
/**
* Creates an External SubServer
@ -68,13 +69,16 @@ public class ExternalSubServer extends SubServerContainer {
this.running = false;
this.temporary = false;
this.lock = false;
}
@Override
public boolean start(UUID player) {
if (isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {
if (!lock && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {
lock = true;
SubStartEvent event = new SubStartEvent(player, this);
host.plugin.getPluginManager().callEvent(event);
lock = false;
if (!event.isCancelled()) {
System.out.println("SubServers > Now starting " + getName());
running = true;

View File

@ -42,6 +42,7 @@ public class InternalSubServer extends SubServerContainer {
private boolean restart;
private boolean allowrestart;
private boolean temporary;
private boolean lock;
/**
* Creates an Internal SubServer
@ -57,12 +58,11 @@ public class InternalSubServer extends SubServerContainer {
* @param stopcmd Stop Command
* @param hidden Hidden Status
* @param restricted Restricted Status
* @param temporary Temporary Status
* @throws InvalidServerException
*/
public InternalSubServer(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted, boolean temporary) throws InvalidServerException {
public InternalSubServer(InternalHost host, String name, boolean enabled, int port, String motd, boolean log, String directory, Executable executable, String stopcmd, boolean hidden, boolean restricted) throws InvalidServerException {
super(host, name, port, motd, hidden, restricted);
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted, temporary)) throw new NullPointerException();
if (Util.isNull(host, name, enabled, port, motd, log, directory, executable, stopcmd, hidden, restricted)) throw new NullPointerException();
this.host = host;
this.enabled = enabled;
this.editable = false;
@ -115,7 +115,8 @@ public class InternalSubServer extends SubServerContainer {
e.printStackTrace();
}
}
this.temporary = temporary && start();
this.temporary = false;
this.lock = false;
}
private void run() {
@ -169,9 +170,11 @@ public class InternalSubServer extends SubServerContainer {
@Override
public boolean start(UUID player) {
if (isEnabled() && !(thread != null && thread.isAlive()) && getCurrentIncompatibilities().size() == 0) {
if (!lock && isEnabled() && !(thread != null && thread.isAlive()) && getCurrentIncompatibilities().size() == 0) {
lock = true;
SubStartEvent event = new SubStartEvent(player, this);
host.plugin.getPluginManager().callEvent(event);
lock = false;
if (!event.isCancelled()) {
(thread = new Thread(this::run)).start();
return true;

View File

@ -303,7 +303,7 @@ public final class SubDataServer {
* @param handle Handle to Bind
*/
public static void registerPacket(PacketIn packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
if (!list.contains(packet)) {
@ -320,7 +320,7 @@ public final class SubDataServer {
* @param packet PacketIn to unregister
*/
public static void unregisterPacket(String channel, PacketIn packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pIn.keySet().contains(channel.toLowerCase())) {
List<String> search = new ArrayList<String>();
search.addAll(pIn.get(channel.toLowerCase()).keySet());
@ -345,7 +345,7 @@ public final class SubDataServer {
* @param handle Handle to bind
*/
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
}
@ -356,7 +356,7 @@ public final class SubDataServer {
* @param packet PacketOut to unregister
*/
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
}
@ -368,7 +368,7 @@ public final class SubDataServer {
* @return PacketIn
*/
public static List<? extends PacketIn> getPacket(String channel, String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
if (Util.isNull(channel, handle)) throw new NullPointerException();
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
}

View File

@ -234,7 +234,7 @@ public final class SubDataClient {
* @param handle Handle to Bind
*/
public static void registerPacket(PacketIn packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
if (!list.contains(packet)) {
@ -251,7 +251,7 @@ public final class SubDataClient {
* @param packet PacketIn to unregister
*/
public static void unregisterPacket(String channel, PacketIn packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pIn.keySet().contains(channel.toLowerCase())) {
List<String> search = new ArrayList<String>();
search.addAll(pIn.get(channel.toLowerCase()).keySet());
@ -276,7 +276,7 @@ public final class SubDataClient {
* @param handle Handle to bind
*/
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
}
@ -287,7 +287,7 @@ public final class SubDataClient {
* @param packet PacketOut to unregister
*/
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
}
@ -299,7 +299,7 @@ public final class SubDataClient {
* @return PacketIn
*/
public static List<? extends PacketIn> getPacket(String channel, String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
if (Util.isNull(channel, handle)) throw new NullPointerException();
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
}

View File

@ -239,7 +239,7 @@ public final class SubDataClient {
* @param handle Handle to Bind
*/
public static void registerPacket(PacketIn packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
if (!list.contains(packet)) {
@ -256,7 +256,7 @@ public final class SubDataClient {
* @param packet PacketIn to unregister
*/
public static void unregisterPacket(String channel, PacketIn packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pIn.keySet().contains(channel.toLowerCase())) {
List<String> search = new ArrayList<String>();
search.addAll(pIn.get(channel.toLowerCase()).keySet());
@ -281,7 +281,7 @@ public final class SubDataClient {
* @param handle Handle to bind
*/
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
}
@ -292,7 +292,7 @@ public final class SubDataClient {
* @param packet PacketOut to unregister
*/
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
}
@ -304,7 +304,7 @@ public final class SubDataClient {
* @return PacketIn
*/
public static List<? extends PacketIn> getPacket(String channel, String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
if (Util.isNull(channel, handle)) throw new NullPointerException();
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
}

View File

@ -255,7 +255,7 @@ public final class SubDataClient {
* @param handle Handle to Bind
*/
public static void registerPacket(PacketIn packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
if (!list.contains(packet)) {
@ -272,7 +272,7 @@ public final class SubDataClient {
* @param packet PacketIn to unregister
*/
public static void unregisterPacket(String channel, PacketIn packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pIn.keySet().contains(channel.toLowerCase())) {
List<String> search = new ArrayList<String>();
search.addAll(pIn.get(channel.toLowerCase()).keySet());
@ -297,7 +297,7 @@ public final class SubDataClient {
* @param handle Handle to bind
*/
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
}
@ -308,7 +308,7 @@ public final class SubDataClient {
* @param packet PacketOut to unregister
*/
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
}
@ -320,7 +320,7 @@ public final class SubDataClient {
* @return PacketIn
*/
public static List<? extends PacketIn> getPacket(String channel, String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
if (Util.isNull(channel, handle)) throw new NullPointerException();
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
}

View File

@ -260,7 +260,7 @@ public final class SubDataClient {
* @param handle Handle to Bind
*/
public static void registerPacket(PacketIn packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
HashMap<String, List<PacketIn>> map = (pIn.keySet().contains(channel.toLowerCase()))?pIn.get(channel.toLowerCase()):new HashMap<String, List<PacketIn>>();
List<PacketIn> list = (map.keySet().contains(handle))?map.get(handle):new ArrayList<PacketIn>();
if (!list.contains(packet)) {
@ -277,7 +277,7 @@ public final class SubDataClient {
* @param packet PacketIn to unregister
*/
public static void unregisterPacket(String channel, PacketIn packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pIn.keySet().contains(channel.toLowerCase())) {
List<String> search = new ArrayList<String>();
search.addAll(pIn.get(channel.toLowerCase()).keySet());
@ -302,7 +302,7 @@ public final class SubDataClient {
* @param handle Handle to bind
*/
public static void registerPacket(Class<? extends PacketOut> packet, String channel, String handle) {
if (Util.isNull(packet, handle)) throw new NullPointerException();
if (Util.isNull(packet, channel, handle)) throw new NullPointerException();
pOut.put(packet, new NamedContainer<String, String>(channel.toLowerCase(), handle));
}
@ -313,7 +313,7 @@ public final class SubDataClient {
* @param packet PacketOut to unregister
*/
public static void unregisterPacket(String channel, Class<? extends PacketOut> packet) {
if (Util.isNull(packet)) throw new NullPointerException();
if (Util.isNull(channel, packet)) throw new NullPointerException();
if (pOut.keySet().contains(packet) && pOut.get(packet).name().equalsIgnoreCase(channel)) pOut.remove(packet);
}
@ -325,7 +325,7 @@ public final class SubDataClient {
* @return PacketIn
*/
public static List<? extends PacketIn> getPacket(String channel, String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
if (Util.isNull(channel, handle)) throw new NullPointerException();
return new ArrayList<PacketIn>(pIn.get(channel.toLowerCase()).get(handle));
}