mirror of https://github.com/Minestom/Minestom.git
More reliable builds
This commit is contained in:
parent
5579392b05
commit
94406d5380
|
@ -4,7 +4,6 @@ import net.minestom.server.MinecraftServer;
|
|||
import net.minestom.server.event.EventDispatcher;
|
||||
import net.minestom.server.event.server.ServerListPingEvent;
|
||||
import net.minestom.server.timer.Task;
|
||||
import net.minestom.server.utils.NetworkUtils;
|
||||
import net.minestom.server.utils.time.Cooldown;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -61,18 +60,8 @@ public class OpenToLAN {
|
|||
Objects.requireNonNull(config, "config");
|
||||
if (socket != null) return false;
|
||||
|
||||
int port = config.port;
|
||||
if (port == 0) {
|
||||
try {
|
||||
port = NetworkUtils.getFreePort();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Could not find an open port!", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
socket = new DatagramSocket(port);
|
||||
socket = new DatagramSocket(config.port);
|
||||
} catch (SocketException e) {
|
||||
LOGGER.warn("Could not bind to the port!", e);
|
||||
return false;
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.minestom.server.event.EventDispatcher;
|
|||
import net.minestom.server.extras.query.event.BasicQueryEvent;
|
||||
import net.minestom.server.extras.query.event.FullQueryEvent;
|
||||
import net.minestom.server.timer.Task;
|
||||
import net.minestom.server.utils.NetworkUtils;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.binary.Writeable;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
|
@ -55,15 +54,7 @@ public class Query {
|
|||
if (socket != null) {
|
||||
throw new IllegalArgumentException("System is already running");
|
||||
} else {
|
||||
int port;
|
||||
|
||||
try {
|
||||
port = NetworkUtils.getFreePort();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Could not find an open port!", e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int port = 0;
|
||||
start(port);
|
||||
return port;
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package net.minestom.server.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
/**
|
||||
* Network related utilities.
|
||||
*/
|
||||
public class NetworkUtils {
|
||||
|
||||
private NetworkUtils() { }
|
||||
|
||||
/**
|
||||
* Gets a free port.
|
||||
*
|
||||
* @return the port
|
||||
* @throws IOException if a port could not be found
|
||||
*/
|
||||
public static int getFreePort() throws IOException {
|
||||
int port;
|
||||
|
||||
final ServerSocket socket = new ServerSocket(0);
|
||||
port = socket.getLocalPort();
|
||||
|
||||
socket.close();
|
||||
|
||||
return port;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package net.minestom.server.network.socket;
|
||||
|
||||
import net.minestom.server.network.PacketProcessor;
|
||||
import net.minestom.server.utils.NetworkUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +14,7 @@ public class ServerAddressTest {
|
|||
|
||||
@Test
|
||||
public void inetAddressTest() throws IOException {
|
||||
InetSocketAddress address = new InetSocketAddress("localhost", NetworkUtils.getFreePort());
|
||||
InetSocketAddress address = new InetSocketAddress("localhost", 0);
|
||||
var server = new Server(new PacketProcessor());
|
||||
server.init(address);
|
||||
assertSame(address, server.socketAddress());
|
||||
|
|
Loading…
Reference in New Issue