mirror of https://github.com/LOOHP/Limbo.git
Fixed stop command
This commit is contained in:
parent
c8e826e25d
commit
2a48ead90d
|
|
@ -37,17 +37,7 @@ public class Console {
|
||||||
String[] input = CustomStringUtils.splitStringToArgs(reader.readLine());
|
String[] input = CustomStringUtils.splitStringToArgs(reader.readLine());
|
||||||
|
|
||||||
if (input[0].equalsIgnoreCase("stop")) {
|
if (input[0].equalsIgnoreCase("stop")) {
|
||||||
for (ClientConnection client : Limbo.getInstance().getServerConnection().getClients()) {
|
Limbo.getInstance().stopServer();
|
||||||
client.getSocket().close();
|
|
||||||
while (client.getSocket().isConnected()) {
|
|
||||||
try {
|
|
||||||
TimeUnit.MILLISECONDS.sleep(500);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.exit(0);
|
|
||||||
} else if (input[0].equalsIgnoreCase("say")) {
|
} else if (input[0].equalsIgnoreCase("say")) {
|
||||||
if (input.length > 1) {
|
if (input.length > 1) {
|
||||||
String message = "[Server] " + String.join(" ", Arrays.copyOfRange(input, 1, input.length));
|
String message = "[Server] " + String.join(" ", Arrays.copyOfRange(input, 1, input.length));
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
|
@ -16,6 +17,7 @@ import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import com.loohp.limbo.File.ServerProperties;
|
import com.loohp.limbo.File.ServerProperties;
|
||||||
import com.loohp.limbo.Location.Location;
|
import com.loohp.limbo.Location.Location;
|
||||||
|
import com.loohp.limbo.Server.ClientConnection;
|
||||||
import com.loohp.limbo.Server.ServerConnection;
|
import com.loohp.limbo.Server.ServerConnection;
|
||||||
import com.loohp.limbo.Server.Packets.Packet;
|
import com.loohp.limbo.Server.Packets.Packet;
|
||||||
import com.loohp.limbo.Server.Packets.PacketIn;
|
import com.loohp.limbo.Server.Packets.PacketIn;
|
||||||
|
|
@ -194,5 +196,26 @@ public class Limbo {
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public void stopServer() {
|
||||||
|
Limbo.getInstance().getConsole().sendMessage("Stopping Server...");
|
||||||
|
for (ClientConnection client : Limbo.getInstance().getServerConnection().getClients()) {
|
||||||
|
try {
|
||||||
|
client.getSocket().close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
client.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!Limbo.getInstance().getServerConnection().getClients().isEmpty()) {
|
||||||
|
try {
|
||||||
|
TimeUnit.MILLISECONDS.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue