diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index cb34986..f0afc09 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -39,8 +39,11 @@ public abstract class Node { public static Node local = null; public static Node getNode() { - Node node = null; - double minLoad = Double.POSITIVE_INFINITY; + Node node = local; + double minLoad = local.getLoad(); + if(minLoad < 0.5) + return local; + synchronized (nodes) { Iterator it = nodes.iterator(); while(it.hasNext()) { @@ -59,17 +62,12 @@ public abstract class Node { } public static void forEach(Consumer consumer) { + consumer.accept(local); synchronized (nodes) { nodes.forEach(consumer); } } - protected Node() { - synchronized (nodes) { - nodes.add(this); - } - } - public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); public abstract void execute(String... command); public abstract String getName(); @@ -120,7 +118,6 @@ public abstract class Node { private final int cores; public LocalNode() { - super(); this.cores = Runtime.getRuntime().availableProcessors(); local = this; } @@ -172,7 +169,6 @@ public abstract class Node { private final String remote; public RemoteNode(String remote) { - super(); this.remote = remote; //Determin core count @@ -199,6 +195,10 @@ public abstract class Node { c = 1; } cores = c; + + synchronized (nodes) { + nodes.add(this); + } } @Override