mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
improve code style even more
This commit is contained in:
parent
44973df41a
commit
d94616937e
@ -25,4 +25,3 @@ code_quality:
|
|||||||
artifacts:
|
artifacts:
|
||||||
expose_as: 'Code Quality Report'
|
expose_as: 'Code Quality Report'
|
||||||
paths: [ gl-code-quality-report.json ]
|
paths: [ gl-code-quality-report.json ]
|
||||||
|
|
||||||
|
@ -136,6 +136,7 @@ public class VillagerData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (super.equals(obj)) {
|
if (super.equals(obj)) {
|
||||||
|
@ -50,49 +50,46 @@ public class EntityMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object getData(EntityMetaDataValueTypes type, InByteBuffer buffer) {
|
public static Object getData(EntityMetaDataValueTypes type, InByteBuffer buffer) {
|
||||||
Object data = null;
|
return switch (type) {
|
||||||
|
case BYTE -> buffer.readByte();
|
||||||
switch (type) {
|
case VAR_INT -> buffer.readVarInt();
|
||||||
case BYTE -> data = buffer.readByte();
|
case SHORT -> buffer.readShort();
|
||||||
case VAR_INT -> data = buffer.readVarInt();
|
case INT -> buffer.readInt();
|
||||||
case SHORT -> data = buffer.readShort();
|
case FLOAT -> buffer.readFloat();
|
||||||
case INT -> data = buffer.readInt();
|
case STRING -> buffer.readString();
|
||||||
case FLOAT -> data = buffer.readFloat();
|
case CHAT -> buffer.readTextComponent();
|
||||||
case STRING -> data = buffer.readString();
|
case BOOLEAN -> buffer.readBoolean();
|
||||||
case CHAT -> data = buffer.readTextComponent();
|
case VECTOR -> new Vector(buffer.readInt(), buffer.readInt(), buffer.readInt());
|
||||||
case BOOLEAN -> data = buffer.readBoolean();
|
case SLOT -> buffer.readSlot();
|
||||||
case VECTOR -> data = new Vector(buffer.readInt(), buffer.readInt(), buffer.readInt());
|
case ROTATION -> new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
||||||
case SLOT -> data = buffer.readSlot();
|
case POSITION -> buffer.readPosition();
|
||||||
case ROTATION -> data = new EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
|
|
||||||
case POSITION -> data = buffer.readPosition();
|
|
||||||
case OPT_CHAT -> {
|
case OPT_CHAT -> {
|
||||||
if (buffer.readBoolean()) {
|
if (buffer.readBoolean()) {
|
||||||
data = buffer.readTextComponent();
|
yield buffer.readTextComponent();
|
||||||
}
|
}
|
||||||
|
yield null;
|
||||||
}
|
}
|
||||||
case OPT_POSITION -> {
|
case OPT_POSITION -> {
|
||||||
if (buffer.readBoolean()) {
|
if (buffer.readBoolean()) {
|
||||||
data = buffer.readPosition();
|
yield buffer.readPosition();
|
||||||
}
|
}
|
||||||
|
yield null;
|
||||||
}
|
}
|
||||||
case DIRECTION -> data = buffer.readDirection();
|
case DIRECTION -> buffer.readDirection();
|
||||||
case OPT_UUID -> {
|
case OPT_UUID -> {
|
||||||
if (buffer.readBoolean()) {
|
if (buffer.readBoolean()) {
|
||||||
data = buffer.readUUID();
|
yield buffer.readUUID();
|
||||||
}
|
}
|
||||||
|
yield null;
|
||||||
}
|
}
|
||||||
case NBT -> data = buffer.readNBT();
|
case NBT -> buffer.readNBT();
|
||||||
case PARTICLE -> data = buffer.readParticle();
|
case PARTICLE -> buffer.readParticle();
|
||||||
case POSE -> data = buffer.readPose();
|
case POSE -> buffer.readPose();
|
||||||
case BLOCK_ID -> {
|
case BLOCK_ID -> buffer.getConnection().getMapping().getBlockById(buffer.readVarInt());
|
||||||
int blockId = buffer.readVarInt();
|
case OPT_VAR_INT -> buffer.readVarInt() - 1;
|
||||||
data = buffer.getConnection().getMapping().getBlockById(blockId);
|
case VILLAGER_DATA -> new VillagerData(VillagerData.VillagerTypes.byId(buffer.readVarInt()), VillagerData.VillagerProfessions.byId(buffer.readVarInt(), buffer.getProtocolId()), VillagerData.VillagerLevels.byId(buffer.readVarInt()));
|
||||||
}
|
|
||||||
case OPT_VAR_INT -> data = buffer.readVarInt() - 1;
|
|
||||||
case VILLAGER_DATA -> data = new VillagerData(VillagerData.VillagerTypes.byId(buffer.readVarInt()), VillagerData.VillagerProfessions.byId(buffer.readVarInt(), buffer.getProtocolId()), VillagerData.VillagerLevels.byId(buffer.readVarInt()));
|
|
||||||
default -> throw new IllegalStateException("Unexpected value: " + type);
|
default -> throw new IllegalStateException("Unexpected value: " + type);
|
||||||
}
|
};
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetaDataHashMap getSets() {
|
public MetaDataHashMap getSets() {
|
||||||
|
@ -46,10 +46,6 @@ public class ZombieVillagerMetaData extends ZombieMetaData {
|
|||||||
return super.getLastDataIndex() + 2;
|
return super.getLastDataIndex() + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VillagerData.VillagerTypes getType() {
|
|
||||||
return getVillageData().getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public VillagerData getVillageData() {
|
public VillagerData getVillageData() {
|
||||||
final VillagerData defaultValue = new VillagerData(VillagerData.VillagerTypes.PLAINS, VillagerData.VillagerProfessions.NONE, VillagerData.VillagerLevels.APPRENTICE);
|
final VillagerData defaultValue = new VillagerData(VillagerData.VillagerTypes.PLAINS, VillagerData.VillagerProfessions.NONE, VillagerData.VillagerLevels.APPRENTICE);
|
||||||
if (protocolId < 451) {
|
if (protocolId < 451) {
|
||||||
@ -58,6 +54,10 @@ public class ZombieVillagerMetaData extends ZombieMetaData {
|
|||||||
return sets.getVillagerData(super.getLastDataIndex() + 2, defaultValue);
|
return sets.getVillagerData(super.getLastDataIndex() + 2, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VillagerData.VillagerTypes getType() {
|
||||||
|
return getVillageData().getType();
|
||||||
|
}
|
||||||
|
|
||||||
public VillagerData.VillagerLevels getLevel() {
|
public VillagerData.VillagerLevels getLevel() {
|
||||||
return getVillageData().getLevel();
|
return getVillageData().getLevel();
|
||||||
}
|
}
|
||||||
|
@ -48,21 +48,16 @@ public class Version {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersionName() {
|
|
||||||
return versionName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> getClientboundPacketMapping() {
|
public HashMap<ConnectionStates, HashBiMap<Packets.Clientbound, Integer>> getClientboundPacketMapping() {
|
||||||
return clientboundPacketMapping;
|
return clientboundPacketMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> getServerboundPacketMapping() {
|
public String getVersionName() {
|
||||||
return serverboundPacketMapping;
|
return versionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public HashMap<ConnectionStates, HashBiMap<Packets.Serverbound, Integer>> getServerboundPacketMapping() {
|
||||||
public int hashCode() {
|
return serverboundPacketMapping;
|
||||||
return getProtocolVersion();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VersionMapping getMapping() {
|
public VersionMapping getMapping() {
|
||||||
@ -73,6 +68,11 @@ public class Version {
|
|||||||
this.mapping = mapping;
|
this.mapping = mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return getProtocolVersion();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isGettingLoaded() {
|
public boolean isGettingLoaded() {
|
||||||
return isGettingLoaded;
|
return isGettingLoaded;
|
||||||
}
|
}
|
||||||
@ -81,6 +81,7 @@ public class Version {
|
|||||||
isGettingLoaded = gettingLoaded;
|
isGettingLoaded = gettingLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getProtocolVersion() {
|
public int getProtocolVersion() {
|
||||||
return protocolVersion;
|
return protocolVersion;
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,6 @@ public class InChunkLocation {
|
|||||||
return getX() == that.getX() && getY() == that.getY() && getZ() == that.getZ();
|
return getX() == that.getX() && getY() == that.getY() && getZ() == that.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChunkNibbleLocation getChunkNibbleLocation() {
|
|
||||||
return new ChunkNibbleLocation(getX(), getY() % 16, getZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@ -54,6 +50,10 @@ public class InChunkLocation {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChunkNibbleLocation getChunkNibbleLocation() {
|
||||||
|
return new ChunkNibbleLocation(getX(), getY() % 16, getZ());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%d %d %d", getX(), getY(), getZ());
|
return String.format("%d %d %d", getX(), getY(), getZ());
|
||||||
|
@ -43,7 +43,7 @@ public class InByteBuffer {
|
|||||||
final Connection connection;
|
final Connection connection;
|
||||||
final int protocolId;
|
final int protocolId;
|
||||||
final byte[] bytes;
|
final byte[] bytes;
|
||||||
int pos;
|
int position;
|
||||||
|
|
||||||
public InByteBuffer(byte[] bytes, Connection connection) {
|
public InByteBuffer(byte[] bytes, Connection connection) {
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
@ -67,19 +67,23 @@ public class InByteBuffer {
|
|||||||
return buffer.getShort(0);
|
return buffer.getShort(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] readBytes(int count) {
|
|
||||||
byte[] ret = new byte[count];
|
|
||||||
System.arraycopy(bytes, pos, ret, 0, count);
|
|
||||||
pos = pos + count;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long readLong() {
|
public Long readLong() {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
||||||
buffer.put(readBytes(Long.BYTES));
|
buffer.put(readBytes(Long.BYTES));
|
||||||
return buffer.getLong(0);
|
return buffer.getLong(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] readBytes(int count) {
|
||||||
|
byte[] ret = new byte[count];
|
||||||
|
System.arraycopy(bytes, position, ret, 0, count);
|
||||||
|
position = position + count;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double readFixedPointNumberInteger() {
|
||||||
|
return readInt() / 32.0D;
|
||||||
|
}
|
||||||
|
|
||||||
public long readVarLong() {
|
public long readVarLong() {
|
||||||
int numRead = 0;
|
int numRead = 0;
|
||||||
long result = 0;
|
long result = 0;
|
||||||
@ -136,36 +140,11 @@ public class InByteBuffer {
|
|||||||
return new UUID(readLong(), readLong());
|
return new UUID(readLong(), readLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte readByte() {
|
|
||||||
byte ret;
|
|
||||||
ret = bytes[pos];
|
|
||||||
pos++;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int readInt() {
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
|
||||||
buffer.put(readBytes(Integer.BYTES));
|
|
||||||
return buffer.getInt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double readFixedPointNumberInteger() {
|
|
||||||
return readInt() / 32.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String readString() {
|
public String readString() {
|
||||||
int length = readVarInt();
|
int length = readVarInt();
|
||||||
return new String(readBytes(length), StandardCharsets.UTF_8);
|
return new String(readBytes(length), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double readFixedPointNumberByte() {
|
|
||||||
return readByte() / 32.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonObject readJSON() {
|
|
||||||
return JsonParser.parseString(readString()).getAsJsonObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int readVarInt() {
|
public int readVarInt() {
|
||||||
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
|
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||||
int numRead = 0;
|
int numRead = 0;
|
||||||
@ -186,6 +165,24 @@ public class InByteBuffer {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int readInt() {
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
||||||
|
buffer.put(readBytes(Integer.BYTES));
|
||||||
|
return buffer.getInt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double readFixedPointNumberByte() {
|
||||||
|
return readByte() / 32.0D;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObject readJSON() {
|
||||||
|
return JsonParser.parseString(readString()).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte readByte() {
|
||||||
|
return bytes[position++];
|
||||||
|
}
|
||||||
|
|
||||||
public BlockPosition readPosition() {
|
public BlockPosition readPosition() {
|
||||||
//ToDo: protocol id 7
|
//ToDo: protocol id 7
|
||||||
if (protocolId < 440) {
|
if (protocolId < 440) {
|
||||||
@ -315,15 +312,15 @@ public class InByteBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
return this.pos;
|
return this.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(int pos) {
|
public void setPosition(int pos) {
|
||||||
this.pos = pos;
|
this.position = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBytesLeft() {
|
public int getBytesLeft() {
|
||||||
return bytes.length - pos;
|
return bytes.length - position;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] readBytes(int pos, int count) {
|
byte[] readBytes(int pos, int count) {
|
||||||
@ -414,7 +411,7 @@ public class InByteBuffer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "dataLen: " + bytes.length + "; pos: " + pos;
|
return "dataLen: " + bytes.length + "; position: " + position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
|
@ -52,12 +52,32 @@ public class OutByteBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeInt(int i) {
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
||||||
|
buffer.putInt(i);
|
||||||
|
for (byte b : buffer.array()) {
|
||||||
|
bytes.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void writeBytes(byte[] b) {
|
public void writeBytes(byte[] b) {
|
||||||
for (byte value : b) {
|
for (byte value : b) {
|
||||||
bytes.add(value);
|
bytes.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeLong(Long l) {
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
||||||
|
buffer.putLong(l);
|
||||||
|
for (byte b : buffer.array()) {
|
||||||
|
bytes.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeJSON(JsonObject j) {
|
||||||
|
writeString(j.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public void writeVarLong(long value) {
|
public void writeVarLong(long value) {
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -75,14 +95,6 @@ public class OutByteBuffer {
|
|||||||
bytes.add(b);
|
bytes.add(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeInt(int i) {
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
|
||||||
buffer.putInt(i);
|
|
||||||
for (byte b : buffer.array()) {
|
|
||||||
bytes.add(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeFloat(Float f) {
|
public void writeFloat(Float f) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Float.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Float.BYTES);
|
||||||
buffer.putFloat(f);
|
buffer.putFloat(f);
|
||||||
@ -108,18 +120,6 @@ public class OutByteBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeLong(Long l) {
|
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
|
||||||
buffer.putLong(l);
|
|
||||||
for (byte b : buffer.array()) {
|
|
||||||
bytes.add(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeJSON(JsonObject j) {
|
|
||||||
writeString(j.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeFixedPointNumberInteger(double d) {
|
public void writeFixedPointNumberInteger(double d) {
|
||||||
writeInt((int) (d * 32.0D));
|
writeInt((int) (d * 32.0D));
|
||||||
}
|
}
|
||||||
|
@ -14,21 +14,22 @@
|
|||||||
package de.bixilon.minosoft.util;
|
package de.bixilon.minosoft.util;
|
||||||
|
|
||||||
public final class OSUtil {
|
public final class OSUtil {
|
||||||
static OS os;
|
final static OS os;
|
||||||
|
|
||||||
|
static {
|
||||||
|
String name = System.getProperty("os.name");
|
||||||
|
if (name.startsWith("Windows")) {
|
||||||
|
os = OS.WINDOWS;
|
||||||
|
} else if (name.startsWith("Linux")) {
|
||||||
|
os = OS.LINUX;
|
||||||
|
} else if (name.startsWith("Mac")) {
|
||||||
|
os = OS.MAC;
|
||||||
|
} else {
|
||||||
|
os = OS.OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static OS getOS() {
|
public static OS getOS() {
|
||||||
if (os == null) {
|
|
||||||
String name = System.getProperty("os.name");
|
|
||||||
if (name.startsWith("Windows")) {
|
|
||||||
os = OS.WINDOWS;
|
|
||||||
} else if (name.startsWith("Linux")) {
|
|
||||||
os = OS.LINUX;
|
|
||||||
} else if (name.startsWith("Mac")) {
|
|
||||||
os = OS.MAC;
|
|
||||||
} else {
|
|
||||||
os = OS.OTHER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user