From 61a72961f5014cc1ebfc91ee1bec2b8aba0868c9 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 27 May 2021 18:27:03 +0200 Subject: [PATCH] remove some old unused/deprecated stuff --- .../{Difficulties.java => Difficulties.kt} | 16 ++--- .../de/bixilon/minosoft/data/LevelTypes.java | 43 ------------- .../data/inventory/InventoryProperties.java | 46 -------------- .../data/inventory/InventoryTypes.java | 60 ------------------- .../modding/event/events/JoinGameEvent.java | 10 +--- .../modding/event/events/RespawnEvent.java | 10 +--- .../protocol/packets/s2c/play/JoinGameS2CP.kt | 13 ++-- .../protocol/packets/s2c/play/RespawnS2CP.kt | 7 +-- .../packets/s2c/play/ServerDifficultyS2CP.kt | 2 +- ...nectionStates.java => ConnectionStates.kt} | 16 ++--- 10 files changed, 30 insertions(+), 193 deletions(-) rename src/main/java/de/bixilon/minosoft/data/{Difficulties.java => Difficulties.kt} (69%) delete mode 100644 src/main/java/de/bixilon/minosoft/data/LevelTypes.java delete mode 100644 src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java delete mode 100644 src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java rename src/main/java/de/bixilon/minosoft/protocol/protocol/{ConnectionStates.java => ConnectionStates.kt} (69%) diff --git a/src/main/java/de/bixilon/minosoft/data/Difficulties.java b/src/main/java/de/bixilon/minosoft/data/Difficulties.kt similarity index 69% rename from src/main/java/de/bixilon/minosoft/data/Difficulties.java rename to src/main/java/de/bixilon/minosoft/data/Difficulties.kt index d672b2241..746eda973 100644 --- a/src/main/java/de/bixilon/minosoft/data/Difficulties.java +++ b/src/main/java/de/bixilon/minosoft/data/Difficulties.kt @@ -10,18 +10,20 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ +package de.bixilon.minosoft.data -package de.bixilon.minosoft.data; +import de.bixilon.minosoft.util.KUtil +import de.bixilon.minosoft.util.enum.ValuesEnum -public enum Difficulties { +enum class Difficulties { PEACEFUL, EASY, NORMAL, - HARD; + HARD, + ; - private static final Difficulties[] DIFFICULTIES = values(); - - public static Difficulties byId(int id) { - return DIFFICULTIES[id]; + companion object : ValuesEnum { + override val VALUES: Array = values() + override val NAME_MAP: Map = KUtil.getEnumValues(VALUES) } } diff --git a/src/main/java/de/bixilon/minosoft/data/LevelTypes.java b/src/main/java/de/bixilon/minosoft/data/LevelTypes.java deleted file mode 100644 index 1b3dde506..000000000 --- a/src/main/java/de/bixilon/minosoft/data/LevelTypes.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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; - -public enum LevelTypes { - DEFAULT("default"), - FLAT("flat"), - LARGE_BIOMES("largeBiomes"), - AMPLIFIED("amplified"), - DEFAULT_1_1("default_1_1"), - CUSTOMIZED("customized"), - BUFFET("buffet"), - UNKNOWN("unknown"); - private final String type; - - LevelTypes(String type) { - this.type = type; - } - - public static LevelTypes byType(String type) { - for (LevelTypes levelType : values()) { - if (levelType.getId().equals(type)) { - return levelType; - } - } - return null; - } - - public String getId() { - return this.type; - } -} diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java deleted file mode 100644 index e6efad996..000000000 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.inventory; - -import de.bixilon.minosoft.data.text.ChatComponent; - -public class InventoryProperties { - private final int windowId; - private final InventoryTypes type; - private final ChatComponent title; - private final byte slotCount; - - public InventoryProperties(int windowId, InventoryTypes type, ChatComponent title, byte slotCount) { - this.windowId = windowId; - this.type = type; - this.title = title; - this.slotCount = slotCount; - } - - public int getWindowId() { - return this.windowId; - } - - public InventoryTypes getType() { - return this.type; - } - - public ChatComponent getTitle() { - return this.title; - } - - public byte getSlotCount() { - return this.slotCount; - } -} diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java deleted file mode 100644 index a95a2c24f..000000000 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.inventory; - -import com.google.common.collect.HashBiMap; -import de.bixilon.minosoft.data.mappings.ResourceLocation; - -@Deprecated -public enum InventoryTypes { - CHEST(new ResourceLocation("minecraft:chest")), - WORKBENCH(new ResourceLocation("minecraft:crafting_table")), - FURNACE(new ResourceLocation("minecraft:furnace")), - DISPENSER(new ResourceLocation("minecraft:dispenser")), - ENCHANTMENT_TABLE(new ResourceLocation("minecraft:enchanting_table")), - BREWING_STAND(new ResourceLocation("minecraft:brewing_stand")), - NPC_TRACE(new ResourceLocation("minecraft:villager")), - BEACON(new ResourceLocation("minecraft:beacon")), - ANVIL(new ResourceLocation("minecraft:anvil")), - HOPPER(new ResourceLocation("minecraft:hopper")), - DROPPER(new ResourceLocation("minecraft:dropper")), - HORSE(new ResourceLocation("EntityHorse")); - - private static final InventoryTypes[] INVENTORY_TYPES = values(); - private static final HashBiMap RESOURCE_LOCATION_TYPE_MAP = HashBiMap.create(); - - static { - for (InventoryTypes type : INVENTORY_TYPES) { - RESOURCE_LOCATION_TYPE_MAP.put(type.getResourceLocation(), type); - } - } - - private final ResourceLocation resourceLocation; - - InventoryTypes(ResourceLocation resourceLocation) { - this.resourceLocation = resourceLocation; - } - - public static InventoryTypes byId(int id) { - return INVENTORY_TYPES[id]; - } - - public static InventoryTypes byResourceLocation(ResourceLocation resourceLocation) { - return RESOURCE_LOCATION_TYPE_MAP.get(resourceLocation); - } - - public ResourceLocation getResourceLocation() { - return this.resourceLocation; - } -} diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java index 254e0de5d..453fad18b 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java @@ -15,7 +15,6 @@ package de.bixilon.minosoft.modding.event.events; import com.google.common.collect.HashBiMap; import de.bixilon.minosoft.data.Difficulties; -import de.bixilon.minosoft.data.LevelTypes; import de.bixilon.minosoft.data.abilities.Gamemodes; import de.bixilon.minosoft.data.mappings.Dimension; import de.bixilon.minosoft.data.mappings.ResourceLocation; @@ -30,13 +29,12 @@ public class JoinGameEvent extends CancelableEvent { private final Difficulties difficulty; private final int viewDistance; private final int maxPlayers; - private final LevelTypes levelType; private final boolean reducedDebugScreen; private final boolean enableRespawnScreen; private final long hashedSeed; private final HashBiMap dimensions; - public JoinGameEvent(PlayConnection connection, int entityId, boolean hardcore, Gamemodes gamemode, Dimension dimension, Difficulties difficulty, int viewDistance, int maxPlayers, LevelTypes levelType, boolean reducedDebugScreen, boolean enableRespawnScreen, long hashedSeed, HashBiMap dimensions) { + public JoinGameEvent(PlayConnection connection, int entityId, boolean hardcore, Gamemodes gamemode, Dimension dimension, Difficulties difficulty, int viewDistance, int maxPlayers, boolean reducedDebugScreen, boolean enableRespawnScreen, long hashedSeed, HashBiMap dimensions) { super(connection); this.entityId = entityId; this.hardcore = hardcore; @@ -45,7 +43,6 @@ public class JoinGameEvent extends CancelableEvent { this.difficulty = difficulty; this.viewDistance = viewDistance; this.maxPlayers = maxPlayers; - this.levelType = levelType; this.reducedDebugScreen = reducedDebugScreen; this.enableRespawnScreen = enableRespawnScreen; this.hashedSeed = hashedSeed; @@ -61,7 +58,6 @@ public class JoinGameEvent extends CancelableEvent { this.difficulty = pkg.getDifficulty(); this.viewDistance = pkg.getViewDistance(); this.maxPlayers = pkg.getMaxPlayers(); - this.levelType = pkg.getLevelType(); this.reducedDebugScreen = pkg.isReducedDebugScreen(); this.enableRespawnScreen = pkg.isEnableRespawnScreen(); this.hashedSeed = pkg.getHashedSeed(); @@ -96,10 +92,6 @@ public class JoinGameEvent extends CancelableEvent { return this.maxPlayers; } - public LevelTypes getLevelType() { - return this.levelType; - } - public boolean isReducedDebugScreen() { return this.reducedDebugScreen; } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java index ebed69e99..d24854c50 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java @@ -14,7 +14,6 @@ package de.bixilon.minosoft.modding.event.events; import de.bixilon.minosoft.data.Difficulties; -import de.bixilon.minosoft.data.LevelTypes; import de.bixilon.minosoft.data.abilities.Gamemodes; import de.bixilon.minosoft.data.mappings.Dimension; import de.bixilon.minosoft.protocol.network.connection.PlayConnection; @@ -24,14 +23,12 @@ public class RespawnEvent extends PlayConnectionEvent { private final Gamemodes gamemode; private final Dimension dimension; private final Difficulties difficulty; - private final LevelTypes levelType; - public RespawnEvent(PlayConnection connection, Gamemodes gamemode, Dimension dimension, Difficulties difficulty, LevelTypes levelType) { + public RespawnEvent(PlayConnection connection, Gamemodes gamemode, Dimension dimension, Difficulties difficulty) { super(connection); this.gamemode = gamemode; this.dimension = dimension; this.difficulty = difficulty; - this.levelType = levelType; } public RespawnEvent(PlayConnection connection, RespawnS2CP pkg) { @@ -39,7 +36,6 @@ public class RespawnEvent extends PlayConnectionEvent { this.gamemode = pkg.getGamemode(); this.dimension = pkg.getDimension(); this.difficulty = pkg.getDifficulty(); - this.levelType = pkg.getLevelType(); } public Gamemodes getGamemode() { @@ -53,8 +49,4 @@ public class RespawnEvent extends PlayConnectionEvent { public Difficulties getDifficulty() { return this.difficulty; } - - public LevelTypes getLevelType() { - return this.levelType; - } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt index 666751b27..a64c244cb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/JoinGameS2CP.kt @@ -14,7 +14,6 @@ package de.bixilon.minosoft.protocol.packets.s2c.play import com.google.common.collect.HashBiMap import de.bixilon.minosoft.data.Difficulties -import de.bixilon.minosoft.data.LevelTypes import de.bixilon.minosoft.data.abilities.Gamemodes import de.bixilon.minosoft.data.mappings.Dimension import de.bixilon.minosoft.data.mappings.ResourceLocation @@ -48,7 +47,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { private set var maxPlayers = 0 private set - var levelType: LevelTypes = LevelTypes.UNKNOWN + var levelType: String? = null private set var isReducedDebugScreen = false private set @@ -74,10 +73,10 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { if (buffer.versionId < ProtocolVersions.V_1_9_1) { dimension = buffer.connection.registries.dimensionRegistry[buffer.readByte().toInt()] - difficulty = Difficulties.byId(buffer.readUnsignedByte().toInt()) + difficulty = Difficulties[buffer.readUnsignedByte()] maxPlayers = buffer.readByte().toInt() if (buffer.versionId >= ProtocolVersions.V_13W42B) { - levelType = LevelTypes.byType(buffer.readString()) + levelType = buffer.readString() } if (buffer.versionId >= ProtocolVersions.V_14W29A) { isReducedDebugScreen = buffer.readBoolean() @@ -107,7 +106,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { hashedSeed = buffer.readLong() } if (buffer.versionId < ProtocolVersions.V_19W11A) { - difficulty = Difficulties.byId(buffer.readUnsignedByte()) + difficulty = Difficulties[buffer.readUnsignedByte()] } maxPlayers = if (buffer.versionId < ProtocolVersions.V_1_16_2_RC1) { buffer.readByte().toInt() @@ -115,7 +114,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { buffer.readVarInt() } if (buffer.versionId < ProtocolVersions.V_20W20A) { - levelType = LevelTypes.byType(buffer.readString()) + levelType = buffer.readString() } if (buffer.versionId >= ProtocolVersions.V_19W13A) { viewDistance = buffer.readVarInt() @@ -123,7 +122,7 @@ class JoinGameS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { if (buffer.versionId >= ProtocolVersions.V_20W20A) { buffer.readBoolean() // isDebug if (buffer.readBoolean()) { - levelType = LevelTypes.FLAT + levelType = "flat" } } isReducedDebugScreen = buffer.readBoolean() diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt index 7280f6148..c83d8eb31 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/RespawnS2CP.kt @@ -13,7 +13,6 @@ package de.bixilon.minosoft.protocol.packets.s2c.play import de.bixilon.minosoft.data.Difficulties -import de.bixilon.minosoft.data.LevelTypes import de.bixilon.minosoft.data.abilities.Gamemodes import de.bixilon.minosoft.data.mappings.Dimension import de.bixilon.minosoft.modding.event.events.RespawnEvent @@ -33,7 +32,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { var difficulty: Difficulties = Difficulties.NORMAL private set val gamemode: Gamemodes - var levelType: LevelTypes = LevelTypes.UNKNOWN + var levelType: String? = null private set var hashedSeed = 0L private set @@ -61,7 +60,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { } } if (buffer.versionId < ProtocolVersions.V_19W11A) { - difficulty = Difficulties.byId(buffer.readUnsignedByte()) + difficulty = Difficulties[buffer.readUnsignedByte()] } if (buffer.versionId >= ProtocolVersions.V_20W22A) { dimension = buffer.connection.registries.dimensionRegistry[buffer.readResourceLocation()]!! @@ -74,7 +73,7 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { buffer.readByte() // previous game mode } if (buffer.versionId >= ProtocolVersions.V_13W42B && buffer.versionId < ProtocolVersions.V_20W20A) { - levelType = LevelTypes.byType(buffer.readString()) + levelType = buffer.readString() } if (buffer.versionId >= ProtocolVersions.V_20W20A) { isDebug = buffer.readBoolean() diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt index 40b7fd2aa..e6483a107 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/ServerDifficultyS2CP.kt @@ -22,7 +22,7 @@ import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType class ServerDifficultyS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() { - val difficulty: Difficulties = Difficulties.byId(buffer.readUnsignedByte()) + val difficulty: Difficulties = Difficulties[buffer.readUnsignedByte()] var locked = false private set diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.kt similarity index 69% rename from src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java rename to src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.kt index eeadb3e09..c0e45986d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.kt @@ -10,10 +10,12 @@ * * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ +package de.bixilon.minosoft.protocol.protocol -package de.bixilon.minosoft.protocol.protocol; +import de.bixilon.minosoft.util.KUtil +import de.bixilon.minosoft.util.enum.ValuesEnum -public enum ConnectionStates { +enum class ConnectionStates { HANDSHAKING, STATUS, LOGIN, @@ -22,11 +24,11 @@ public enum ConnectionStates { DISCONNECTING, DISCONNECTED, FAILED, - FAILED_NO_RETRY; + FAILED_NO_RETRY, + ; - private static final ConnectionStates[] CONNECTION_STATES = values(); - - public static ConnectionStates byId(int id) { - return CONNECTION_STATES[id]; + companion object : ValuesEnum { + override val VALUES: Array = values() + override val NAME_MAP: Map = KUtil.getEnumValues(VALUES) } }