Code style

This commit is contained in:
Nanit
2021-10-28 21:08:14 +03:00
parent 1c6da4ee0a
commit d170bcbee2
24 changed files with 120 additions and 120 deletions

View File

@@ -23,11 +23,11 @@ public class ByteMessage extends ByteBuf {
private final ByteBuf buf;
public ByteMessage(ByteBuf buf){
public ByteMessage(ByteBuf buf) {
this.buf = buf;
}
public byte[] toByteArray(){
public byte[] toByteArray() {
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
return bytes;
@@ -50,7 +50,7 @@ public class ByteMessage extends ByteBuf {
throw new IllegalArgumentException("Cannot read VarInt");
}
public void writeVarInt(int value){
public void writeVarInt(int value) {
while (true) {
if ((value & 0xFFFFFF80) == 0) {
buf.writeByte(value);
@@ -78,7 +78,7 @@ public class ByteMessage extends ByteBuf {
buf.writeCharSequence(str, StandardCharsets.UTF_8);
}
public byte[] readBytesArray(){
public byte[] readBytesArray() {
int length = readVarInt();
byte[] array = new byte[length];
buf.readBytes(array);
@@ -146,7 +146,7 @@ public class ByteMessage extends ByteBuf {
writeVarInt(compoundTags.length);
for (CompoundBinaryTag tag : compoundTags){
for (CompoundBinaryTag tag : compoundTags) {
BinaryTagIO.writeDataOutput(tag, stream);
}
} catch (IOException e) {
@@ -1139,7 +1139,7 @@ public class ByteMessage extends ByteBuf {
return buf.release(decrement);
}
public static ByteMessage create(){
public static ByteMessage create() {
return new ByteMessage(Unpooled.buffer());
}
}

View File

@@ -26,7 +26,7 @@ public class PacketLoginPluginResponse implements PacketIn {
messageId = msg.readVarInt();
successful = msg.readBoolean();
if (msg.readableBytes() > 0){
if (msg.readableBytes() > 0) {
int i = msg.readableBytes();
data = new ByteMessage(msg.readBytes(i));
}

View File

@@ -38,7 +38,7 @@ public class PacketChatMessage implements PacketOut {
private final int index;
Position(int index){
Position(int index) {
this.index = index;
}

View File

@@ -22,14 +22,14 @@ public class PacketDeclareCommands implements PacketOut {
msg.writeByte(0);
msg.writeVarInt(commands.size());
for (int i = 1; i <= commands.size() * 2; i++){
for (int i = 1; i <= commands.size() * 2; i++) {
msg.writeVarInt(i++);
}
// Declare other commands
int i = 1;
for (String cmd : commands){
for (String cmd : commands) {
msg.writeByte(1 | 0x04);
msg.writeVarInt(1);
msg.writeVarInt(i + 1);

View File

@@ -18,11 +18,11 @@ public class PacketPlayerInfo implements PacketOut {
this.gameMode = gameMode;
}
public void setUsername(String username){
public void setUsername(String username) {
this.username = username;
}
public void setUuid(UUID uuid){
public void setUuid(UUID uuid) {
this.uuid = uuid;
}

View File

@@ -10,9 +10,9 @@ public class PacketStatusResponse implements PacketOut {
private LimboServer server;
public PacketStatusResponse(){ }
public PacketStatusResponse() { }
public PacketStatusResponse(LimboServer server){
public PacketStatusResponse(LimboServer server) {
this.server = server;
}
@@ -26,7 +26,7 @@ public class PacketStatusResponse implements PacketOut {
msg.writeString(json);
}
private String getResponseJson(String version, int protocol, int maxPlayers, int online, String description){
private String getResponseJson(String version, int protocol, int maxPlayers, int online, String description) {
return String.format(TEMPLATE, version, protocol, maxPlayers, online, description);
}
}

View File

@@ -14,12 +14,12 @@ import java.util.function.Supplier;
public enum State {
HANDSHAKING(0){
HANDSHAKING(0) {
{
serverBound.register(0x00, PacketHandshake::new);
}
},
STATUS(1){
STATUS(1) {
{
serverBound.register(0x01, PacketStatusPing::new);
serverBound.register(0x00, PacketStatusRequest::new);
@@ -27,7 +27,7 @@ public enum State {
clientBound.register(0x01, PacketStatusPing::new);
}
},
LOGIN(2){
LOGIN(2) {
{
serverBound.register(0x00, PacketLoginStart::new);
serverBound.register(0x02, PacketLoginPluginResponse::new);
@@ -36,7 +36,7 @@ public enum State {
clientBound.register(0x04, PacketLoginPluginRequest::new);
}
},
PLAY(3){
PLAY(3) {
{
serverBound.register(0x10, PacketKeepAlive::new);
clientBound.register(0x10, PacketDeclareCommands::new);
@@ -53,7 +53,7 @@ public enum State {
private static final Map<Integer, State> STATE_BY_ID = new HashMap<>();
static {
for (State registry : values()){
for (State registry : values()) {
STATE_BY_ID.put(registry.stateId, registry);
}
}
@@ -62,11 +62,11 @@ public enum State {
public final PacketRegistry serverBound = new PacketRegistry();
public final PacketRegistry clientBound = new PacketRegistry();
State(int stateId){
State(int stateId) {
this.stateId = stateId;
}
public static State getById(int stateId){
public static State getById(int stateId) {
return STATE_BY_ID.get(stateId);
}
@@ -75,16 +75,16 @@ public enum State {
private final Map<Integer, Supplier<?>> packetsById = new HashMap<>();
private final Map<Class<?>, Integer> packetIdByClass = new HashMap<>();
public Packet getPacket(int packetId){
public Packet getPacket(int packetId) {
Supplier<?> supplier = packetsById.get(packetId);
return supplier == null ? null : (Packet) supplier.get();
}
public int getPacketId(Class<?> packetClass){
public int getPacketId(Class<?> packetClass) {
return packetIdByClass.getOrDefault(packetClass, -1);
}
public void register(int packetId, Supplier<?> supplier){
public void register(int packetId, Supplier<?> supplier) {
packetsById.put(packetId, supplier);
packetIdByClass.put(supplier.get().getClass(), packetId);
}

View File

@@ -38,26 +38,26 @@ public enum Version {
static {
VERSION_MAP = new HashMap<>();
for (Version version : values()){
for (Version version : values()) {
VERSION_MAP.put(version.getProtocolNumber(), version);
}
}
public static Version getCurrentSupported(){
public static Version getCurrentSupported() {
return V1_16_4;
}
public static Version of(int protocolNumber){
public static Version of(int protocolNumber) {
return VERSION_MAP.getOrDefault(protocolNumber, UNDEFINED);
}
private final int protocolNumber;
Version(int protocolNumber){
Version(int protocolNumber) {
this.protocolNumber = protocolNumber;
}
public int getProtocolNumber(){
public int getProtocolNumber() {
return this.protocolNumber;
}