Cache invalid version text and add clarification to the version which should be used

This commit is contained in:
themode 2020-09-23 15:44:52 +02:00
parent dc8f885aff
commit 9a567811c7
3 changed files with 21 additions and 14 deletions

View File

@ -83,6 +83,7 @@ public class ChunkBatch implements InstanceBatch {
/**
* Execute the batch in the dedicated pool and run the callback during the next instance update when blocks are placed
* (which means that the callback can be called 50ms after, and in a determinable thread)
*
* @param callback the callback to execute once the blocks are placed
*/
@ -93,7 +94,7 @@ public class ChunkBatch implements InstanceBatch {
}
/**
* Execute the batch in the dedicated pool and run the callback once blocks are placed (in the current thread)
* Execute the batch in the dedicated pool and run the callback once blocks are placed (in the block batch pool)
*
* @param callback the callback to execute once the blocks are placed
*/

View File

@ -11,6 +11,11 @@ import net.minestom.server.utils.binary.BinaryReader;
public class HandshakePacket implements ClientPreplayPacket {
/**
* Text sent if a player tries to connect with an invalid version of the client
*/
private static final ColoredText INVALID_VERSION_TEXT = ColoredText.of(ChatColor.RED, "Invalid Version, please use " + MinecraftServer.VERSION_NAME);
private int protocolVersion;
private String serverAddress;
private int serverPort;
@ -33,7 +38,7 @@ public class HandshakePacket implements ClientPreplayPacket {
case 2:
connection.setConnectionState(ConnectionState.LOGIN);
if (protocolVersion != MinecraftServer.PROTOCOL_VERSION) {
connection.sendPacket(new LoginDisconnect(ColoredText.of(ChatColor.RED, "Invalid Version").toString()));
connection.sendPacket(new LoginDisconnect(INVALID_VERSION_TEXT.toString()));
connection.disconnect();
}
break;

View File

@ -4,20 +4,21 @@ import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.utils.binary.BinaryWriter;
public class LoginDisconnect implements ServerPacket {
private String kickMessage;
public LoginDisconnect(String kickMessage) {
this.kickMessage = kickMessage;
}
private String kickMessage;
@Override
public void write(BinaryWriter writer) {
writer.writeSizedString(kickMessage);
}
public LoginDisconnect(String kickMessage) {
this.kickMessage = kickMessage;
}
@Override
public int getId() {
return 0x00;
}
@Override
public void write(BinaryWriter writer) {
writer.writeSizedString(kickMessage);
}
@Override
public int getId() {
return 0x00;
}
}