From d47b5be7f304ab0d7d2a8cdfac9a74554377e594 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 11 May 2024 19:12:28 +0200 Subject: [PATCH] Move GameMode enum into api module Actually not needed there but still fits in there --- .../viaversion/api/minecraft/GameMode.java | 51 +++++++++++++++++++ .../protocols/v1_8to1_9/data/GameMode.java | 48 ----------------- .../rewriter/PlayerPacketRewriter1_9.java | 4 +- .../v1_8to1_9/storage/EntityTracker1_9.java | 2 +- 4 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/GameMode.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/data/GameMode.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameMode.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameMode.java new file mode 100644 index 000000000..4520c33ab --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameMode.java @@ -0,0 +1,51 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft; + +public enum GameMode { + + SURVIVAL("Survival Mode"), + CREATIVE("Creative Mode"), + ADVENTURE("Adventure Mode"), + SPECTATOR( "Spectator Mode"); + + private final String text; + + GameMode(String text) { + this.text = text; + } + + public String text() { + return text; + } + + public static GameMode getById(int id) { + return switch (id) { + case 0 -> SURVIVAL; + case 1 -> CREATIVE; + case 2 -> ADVENTURE; + case 3 -> SPECTATOR; + default -> throw new IllegalArgumentException("Unknown gamemode id: " + id); + }; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/data/GameMode.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/data/GameMode.java deleted file mode 100644 index 326b50387..000000000 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/data/GameMode.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * 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 . - */ -package com.viaversion.viaversion.protocols.v1_8to1_9.data; - -public enum GameMode { - SURVIVAL(0, "Survival Mode"), - CREATIVE(1, "Creative Mode"), - ADVENTURE(2, "Adventure Mode"), - SPECTATOR(3, "Spectator Mode"); - - private final int id; - private final String text; - - GameMode(int id, String text) { - this.id = id; - this.text = text; - } - - public int getId() { - return id; - } - - public String getText() { - return text; - } - - public static GameMode getById(int id) { - for (GameMode gm : GameMode.values()) - if (gm.getId() == id) - return gm; - return null; - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java index a2de0c000..fc9bbb07d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/PlayerPacketRewriter1_9.java @@ -31,7 +31,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9; -import com.viaversion.viaversion.protocols.v1_8to1_9.data.GameMode; +import com.viaversion.viaversion.api.minecraft.GameMode; import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_9; import com.viaversion.viaversion.protocols.v1_8to1_9.provider.CommandBlockProvider; import com.viaversion.viaversion.protocols.v1_8to1_9.provider.CompressionProvider; @@ -54,7 +54,7 @@ public class PlayerPacketRewriter1_9 { JsonObject obj = (JsonObject) wrapper.get(Types.COMPONENT, 0); if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) { EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); - String gameMode = tracker.getGameMode().getText(); + String gameMode = tracker.getGameMode().text(); JsonObject gameModeObject = new JsonObject(); gameModeObject.addProperty("text", gameMode); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/storage/EntityTracker1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/storage/EntityTracker1_9.java index 95cda341c..1444a0bb6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/storage/EntityTracker1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/storage/EntityTracker1_9.java @@ -34,7 +34,7 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_8to1_9.Protocol1_8To1_9; -import com.viaversion.viaversion.protocols.v1_8to1_9.data.GameMode; +import com.viaversion.viaversion.api.minecraft.GameMode; import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_9; import com.viaversion.viaversion.protocols.v1_8to1_9.provider.BossBarProvider; import com.viaversion.viaversion.protocols.v1_8to1_9.provider.EntityIdProvider;