Small random cleanup

This commit is contained in:
Nassim Jahnke 2024-02-10 17:58:54 +01:00
parent c7265abfe9
commit cfc048ba53
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
18 changed files with 36 additions and 45 deletions

View File

@ -106,7 +106,7 @@ public class CollisionChecker {
} }
private static class DummyList<T> extends AbstractList<T> { private static class DummyList<T> extends AbstractList<T> {
private boolean any = false; private boolean any;
@Override @Override
public T get(int index) { public T get(int index) {

View File

@ -199,10 +199,6 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
private boolean isSupported() { private boolean isSupported() {
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion(); int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) { return protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion(); // 1.8-1.11.2, not needed with 1.12
return true; // 1.8-1.11.2
}
// this is not needed on 1.12+ servers
return false;
} }
} }

View File

@ -31,6 +31,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -56,7 +57,7 @@ public class CommonBoss implements BossBar {
this.color = color == null ? BossColor.PURPLE : color; this.color = color == null ? BossColor.PURPLE : color;
this.style = style == null ? BossStyle.SOLID : style; this.style = style == null ? BossStyle.SOLID : style;
this.connections = new MapMaker().weakValues().makeMap(); this.connections = new MapMaker().weakValues().makeMap();
this.flags = new HashSet<>(); this.flags = EnumSet.noneOf(BossFlag.class);
this.visible = true; this.visible = true;
} }

View File

