mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-26 18:11:40 +01:00
Moved the ResponseDataConsumer definition to MinecraftServer#start
This commit is contained in:
parent
7ea87b56c2
commit
0946c8ce11
@ -52,7 +52,7 @@ public class Main {
|
||||
|
||||
PlayerInit.init();
|
||||
|
||||
minecraftServer.start("localhost", 55555);
|
||||
minecraftServer.start("localhost", 55555, PlayerInit.getResponseDataConsumer());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
import net.minestom.server.timer.TaskRunnable;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
@ -76,17 +77,6 @@ public class PlayerInit {
|
||||
}
|
||||
}, new UpdateOption(5, TimeUnit.TICK));
|
||||
|
||||
connectionManager.setResponseDataConsumer((playerConnection, responseData) -> {
|
||||
responseData.setName("1.15.2");
|
||||
responseData.setProtocol(578);
|
||||
responseData.setMaxPlayer(100);
|
||||
responseData.setOnline(connectionManager.getOnlinePlayers().size());
|
||||
responseData.addPlayer("A name", UUID.randomUUID());
|
||||
responseData.addPlayer("Could be some message", UUID.randomUUID());
|
||||
responseData.setDescription("IP test: " + playerConnection.getRemoteAddress());
|
||||
responseData.setFavicon("data:image/png;base64,<data>");
|
||||
});
|
||||
|
||||
connectionManager.addPacketConsumer((player, packet) -> {
|
||||
// Listen to all received packet
|
||||
// Returning true means cancelling the packet
|
||||
@ -195,4 +185,17 @@ public class PlayerInit {
|
||||
});
|
||||
}
|
||||
|
||||
public static ResponseDataConsumer getResponseDataConsumer() {
|
||||
return (playerConnection, responseData) -> {
|
||||
responseData.setName("1.15.2");
|
||||
responseData.setProtocol(578);
|
||||
responseData.setMaxPlayer(100);
|
||||
responseData.setOnline(MinecraftServer.getConnectionManager().getOnlinePlayers().size());
|
||||
responseData.addPlayer("A name", UUID.randomUUID());
|
||||
responseData.addPlayer("Could be some message", UUID.randomUUID());
|
||||
responseData.setDescription("IP test: " + playerConnection.getRemoteAddress());
|
||||
responseData.setFavicon("data:image/png;base64,<data>");
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.PacketProcessor;
|
||||
import net.minestom.server.network.netty.NettyServer;
|
||||
import net.minestom.server.network.packet.server.play.ServerDifficultyPacket;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.registry.RegistryMain;
|
||||
import net.minestom.server.scoreboard.TeamManager;
|
||||
@ -79,6 +80,7 @@ public class MinecraftServer {
|
||||
private static MinecraftServer minecraftServer;
|
||||
|
||||
// Data
|
||||
private static ResponseDataConsumer responseDataConsumer;
|
||||
private static Difficulty difficulty = Difficulty.NORMAL;
|
||||
|
||||
public static MinecraftServer init() {
|
||||
@ -175,7 +177,12 @@ public class MinecraftServer {
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
public void start(String address, int port) {
|
||||
public static ResponseDataConsumer getResponseDataConsumer() {
|
||||
return responseDataConsumer;
|
||||
}
|
||||
|
||||
public void start(String address, int port, ResponseDataConsumer responseDataConsumer) {
|
||||
MinecraftServer.responseDataConsumer = responseDataConsumer;
|
||||
updateManager.start();
|
||||
nettyServer.start(address, port);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package net.minestom.server.network;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.listener.manager.PacketConsumer;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -16,7 +15,6 @@ public class ConnectionManager {
|
||||
private Set<Player> players = new CopyOnWriteArraySet<>();
|
||||
private Map<PlayerConnection, Player> connectionPlayerMap = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private ResponseDataConsumer responseDataConsumer;
|
||||
private List<PacketConsumer> packetConsumers = new CopyOnWriteArrayList<>();
|
||||
private List<Consumer<Player>> playerInitializations = new CopyOnWriteArrayList<>();
|
||||
|
||||
@ -52,14 +50,6 @@ public class ConnectionManager {
|
||||
broadcastMessage(message, null);
|
||||
}
|
||||
|
||||
public ResponseDataConsumer getResponseDataConsumer() {
|
||||
return responseDataConsumer;
|
||||
}
|
||||
|
||||
public void setResponseDataConsumer(ResponseDataConsumer responseDataConsumer) {
|
||||
this.responseDataConsumer = responseDataConsumer;
|
||||
}
|
||||
|
||||
public List<PacketConsumer> getPacketConsumers() {
|
||||
return Collections.unmodifiableList(packetConsumers);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class StatusRequestPacket implements ClientPreplayPacket {
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
ResponseDataConsumer consumer = MinecraftServer.getConnectionManager().getResponseDataConsumer();
|
||||
ResponseDataConsumer consumer = MinecraftServer.getResponseDataConsumer();
|
||||
ResponseData responseData = new ResponseData();
|
||||
if (consumer == null)
|
||||
throw new NullPointerException("You need to register a ResponseDataConsumer");
|
||||
|
Loading…
Reference in New Issue
Block a user