locales, packet client settings and client support for plugin messages

This commit is contained in:
bixilon 2020-06-05 01:01:00 +02:00
parent 9b360bc500
commit 1702c8ac14
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package de.bixilon.minosoft.game.datatypes;
public enum Locale {
EN_US("en_US"),
EN_GB("en_gb"),
DE_DE("de_DE");
String name;
Locale(String name) {
this.name = name;
}
public static Locale byId(String name) {
for (Locale g : values()) {
if (g.getName().equals(name)) {
return g;
}
}
return null;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,43 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.game.datatypes.Difficulty;
import de.bixilon.minosoft.game.datatypes.Locale;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketClientSettings implements ServerboundPacket {
public final Locale locale;
public final byte renderDistance;
public PacketClientSettings(Locale locale, int renderDistance) {
this.locale = locale;
this.renderDistance = (byte) renderDistance;
}
@Override
public OutPacketBuffer write(ProtocolVersion v) {
log();
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS));
switch (v) {
case VERSION_1_7_10:
buffer.writeString(locale.getName()); // locale
buffer.writeByte(renderDistance); // render Distance
buffer.writeByte((byte) 0x00); // chat settings (nobody uses them)
buffer.writeBoolean(true); // chat colors
buffer.writeByte((byte) Difficulty.NORMAL.getId()); // difficulty
buffer.writeBoolean(true); // cape
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending settings (%s, render distance: %s)", locale.getName(), renderDistance));
}
}

View File

@ -0,0 +1,38 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketPluginMessageSended implements ServerboundPacket {
public final String channel;
public final byte[] data;
public PacketPluginMessageSended(String channel, byte[] data) {
this.channel = channel;
this.data = data;
}
@Override
public OutPacketBuffer write(ProtocolVersion v) {
log();
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLUGIN_MESSAGE));
switch (v) {
case VERSION_1_7_10:
buffer.writeString(channel); // name
buffer.writeShort((short) data.length); // length
buffer.writeBytes(data); // data
break;
}
return buffer;
}
@Override
public void log() {
Log.protocol(String.format("Sending data in plugin channel %s with a length of %s bytes", channel, data.length));
}
}