From 2029deeca78e80123612d8ed8efdeddc0b2e9a5e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 14 Oct 2020 15:00:32 +0200 Subject: [PATCH] mojang: remove status, more enum refactoring, code quality improvement --- .../de/bixilon/minosoft/data/GameModes.java | 18 +-- .../data/entities/EntityEnumInterface.java | 21 ---- .../data/entities/EntityPropertyKeys.java | 46 +++---- .../minosoft/data/entities/Objects.java | 32 ++--- .../data/entities/meta/MooshroomMetaData.java | 22 +--- .../java/de/bixilon/minosoft/logging/Log.java | 12 +- .../de/bixilon/minosoft/modding/Logger.java | 39 ------ .../play/PacketEntityProperties.java | 4 +- .../clientbound/play/PacketSpawnObject.java | 2 +- .../play/PacketAdvancementTab.java | 23 +--- .../play/PacketInteractEntity.java | 18 +-- .../play/PacketResourcePackStatus.java | 20 +-- .../minosoft/protocol/protocol/Packets.java | 7 +- .../util/mojang/api/MojangStatus.java | 116 ------------------ .../minosoft/util/mojang/api/MojangURLs.java | 10 -- .../minosoft/util/nbt/tag/CompoundTag.java | 4 +- .../minosoft/util/nbt/tag/ListTag.java | 2 +- .../minosoft/util/nbt/tag/TagTypes.java | 42 +++---- 18 files changed, 90 insertions(+), 348 deletions(-) delete mode 100644 src/main/java/de/bixilon/minosoft/data/entities/EntityEnumInterface.java delete mode 100644 src/main/java/de/bixilon/minosoft/util/mojang/api/MojangStatus.java diff --git a/src/main/java/de/bixilon/minosoft/data/GameModes.java b/src/main/java/de/bixilon/minosoft/data/GameModes.java index 4212c2102..2da422d22 100644 --- a/src/main/java/de/bixilon/minosoft/data/GameModes.java +++ b/src/main/java/de/bixilon/minosoft/data/GameModes.java @@ -14,22 +14,12 @@ package de.bixilon.minosoft.data; public enum GameModes { - SURVIVAL(0), - CREATIVE(1), - ADVENTURE(2), - SPECTATOR(3); - - final int id; - - GameModes(int id) { - this.id = id; - } + SURVIVAL, + CREATIVE, + ADVENTURE, + SPECTATOR; public static GameModes byId(int id) { return values()[id]; } - - public int getId() { - return id; - } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityEnumInterface.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityEnumInterface.java deleted file mode 100644 index 4870597cd..000000000 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityEnumInterface.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Codename Minosoft - * Copyright (C) 2020 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.data.entities; - -public interface EntityEnumInterface { - - int getType(); - - Class getClazz(); -} diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java index 176986cde..f51b9cecc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java @@ -13,33 +13,37 @@ package de.bixilon.minosoft.data.entities; -import de.bixilon.minosoft.data.ChangeableIdentifier; +import com.google.common.collect.HashBiMap; public enum EntityPropertyKeys { - MAX_HEALTH(new ChangeableIdentifier("generic.maxHealth")), - FOLLOW_RANGE(new ChangeableIdentifier("generic.followRange")), - KNOCKBACK_RESISTANCE(new ChangeableIdentifier("generic.knockbackResistance")), - MOVEMENT_SPEED(new ChangeableIdentifier("generic.movementSpeed")), - ATTACK_DAMAGE(new ChangeableIdentifier("generic.attackDamage")), - HORSE_JUMP_STRENGTH(new ChangeableIdentifier("horse.jumpStrength")), - ZOMBIE_SPAWN_REINFORCEMENT(new ChangeableIdentifier("zombie.spawnReinforcements")); + MAX_HEALTH("generic.maxHealth"), + FOLLOW_RANGE("generic.followRange"), + KNOCKBACK_RESISTANCE("generic.knockbackResistance"), + MOVEMENT_SPEED("generic.movementSpeed"), + ATTACK_DAMAGE("generic.attackDamage"), + HORSE_JUMP_STRENGTH("horse.jumpStrength"), + ZOMBIE_SPAWN_REINFORCEMENT("zombie.spawnReinforcements"); - final ChangeableIdentifier changeableIdentifier; + final static HashBiMap keys = HashBiMap.create(); - EntityPropertyKeys(ChangeableIdentifier changeableIdentifier) { - this.changeableIdentifier = changeableIdentifier; - } - - public static EntityPropertyKeys byName(String name, int protocolId) { - for (EntityPropertyKeys propertyKey : values()) { - if (propertyKey.getChangeableIdentifier().isValidName(name, protocolId)) { - return propertyKey; - } + static { + for (EntityPropertyKeys key : values()) { + keys.put(key.getIdentifier(), key); } - return null; } - public ChangeableIdentifier getChangeableIdentifier() { - return changeableIdentifier; + final String identifier; + + + EntityPropertyKeys(String identifier) { + this.identifier = identifier; + } + + public static EntityPropertyKeys byName(String name) { + return keys.get(name); + } + + public String getIdentifier() { + return identifier; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/Objects.java b/src/main/java/de/bixilon/minosoft/data/entities/Objects.java index 7a6454221..fc3b36c03 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/Objects.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/Objects.java @@ -13,9 +13,10 @@ package de.bixilon.minosoft.data.entities; +import com.google.common.collect.HashBiMap; import de.bixilon.minosoft.data.entities.objects.*; -public enum Objects implements EntityEnumInterface { +public enum Objects { BOAT(1, Boat.class), ITEM_STACK(2, ItemStack.class), AREA_EFFECT_CLOUD(3, AreaEffectCloud.class), @@ -46,31 +47,30 @@ public enum Objects implements EntityEnumInterface { DRAGON_FIREBALL(93, DragonFireball.class), TRIDENT(94, Trident.class); - // ToDo: size changed between versions, fix it! + final static HashBiMap objects = HashBiMap.create(); - final int type; + static { + for (Objects object : values()) { + objects.put(object.getId(), object); + } + } + + final int id; final Class clazz; - Objects(int type, Class clazz) { - this.type = type; + Objects(int id, Class clazz) { + this.id = id; this.clazz = clazz; } - public static Objects byType(int type) { - for (Objects object : values()) { - if (object.getType() == type) { - return object; - } - } - return null; + public static Objects byId(int id) { + return objects.get(id); } - @Override - public int getType() { - return type; + public int getId() { + return id; } - @Override public Class getClazz() { return clazz; } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/meta/MooshroomMetaData.java b/src/main/java/de/bixilon/minosoft/data/entities/meta/MooshroomMetaData.java index 4f4597046..acdfb38c2 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/meta/MooshroomMetaData.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/meta/MooshroomMetaData.java @@ -19,7 +19,7 @@ public class MooshroomMetaData extends AnimalMetaData { } public MooshroomTypes getType() { - final String defaultValue = MooshroomTypes.RED.getTypeName(); + final String defaultValue = MooshroomTypes.RED.name(); if (protocolId < 461) { return MooshroomTypes.byTypeName(defaultValue); } @@ -35,26 +35,12 @@ public class MooshroomMetaData extends AnimalMetaData { } public enum MooshroomTypes { - RED("red"), - BROWN("brown"); - - final String typeName; - - MooshroomTypes(String typeName) { - this.typeName = typeName; - } + RED, + BROWN; public static MooshroomTypes byTypeName(String typeName) { - for (MooshroomTypes type : values()) { - if (type.getTypeName().equals(typeName)) { - return type; - } - } - return null; + return valueOf(typeName.toUpperCase()); } - public String getTypeName() { - return typeName; - } } } diff --git a/src/main/java/de/bixilon/minosoft/logging/Log.java b/src/main/java/de/bixilon/minosoft/logging/Log.java index 5fd6e24d9..682ae9ccf 100644 --- a/src/main/java/de/bixilon/minosoft/logging/Log.java +++ b/src/main/java/de/bixilon/minosoft/logging/Log.java @@ -46,7 +46,7 @@ public class Log { } /** - * Logs all game related things (chunk loading, rendering, ...) + * Logs all game related things (mostly visible stuff to the user) * * @param message Raw message to log */ @@ -97,7 +97,7 @@ public class Log { } /** - * Logs all warnings (connection to server failed, ...) + * Logs all warnings (error occurrence, ...) * * @param message Raw message to log */ @@ -106,7 +106,7 @@ public class Log { } /** - * Logs all debug relevant infos (...) + * Logs way more data (data that might be important for resolving issues) * * @param message Raw message to log */ @@ -115,7 +115,7 @@ public class Log { } /** - * Logs all debug relevant infos (even higher level!) (connection status, ...) + * Logs all debug relevant infos (even higher level!) (connection status, ...). Basically everything that happens * * @param message Raw message to log */ @@ -124,7 +124,7 @@ public class Log { } /** - * Logs all protocol data (received protocol with length and command x,...) + * Logs all protocol data (received packet x with data, etc). Should only be used in packets * * @param message Raw message to log */ @@ -154,7 +154,7 @@ public class Log { } /** - * Logs all general infos (connecting to server, ...) + * Logs all general infos, that are more or less important to the user (connecting to server, ...) * * @param message Raw message to log */ diff --git a/src/main/java/de/bixilon/minosoft/modding/Logger.java b/src/main/java/de/bixilon/minosoft/modding/Logger.java index 2dd1bbe1b..aaedf75b1 100644 --- a/src/main/java/de/bixilon/minosoft/modding/Logger.java +++ b/src/main/java/de/bixilon/minosoft/modding/Logger.java @@ -25,11 +25,6 @@ public class Logger { this.modName = modName; } - /** - * Logs all game related things (chunk loading, rendering, ...) - * - * @param message Raw message to log - */ public void game(String message) { log(LogLevels.GAME, message, ChatColors.getColorByName("green")); } @@ -38,57 +33,23 @@ public class Logger { Log.log(level, String.format("[%s] ", modName), message, color); } - /** - * Logs all fatal errors (critical exceptions, etc) - * - * @param message Raw message to log - */ public void fatal(String message) { log(LogLevels.FATAL, message, ChatColors.getColorByName("dark_red")); } - /** - * Logs all general infos (connecting to server, ...) - * - * @param message Raw message to log - */ public void info(String message) { log(LogLevels.INFO, message, ChatColors.getColorByName("white")); } - /** - * Logs all warnings (connection to server failed, ...) - * - * @param message Raw message to log - */ public void warn(String message) { log(LogLevels.WARNING, message, ChatColors.getColorByName("red")); } - /** - * Logs all debug relevant infos (...) - * - * @param message Raw message to log - */ public void debug(String message) { log(LogLevels.DEBUG, message, ChatColors.getColorByName("gray")); } - /** - * Logs all debug relevant infos (even higher level!) (connection status, ...) - * - * @param message Raw message to log - */ public void verbose(String message) { log(LogLevels.VERBOSE, message, ChatColors.getColorByName("yellow")); } - - /** - * Logs all protocol data (received protocol with length and command x,...) - * - * @param message Raw message to log - */ - public void protocol(String message) { - log(LogLevels.PROTOCOL, message, ChatColors.getColorByName("blue")); - } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java index 1b346dc48..fb81912e5 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java @@ -33,7 +33,7 @@ public class PacketEntityProperties implements ClientboundPacket { if (buffer.getProtocolId() < 7) { int count = buffer.readInt(); for (int i = 0; i < count; i++) { - EntityPropertyKeys key = EntityPropertyKeys.byName(buffer.readString(), buffer.getProtocolId()); + EntityPropertyKeys key = EntityPropertyKeys.byName(buffer.readString()); double value = buffer.readDouble(); short listLength = buffer.readShort(); for (int ii = 0; ii < listLength; ii++) { @@ -48,7 +48,7 @@ public class PacketEntityProperties implements ClientboundPacket { } int count = buffer.readInt(); for (int i = 0; i < count; i++) { - EntityPropertyKeys key = EntityPropertyKeys.byName(buffer.readString(), buffer.getProtocolId()); + EntityPropertyKeys key = EntityPropertyKeys.byName(buffer.readString()); double value = buffer.readDouble(); int listLength = buffer.readVarInt(); for (int ii = 0; ii < listLength; ii++) { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java index a3d97a06f..411451fc1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java @@ -47,7 +47,7 @@ public class PacketSpawnObject implements ClientboundPacket { } Class typeClass; if (buffer.getProtocolId() < 458) { - typeClass = Objects.byType(type).getClazz(); + typeClass = Objects.byId(type).getClazz(); } else { typeClass = Entities.getClassByIdentifier(buffer.getConnection().getMapping().getEntityIdentifierById(type)); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java index 6bbf47dce..3b419f69b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java @@ -36,7 +36,7 @@ public class PacketAdvancementTab implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ADVANCEMENT_TAB); - buffer.writeVarInt(action.getId()); + buffer.writeVarInt(action.ordinal()); if (action == AdvancementTabStatus.OPEN_TAB) { buffer.writeString(tabToOpen); } @@ -49,26 +49,11 @@ public class PacketAdvancementTab implements ServerboundPacket { } public enum AdvancementTabStatus { - OPEN_TAB(0), - CLOSE_TAB(1); - - final int id; - - AdvancementTabStatus(int id) { - this.id = id; - } + OPEN_TAB, + CLOSE_TAB; public static AdvancementTabStatus byId(int id) { - for (AdvancementTabStatus action : values()) { - if (action.getId() == id) { - return action; - } - } - return null; - } - - public int getId() { - return id; + return values()[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java index c62c6ffbd..9a102691a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java @@ -69,7 +69,7 @@ public class PacketInteractEntity implements ServerboundPacket { click = EntityInteractionClicks.INTERACT; } } - buffer.writeByte((byte) click.getId()); + buffer.writeByte((byte) click.ordinal()); if (buffer.getProtocolId() >= 33) { if (click == EntityInteractionClicks.INTERACT_AT) { // position @@ -100,18 +100,8 @@ public class PacketInteractEntity implements ServerboundPacket { } public enum EntityInteractionClicks { - INTERACT(0), - ATTACK(1), - INTERACT_AT(2); - - final int id; - - EntityInteractionClicks(int id) { - this.id = id; - } - - public int getId() { - return id; - } + INTERACT, + ATTACK, + INTERACT_AT } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java index b87881940..2c1b7d8ea 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java @@ -34,7 +34,7 @@ public class PacketResourcePackStatus implements ServerboundPacket { if (buffer.getProtocolId() < 204) { buffer.writeString(hash); } - buffer.writeVarInt(status.getId()); + buffer.writeVarInt(status.ordinal()); return buffer; } @@ -44,19 +44,9 @@ public class PacketResourcePackStatus implements ServerboundPacket { } public enum ResourcePackStates { - SUCCESSFULLY(0), - DECLINED(1), - FAILED_DOWNLOAD(2), - ACCEPTED(3); - - final int id; - - ResourcePackStates(int id) { - this.id = id; - } - - public int getId() { - return id; - } + SUCCESSFULLY, + DECLINED, + FAILED_DOWNLOAD, + ACCEPTED } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java index 07e960670..d0ccbe111 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java @@ -21,7 +21,7 @@ import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusRespo public class Packets { - public enum Serverbound implements PacketBoundary { + public enum Serverbound { HANDSHAKING_HANDSHAKE, STATUS_PING, STATUS_REQUEST, @@ -92,7 +92,7 @@ public class Packets { } } - public enum Clientbound implements PacketBoundary { + public enum Clientbound { STATUS_RESPONSE(PacketStatusResponse.class), STATUS_PONG(PacketStatusPong.class), LOGIN_DISCONNECT(PacketLoginDisconnect.class), @@ -216,7 +216,4 @@ public class Packets { return clazz; } } - - public interface PacketBoundary { - } } diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangStatus.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangStatus.java deleted file mode 100644 index 3d12efa34..000000000 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangStatus.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Codename Minosoft - * Copyright (C) 2020 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.util.mojang.api; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonParser; -import de.bixilon.minosoft.logging.Log; -import de.bixilon.minosoft.logging.LogLevels; -import de.bixilon.minosoft.util.HTTP; - -import java.net.http.HttpResponse; -import java.util.HashMap; - -public final class MojangStatus { - public static HashMap getStatus() { - HttpResponse response = HTTP.get(MojangURLs.STATUS.getUrl()); - if (response == null) { - Log.mojang("Failed to fetch Status"); - return getUnknownStatusMap(); - } - if (response.statusCode() != 200) { - Log.mojang(String.format("Failed to fetch Status with error code %d", response.statusCode())); - return getUnknownStatusMap(); - } - // now it is hopefully okay - HashMap ret = new HashMap<>(); - try { - JsonArray json = JsonParser.parseString(response.body()).getAsJsonArray(); - for (int i = 0; i < json.size(); i++) { - JsonObject innerJson = json.get(i).getAsJsonObject(); - for (String key : innerJson.keySet()) { - Services service = Services.byKey(key); - ret.put(service, ServiceStatus.byKey(innerJson.get(key).getAsString())); - } - } - if (ret.size() != Services.values().length) { - // new service or old one removed, technically an error - return ret; - } - return ret; - - } catch (NullPointerException | JsonParseException e) { - if (Log.getLevel().ordinal() >= LogLevels.DEBUG.ordinal()) { - e.printStackTrace(); - } - return getUnknownStatusMap(); - } - } - - static HashMap getUnknownStatusMap() { - HashMap ret = new HashMap<>(); - for (Services service : Services.values()) { - ret.put(service, ServiceStatus.UNKNOWN); - } - return ret; - } - - enum Services { - MINECRAFT_NET("minecraft.net"), - ACCOUNT("account.mojang.com"), - AUTH("auth.mojang.com"), - AUTHENTICATION_SERVER("authserver.mojang.com"), - SESSION_SERVER("sessionserver.mojang.com"), - API("api.mojang.com"), - TEXTURES("textures.minecraft.net"), - MOJANG_COM("mojang.com"); - - final String key; - - Services(String key) { - this.key = key; - } - - public static Services byKey(String key) { - for (Services service : values()) { - if (service.getKey().equals(key)) { - return service; - } - } - return null; - } - - public String getKey() { - return key; - } - } - - enum ServiceStatus { - GREEN, - YELLOW, - RED, - UNKNOWN; - - public static ServiceStatus byKey(String key) { - for (ServiceStatus status : values()) { - if (status.name().equals(key)) { - return status; - } - } - return UNKNOWN; - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java index ab27079ea..e172d7380 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java @@ -14,7 +14,6 @@ package de.bixilon.minosoft.util.mojang.api; public enum MojangURLs { - STATUS("https://status.mojang.com/check"), BLOCKED_SERVERS("https://sessionserver.mojang.com/blockedservers"), LOGIN("https://authserver.mojang.com/authenticate"), JOIN("https://sessionserver.mojang.com/session/minecraft/join"), @@ -26,15 +25,6 @@ public enum MojangURLs { this.url = url; } - public static MojangURLs byUrl(String key) { - for (MojangURLs url : values()) { - if (url.getUrl().equals(key)) { - return url; - } - } - return null; - } - public String getUrl() { return url; } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java index 6f4842fe9..537204603 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java @@ -66,7 +66,7 @@ public class CompoundTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeByte((byte) TagTypes.COMPOUND.getId()); + buffer.writeByte((byte) TagTypes.COMPOUND.ordinal()); buffer.writeShort((short) name.length()); buffer.writeStringNoLength(name); // now with prefixed name, etc it is technically the same as a subtag @@ -75,7 +75,7 @@ public class CompoundTag extends NBTTag { public void writeBytesSubTag(OutByteBuffer buffer) { for (Map.Entry set : data.entrySet()) { - buffer.writeByte((byte) set.getValue().getType().getId()); + buffer.writeByte((byte) set.getValue().getType().ordinal()); buffer.writeShort((short) set.getKey().length()); buffer.writeStringNoLength(set.getKey()); diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java index 08ba093af..959f242d9 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java @@ -60,7 +60,7 @@ public class ListTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - new ByteTag((byte) type.getId()).writeBytes(buffer); + new ByteTag((byte) type.ordinal()).writeBytes(buffer); new IntTag(list.size()).writeBytes(buffer); diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java index 7e93f55ca..0268a9be6 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java @@ -14,36 +14,22 @@ package de.bixilon.minosoft.util.nbt.tag; public enum TagTypes { - END(0), - BYTE(1), - SHORT(2), - INT(3), - LONG(4), - FLOAT(5), - DOUBLE(6), - BYTE_ARRAY(7), - STRING(8), - LIST(9), - COMPOUND(10), - INT_ARRAY(11), - LONG_ARRAY(12); + END, + BYTE, + SHORT, + INT, + LONG, + FLOAT, + DOUBLE, + BYTE_ARRAY, + STRING, + LIST, + COMPOUND, + INT_ARRAY, + LONG_ARRAY; - final int id; - - TagTypes(int id) { - this.id = id; - } public static TagTypes getById(int id) { - for (TagTypes state : values()) { - if (state.getId() == id) { - return state; - } - } - return null; - } - - public int getId() { - return this.id; + return values()[id]; } }