@ -22,7 +22,7 @@ import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.Key;
public class BlockEntityRewriter { public class BlockEntityRewriter {
private static BiMap<String, String> oldToNewNames = HashBiMap.create(); private static final BiMap<String, String> OLD_TO_NEW_NAMES = HashBiMap.create();
// Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles // Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles
static { static {
@ -52,15 +52,15 @@ public class BlockEntityRewriter {
} }
private static void rewrite(String oldName, String newName) { private static void rewrite(String oldName, String newName) {
oldToNewNames.put(oldName, Key.namespaced(newName)); OLD_TO_NEW_NAMES.put(oldName, Key.namespaced(newName));
} }
public static BiMap<String, String> inverse() { public static BiMap<String, String> inverse() {
return oldToNewNames.inverse(); return OLD_TO_NEW_NAMES.inverse();
} }
public static String toNewIdentifier(String oldId) { public static String toNewIdentifier(String oldId) {
String newName = oldToNewNames.get(oldId); String newName = OLD_TO_NEW_NAMES.get(oldId);
if (newName != null) { if (newName != null) {
return newName; return newName;
} }

View File

@ -36,7 +36,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
Arrays.fill(connectedBlockStates, -1); Arrays.fill(connectedBlockStates, -1);
} }
public ConnectionData.ConnectorInitAction getInitAction(final String key) { ConnectionData.ConnectorInitAction getInitAction(final String key) {
final AbstractFenceConnectionHandler handler = this; final AbstractFenceConnectionHandler handler = this;
return blockData -> { return blockData -> {
if (key.equals(blockData.getMinecraftKey())) { if (key.equals(blockData.getMinecraftKey())) {

View File

@ -38,7 +38,7 @@ public abstract class AbstractStempConnectionHandler extends ConnectionHandler {
this.baseStateId = ConnectionData.getId(baseStateId); this.baseStateId = ConnectionData.getId(baseStateId);
} }
public ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) { ConnectionData.ConnectorInitAction getInitAction(final String blockId, final String toKey) {
final AbstractStempConnectionHandler handler = this; final AbstractStempConnectionHandler handler = this;
return blockData -> { return blockData -> {
if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) { if (blockData.getSavedBlockStateId() == baseStateId || blockId.equals(blockData.getMinecraftKey())) {

View File

@ -39,7 +39,7 @@ public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler
endstone = ConnectionData.getId("minecraft:end_stone"); endstone = ConnectionData.getId("minecraft:end_stone");
} }
public ConnectionData.ConnectorInitAction getExtraAction() { private ConnectionData.ConnectorInitAction getExtraAction() {
return blockData -> { return blockData -> {
if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) { if (blockData.getMinecraftKey().equals("minecraft:chorus_flower")) {
getBlockStates().add(blockData.getSavedBlockStateId()); getBlockStates().add(blockData.getSavedBlockStateId());

View File

@ -59,13 +59,12 @@ public class RedstoneConnectionHandler extends ConnectionHandler {
private static int getState(String value) { private static int getState(String value) {
switch (value) { switch (value) {
case "none": case "none":
default:
return 0; return 0;
case "side": case "side":
return 1; return 1;
case "up": case "up":
return 2; return 2;
default:
return 0;
} }
} }

View File

@ -99,7 +99,7 @@ public class ParticleRewriter {
} }
NewParticle rewrite = particles.get(particleId); NewParticle rewrite = particles.get(particleId);
return rewrite.handle(new Particle(rewrite.getId()), data); return rewrite.handle(new Particle(rewrite.id()), data);
} }
private static void add(int newId) { private static void add(int newId) {
@ -157,6 +157,7 @@ public class ParticleRewriter {
}; };
} }
@FunctionalInterface
interface ParticleDataHandler { interface ParticleDataHandler {
Particle handler(Particle particle, Integer[] data); Particle handler(Particle particle, Integer[] data);
} }
@ -176,11 +177,11 @@ public class ParticleRewriter {
return particle; return particle;
} }
public int getId() { public int id() {
return id; return id;
} }
public ParticleDataHandler getHandler() { public ParticleDataHandler handler() {
return handler; return handler;
} }
} }

View File

@ -31,20 +31,16 @@ public class RecipeData {
public static void init() { public static void init() {
InputStream stream = MappingData.class.getClassLoader() InputStream stream = MappingData.class.getClassLoader()
.getResourceAsStream("assets/viaversion/data/itemrecipes1_12_2to1_13.json"); .getResourceAsStream("assets/viaversion/data/itemrecipes1_12_2to1_13.json");
InputStreamReader reader = new InputStreamReader(stream); try (InputStreamReader reader = new InputStreamReader(stream)) {
try {
recipes = GsonUtil.getGson().fromJson( recipes = GsonUtil.getGson().fromJson(
reader, reader,
new TypeToken<Map<String, Recipe>>() { new TypeToken<Map<String, Recipe>>() {
}.getType() }.getType()
); );
} finally { } catch (IOException e) {
try { throw new RuntimeException(e);
reader.close();
} catch (IOException ignored) {
// Ignored
}
} }
// Ignored
} }
public static class Recipe { public static class Recipe {

View File

@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
public class InventoryTracker1_16 implements StorableObject { public class InventoryTracker1_16 implements StorableObject {
private boolean inventoryOpen = false; private boolean inventoryOpen;
public boolean isInventoryOpen() { public boolean isInventoryOpen() {
return inventoryOpen; return inventoryOpen;

View File

@ -61,7 +61,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
} }
public static boolean isTextComponentNull(final JsonElement element) { public static boolean isTextComponentNull(final JsonElement element) {
return element == null || element.isJsonNull() || (element.isJsonArray() && element.getAsJsonArray().size() == 0); return element == null || element.isJsonNull() || (element.isJsonArray() && element.getAsJsonArray().isEmpty());
} }
public static JsonElement mapTextComponentIfNull(JsonElement component) { public static JsonElement mapTextComponentIfNull(JsonElement component) {
@ -126,9 +126,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
new StatisticsRewriter<>(this).register(ClientboundPackets1_18.STATISTICS); new StatisticsRewriter<>(this).register(ClientboundPackets1_18.STATISTICS);
final PacketHandler singleNullTextComponentMapper = wrapper -> { final PacketHandler singleNullTextComponentMapper = wrapper -> wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT)));
wrapper.write(Type.COMPONENT, mapTextComponentIfNull(wrapper.read(Type.COMPONENT)));
};
registerClientbound(ClientboundPackets1_18.TITLE_TEXT, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.TITLE_TEXT, singleNullTextComponentMapper);
registerClientbound(ClientboundPackets1_18.TITLE_SUBTITLE, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.TITLE_SUBTITLE, singleNullTextComponentMapper);
registerClientbound(ClientboundPackets1_18.ACTIONBAR, singleNullTextComponentMapper); registerClientbound(ClientboundPackets1_18.ACTIONBAR, singleNullTextComponentMapper);

View File

@ -98,13 +98,16 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
} }
public static boolean isSword(int id) { public static boolean isSword(int id) {
if (id == 267) return true; // Iron switch (id) {
if (id == 268) return true; // Wood case 267: // Iron sword
if (id == 272) return true; // Stone case 268: // Wooden sword
if (id == 276) return true; // Diamond case 272: // Stone sword
if (id == 283) return true; // Gold case 276: // Diamond sword
case 283: // Gold sword
return false; return true;
default:
return false;
}
} }
@Override @Override

View File

@ -72,7 +72,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
} }
// After writing the last one // After writing the last one
if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityTypes1_10.EntityType.PLAYER) { if (metaIndex == MetaIndex.ENTITY_STATUS && type == EntityTypes1_10.EntityType.PLAYER) {
Byte val = 0; byte val = 0;
if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking if ((((Byte) value) & 0x10) == 0x10) { // Player eating/aiming/drinking
val = 1; val = 1;
} }

View File

@ -253,8 +253,6 @@ public class PlayerPackets {
String displayName = wrapper.read(Type.OPTIONAL_STRING); String displayName = wrapper.read(Type.OPTIONAL_STRING);
wrapper.write(Type.OPTIONAL_COMPONENT, displayName != null ? wrapper.write(Type.OPTIONAL_COMPONENT, displayName != null ?
Protocol1_9To1_8.FIX_JSON.transform(wrapper, displayName) : null); Protocol1_9To1_8.FIX_JSON.transform(wrapper, displayName) : null);
} else if (action == 4) { // remove player
// no fields
} }
} }
}); });

View File

@ -160,7 +160,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
slot = wrapper.passthrough(Type.BYTE); slot = wrapper.passthrough(Type.BYTE);
// & 0x7F into an extra variable if slot is needed // & 0x7F into an extra variable if slot is needed
handleItemToClient(wrapper.passthrough(itemType)); handleItemToClient(wrapper.passthrough(itemType));
} while ((slot & 0xFFFFFF80) != 0); } while (slot < 0);
}); });
} }
}); });

View File

@ -76,7 +76,6 @@ public class SpongePlugin implements ViaPlatform<Player> {
@ConfigDir(sharedRoot = false) @ConfigDir(sharedRoot = false)
private Path configDir; private Path configDir;
@SuppressWarnings("SpongeInjection")
@Inject @Inject
SpongePlugin(final PluginContainer container, final Game game, final org.apache.logging.log4j.Logger logger) { SpongePlugin(final PluginContainer container, final Game game, final org.apache.logging.log4j.Logger logger) {
this.container = container; this.container = container;

View File

@ -52,7 +52,7 @@ public class SpongeChannelInitializer extends ChannelInitializer<Channel> implem
// Ensure ViaVersion is loaded // Ensure ViaVersion is loaded
if (Via.getAPI().getServerVersion().isKnown() if (Via.getAPI().getServerVersion().isKnown()
&& channel instanceof SocketChannel) { // channel can be LocalChannel on internal server && channel instanceof SocketChannel) { // channel can be LocalChannel on internal server
UserConnection info = new UserConnectionImpl((SocketChannel) channel); UserConnection info = new UserConnectionImpl(channel);
// init protocol // init protocol
new ProtocolPipelineImpl(info); new ProtocolPipelineImpl(info);
// Add originals // Add originals