From b60464296b563eba2d83653513ddc9ee17fc323d Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 12 Feb 2024 11:02:55 +0100 Subject: [PATCH] Small cleanups --- .../api/exceptions/RemovedValueException.java | 34 -------- .../api/rewriters/ItemRewriter.java | 3 +- .../api/rewriters/ItemRewriterBase.java | 2 +- .../block_entity_handlers/BannerHandler.java | 3 +- .../block_entity_handlers/BedHandler.java | 3 +- .../FlowerPotHandler.java | 3 +- .../block_entity_handlers/PistonHandler.java | 3 +- .../block_entity_handlers/SkullHandler.java | 3 +- .../block_entity_handlers/SpawnerHandler.java | 3 +- .../packets/BlockItemPackets1_13.java | 2 +- .../packets/PlayerPacket1_13.java | 12 ++- .../BackwardsBlockEntityProvider.java | 5 +- .../storage/BackwardsBlockStorage.java | 7 +- .../storage/PlayerPositionStorage1_13.java | 3 - .../packets/BlockItemPackets1_16_2.java | 4 +- .../Protocol1_19_1To1_19_3.java | 84 ++++++++----------- .../viaversion/viabackwards/utils/Block.java | 5 -- .../viabackwards/utils/ChatUtil.java | 2 +- .../viaversion/viabackwards/SpongePlugin.java | 2 - .../viabackwards/VelocityPlugin.java | 1 - 20 files changed, 59 insertions(+), 125 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java b/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java deleted file mode 100644 index 91c32b9d..00000000 --- a/common/src/main/java/com/viaversion/viabackwards/api/exceptions/RemovedValueException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards - * 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.viabackwards.api.exceptions; - -import java.io.IOException; - -public class RemovedValueException extends IOException { - - /** - * May be cached since it is never actually printed, only checked. - */ - public static final RemovedValueException EX = new RemovedValueException() { - @Override - public Throwable fillInStackTrace() { - return this; - } - }; -} diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java index c98cf953..e78d7d62 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/ItemRewriter.java @@ -29,6 +29,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.ByteTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; +import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import org.checkerframework.checker.nullness.qual.Nullable; @@ -118,7 +119,7 @@ public class ItemRewriter itemType, Type itemArrayType, boolean jsonNameFormat) { + protected ItemRewriterBase(T protocol, Type itemType, Type itemArrayType, boolean jsonNameFormat) { super(protocol, itemType, itemArrayType); this.jsonNameFormat = jsonNameFormat; nbtTagName = "VB|" + protocol.getClass().getSimpleName(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java index 0823a154..ee766d85 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BannerHandler.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; @@ -34,7 +33,7 @@ public class BannerHandler implements BackwardsBlockEntityHandler { private static final int BANNER_STOP = 7109; @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { // Normal banners if (blockId >= BANNER_START && blockId <= BANNER_STOP) { int color = (blockId - BANNER_START) >> 4; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java index fa12bc46..25042c25 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/BedHandler.java @@ -19,13 +19,12 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class BedHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { int offset = blockId - 748; int color = offset >> 4; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java index 8309cd03..cf60ae3a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/FlowerPotHandler.java @@ -19,7 +19,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap; import com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -70,7 +69,7 @@ public class FlowerPotHandler implements BackwardsBlockEntityProvider.BackwardsB // TODO THIS IS NEVER CALLED BECAUSE ITS NO LONGER A BLOCK ENTITY :( @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { Pair item = getOrDefault(blockId); tag.putString("Item", item.key()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java index 63d3fddd..50fdf223 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/PistonHandler.java @@ -20,7 +20,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap; import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; @@ -77,7 +76,7 @@ public class PistonHandler implements BackwardsBlockEntityProvider.BackwardsBloc } @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { CompoundTag blockState = tag.getCompoundTag("blockState"); if (blockState == null) return tag; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java index 59e695f4..2774a86f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SkullHandler.java @@ -19,14 +19,13 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider.BackwardsBlockEntityHandler; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; public class SkullHandler implements BackwardsBlockEntityHandler { private static final int SKULL_START = 5447; @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { int diff = blockId - SKULL_START; int pos = diff % 20; byte type = (byte) Math.floor(diff / 20f); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java index b2ac7ea8..8d589189 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/block_entity_handlers/SpawnerHandler.java @@ -20,14 +20,13 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_h import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler { @Override - public CompoundTag transform(UserConnection user, int blockId, CompoundTag tag) { + public CompoundTag transform(int blockId, CompoundTag tag) { CompoundTag dataTag = tag.getCompoundTag("SpawnData"); if (dataTag != null) { StringTag idTag = dataTag.getStringTag("id"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 6cb587c7..a568340a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -711,7 +711,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit tag.putInt("HideFlags", value); } - if (noMapped.size() != 0) { + if (!noMapped.isEmpty()) { tag.put(extraNbtTag + "|" + key, noMapped); if (!lore.isEmpty()) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index fc87aa9a..1ffba60c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -61,12 +61,10 @@ public class PlayerPacket1_13 extends RewriterBase { public void register() { handler(packetWrapper -> { packetWrapper.cancel(); - packetWrapper.create(0x02, new PacketHandler() { // Plugin response - @Override - public void handle(PacketWrapper newWrapper) throws Exception { - newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id - newWrapper.write(Type.BOOLEAN, false); // Success - } + // Plugin response + packetWrapper.create(0x02, wrapper -> { + wrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id + wrapper.write(Type.BOOLEAN, false); // Success }).sendToServer(Protocol1_12_2To1_13.class); }); } @@ -392,7 +390,7 @@ public class PlayerPacket1_13 extends RewriterBase { if (type == 0) { //Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089 //The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either. - //Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types + //Maybe older versions used this and we need to implement this? The issue is that we would have to save the command block types wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); wrapper.cancel(); ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!"); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java index 64dcfc62..1daf268d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java @@ -80,7 +80,7 @@ public class BackwardsBlockEntityProvider implements Provider { return tag; } - return handler.transform(user, blockId, tag); + return handler.transform(blockId, tag); } /** @@ -102,6 +102,7 @@ public class BackwardsBlockEntityProvider implements Provider { @FunctionalInterface public interface BackwardsBlockEntityHandler { - CompoundTag transform(UserConnection user, int blockId, CompoundTag tag); + + CompoundTag transform(int blockId, CompoundTag tag); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java index e7ed334d..c62080d2 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java @@ -24,6 +24,7 @@ import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet; import com.viaversion.viaversion.libs.fastutil.ints.IntSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.checkerframework.checker.nullness.qual.Nullable; public class BackwardsBlockStorage implements StorableObject { // This BlockStorage is very exclusive (; @@ -77,11 +78,7 @@ public class BackwardsBlockStorage implements StorableObject { blocks.put(position, block); } - public boolean isWelcome(int block) { - return WHITELIST.contains(block); - } - - public Integer get(Position position) { + public @Nullable Integer get(Position position) { return blocks.get(position); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java index f3de9337..0ae11884 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/storage/PlayerPositionStorage1_13.java @@ -20,7 +20,4 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage; import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage; public class PlayerPositionStorage1_13 extends PlayerPositionStorage { - - public PlayerPositionStorage1_13() { - } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index 25112222..9990865a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -103,9 +103,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr public void register() { map(Type.POSITION1_14); map(Type.UNSIGNED_BYTE); - handler(wrapper -> { - handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG)); - }); + handler(wrapper -> handleBlockEntity(wrapper.passthrough(Type.NAMED_COMPOUND_TAG))); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index 805cc41e..6c81a856 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -37,6 +37,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_3; import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider; import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata; import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; @@ -59,6 +60,7 @@ import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.Pair; import java.util.BitSet; import java.util.List; +import org.checkerframework.checker.nullness.qual.Nullable; public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol { @@ -91,60 +93,19 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol soundRewriter = new SoundRewriter<>(this); soundRewriter.registerStopSound(ClientboundPackets1_19_3.STOP_SOUND); registerClientbound(ClientboundPackets1_19_3.SOUND, wrapper -> { - final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id - if (soundId != -1) { - final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId); - if (mappedId == -1) { - wrapper.cancel(); - return; - } - - wrapper.write(Type.VAR_INT, mappedId); - return; - } - - String soundIdentifier = wrapper.read(Type.STRING); - wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range - final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier); + final String mappedIdentifier = rewriteSound(wrapper); if (mappedIdentifier != null) { - if (mappedIdentifier.isEmpty()) { - wrapper.cancel(); - return; - } - - soundIdentifier = mappedIdentifier; + wrapper.write(Type.STRING, mappedIdentifier); + wrapper.setPacketType(ClientboundPackets1_19_1.NAMED_SOUND); } - - wrapper.write(Type.STRING, soundIdentifier); - wrapper.setPacketType(ClientboundPackets1_19_1.NAMED_SOUND); }); registerClientbound(ClientboundPackets1_19_3.ENTITY_SOUND, wrapper -> { - final int soundId = wrapper.read(Type.VAR_INT) - 1; // Normalize the id - if (soundId != -1) { - final int mappedId = MAPPINGS.getSoundMappings().getNewId(soundId); - if (mappedId == -1) { - wrapper.cancel(); - return; - } - - wrapper.write(Type.VAR_INT, mappedId); + final String mappedIdentifier = rewriteSound(wrapper); + if (mappedIdentifier == null) { return; } - // Convert the resource location to the corresponding integer id - String soundIdentifier = wrapper.read(Type.STRING); - wrapper.read(Type.OPTIONAL_FLOAT); // Fixed range - final String mappedIdentifier = MAPPINGS.getMappedNamedSound(soundIdentifier); - if (mappedIdentifier != null) { - if (mappedIdentifier.isEmpty()) { - wrapper.cancel(); - return; - } - - soundIdentifier = mappedIdentifier; - } - - final int mappedId = MAPPINGS.mappedSound(soundIdentifier); + final int mappedId = MAPPINGS.mappedSound(mappedIdentifier); if (mappedId == -1) { wrapper.cancel(); return; @@ -387,6 +348,35 @@ public final class Protocol1_19_1To1_19_3 extends BackwardsProtocol(?>§[0-fk-or])*(§r|\\Z))|(?>(?>§[0-f])*(§[0-f]))"); private static final Pattern UNUSED_COLOR_PATTERN_PREFIX = Pattern.compile("(?>(?>§[0-fk-or])*(§r))|(?>(?>§[0-f])*(§[0-f]))"); diff --git a/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java index e29164cc..13a6b061 100644 --- a/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viabackwards/SpongePlugin.java @@ -21,7 +21,6 @@ package com.viaversion.viabackwards; import com.google.inject.Inject; import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.sponge.util.LoggerWrapper; import java.io.File; import java.nio.file.Path; @@ -39,7 +38,6 @@ public class SpongePlugin implements ViaBackwardsPlatform { @ConfigDir(sharedRoot = false) private Path configPath; - @SuppressWarnings("SpongeInjection") @Inject SpongePlugin(final org.apache.logging.log4j.Logger logger) { this.logger = new LoggerWrapper(logger); diff --git a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java index 07629011..87ac645a 100644 --- a/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viabackwards/VelocityPlugin.java @@ -28,7 +28,6 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.viaversion.viabackwards.api.ViaBackwardsPlatform; import com.viaversion.viabackwards.utils.VersionInfo; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.data.MappingDataLoader; import com.viaversion.viaversion.velocity.util.LoggerWrapper; import java.io.File; import java.nio.file.Path;