From 75db1a7cdfa7f6e04c225ee50b72fd6869ad4a29 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 28 Aug 2021 16:50:52 +0200 Subject: [PATCH] Start work on ViaVersion 5.0.0 Bump Java target to 17, clean up using its new language features Remove unnecessary checked exception throwing Remove deprecated code --- README.md | 2 + api-legacy/build.gradle.kts | 3 - .../java/us/myles/ViaVersion/api/Via.java | 101 ------- .../java/us/myles/ViaVersion/api/ViaAPI.java | 62 ----- .../us/myles/ViaVersion/api/boss/BossBar.java | 133 --------- .../myles/ViaVersion/api/boss/BossColor.java | 45 ---- .../myles/ViaVersion/api/boss/BossFlag.java | 40 --- .../myles/ViaVersion/api/boss/BossStyle.java | 43 --- .../api/protocol/ProtocolRegistry.java | 33 --- .../api/protocol/ProtocolVersion.java | 255 ------------------ .../com/viaversion/viaversion/api/ViaAPI.java | 2 +- .../viaversion/api/command/ViaSubCommand.java | 18 +- .../api/command/ViaVersionCommand.java | 2 +- .../api/configuration/ViaVersionConfig.java | 1 + .../api/connection/ProtocolInfo.java | 21 +- .../api/connection/UserConnection.java | 30 +-- .../viaversion/api/data/IdentityMappings.java | 20 +- .../viaversion/api/debug/DebugHandler.java | 8 +- .../viaversion/api/minecraft/BlockFace.java | 21 -- .../viaversion/api/minecraft/Environment.java | 19 +- .../viaversion/api/minecraft/EulerAngle.java | 38 +-- .../viaversion/api/minecraft/GameProfile.java | 47 +--- .../viaversion/api/minecraft/Particle.java | 7 +- .../api/minecraft/PlayerMessageSignature.java | 17 +- .../viaversion/api/minecraft/Position.java | 20 -- .../viaversion/api/minecraft/Position3d.java | 23 +- .../viaversion/api/minecraft/ProfileKey.java | 23 +- .../viaversion/api/minecraft/Quaternion.java | 39 +-- .../api/minecraft/RegistryEntry.java | 17 +- .../viaversion/api/minecraft/SoundEvent.java | 18 +- .../viaversion/api/minecraft/TagData.java | 31 +-- .../viaversion/api/minecraft/Vector.java | 53 +--- .../viaversion/api/minecraft/Vector3f.java | 23 +- .../api/minecraft/VillagerData.java | 38 +-- .../api/minecraft/WorldIdentifiers.java | 24 +- .../blockentity/BlockEntityImpl.java | 33 +-- .../api/minecraft/chunks/ChunkSection.java | 80 ------ .../minecraft/data/FilledStructuredData.java | 2 +- .../api/minecraft/data/StructuredData.java | 2 +- .../api/minecraft/data/StructuredDataKey.java | 18 +- .../minecraft/entities/EntityTypes1_10.java | 11 +- .../minecraft/entities/EntityTypes1_11.java | 11 +- .../minecraft/entities/EntityTypes1_12.java | 11 +- .../minecraft/entities/EntityTypes1_13.java | 6 +- .../api/minecraft/item/DataItem.java | 6 +- .../item/data/AdventureModePredicate.java | 23 +- .../api/minecraft/item/data/ArmorTrim.java | 29 +- .../item/data/ArmorTrimMaterial.java | 42 +-- .../minecraft/item/data/ArmorTrimPattern.java | 35 +-- .../item/data/AttributeModifier.java | 29 +- .../item/data/AttributeModifiers.java | 23 +- .../minecraft/item/data/BannerPattern.java | 23 +- .../item/data/BannerPatternLayer.java | 23 +- .../api/minecraft/item/data/Bee.java | 29 +- .../minecraft/item/data/BlockPredicate.java | 30 +-- .../item/data/BlockStateProperties.java | 17 +- .../api/minecraft/item/data/DyedColor.java | 19 +- .../api/minecraft/item/data/Enchantments.java | 20 +- .../api/minecraft/item/data/Filterable.java | 4 +- .../item/data/FilterableComponent.java | 2 +- .../minecraft/item/data/FilterableString.java | 2 +- .../item/data/FireworkExplosion.java | 41 +-- .../api/minecraft/item/data/Fireworks.java | 23 +- .../api/minecraft/item/data/FoodEffect.java | 23 +- .../minecraft/item/data/FoodProperties.java | 42 +-- .../api/minecraft/item/data/Instrument.java | 29 +- .../minecraft/item/data/LodestoneTracker.java | 23 +- .../minecraft/item/data/MapDecoration.java | 37 +-- .../minecraft/item/data/MapDecorations.java | 18 +- .../api/minecraft/item/data/ModifierData.java | 35 +-- .../minecraft/item/data/PotDecorations.java | 6 +- .../minecraft/item/data/PotionContents.java | 30 +-- .../api/minecraft/item/data/PotionEffect.java | 23 +- .../minecraft/item/data/PotionEffectData.java | 52 +--- .../item/data/StatePropertyMatcher.java | 41 +-- .../item/data/SuspiciousStewEffect.java | 21 +- .../minecraft/item/data/ToolProperties.java | 29 +- .../api/minecraft/item/data/ToolRule.java | 29 +- .../api/minecraft/item/data/Unbreakable.java | 13 +- .../api/minecraft/item/data/WrittenBook.java | 42 +-- .../viaversion/api/platform/PlatformTask.java | 11 - .../viaversion/api/platform/ViaPlatform.java | 5 - .../api/protocol/AbstractProtocol.java | 4 +- .../viaversion/api/protocol/Protocol.java | 88 +----- .../api/protocol/ProtocolManager.java | 15 +- .../packet/ClientboundPacketType.java | 2 +- .../api/protocol/packet/PacketTracker.java | 9 + .../api/protocol/packet/PacketType.java | 2 +- .../api/protocol/packet/PacketWrapper.java | 132 +++------ .../packet/ServerboundPacketType.java | 2 +- .../packet/VersionedPacketTransformer.java | 25 +- .../provider/SimplePacketTypesProvider.java | 43 +-- .../api/protocol/remapper/PacketHandler.java | 4 +- .../api/protocol/remapper/PacketHandlers.java | 5 +- .../api/protocol/remapper/PacketRemapper.java | 181 ------------- .../api/protocol/remapper/TypeRemapper.java | 12 +- .../api/protocol/remapper/ValueReader.java | 4 +- .../protocol/remapper/ValueTransformer.java | 5 +- .../api/protocol/remapper/ValueWriter.java | 4 +- .../api/protocol/version/ProtocolVersion.java | 18 +- .../api/protocol/version/SubVersionRange.java | 10 +- .../api/rewriter/EntityRewriter.java | 2 +- .../viaversion/api/rewriter/ItemRewriter.java | 2 +- .../viaversion/api/rewriter/Rewriter.java | 2 +- .../viaversion/api/rewriter/RewriterBase.java | 2 +- .../viaversion/api/type/ByteBufReader.java | 3 +- .../viaversion/api/type/ByteBufWriter.java | 3 +- .../viaversion/api/type/OptionalType.java | 4 +- .../viaversion/api/type/PartialType.java | 54 ---- .../viaversion/viaversion/api/type/Type.java | 20 -- .../viaversion/api/type/types/ArrayType.java | 4 +- .../api/type/types/BooleanType.java | 4 +- .../api/type/types/ByteArrayType.java | 4 +- .../viaversion/api/type/types/ByteType.java | 10 +- .../api/type/types/ComponentType.java | 4 +- .../viaversion/api/type/types/DoubleType.java | 10 +- .../viaversion/api/type/types/EmptyType.java | 4 +- .../api/type/types/FixedByteArrayType.java | 4 +- .../viaversion/api/type/types/FloatType.java | 10 +- .../api/type/types/IntArrayType.java | 4 +- .../viaversion/api/type/types/IntType.java | 10 +- .../api/type/types/LongArrayType.java | 4 +- .../viaversion/api/type/types/LongType.java | 10 +- .../api/type/types/OptionalVarIntType.java | 4 +- .../api/type/types/RegistryEntryType.java | 4 +- .../api/type/types/ShortByteArrayType.java | 4 +- .../viaversion/api/type/types/ShortType.java | 10 +- .../viaversion/api/type/types/StringType.java | 4 +- .../api/type/types/UnsignedByteType.java | 10 +- .../api/type/types/UnsignedShortType.java | 10 +- .../api/type/types/VarIntArrayType.java | 4 +- .../viaversion/api/type/types/VarIntType.java | 10 +- .../api/type/types/VarLongType.java | 10 +- .../viaversion/api/type/types/VoidType.java | 49 ---- .../types/block/BlockChangeRecordType.java | 4 +- .../type/types/block/BlockEntityType1_18.java | 4 +- .../types/block/BlockEntityType1_20_2.java | 4 +- .../block/VarLongBlockChangeRecordType.java | 4 +- .../type/types/chunk/BulkChunkType1_8.java | 4 +- .../types/chunk/ChunkSectionType1_13.java | 4 +- .../types/chunk/ChunkSectionType1_16.java | 4 +- .../types/chunk/ChunkSectionType1_18.java | 4 +- .../type/types/chunk/ChunkSectionType1_8.java | 4 +- .../type/types/chunk/ChunkSectionType1_9.java | 4 +- .../api/type/types/chunk/ChunkType1_13.java | 4 +- .../api/type/types/chunk/ChunkType1_14.java | 4 +- .../api/type/types/chunk/ChunkType1_15.java | 4 +- .../api/type/types/chunk/ChunkType1_16.java | 4 +- .../api/type/types/chunk/ChunkType1_16_2.java | 4 +- .../api/type/types/chunk/ChunkType1_17.java | 4 +- .../api/type/types/chunk/ChunkType1_18.java | 4 +- .../api/type/types/chunk/ChunkType1_20_2.java | 4 +- .../api/type/types/chunk/ChunkType1_8.java | 8 +- .../api/type/types/chunk/ChunkType1_9_1.java | 4 +- .../api/type/types/chunk/ChunkType1_9_3.java | 4 +- .../api/type/types/chunk/PaletteType1_18.java | 4 +- .../type/types/item/ItemCostType1_20_5.java | 7 +- .../types/item/ItemShortArrayType1_13.java | 4 +- .../types/item/ItemShortArrayType1_13_2.java | 4 +- .../types/item/ItemShortArrayType1_8.java | 4 +- .../api/type/types/item/ItemType1_13.java | 4 +- .../api/type/types/item/ItemType1_13_2.java | 4 +- .../api/type/types/item/ItemType1_20_2.java | 4 +- .../api/type/types/item/ItemType1_20_5.java | 6 +- .../api/type/types/item/ItemType1_8.java | 4 +- .../type/types/item/StructuredDataType.java | 6 +- .../type/types/math/ChunkPositionType.java | 4 +- .../api/type/types/math/EulerAngleType.java | 4 +- .../type/types/math/GlobalPositionType.java | 4 +- .../api/type/types/math/QuaternionType.java | 4 +- .../api/type/types/math/Vector3fType.java | 4 +- .../api/type/types/math/VectorType.java | 4 +- .../api/type/types/metadata/MetaListType.java | 4 +- .../type/types/metadata/ModernMetaType.java | 4 +- .../api/type/types/metadata/OldMetaType.java | 4 +- .../api/type/types/misc/CompoundTagType.java | 16 +- .../api/type/types/misc/DynamicType.java | 5 +- .../api/type/types/misc/GameProfileType.java | 4 +- .../api/type/types/misc/HolderSetType.java | 4 +- .../api/type/types/misc/HolderType.java | 8 +- .../type/types/misc/NamedCompoundTagType.java | 16 +- .../api/type/types/misc/ParticleType.java | 4 +- .../misc/PlayerMessageSignatureType.java | 4 +- .../api/type/types/misc/ProfileKeyType.java | 4 +- .../api/type/types/misc/SoundEventType.java | 4 +- .../api/type/types/misc/TagType.java | 16 +- .../api/type/types/misc/VillagerDataType.java | 4 +- .../exception/CancelDecoderException.java | 3 +- .../exception/CancelEncoderException.java | 3 +- .../viaversion/exception/CancelException.java | 2 +- .../exception/InformativeException.java | 2 +- .../viaversion/util/CompactArrayUtil.java | 2 +- .../com/viaversion/viaversion/util/Pair.java | 57 +--- .../viaversion/util/PipelineUtil.java | 107 +++++--- .../viaversion/util/ProtocolUtil.java | 3 +- .../viaversion/viaversion/util/Triple.java | 62 +---- .../kotlin/via.base-conventions.gradle.kts | 2 +- .../protocol1_9to1_8/ArmorListener.java | 48 ++-- .../viaversion/ViaVersionPlugin.java | 7 +- .../bukkit/commands/BukkitCommandSender.java | 11 +- .../handlers/BukkitChannelInitializer.java | 2 +- .../bukkit/listeners/JoinListener.java | 15 +- .../EntityToggleGlideListener.java | 57 ++-- .../bukkit/platform/BukkitViaTask.java | 12 +- .../bukkit/platform/BukkitViaTaskTask.java | 6 - .../BukkitInventoryQuickMoveProvider.java | 6 +- .../bungee/commands/BungeeCommandHandler.java | 1 + .../bungee/commands/BungeeCommandSender.java | 11 +- .../bungee/commands/subs/ProbeSubCmd.java | 2 +- .../bungee/handlers/BungeeServerHandler.java | 76 +++--- .../bungee/listeners/ElytraPatch.java | 18 +- .../bungee/platform/BungeeViaConfig.java | 4 +- .../bungee/platform/BungeeViaInjector.java | 28 +- .../bungee/platform/BungeeViaTask.java | 12 +- .../providers/BungeeVersionProvider.java | 2 +- .../service/ProtocolDetectorService.java | 2 +- common/build.gradle.kts | 1 - .../viaversion/viaversion/ViaListener.java | 6 +- .../commands/ViaCommandHandler.java | 2 +- .../commands/defaultsubs/AutoTeamSubCmd.java | 2 +- .../commands/defaultsubs/DebugSubCmd.java | 2 +- .../defaultsubs/DisplayLeaksSubCmd.java | 2 +- .../commands/defaultsubs/DontBugMeSubCmd.java | 2 +- .../commands/defaultsubs/DumpSubCmd.java | 2 +- .../commands/defaultsubs/ListSubCmd.java | 2 +- .../commands/defaultsubs/PPSSubCmd.java | 2 +- .../commands/defaultsubs/ReloadSubCmd.java | 4 +- .../connection/ProtocolInfoImpl.java | 11 - .../connection/UserConnectionImpl.java | 35 +-- .../viaversion/dump/DumpTemplate.java | 36 +-- .../viaversion/dump/PluginInfo.java | 35 +-- .../viaversion/dump/VersionInfo.java | 77 +----- .../ChannelHandlerContextWrapper.java | 9 +- .../viaversion/handlers/ViaCodecHandler.java | 1 + .../platform/LegacyViaInjector.java | 12 +- .../protocol/BlockedProtocolVersionsImpl.java | 27 +- .../protocol/ProtocolManagerImpl.java | 7 +- .../protocol/ProtocolPathEntryImpl.java | 43 +-- .../protocol/ProtocolPathKeyImpl.java | 33 +-- .../protocol/ProtocolPipelineImpl.java | 4 +- .../protocol/ServerProtocolVersionRange.java | 27 +- .../ServerProtocolVersionSingleton.java | 7 +- .../protocol/packet/PacketWrapperImpl.java | 114 ++++---- .../VersionedPacketTransformerImpl.java | 35 +-- .../version}/BaseVersionProvider.java | 2 +- .../protocols/base/BaseProtocol.java | 13 +- .../protocols/base/BaseProtocol1_16.java | 2 +- .../protocols/base/BaseProtocol1_7.java | 10 +- .../Protocol1_10To1_9_3_4.java | 8 +- .../Protocol1_11To1_10.java | 6 +- .../metadata/MetadataRewriter1_11To1_10.java | 22 +- .../Protocol1_12To1_11_1.java | 12 +- .../rewriter/ChatItemRewriter.java | 9 +- .../rewriter/TranslateRewriter.java | 14 +- .../storage/ItemTransaction.java | 32 +-- .../Protocol1_13_1To1_13.java | 2 +- .../packets/InventoryPackets.java | 2 +- .../Protocol1_13To1_12_2.java | 77 ++---- .../AbstractFenceConnectionHandler.java | 8 +- .../AbstractStempConnectionHandler.java | 2 +- .../ChestConnectionHandler.java | 2 +- .../ChorusPlantConnectionHandler.java | 4 +- .../blockconnections/ConnectionData.java | 4 +- .../blockconnections/ConnectionHandler.java | 7 +- .../DoorConnectionHandler.java | 73 ++--- .../FireConnectionHandler.java | 2 +- .../FlowerConnectionHandler.java | 2 +- .../GlassConnectionHandler.java | 4 +- .../RedstoneConnectionHandler.java | 16 +- .../SnowyGrassConnectionHandler.java | 27 +- .../StairConnectionHandler.java | 75 ++---- .../TripwireConnectionHandler.java | 29 +- .../VineConnectionHandler.java | 2 +- .../WallConnectionHandler.java | 4 +- .../providers/BlockConnectionProvider.java | 8 +- .../data/BlockIdData.java | 13 +- .../data/EntityTypeRewriter.java | 4 + .../data/ParticleRewriter.java | 24 +- .../data/StatisticData.java | 25 +- .../MetadataRewriter1_13To1_12_2.java | 2 +- .../packets/EntityPackets.java | 16 +- .../packets/InventoryPackets.java | 2 +- .../packets/WorldPackets.java | 8 +- .../providers/BlockEntityProvider.java | 5 +- .../storage/BlockConnectionStorage.java | 2 +- .../storage/TabCompleteTracker.java | 6 +- .../Protocol1_14To1_13_2.java | 2 +- .../MetadataRewriter1_14To1_13_2.java | 25 +- .../packets/EntityPackets.java | 30 +-- .../packets/InventoryPackets.java | 8 +- .../packets/WorldPackets.java | 6 +- .../packets/EntityPackets.java | 2 +- .../Protocol1_17To1_16_4.java | 46 ++-- .../packets/EntityPackets.java | 30 +-- .../packets/WorldPackets.java | 36 +-- .../Protocol1_18_2To1_18.java | 3 +- .../storage/ChunkLightStorage.java | 50 +--- .../Protocol1_19_1To1_19.java | 15 +- .../data/ChatDecorationResult.java | 18 +- .../storage/NonceStorage.java | 11 +- .../Protocol1_19_3To1_19_1.java | 66 ++--- .../rewriter/RecipeRewriter1_19_3.java | 6 +- .../storage/NonceStorage.java | 12 +- .../Protocol1_19_4To1_19_3.java | 4 +- .../packets/EntityPackets.java | 22 +- .../packets/InventoryPackets.java | 4 +- .../rewriter/RecipeRewriter1_19_4.java | 2 +- .../packets/EntityPackets.java | 25 +- .../provider/AckSequenceProvider.java | 2 +- .../storage/NonceStorage.java | 12 +- .../Protocol1_20_2To1_20.java | 5 +- .../BlockItemPacketRewriter1_20_2.java | 33 +-- .../storage/ConfigurationState.java | 8 +- .../storage/LastResourcePack.java | 31 +-- .../storage/LastTags.java | 22 +- .../Protocol1_20_3To1_20_2.java | 4 +- .../BlockItemPacketRewriter1_20_3.java | 4 +- .../rewriter/EntityPacketRewriter1_20_3.java | 4 +- .../rewriter/RecipeRewriter1_20_3.java | 2 +- .../Protocol1_20_5To1_20_3.java | 2 +- .../data/DyeColors.java | 52 ++-- .../BlockItemPacketRewriter1_20_5.java | 69 +++-- .../rewriter/ComponentRewriter1_20_5.java | 13 +- .../rewriter/EntityPacketRewriter1_20_5.java | 2 +- .../rewriter/StructuredDataConverter.java | 8 +- .../storage/AcknowledgedMessagesStorage.java | 19 +- .../Protocol1_9_3To1_9_1_2.java | 4 +- .../protocol1_9to1_8/ItemRewriter.java | 77 ++---- .../protocol1_9to1_8/Protocol1_9To1_8.java | 21 +- .../metadata/MetadataRewriter1_9To1_8.java | 3 +- .../packets/EntityPackets.java | 6 +- .../packets/PlayerPackets.java | 12 +- .../packets/SpawnPackets.java | 8 +- .../packets/WorldPackets.java | 24 +- .../providers/BossBarProvider.java | 3 +- .../providers/CommandBlockProvider.java | 10 +- .../storage/EntityTracker1_9.java | 55 ++-- .../storage/InventoryTracker.java | 13 +- .../viaversion/rewriter/BlockRewriter.java | 5 - .../viaversion/rewriter/CommandRewriter.java | 4 +- .../rewriter/ComponentRewriter.java | 2 +- .../viaversion/rewriter/EntityRewriter.java | 2 +- .../viaversion/rewriter/ItemRewriter.java | 4 +- .../viaversion/rewriter/RecipeRewriter.java | 24 +- .../rewriter/StatisticsRewriter.java | 39 ++- .../viaversion/rewriter/TagRewriter.java | 25 +- .../viaversion/rewriter/meta/MetaFilter.java | 15 +- .../viaversion/viaversion/update/Version.java | 2 +- .../viaversion/util/CipherUtil.java | 16 +- .../viaversion/viaversion/util/Config.java | 3 +- .../viaversion/viaversion/util/DumpUtil.java | 2 +- .../viaversion/util/ReflectionUtil.java | 76 +----- .../viaversion/viaversion/util/TagUtil.java | 7 +- .../assets/viaversion/data/en_US.properties | 1 - .../common/protocol/ProtocolVersionTest.java | 2 +- .../viaversion/common/type/ItemTypeTest.java | 12 +- .../common/type/StringTypeTest.java | 10 +- gradle.properties | 2 +- gradle/libs.versions.toml | 4 +- settings.gradle.kts | 1 - .../sponge/commands/SpongeCommandHandler.java | 2 +- .../sponge/commands/SpongeCommandSender.java | 4 +- .../sponge/handlers/SpongeDecodeHandler.java | 11 +- .../sponge/handlers/SpongeEncodeHandler.java | 12 +- .../sponge/platform/SpongeViaTask.java | 12 +- .../command/VelocityCommandSender.java | 15 +- .../velocity/command/subs/ProbeSubCmd.java | 2 +- .../velocity/platform/VelocityViaConfig.java | 10 +- .../velocity/platform/VelocityViaTask.java | 12 +- .../providers/VelocityVersionProvider.java | 4 +- .../service/ProtocolDetectorService.java | 2 +- 371 files changed, 1486 insertions(+), 5001 deletions(-) delete mode 100644 api-legacy/build.gradle.kts delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/ViaAPI.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java delete mode 100644 api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java delete mode 100644 api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketRemapper.java delete mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/PartialType.java delete mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/VoidType.java rename common/src/main/java/com/viaversion/viaversion/{protocols/base => protocol/version}/BaseVersionProvider.java (96%) diff --git a/README.md b/README.md index 59e4bebe9..4e38bfcab 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ Building After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out of the `build/libs` directory. +You need JDK 17 or newer to build ViaVersion. + Mapping Files -------------- diff --git a/api-legacy/build.gradle.kts b/api-legacy/build.gradle.kts deleted file mode 100644 index a42a4f44d..000000000 --- a/api-legacy/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - compileOnly(projects.viaversionApi) -} \ No newline at end of file diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java deleted file mode 100644 index 505cd6af9..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/Via.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api; - -import io.netty.buffer.ByteBuf; -import java.util.SortedSet; -import java.util.UUID; -import us.myles.ViaVersion.api.boss.BossBar; -import us.myles.ViaVersion.api.boss.BossColor; -import us.myles.ViaVersion.api.boss.BossStyle; - -/** - * @deprecated may be removed at some point, use {@link com.viaversion.viaversion.api.Via} - */ -@Deprecated -public class Via implements ViaAPI { - - private static final ViaAPI INSTANCE = new Via(); - - private Via() { - } - - @Deprecated - public static ViaAPI getAPI() { - return INSTANCE; - } - - @Override - public int getPlayerVersion(T player) { - return com.viaversion.viaversion.api.Via.getAPI().getPlayerVersion(player); - } - - @Override - public int getPlayerVersion(UUID uuid) { - return com.viaversion.viaversion.api.Via.getAPI().getPlayerVersion(uuid); - } - - @Override - public boolean isInjected(UUID playerUUID) { - return com.viaversion.viaversion.api.Via.getAPI().isInjected(playerUUID); - } - - @Override - public String getVersion() { - return com.viaversion.viaversion.api.Via.getAPI().getVersion(); - } - - @Override - public void sendRawPacket(T player, ByteBuf packet) { - com.viaversion.viaversion.api.Via.getAPI().sendRawPacket(player, packet); - } - - @Override - public void sendRawPacket(UUID uuid, ByteBuf packet) { - com.viaversion.viaversion.api.Via.getAPI().sendRawPacket(uuid, packet); - } - - @Override - public BossBar createBossBar(String title, BossColor color, BossStyle style) { - return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, - com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()], - com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()])); - } - - @Override - public BossBar createBossBar(String title, float health, BossColor color, BossStyle style) { - return new BossBar(com.viaversion.viaversion.api.Via.getAPI().legacyAPI().createLegacyBossBar(title, health, - com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()], - com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()])); - } - - @Override - public SortedSet getSupportedVersions() { - return com.viaversion.viaversion.api.Via.getAPI().getSupportedVersions(); - } - - @Override - public SortedSet getFullSupportedVersions() { - return com.viaversion.viaversion.api.Via.getAPI().getFullSupportedVersions(); - } -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/ViaAPI.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/ViaAPI.java deleted file mode 100644 index 8218667f2..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/ViaAPI.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api; - -import com.viaversion.viaversion.api.Via; -import io.netty.buffer.ByteBuf; -import java.util.SortedSet; -import java.util.UUID; -import us.myles.ViaVersion.api.boss.BossBar; -import us.myles.ViaVersion.api.boss.BossColor; -import us.myles.ViaVersion.api.boss.BossStyle; - -/** - * @deprecated may be removed at some point, use {@link Via#getAPI()} - */ -@Deprecated -public interface ViaAPI { - - int getPlayerVersion(T player); - - int getPlayerVersion(UUID uuid); - - default boolean isPorted(UUID playerUUID) { - return isInjected(playerUUID); - } - - boolean isInjected(UUID playerUUID); - - String getVersion(); - - void sendRawPacket(T player, ByteBuf packet); - - void sendRawPacket(UUID uuid, ByteBuf packet); - - BossBar createBossBar(String title, BossColor color, BossStyle style); - - BossBar createBossBar(String title, float health, BossColor color, BossStyle style); - - SortedSet getSupportedVersions(); - - SortedSet getFullSupportedVersions(); -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java deleted file mode 100644 index 643b0f4fa..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.boss; - -import java.util.Set; -import java.util.UUID; - -@Deprecated -public class BossBar { - - private final com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar; - - public BossBar(com.viaversion.viaversion.api.legacy.bossbar.BossBar bossBar) { - this.bossBar = bossBar; - } - - public String getTitle() { - return bossBar.getTitle(); - } - - public BossBar setTitle(String title) { - bossBar.setTitle(title); - return this; - } - - public float getHealth() { - return bossBar.getHealth(); - } - - public BossBar setHealth(float health) { - bossBar.setHealth(health); - return this; - } - - public BossColor getColor() { - return BossColor.values()[bossBar.getColor().ordinal()]; - } - - public BossBar setColor(BossColor color) { - bossBar.setColor(com.viaversion.viaversion.api.legacy.bossbar.BossColor.values()[color.ordinal()]); - return this; - } - - public BossStyle getStyle() { - return BossStyle.values()[bossBar.getStyle().ordinal()]; - } - - public BossBar setStyle(BossStyle style) { - bossBar.setStyle(com.viaversion.viaversion.api.legacy.bossbar.BossStyle.values()[style.ordinal()]); - return this; - } - - @Deprecated - public BossBar addPlayer(T player) { - return this; - } - - public BossBar addPlayer(UUID player) { - bossBar.addPlayer(player); - return this; - } - - @Deprecated - public BossBar addPlayers(T... players) { - return this; - } - - @Deprecated - public BossBar removePlayer(T player) { - return this; - } - - public BossBar removePlayer(UUID uuid) { - bossBar.removePlayer(uuid); - return this; - } - - public BossBar addFlag(BossFlag flag) { - bossBar.addFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); - return this; - } - - public BossBar removeFlag(BossFlag flag) { - bossBar.removeFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); - return this; - } - - public boolean hasFlag(BossFlag flag) { - return bossBar.hasFlag(com.viaversion.viaversion.api.legacy.bossbar.BossFlag.values()[flag.ordinal()]); - } - - public Set getPlayers() { - return bossBar.getPlayers(); - } - - public BossBar show() { - bossBar.show(); - return this; - } - - public BossBar hide() { - bossBar.hide(); - return this; - } - - public boolean isVisible() { - return bossBar.isVisible(); - } - - public UUID getId() { - return bossBar.getId(); - } -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java deleted file mode 100644 index 42ea8ce0a..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossColor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.boss; - -@Deprecated -public enum BossColor { - - PINK(0), - BLUE(1), - RED(2), - GREEN(3), - YELLOW(4), - PURPLE(5), - WHITE(6); - - private final int id; - - BossColor(int id) { - this.id = id; - } - - public int getId() { - return id; - } -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java deleted file mode 100644 index 91bff9d56..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossFlag.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.boss; - -@Deprecated -public enum BossFlag { - - DARKEN_SKY(1), - PLAY_BOSS_MUSIC(2); - - private final int id; - - BossFlag(int id) { - this.id = id; - } - - public int getId() { - return id; - } -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java deleted file mode 100644 index 9c691be6b..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/boss/BossStyle.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.boss; - -@Deprecated -public enum BossStyle { - - SOLID(0), - SEGMENTED_6(1), - SEGMENTED_10(2), - SEGMENTED_12(3), - SEGMENTED_20(4); - - private final int id; - - BossStyle(int id) { - this.id = id; - } - - public int getId() { - return id; - } -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java deleted file mode 100644 index 9806fd86e..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.protocol; - -/** - * @deprecated may be removed at some point, use {@link com.viaversion.viaversion.api.protocol.ProtocolManager} - */ -@Deprecated -public class ProtocolRegistry { - - @Deprecated - public static int SERVER_PROTOCOL = -1; -} diff --git a/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java deleted file mode 100644 index 3b312bad6..000000000 --- a/api-legacy/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * 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 us.myles.ViaVersion.api.protocol; - -import com.google.common.base.Preconditions; -import com.viaversion.viaversion.api.protocol.version.SubVersionRange; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * @deprecated will no longer be updated and may be removed at some point, use {@link com.viaversion.viaversion.api.protocol.version.ProtocolVersion} - */ -@Deprecated -public class ProtocolVersion { - private static final Int2ObjectMap versions = new Int2ObjectOpenHashMap<>(); - private static final List versionList = new ArrayList<>(); - - public static final ProtocolVersion v1_4_6 = register(51, "1.4.6/7", new SubVersionRange("1.4", 6, 7)); - public static final ProtocolVersion v1_5_1 = register(60, "1.5.1"); - public static final ProtocolVersion v1_5_2 = register(61, "1.5.2"); - public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1"); - public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2"); - public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3"); - public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4"); - public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5", new SubVersionRange("1.7", 0, 5)); - public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10)); - public static final ProtocolVersion v1_8 = register(47, "1.8.x"); - public static final ProtocolVersion v1_9 = register(107, "1.9"); - public static final ProtocolVersion v1_9_1 = register(108, "1.9.1"); - public static final ProtocolVersion v1_9_2 = register(109, "1.9.2"); - public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/1.9.4", new SubVersionRange("1.9", 3, 4)); - public static final ProtocolVersion v1_10 = register(210, "1.10.x"); - public static final ProtocolVersion v1_11 = register(315, "1.11"); - public static final ProtocolVersion v1_11_1 = register(316, "1.11.1/1.11.2", new SubVersionRange("1.11", 1, 2)); - public static final ProtocolVersion v1_12 = register(335, "1.12"); - public static final ProtocolVersion v1_12_1 = register(338, "1.12.1"); - public static final ProtocolVersion v1_12_2 = register(340, "1.12.2"); - public static final ProtocolVersion v1_13 = register(393, "1.13"); - public static final ProtocolVersion v1_13_1 = register(401, "1.13.1"); - public static final ProtocolVersion v1_13_2 = register(404, "1.13.2"); - public static final ProtocolVersion v1_14 = register(477, "1.14"); - public static final ProtocolVersion v1_14_1 = register(480, "1.14.1"); - public static final ProtocolVersion v1_14_2 = register(485, "1.14.2"); - public static final ProtocolVersion v1_14_3 = register(490, "1.14.3"); - public static final ProtocolVersion v1_14_4 = register(498, "1.14.4"); - public static final ProtocolVersion v1_15 = register(573, "1.15"); - public static final ProtocolVersion v1_15_1 = register(575, "1.15.1"); - public static final ProtocolVersion v1_15_2 = register(578, "1.15.2"); - public static final ProtocolVersion v1_16 = register(735, "1.16"); - public static final ProtocolVersion v1_16_1 = register(736, "1.16.1"); - public static final ProtocolVersion v1_16_2 = register(751, "1.16.2"); - public static final ProtocolVersion v1_16_3 = register(753, "1.16.3"); - public static final ProtocolVersion v1_16_4 = register(754, "1.16.4/1.16.5", new SubVersionRange("1.16", 4, 5)); - public static final ProtocolVersion v1_17 = register(755, "1.17"); - public static final ProtocolVersion v1_17_1 = register(756, "1.17.1"); - public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new SubVersionRange("1.18", 0, 1)); - public static final ProtocolVersion v1_18_2 = register(758, "1.18.2"); - public static final ProtocolVersion v1_19 = register(759, "1.19"); - public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/1.19.2", new SubVersionRange("1.19", 1, 2)); - public static final ProtocolVersion v1_19_3 = register(761, "1.19.3"); - public static final ProtocolVersion v1_19_4 = register(762, "1.19.4"); - public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1)); - public static final ProtocolVersion v1_20_2 = register(764, "1.20.2"); - public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4)); - public static final ProtocolVersion v1_20_5 = register(766, "1.20.5"); - public static final ProtocolVersion unknown = register(-1, "UNKNOWN"); - - public static ProtocolVersion register(int version, String name) { - return register(version, -1, name); - } - - public static ProtocolVersion register(int version, int snapshotVersion, String name) { - return register(version, snapshotVersion, name, null); - } - - public static ProtocolVersion register(int version, String name, @Nullable SubVersionRange versionRange) { - return register(version, -1, name, versionRange); - } - - public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) { - ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange); - versionList.add(protocol); - versions.put(protocol.getVersion(), protocol); - if (protocol.isSnapshot()) { - versions.put(protocol.getFullSnapshotVersion(), protocol); - } - return protocol; - } - - public static boolean isRegistered(int id) { - return versions.containsKey(id); - } - - public static @NonNull ProtocolVersion getProtocol(int id) { - ProtocolVersion protocolVersion = versions.get(id); - if (protocolVersion != null) { - return protocolVersion; - } else { - return new ProtocolVersion(id, "Unknown (" + id + ")"); - } - } - - public static int getIndex(ProtocolVersion version) { - return versionList.indexOf(version); - } - - public static List getProtocols() { - return Collections.unmodifiableList(new ArrayList<>(versions.values())); - } - - public static @Nullable ProtocolVersion getClosest(String protocol) { - for (ProtocolVersion version : versions.values()) { - String name = version.getName(); - if (name.equals(protocol)) { - return version; - } - - if (version.isVersionWildcard()) { - // Test against the major version with and without a minor version - String majorVersion = name.substring(0, name.length() - 2); - if (majorVersion.equals(protocol) || (protocol.startsWith(name.substring(0, name.length() - 1)))) { - return version; - } - } else if (version.isRange()) { - if (version.getIncludedVersions().contains(protocol)) { - return version; - } - } - } - return null; - } - - private final int version; - private final int snapshotVersion; - private final String name; - private final boolean versionWildcard; - private final Set includedVersions; - - public ProtocolVersion(int version, String name) { - this(version, -1, name, null); - } - - public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) { - this.version = version; - this.snapshotVersion = snapshotVersion; - this.name = name; - this.versionWildcard = name.endsWith(".x"); - - Preconditions.checkArgument(!versionWildcard || versionRange == null, "A version cannot be a wildcard and a range at the same time!"); - if (versionRange != null) { - includedVersions = new LinkedHashSet<>(); - for (int i = versionRange.rangeFrom(); i <= versionRange.rangeTo(); i++) { - if (i == 0) { - includedVersions.add(versionRange.baseVersion()); // Keep both the base version and with ".0" appended - } - - includedVersions.add(versionRange.baseVersion() + "." + i); - } - } else { - includedVersions = Collections.singleton(name); - } - } - - public int getVersion() { - return version; - } - - public int getSnapshotVersion() { - Preconditions.checkArgument(isSnapshot()); - return snapshotVersion; - } - - public int getFullSnapshotVersion() { - Preconditions.checkArgument(isSnapshot()); - return (1 << 30) | snapshotVersion; // Bit indicating snapshot versions - } - - public int getOriginalVersion() { - return snapshotVersion == -1 ? version : ((1 << 30) | snapshotVersion); - } - - public boolean isKnown() { - return version != -1; - } - - public boolean isRange() { - return includedVersions.size() != 1; - } - - public Set getIncludedVersions() { - return Collections.unmodifiableSet(includedVersions); - } - - public boolean isVersionWildcard() { - return versionWildcard; - } - - public String getName() { - return name; - } - - public boolean isSnapshot() { - return snapshotVersion != -1; - } - - public int getId() { - return version; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ProtocolVersion that = (ProtocolVersion) o; - return version == that.version; - } - - @Override - public int hashCode() { - return version; - } - - @Override - public String toString() { - return String.format("%s (%d)", this.name, this.version); - } -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index d0bcb8c8b..28824ce4a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -56,7 +56,7 @@ public interface ViaAPI { * @since 4.0.2 */ default int majorVersion() { - return 4; + return 5; } /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/command/ViaSubCommand.java b/api/src/main/java/com/viaversion/viaversion/api/command/ViaSubCommand.java index d2c831302..8bdb1b563 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/command/ViaSubCommand.java +++ b/api/src/main/java/com/viaversion/viaversion/api/command/ViaSubCommand.java @@ -26,21 +26,21 @@ import com.viaversion.viaversion.util.ChatColorUtil; import java.util.Collections; import java.util.List; -public abstract class ViaSubCommand { +public interface ViaSubCommand { /** * Subcommand name * * @return The commands name */ - public abstract String name(); + String name(); /** * subcommand description, this'll show in /viaversion list * * @return The commands description */ - public abstract String description(); + String description(); /** * Usage example: @@ -48,7 +48,7 @@ public abstract class ViaSubCommand { * * @return The commands usage */ - public String usage() { + default String usage() { return name(); } @@ -57,7 +57,7 @@ public abstract class ViaSubCommand { * * @return The permission required to use the commands */ - public String permission() { + default String permission() { return "viaversion.admin." + name(); } @@ -68,7 +68,7 @@ public abstract class ViaSubCommand { * @param args Arguments * @return commands executed succesfully if false, show usage */ - public abstract boolean execute(ViaCommandSender sender, String[] args); + boolean execute(ViaCommandSender sender, String[] args); /** * Yay, possibility to implement tab-completion @@ -77,7 +77,7 @@ public abstract class ViaSubCommand { * @param args args * @return tab complete possibilities */ - public List onTabComplete(ViaCommandSender sender, String[] args) { + default List onTabComplete(ViaCommandSender sender, String[] args) { return Collections.emptyList(); } @@ -87,7 +87,7 @@ public abstract class ViaSubCommand { * @param s string to replace * @return output String */ - public static String color(String s) { + static String color(String s) { return ChatColorUtil.translateAlternateColorCodes(s); } @@ -98,7 +98,7 @@ public abstract class ViaSubCommand { * @param message message * @param args objects to replace */ - public static void sendMessage(ViaCommandSender sender, String message, Object... args) { + default void sendMessage(ViaCommandSender sender, String message, Object... args) { sender.sendMessage(color(args == null ? message : String.format(message, args))); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java index 65201683d..361faf866 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java +++ b/api/src/main/java/com/viaversion/viaversion/api/command/ViaVersionCommand.java @@ -30,7 +30,7 @@ public interface ViaVersionCommand { * Register your own subcommand inside ViaVersion * * @param command Your own SubCommand instance to handle it. - * @throws Exception throws an exception when the subcommand already exists or if it's not valid, example: spacee + * @throws IllegalArgumentException throws an exception when the subcommand already exists or if it's not valid, example: spacee */ void registerSubCommand(ViaSubCommand command); diff --git a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java index ab564277a..91e2b9fd9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java +++ b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java @@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.WorldIdentifiers; import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions; +import org.checkerframework.checker.nullness.qual.Nullable; public interface ViaVersionConfig extends Config { diff --git a/api/src/main/java/com/viaversion/viaversion/api/connection/ProtocolInfo.java b/api/src/main/java/com/viaversion/viaversion/api/connection/ProtocolInfo.java index 912a1fc43..65ef63984 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/connection/ProtocolInfo.java +++ b/api/src/main/java/com/viaversion/viaversion/api/connection/ProtocolInfo.java @@ -31,17 +31,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; public interface ProtocolInfo { - /** - * Returns the protocol state the user is currently in. - * - * @return protocol state - * @deprecated server and client can be in different states, use {@link #getClientState()} or {@link #getServerState()} - */ - @Deprecated/*(forRemoval = true)*/ - default State getState() { - return this.getServerState(); - } - /** * Returns the protocol state the client is currently in. * @@ -153,12 +142,4 @@ public interface ProtocolInfo { ProtocolPipeline getPipeline(); void setPipeline(ProtocolPipeline pipeline); - - /** - * Returns the user connection this info represents. - * - * @return user connection - */ - @Deprecated/*(forRemoval = true)*/ - UserConnection getUser(); -} +} \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java index 1c5095df8..2618ad59d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java +++ b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java @@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.packet.PacketTracker; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.InformativeException; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; +import io.netty.handler.codec.CodecException; import java.util.Collection; import java.util.Map; import java.util.UUID; @@ -205,11 +205,10 @@ public interface UserConnection { * * @param buf ByteBuf with packet id and packet contents * @param cancelSupplier function called with original CancelException for generating the Exception when the packet is cancelled - * @throws CancelException if the packet should be cancelled + * @throws CodecException if the packet should be cancelled (by netty) * @throws InformativeException if packet transforming failed - * @throws Exception if any other processing outside of transforming fails */ - void transformClientbound(ByteBuf buf, Function cancelSupplier) throws Exception; + void transformClientbound(ByteBuf buf, Function cancelSupplier) throws InformativeException; /** * Transforms the serverbound packet contained in ByteBuf. @@ -217,11 +216,10 @@ public interface UserConnection { * @param buf ByteBuf with packet id and packet contents * @param cancelSupplier Function called with original CancelException for generating the Exception used when * packet is cancelled - * @throws CancelException if the packet should be cancelled + * @throws CodecException if the packet should be cancelled (by netty) * @throws InformativeException if packet transforming failed - * @throws Exception if any other processing outside of transforming fails */ - void transformServerbound(ByteBuf buf, Function cancelSupplier) throws Exception; + void transformServerbound(ByteBuf buf, Function cancelSupplier) throws InformativeException; /** * Transforms the packet depending on whether the connection is clientside or not. @@ -229,7 +227,7 @@ public interface UserConnection { * @see #transformClientbound(ByteBuf, Function) * @see #transformServerbound(ByteBuf, Function) */ - default void transformOutgoing(ByteBuf buf, Function cancelSupplier) throws Exception { + default void transformOutgoing(ByteBuf buf, Function cancelSupplier) throws InformativeException { if (isClientSide()) { transformServerbound(buf, cancelSupplier); } else { @@ -243,7 +241,7 @@ public interface UserConnection { * @see #transformClientbound(ByteBuf, Function) * @see #transformServerbound(ByteBuf, Function) */ - default void transformIncoming(ByteBuf buf, Function cancelSupplier) throws Exception { + default void transformIncoming(ByteBuf buf, Function cancelSupplier) throws InformativeException { if (isClientSide()) { transformClientbound(buf, cancelSupplier); } else { @@ -315,20 +313,6 @@ public interface UserConnection { */ boolean shouldApplyBlockProtocol(); - /** - * Returns whether the packet limiter applies to this user. - * - * @return whether the packet limiter applies to this user - */ - boolean isPacketLimiterEnabled(); - - /** - * Sets the status of the packet limiter. - * - * @param packetLimiterEnabled whether the packet limiter should be enabled - */ - void setPacketLimiterEnabled(boolean packetLimiterEnabled); - /** * Returns a newly generated uuid that will let a packet be passed through without * transformig its contents if used together with {@link PacketWrapper#PASSTHROUGH_ID}. diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/IdentityMappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/IdentityMappings.java index 168522760..650f652ec 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/IdentityMappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/IdentityMappings.java @@ -22,15 +22,7 @@ */ package com.viaversion.viaversion.api.data; -public class IdentityMappings implements Mappings { - - private final int size; - private final int mappedSize; - - public IdentityMappings(final int size, final int mappedSize) { - this.size = size; - this.mappedSize = mappedSize; - } +public record IdentityMappings(int size, int mappedSize) implements Mappings { @Override public int getNewId(final int id) { @@ -42,16 +34,6 @@ public class IdentityMappings implements Mappings { throw new UnsupportedOperationException(); } - @Override - public int size() { - return size; - } - - @Override - public int mappedSize() { - return mappedSize; - } - @Override public Mappings inverse() { return new IdentityMappings(mappedSize, size); diff --git a/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java b/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java index 30e1b1032..84ad255a3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java +++ b/api/src/main/java/com/viaversion/viaversion/api/debug/DebugHandler.java @@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import java.util.logging.Level; -@Beta public interface DebugHandler { /** @@ -51,6 +50,7 @@ public interface DebugHandler { * * @param packetTypeName packet type name */ + @Beta void addPacketTypeNameToLog(String packetTypeName); /** @@ -59,6 +59,7 @@ public interface DebugHandler { * * @param packetType packet type */ + @Beta void addPacketTypeToLog(PacketType packetType); /** @@ -66,11 +67,13 @@ public interface DebugHandler { * * @param packetTypeName packet type name */ + @Beta boolean removePacketTypeNameToLog(String packetTypeName); /** * Resets packet type filters. */ + @Beta void clearPacketTypesToLog(); /** @@ -79,6 +82,7 @@ public interface DebugHandler { * * @return whether packets should be logged after being transformed */ + @Beta boolean logPostPacketTransform(); /** @@ -86,6 +90,7 @@ public interface DebugHandler { * * @param logPostPacketTransform whether packets should be logged after being transformed */ + @Beta void setLogPostPacketTransform(boolean logPostPacketTransform); /** @@ -98,6 +103,7 @@ public interface DebugHandler { */ boolean shouldLog(PacketWrapper wrapper, Direction direction); + @Beta default void enableAndLogIds(final PacketType... packetTypes) { setEnabled(true); for (final PacketType packetType : packetTypes) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java index 63fa4e6ff..30b287c0b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java @@ -34,7 +34,6 @@ public enum BlockFace { BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y); public static final BlockFace[] HORIZONTAL = {NORTH, SOUTH, EAST, WEST}; - private static final Map opposites = new EnumMap<>(BlockFace.class); static { @@ -78,26 +77,6 @@ public enum BlockFace { return axis; } - @Deprecated/*(forRemoval = true)*/ - public byte getModX() { - return modX; - } - - @Deprecated/*(forRemoval = true)*/ - public byte getModY() { - return modY; - } - - @Deprecated/*(forRemoval = true)*/ - public byte getModZ() { - return modZ; - } - - @Deprecated/*(forRemoval = true)*/ - public EnumAxis getAxis() { - return axis; - } - public enum EnumAxis { X, Y, Z } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Environment.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Environment.java index d87578ff6..bd97d47ce 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Environment.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Environment.java @@ -38,20 +38,11 @@ public enum Environment { return id; } - @Deprecated/*(forRemoval = true)*/ - public int getId() { - return id; - } - public static Environment getEnvironmentById(int id) { - switch (id) { - default: - case -1: - return NETHER; - case 0: - return NORMAL; - case 1: - return END; - } + return switch (id) { + case 0 -> NORMAL; + case 1 -> END; + default -> NETHER; // -1 implicitly + }; } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/EulerAngle.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/EulerAngle.java index 9e16aad52..21848aac1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/EulerAngle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/EulerAngle.java @@ -22,41 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public class EulerAngle { - private final float x; - private final float y; - private final float z; - - public EulerAngle(final float x, final float y, final float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public float x() { - return x; - } - - public float y() { - return y; - } - - public float z() { - return z; - } - - @Deprecated/*(forRemoval = true)*/ - public float getX() { - return x; - } - - @Deprecated/*(forRemoval = true)*/ - public float getY() { - return y; - } - - @Deprecated/*(forRemoval = true)*/ - public float getZ() { - return z; - } +public record EulerAngle(float x, float y, float z) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameProfile.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameProfile.java index 64cb02408..8b18e244c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameProfile.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GameProfile.java @@ -25,51 +25,8 @@ package com.viaversion.viaversion.api.minecraft; import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; -public final class GameProfile { +public record GameProfile(@Nullable String name, @Nullable UUID id, Property[] properties) { - private final String name; - private final UUID id; - private final Property[] properties; - - public GameProfile(@Nullable final String name, @Nullable final UUID id, final Property[] properties) { - this.name = name; - this.id = id; - this.properties = properties; - } - - public @Nullable String name() { - return name; - } - - public @Nullable UUID id() { - return id; - } - - public Property[] properties() { - return properties; - } - - public static final class Property { - private final String name; - private final String value; - private final String signature; - - public Property(final String name, final String value, @Nullable final String signature) { - this.name = name; - this.value = value; - this.signature = signature; - } - - public String name() { - return name; - } - - public String value() { - return value; - } - - public @Nullable String signature() { - return signature; - } + public record Property(String name, String value, @Nullable String signature) { } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java index 41de2c114..8254086b9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Particle.java @@ -37,11 +37,6 @@ public final class Particle implements IdHolder { this.id = id; } - @Deprecated - public int getId() { - return id; - } - @Override public int id() { return id; @@ -106,7 +101,7 @@ public final class Particle implements IdHolder { this.value = value; } - public void write(final ByteBuf buf) throws Exception { + public void write(final ByteBuf buf) { type.write(buf, value); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/PlayerMessageSignature.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/PlayerMessageSignature.java index 49cc58d37..be67c9048 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/PlayerMessageSignature.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/PlayerMessageSignature.java @@ -24,20 +24,5 @@ package com.viaversion.viaversion.api.minecraft; import java.util.UUID; -public final class PlayerMessageSignature { - private final UUID uuid; - private final byte[] signatureBytes; - - public PlayerMessageSignature(final UUID uuid, final byte[] signatureBytes) { - this.uuid = uuid; - this.signatureBytes = signatureBytes; - } - - public UUID uuid() { - return uuid; - } - - public byte[] signatureBytes() { - return signatureBytes; - } +public record PlayerMessageSignature(UUID uuid, byte[] signatureBytes) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java index 1b7ee0164..ead39b4e7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java @@ -38,11 +38,6 @@ public class Position { this(x, (int) y, z); } - @Deprecated/*(forRemoval=true)*/ - public Position(Position toCopy) { - this(toCopy.x(), toCopy.y(), toCopy.z()); - } - public Position getRelative(BlockFace face) { return new Position(x + face.modX(), (short) (y + face.modY()), z + face.modZ()); } @@ -63,21 +58,6 @@ public class Position { return new GlobalPosition(dimension, x, y, z); } - @Deprecated/*(forRemoval=true)*/ - public int getX() { - return x; - } - - @Deprecated/*(forRemoval=true)*/ - public int getY() { - return y; - } - - @Deprecated/*(forRemoval=true)*/ - public int getZ() { - return z; - } - @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position3d.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position3d.java index c43126878..de425ec4e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position3d.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position3d.java @@ -22,26 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public class Position3d { - private final double x; - private final double y; - private final double z; - - public Position3d(final double x, final double y, final double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public double x() { - return x; - } - - public double y() { - return y; - } - - public double z() { - return z; - } +public record Position3d(double x, double y, double z) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/ProfileKey.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/ProfileKey.java index e578ee9b1..9db18a2fe 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/ProfileKey.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/ProfileKey.java @@ -22,26 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public final class ProfileKey { - private final long expiresAt; - private final byte[] publicKey; - private final byte[] keySignature; - - public ProfileKey(final long expiresAt, final byte[] publicKey, final byte[] keySignature) { - this.expiresAt = expiresAt; - this.publicKey = publicKey; - this.keySignature = keySignature; - } - - public long expiresAt() { - return expiresAt; - } - - public byte[] publicKey() { - return publicKey; - } - - public byte[] keySignature() { - return keySignature; - } +public record ProfileKey(long expiresAt, byte[] publicKey, byte[] keySignature) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Quaternion.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Quaternion.java index 1d81b45d7..c371073d5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Quaternion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Quaternion.java @@ -22,42 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public final class Quaternion { - private final float x; - private final float y; - private final float z; - private final float w; - - public Quaternion(final float x, final float y, final float z, final float w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - public float x() { - return x; - } - - public float y() { - return y; - } - - public float z() { - return z; - } - - public float w() { - return w; - } - - @Override - public String toString() { - return "Quaternion{" + - "x=" + x + - ", y=" + y + - ", z=" + z + - ", w=" + w + - '}'; - } +public record Quaternion(float x, float y, float z, float w) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java index 018c56a8d..b175581ed 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/RegistryEntry.java @@ -25,22 +25,7 @@ package com.viaversion.viaversion.api.minecraft; import com.github.steveice10.opennbt.tag.builtin.Tag; import org.checkerframework.checker.nullness.qual.Nullable; -public final class RegistryEntry { - private final String key; - private final Tag tag; - - public RegistryEntry(String key, @Nullable Tag tag) { - this.key = key; - this.tag = tag; - } - - public String key() { - return key; - } - - public @Nullable Tag tag() { - return tag; - } +public record RegistryEntry(String key, @Nullable Tag tag) { public RegistryEntry withKey(final String key) { return new RegistryEntry(key, tag != null ? tag.copy() : null); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/SoundEvent.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/SoundEvent.java index 012f1696e..443847ef7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/SoundEvent.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/SoundEvent.java @@ -24,23 +24,7 @@ package com.viaversion.viaversion.api.minecraft; import org.checkerframework.checker.nullness.qual.Nullable; -public final class SoundEvent { - - private final String identifier; - private final Float fixedRange; - - public SoundEvent(final String identifier, @Nullable final Float fixedRange) { - this.identifier = identifier; - this.fixedRange = fixedRange; - } - - public String identifier() { - return identifier; - } - - public @Nullable Float fixedRange() { - return fixedRange; - } +public record SoundEvent(String identifier, @Nullable Float fixedRange) { public SoundEvent withIdentifier(final String identifier) { return new SoundEvent(identifier, this.fixedRange); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/TagData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/TagData.java index 9d9cb279f..22a1974cc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/TagData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/TagData.java @@ -24,28 +24,21 @@ package com.viaversion.viaversion.api.minecraft; import java.util.Arrays; -public final class TagData { - private final String identifier; - private final int[] entries; +public record TagData(String identifier, int[] entries) { - public TagData(final String identifier, final int[] entries) { - this.identifier = identifier; - this.entries = entries; - } - - public String identifier() { - return identifier; - } - - public int[] entries() { - return entries; + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final TagData tagData = (TagData) o; + if (!identifier.equals(tagData.identifier)) return false; + return Arrays.equals(entries, tagData.entries); } @Override - public String toString() { - return "TagData{" + - "identifier='" + identifier + '\'' + - ", entries=" + Arrays.toString(entries) + - '}'; + public int hashCode() { + int result = identifier.hashCode(); + result = 31 * result + Arrays.hashCode(entries); + return result; } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector.java index 62c78cad7..b79322d8e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector.java @@ -22,56 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public class Vector { - private int blockX; - private int blockY; - private int blockZ; - - public Vector(int blockX, int blockY, int blockZ) { - this.blockX = blockX; - this.blockY = blockY; - this.blockZ = blockZ; - } - - public int blockX() { - return blockX; - } - - public int blockY() { - return blockY; - } - - public int blockZ() { - return blockZ; - } - - @Deprecated/*(forRemoval=true)*/ - public int getBlockX() { - return blockX; - } - - @Deprecated/*(forRemoval=true)*/ - public int getBlockY() { - return blockY; - } - - @Deprecated/*(forRemoval=true)*/ - public int getBlockZ() { - return blockZ; - } - - @Deprecated/*(forRemoval=true)*/ - public void setBlockX(int blockX) { - this.blockX = blockX; - } - - @Deprecated/*(forRemoval=true)*/ - public void setBlockY(int blockY) { - this.blockY = blockY; - } - - @Deprecated/*(forRemoval=true)*/ - public void setBlockZ(int blockZ) { - this.blockZ = blockZ; - } +public record Vector(int blockX, int blockY, int blockZ) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector3f.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector3f.java index 8f1cb788a..972fdb938 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector3f.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Vector3f.java @@ -22,26 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public final class Vector3f { - private final float x; - private final float y; - private final float z; - - public Vector3f(final float x, final float y, final float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public float x() { - return x; - } - - public float y() { - return y; - } - - public float z() { - return z; - } +public record Vector3f(float x, float y, float z) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/VillagerData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/VillagerData.java index e34767438..0a2fcef22 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/VillagerData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/VillagerData.java @@ -22,41 +22,5 @@ */ package com.viaversion.viaversion.api.minecraft; -public class VillagerData { - private final int type; - private final int profession; - private final int level; - - public VillagerData(final int type, final int profession, final int level) { - this.type = type; - this.profession = profession; - this.level = level; - } - - public int type() { - return type; - } - - public int profession() { - return profession; - } - - public int level() { - return level; - } - - @Deprecated/*(forRemoval=true)*/ - public int getType() { - return type; - } - - @Deprecated/*(forRemoval=true)*/ - public int getProfession() { - return profession; - } - - @Deprecated/*(forRemoval=true)*/ - public int getLevel() { - return level; - } +public record VillagerData(int type, int profession, int level) { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/WorldIdentifiers.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/WorldIdentifiers.java index 52839c8e7..be5856412 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/WorldIdentifiers.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/WorldIdentifiers.java @@ -24,34 +24,12 @@ package com.viaversion.viaversion.api.minecraft; import com.viaversion.viaversion.api.connection.StorableObject; -public class WorldIdentifiers implements StorableObject { +public record WorldIdentifiers(String overworld, String nether, String end) implements StorableObject { public static final String OVERWORLD_DEFAULT = "minecraft:overworld"; public static final String NETHER_DEFAULT = "minecraft:the_nether"; public static final String END_DEFAULT = "minecraft:the_end"; - private final String overworld; - private final String nether; - private final String end; - public WorldIdentifiers(String overworld) { this(overworld, NETHER_DEFAULT, END_DEFAULT); } - - public WorldIdentifiers(String overworld, String nether, String end) { - this.overworld = overworld; - this.nether = nether; - this.end = end; - } - - public String overworld() { - return this.overworld; - } - - public String nether() { - return this.nether; - } - - public String end() { - return this.end; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/blockentity/BlockEntityImpl.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/blockentity/BlockEntityImpl.java index 648c85c82..91c080bbe 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/blockentity/BlockEntityImpl.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/blockentity/BlockEntityImpl.java @@ -24,38 +24,7 @@ package com.viaversion.viaversion.api.minecraft.blockentity; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -public final class BlockEntityImpl implements BlockEntity { - private final byte packedXZ; - private final short y; - private final int typeId; - private final CompoundTag tag; - - public BlockEntityImpl(final byte packedXZ, final short y, final int typeId, final CompoundTag tag) { - this.packedXZ = packedXZ; - this.y = y; - this.typeId = typeId; - this.tag = tag; - } - - @Override - public byte packedXZ() { - return packedXZ; - } - - @Override - public short y() { - return y; - } - - @Override - public int typeId() { - return typeId; - } - - @Override - public CompoundTag tag() { - return tag; - } +public record BlockEntityImpl(byte packedXZ, short y, int typeId, CompoundTag tag) implements BlockEntity { @Override public BlockEntity withTypeId(int typeId) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/chunks/ChunkSection.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/chunks/ChunkSection.java index 2a3e2901b..1a33a7459 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/chunks/ChunkSection.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/chunks/ChunkSection.java @@ -52,86 +52,6 @@ public interface ChunkSection { return idx >> 4 & 0xF; } - @Deprecated/*(forRemoval = true)*/ - default int getFlatBlock(int idx) { - return palette(PaletteType.BLOCKS).idAt(idx); - } - - @Deprecated/*(forRemoval = true)*/ - default int getFlatBlock(int x, int y, int z) { - return getFlatBlock(index(x, y, z)); - } - - @Deprecated/*(forRemoval = true)*/ - default void setFlatBlock(int idx, int id) { - palette(PaletteType.BLOCKS).setIdAt(idx, id); - } - - @Deprecated/*(forRemoval = true)*/ - default void setFlatBlock(int x, int y, int z, int id) { - setFlatBlock(index(x, y, z), id); - } - - @Deprecated/*(forRemoval = true)*/ - default int getBlockWithoutData(int x, int y, int z) { - return getFlatBlock(x, y, z) >> 4; - } - - @Deprecated/*(forRemoval = true)*/ - default int getBlockData(int x, int y, int z) { - return getFlatBlock(x, y, z) & 0xF; - } - - @Deprecated/*(forRemoval = true)*/ - default void setBlockWithData(int x, int y, int z, int type, int data) { - setFlatBlock(index(x, y, z), type << 4 | (data & 0xF)); - } - - @Deprecated/*(forRemoval = true)*/ - default void setBlockWithData(int idx, int type, int data) { - setFlatBlock(idx, type << 4 | (data & 0xF)); - } - - @Deprecated/*(forRemoval = true)*/ - default void setPaletteIndex(int idx, int index) { - palette(PaletteType.BLOCKS).setPaletteIndexAt(idx, index); - } - - @Deprecated/*(forRemoval = true)*/ - default int getPaletteIndex(int idx) { - return palette(PaletteType.BLOCKS).paletteIndexAt(idx); - } - - @Deprecated/*(forRemoval = true)*/ - default int getPaletteSize() { - return palette(PaletteType.BLOCKS).size(); - } - - @Deprecated/*(forRemoval = true)*/ - default int getPaletteEntry(int index) { - return palette(PaletteType.BLOCKS).idByIndex(index); - } - - @Deprecated/*(forRemoval = true)*/ - default void setPaletteEntry(int index, int id) { - palette(PaletteType.BLOCKS).setIdByIndex(index, id); - } - - @Deprecated/*(forRemoval = true)*/ - default void replacePaletteEntry(int oldId, int newId) { - palette(PaletteType.BLOCKS).replaceId(oldId, newId); - } - - @Deprecated/*(forRemoval = true)*/ - default void addPaletteEntry(int id) { - palette(PaletteType.BLOCKS).addId(id); - } - - @Deprecated/*(forRemoval = true)*/ - default void clearPalette() { - palette(PaletteType.BLOCKS).clear(); - } - /** * Returns the number of non-air blocks in this section. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/FilledStructuredData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/FilledStructuredData.java index eed092e43..79a2ecf0c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/FilledStructuredData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/FilledStructuredData.java @@ -45,7 +45,7 @@ final class FilledStructuredData implements StructuredData { } @Override - public void write(final ByteBuf buffer) throws Exception { + public void write(final ByteBuf buffer) { key.type().write(buffer, value); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredData.java index 3d7cf69f4..45e110e62 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredData.java @@ -54,7 +54,7 @@ public interface StructuredData extends IdHolder { void setValue(final T value); - void write(final ByteBuf buffer) throws Exception; + void write(final ByteBuf buffer); void setId(final int id); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java index 5b0fade61..857fe081f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java @@ -51,7 +51,7 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.util.Unit; -public final class StructuredDataKey { +public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CUSTOM_DATA = new StructuredDataKey<>("custom_data", Type.COMPOUND_TAG); public static final StructuredDataKey MAX_STACK_SIZE = new StructuredDataKey<>("max_stack_size", Type.VAR_INT); @@ -110,22 +110,6 @@ public final class StructuredDataKey { public static final StructuredDataKey LOCK = new StructuredDataKey<>("lock", Type.TAG); public static final StructuredDataKey CONTAINER_LOOT = new StructuredDataKey<>("container_loot", Type.COMPOUND_TAG); - private final String identifier; - private final Type type; - - public StructuredDataKey(final String identifier, final Type type) { - this.identifier = identifier; - this.type = type; - } - - public Type type() { - return type; - } - - public String identifier() { - return identifier; - } - @Override public String toString() { return "StructuredDataKey{" + diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java index b5b7b93f5..f2240a718 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java @@ -38,7 +38,7 @@ public class EntityTypes1_10 { else type = EntityType.findById(typeID); - if (!type.isPresent()) { + if (type.isEmpty()) { Via.getPlatform().getLogger().severe("Could not find 1.10 type id " + typeID + " isObject=" + isObject); return EntityType.ENTITY; // Fall back to the basic ENTITY } @@ -50,8 +50,8 @@ public class EntityTypes1_10 { ENTITY(-1), DROPPED_ITEM(1, ENTITY), EXPERIENCE_ORB(2, ENTITY), - LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata - PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata + LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata + PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata ARROW(10, ENTITY), SNOWBALL(11, ENTITY), // Actually EntityProjectile FIREBALL(12, ENTITY), @@ -242,10 +242,7 @@ public class EntityTypes1_10 { public static Optional getPCEntity(int id) { Optional output = findById(id); - - if (!output.isPresent()) - return Optional.empty(); - return Optional.of(output.get().type); + return output.map(objectType -> objectType.type); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java index 35cbd09f9..45fff2104 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java @@ -38,7 +38,7 @@ public class EntityTypes1_11 { else type = EntityType.findById(typeID); - if (!type.isPresent()) { + if (type.isEmpty()) { Via.getPlatform().getLogger().severe("Could not find 1.11 type id " + typeID + " isObject=" + isObject); return EntityType.ENTITY; // Fall back to the basic ENTITY } @@ -50,8 +50,8 @@ public class EntityTypes1_11 { ENTITY(-1), DROPPED_ITEM(1, ENTITY), EXPERIENCE_ORB(2, ENTITY), - LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata - PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata + LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata + PAINTING(9, ENTITY), // Actually entity hanging but, it doesn't make a lot of difference for metadata ARROW(10, ENTITY), SNOWBALL(11, ENTITY), // Actually EntityProjectile FIREBALL(12, ENTITY), @@ -272,10 +272,7 @@ public class EntityTypes1_11 { public static Optional getPCEntity(int id) { Optional output = findById(id); - - if (!output.isPresent()) - return Optional.empty(); - return Optional.of(output.get().type); + return output.map(objectType -> objectType.type); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java index d574b9181..77ed1d7a8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java @@ -39,7 +39,7 @@ public class EntityTypes1_12 { else type = EntityType.findById(typeID); - if (!type.isPresent()) { + if (type.isEmpty()) { Via.getPlatform().getLogger().severe("Could not find 1.12 type id " + typeID + " isObject=" + isObject); return EntityType.ENTITY; // Fall back to the basic ENTITY } @@ -51,8 +51,8 @@ public class EntityTypes1_12 { ENTITY(-1), DROPPED_ITEM(1, ENTITY), EXPERIENCE_ORB(2, ENTITY), - LEASH_HITCH(8, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata - PAINTING(9, ENTITY), // Actually entity hanging but it doesn't make a lot of difference for metadata + LEASH_HITCH(8, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata + PAINTING(9, ENTITY), // Actually entity hanging, but it doesn't make a lot of difference for metadata ARROW(10, ENTITY), SNOWBALL(11, ENTITY), // Actually EntityProjectile FIREBALL(12, ENTITY), @@ -276,10 +276,7 @@ public class EntityTypes1_12 { public static Optional getPCEntity(int id) { Optional output = findById(id); - - if (!output.isPresent()) - return Optional.empty(); - return Optional.of(output.get().type); + return output.map(objectType -> objectType.type); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java index dd438a232..ef691a6ec 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java @@ -37,7 +37,7 @@ public class EntityTypes1_13 { else type = EntityType.findById(typeID); - if (!type.isPresent()) { + if (type.isEmpty()) { Via.getPlatform().getLogger().severe("Could not find 1.13 type id " + typeID + " isObject=" + isObject); return EntityType.ENTITY; // Fall back to the basic ENTITY } @@ -326,9 +326,7 @@ public class EntityTypes1_13 { public static Optional getPCEntity(int id) { Optional output = findById(id); - if (!output.isPresent()) - return Optional.empty(); - return Optional.of(output.get().type); + return output.map(objectType -> objectType.type); } public static Optional fromEntityType(EntityType type) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/DataItem.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/DataItem.java index dfc7c2f03..fd9a99fe2 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/DataItem.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/DataItem.java @@ -66,7 +66,7 @@ public class DataItem implements Item { @Override public void setAmount(int amount) { - if (amount > Byte.MAX_VALUE || amount < Byte.MIN_VALUE) { + if (amount != (byte) amount) { throw new IllegalArgumentException("Invalid item amount: " + amount); } this.amount = (byte) amount; @@ -116,8 +116,8 @@ public class DataItem implements Item { @Override public int hashCode() { int result = identifier; - result = 31 * result + (int) amount; - result = 31 * result + (int) data; + result = 31 * result + amount; + result = 31 * result + data; result = 31 * result + (tag != null ? tag.hashCode() : 0); return result; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AdventureModePredicate.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AdventureModePredicate.java index 169c41c64..05b9d4d45 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AdventureModePredicate.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AdventureModePredicate.java @@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class AdventureModePredicate { +public record AdventureModePredicate(BlockPredicate[] predicates, boolean showInTooltip) { - public static final Type TYPE = new Type(AdventureModePredicate.class) { + public static final Type TYPE = new Type<>(AdventureModePredicate.class) { @Override - public AdventureModePredicate read(final ByteBuf buffer) throws Exception { + public AdventureModePredicate read(final ByteBuf buffer) { final BlockPredicate[] predicates = BlockPredicate.ARRAY_TYPE.read(buffer); final boolean showInTooltip = buffer.readBoolean(); return new AdventureModePredicate(predicates, showInTooltip); } @Override - public void write(final ByteBuf buffer, final AdventureModePredicate value) throws Exception { + public void write(final ByteBuf buffer, final AdventureModePredicate value) { BlockPredicate.ARRAY_TYPE.write(buffer, value.predicates); buffer.writeBoolean(value.showInTooltip); } }; - private final BlockPredicate[] predicates; - private final boolean showInTooltip; - - public AdventureModePredicate(final BlockPredicate[] predicates, final boolean showInTooltip) { - this.predicates = predicates; - this.showInTooltip = showInTooltip; - } - - public BlockPredicate[] predicates() { - return predicates; - } - - public boolean showInTooltip() { - return showInTooltip; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java index c09da1072..225e0bb67 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java @@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class ArmorTrim { +public record ArmorTrim(Holder material, Holder pattern, boolean showInTooltip) { - public static final Type TYPE = new Type(ArmorTrim.class) { + public static final Type TYPE = new Type<>(ArmorTrim.class) { @Override - public ArmorTrim read(final ByteBuf buffer) throws Exception { + public ArmorTrim read(final ByteBuf buffer) { final Holder material = ArmorTrimMaterial.TYPE.read(buffer); final Holder pattern = ArmorTrimPattern.TYPE.read(buffer); final boolean showInTooltip = buffer.readBoolean(); @@ -38,32 +38,11 @@ public final class ArmorTrim { } @Override - public void write(final ByteBuf buffer, final ArmorTrim value) throws Exception { + public void write(final ByteBuf buffer, final ArmorTrim value) { ArmorTrimMaterial.TYPE.write(buffer, value.material); ArmorTrimPattern.TYPE.write(buffer, value.pattern); buffer.writeBoolean(value.showInTooltip); } }; - private final Holder material; - private final Holder pattern; - private final boolean showInTooltip; - - public ArmorTrim(final Holder material, final Holder pattern, final boolean showInTooltip) { - this.material = material; - this.pattern = pattern; - this.showInTooltip = showInTooltip; - } - - public Holder material() { - return material; - } - - public Holder pattern() { - return pattern; - } - - public boolean showInTooltip() { - return showInTooltip; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java index d5e7c971c..c289c5e20 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java @@ -29,11 +29,12 @@ import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -public final class ArmorTrimMaterial { +public record ArmorTrimMaterial(String assetName, int itemId, float itemModelIndex, + Int2ObjectMap overrideArmorMaterials, Tag description) { - public static final HolderType TYPE = new HolderType() { + public static final HolderType TYPE = new HolderType<>() { @Override - public ArmorTrimMaterial readDirect(final ByteBuf buffer) throws Exception { + public ArmorTrimMaterial readDirect(final ByteBuf buffer) { final String assetName = Type.STRING.read(buffer); final int item = Type.VAR_INT.readPrimitive(buffer); final float itemModelIndex = buffer.readFloat(); @@ -51,7 +52,7 @@ public final class ArmorTrimMaterial { } @Override - public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) throws Exception { + public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) { Type.STRING.write(buffer, value.assetName()); Type.VAR_INT.writePrimitive(buffer, value.itemId()); buffer.writeFloat(value.itemModelIndex()); @@ -66,37 +67,4 @@ public final class ArmorTrimMaterial { } }; - private final String assetName; - private final int itemId; - private final float itemModelIndex; - private final Int2ObjectMap overrideArmorMaterials; - private final Tag description; - - public ArmorTrimMaterial(final String assetName, final int itemId, final float itemModelIndex, final Int2ObjectMap overrideArmorMaterials, final Tag description) { - this.assetName = assetName; - this.itemId = itemId; - this.itemModelIndex = itemModelIndex; - this.overrideArmorMaterials = overrideArmorMaterials; - this.description = description; - } - - public String assetName() { - return assetName; - } - - public int itemId() { - return itemId; - } - - public float itemModelIndex() { - return itemModelIndex; - } - - public Int2ObjectMap overrideArmorMaterials() { - return overrideArmorMaterials; - } - - public Tag description() { - return description; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimPattern.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimPattern.java index b6a0cafae..e427a076f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimPattern.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimPattern.java @@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.misc.HolderType; import io.netty.buffer.ByteBuf; -public final class ArmorTrimPattern { +public record ArmorTrimPattern(String assetName, int itemId, Tag description, boolean decal) { - public static final HolderType TYPE = new HolderType() { + public static final HolderType TYPE = new HolderType<>() { @Override - public ArmorTrimPattern readDirect(final ByteBuf buffer) throws Exception { + public ArmorTrimPattern readDirect(final ByteBuf buffer) { final String assetName = Type.STRING.read(buffer); final int itemId = Type.VAR_INT.readPrimitive(buffer); final Tag description = Type.TAG.read(buffer); @@ -40,7 +40,7 @@ public final class ArmorTrimPattern { } @Override - public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) throws Exception { + public void writeDirect(final ByteBuf buffer, final ArmorTrimPattern value) { Type.STRING.write(buffer, value.assetName()); Type.VAR_INT.writePrimitive(buffer, value.itemId()); Type.TAG.write(buffer, value.description()); @@ -48,31 +48,4 @@ public final class ArmorTrimPattern { } }; - private final String assetName; - private final int itemId; - private final Tag description; - private final boolean decal; - - public ArmorTrimPattern(final String assetName, final int itemId, final Tag description, final boolean decal) { - this.assetName = assetName; - this.itemId = itemId; - this.description = description; - this.decal = decal; - } - - public String assetName() { - return assetName; - } - - public int itemId() { - return itemId; - } - - public Tag description() { - return description; - } - - public boolean decal() { - return decal; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java index 894740e79..53ef3ee45 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java @@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class AttributeModifier { +public record AttributeModifier(int attribute, ModifierData modifier, int slotType) { - public static final Type TYPE = new Type(AttributeModifier.class) { + public static final Type TYPE = new Type<>(AttributeModifier.class) { @Override - public AttributeModifier read(final ByteBuf buffer) throws Exception { + public AttributeModifier read(final ByteBuf buffer) { final int attribute = Type.VAR_INT.readPrimitive(buffer); final ModifierData modifier = ModifierData.TYPE.read(buffer); final int slot = Type.VAR_INT.readPrimitive(buffer); @@ -38,7 +38,7 @@ public final class AttributeModifier { } @Override - public void write(final ByteBuf buffer, final AttributeModifier value) throws Exception { + public void write(final ByteBuf buffer, final AttributeModifier value) { Type.VAR_INT.writePrimitive(buffer, value.attribute); ModifierData.TYPE.write(buffer, value.modifier); Type.VAR_INT.writePrimitive(buffer, value.slotType); @@ -46,25 +46,4 @@ public final class AttributeModifier { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final int attribute; - private final ModifierData modifier; - private final int slotType; - - public AttributeModifier(final int attribute, final ModifierData modifier, final int slotType) { - this.attribute = attribute; - this.modifier = modifier; - this.slotType = slotType; - } - - public int attribute() { - return attribute; - } - - public ModifierData modifier() { - return modifier; - } - - public int slotType() { - return slotType; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java index da2a3ff85..85fec4c8b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java @@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class AttributeModifiers { +public record AttributeModifiers(AttributeModifier[] modifiers, boolean showInTooltip) { - public static final Type TYPE = new Type(AttributeModifiers.class) { + public static final Type TYPE = new Type<>(AttributeModifiers.class) { @Override - public AttributeModifiers read(final ByteBuf buffer) throws Exception { + public AttributeModifiers read(final ByteBuf buffer) { final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer); final boolean showInTooltip = buffer.readBoolean(); return new AttributeModifiers(modifiers, showInTooltip); } @Override - public void write(final ByteBuf buffer, final AttributeModifiers value) throws Exception { + public void write(final ByteBuf buffer, final AttributeModifiers value) { AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers()); buffer.writeBoolean(value.showInTooltip()); } }; - private final AttributeModifier[] modifiers; - private final boolean showInTooltip; - - public AttributeModifiers(final AttributeModifier[] modifiers, final boolean showInTooltip) { - this.modifiers = modifiers; - this.showInTooltip = showInTooltip; - } - - public AttributeModifier[] modifiers() { - return modifiers; - } - - public boolean showInTooltip() { - return showInTooltip; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPattern.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPattern.java index 7f87d9b54..b80184c93 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPattern.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPattern.java @@ -26,36 +26,21 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.misc.HolderType; import io.netty.buffer.ByteBuf; -public final class BannerPattern { +public record BannerPattern(String assetId, String translationKey) { - public static final HolderType TYPE = new HolderType() { + public static final HolderType TYPE = new HolderType<>() { @Override - public BannerPattern readDirect(final ByteBuf buffer) throws Exception { + public BannerPattern readDirect(final ByteBuf buffer) { final String assetId = Type.STRING.read(buffer); final String translationKey = Type.STRING.read(buffer); return new BannerPattern(assetId, translationKey); } @Override - public void writeDirect(final ByteBuf buffer, final BannerPattern value) throws Exception { + public void writeDirect(final ByteBuf buffer, final BannerPattern value) { Type.STRING.write(buffer, value.assetId); Type.STRING.write(buffer, value.translationKey); } }; - private final String assetId; - private final String translationKey; - - public BannerPattern(final String assetId, final String translationKey) { - this.assetId = assetId; - this.translationKey = translationKey; - } - - public String assetId() { - return assetId; - } - - public String translationKey() { - return translationKey; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPatternLayer.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPatternLayer.java index 95c40f39e..2468b2c29 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPatternLayer.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BannerPatternLayer.java @@ -27,37 +27,22 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class BannerPatternLayer { +public record BannerPatternLayer(Holder pattern, int dyeColor) { - public static final Type TYPE = new Type(BannerPatternLayer.class) { + public static final Type TYPE = new Type<>(BannerPatternLayer.class) { @Override - public BannerPatternLayer read(final ByteBuf buffer) throws Exception { + public BannerPatternLayer read(final ByteBuf buffer) { final Holder pattern = BannerPattern.TYPE.read(buffer); final int color = Type.VAR_INT.readPrimitive(buffer); return new BannerPatternLayer(pattern, color); } @Override - public void write(final ByteBuf buffer, final BannerPatternLayer value) throws Exception { + public void write(final ByteBuf buffer, final BannerPatternLayer value) { BannerPattern.TYPE.write(buffer, value.pattern); Type.VAR_INT.writePrimitive(buffer, value.dyeColor); } }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final Holder pattern; - private final int dyeColor; - - public BannerPatternLayer(final Holder pattern, final int dyeColor) { - this.pattern = pattern; - this.dyeColor = dyeColor; - } - - public Holder pattern() { - return pattern; - } - - public int dyeColor() { - return dyeColor; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Bee.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Bee.java index cccc45444..28fed564c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Bee.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Bee.java @@ -27,11 +27,11 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class Bee { +public record Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) { - public static final Type TYPE = new Type(Bee.class) { + public static final Type TYPE = new Type<>(Bee.class) { @Override - public Bee read(final ByteBuf buffer) throws Exception { + public Bee read(final ByteBuf buffer) { final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer); final int ticksInHive = Type.VAR_INT.readPrimitive(buffer); final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer); @@ -39,7 +39,7 @@ public final class Bee { } @Override - public void write(final ByteBuf buffer, final Bee value) throws Exception { + public void write(final ByteBuf buffer, final Bee value) { Type.COMPOUND_TAG.write(buffer, value.entityData); Type.VAR_INT.writePrimitive(buffer, value.ticksInHive); Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive); @@ -47,25 +47,4 @@ public final class Bee { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final CompoundTag entityData; - private final int ticksInHive; - private final int minTicksInHive; - - public Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) { - this.entityData = entityData; - this.ticksInHive = ticksInHive; - this.minTicksInHive = minTicksInHive; - } - - public CompoundTag entityData() { - return entityData; - } - - public int ticksInHive() { - return ticksInHive; - } - - public int minTicksInHive() { - return minTicksInHive; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockPredicate.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockPredicate.java index 149cea6b4..fdcd04417 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockPredicate.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockPredicate.java @@ -29,11 +29,12 @@ import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class BlockPredicate { +public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher @Nullable [] propertyMatchers, + @Nullable CompoundTag tag) { - public static final Type TYPE = new Type(BlockPredicate.class) { + public static final Type TYPE = new Type<>(BlockPredicate.class) { @Override - public BlockPredicate read(final ByteBuf buffer) throws Exception { + public BlockPredicate read(final ByteBuf buffer) { final HolderSet holders = Type.OPTIONAL_HOLDER_SET.read(buffer); final StatePropertyMatcher[] propertyMatchers = buffer.readBoolean() ? StatePropertyMatcher.ARRAY_TYPE.read(buffer) : null; final CompoundTag tag = Type.OPTIONAL_COMPOUND_TAG.read(buffer); @@ -41,7 +42,7 @@ public final class BlockPredicate { } @Override - public void write(final ByteBuf buffer, final BlockPredicate value) throws Exception { + public void write(final ByteBuf buffer, final BlockPredicate value) { Type.OPTIONAL_HOLDER_SET.write(buffer, value.holderSet); buffer.writeBoolean(value.propertyMatchers != null); @@ -54,25 +55,4 @@ public final class BlockPredicate { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final HolderSet holderSet; - private final StatePropertyMatcher[] propertyMatchers; - private final CompoundTag tag; - - public BlockPredicate(@Nullable final HolderSet holderSet, final StatePropertyMatcher @Nullable [] propertyMatchers, @Nullable final CompoundTag tag) { - this.holderSet = holderSet; - this.propertyMatchers = propertyMatchers; - this.tag = tag; - } - - public @Nullable HolderSet holderSet() { - return holderSet; - } - - public StatePropertyMatcher @Nullable [] propertyMatchers() { - return propertyMatchers; - } - - public @Nullable CompoundTag tag() { - return tag; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockStateProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockStateProperties.java index b13305928..aa02b5f88 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockStateProperties.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/BlockStateProperties.java @@ -27,11 +27,11 @@ import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.util.Map; -public final class BlockStateProperties { +public record BlockStateProperties(Map properties) { - public static final Type TYPE = new Type(BlockStateProperties.class) { + public static final Type TYPE = new Type<>(BlockStateProperties.class) { @Override - public BlockStateProperties read(final ByteBuf buffer) throws Exception { + public BlockStateProperties read(final ByteBuf buffer) { final int size = Type.VAR_INT.readPrimitive(buffer); final Map properties = new Object2ObjectOpenHashMap<>(size); for (int i = 0; i < size; i++) { @@ -41,7 +41,7 @@ public final class BlockStateProperties { } @Override - public void write(final ByteBuf buffer, final BlockStateProperties value) throws Exception { + public void write(final ByteBuf buffer, final BlockStateProperties value) { Type.VAR_INT.writePrimitive(buffer, value.properties.size()); for (final Map.Entry entry : value.properties.entrySet()) { Type.STRING.write(buffer, entry.getKey()); @@ -50,13 +50,4 @@ public final class BlockStateProperties { } }; - private final Map properties; - - public BlockStateProperties(final Map properties) { - this.properties = properties; - } - - public Map properties() { - return properties; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/DyedColor.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/DyedColor.java index dcc29fce7..61cbd39a1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/DyedColor.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/DyedColor.java @@ -25,9 +25,9 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class DyedColor { +public record DyedColor(int rgb, boolean showInTooltip) { - public static final Type TYPE = new Type(DyedColor.class) { + public static final Type TYPE = new Type<>(DyedColor.class) { @Override public DyedColor read(final ByteBuf buffer) { final int rgb = buffer.readInt(); @@ -42,19 +42,4 @@ public final class DyedColor { } }; - private final int rgb; - private final boolean showInTooltip; - - public DyedColor(final int rgb, final boolean showInTooltip) { - this.rgb = rgb; - this.showInTooltip = showInTooltip; - } - - public int rgb() { - return this.rgb; - } - - public boolean showInTooltip() { - return this.showInTooltip; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Enchantments.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Enchantments.java index 05731586b..1a5044cb4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Enchantments.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Enchantments.java @@ -27,9 +27,9 @@ import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -public final class Enchantments { +public record Enchantments(Int2IntMap enchantments, boolean showInTooltip) { - public static final Type TYPE = new Type(Enchantments.class) { + public static final Type TYPE = new Type<>(Enchantments.class) { @Override public Enchantments read(final ByteBuf buffer) { final Int2IntMap enchantments = new Int2IntOpenHashMap(); @@ -54,30 +54,14 @@ public final class Enchantments { } }; - private final Int2IntMap enchantments; - private final boolean showInTooltip; - - public Enchantments(final Int2IntMap enchantments, final boolean showInTooltip) { - this.enchantments = enchantments; - this.showInTooltip = showInTooltip; - } - public Enchantments(final boolean showInTooltip) { this(new Int2IntOpenHashMap(), showInTooltip); } - public Int2IntMap enchantments() { - return enchantments; - } - public int size() { return enchantments.size(); } - public boolean showInTooltip() { - return showInTooltip; - } - public void add(final int id, final int level) { enchantments.put(id, level); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java index 04cf554d5..d7c307112 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java @@ -62,14 +62,14 @@ public abstract class Filterable { } @Override - public F read(final ByteBuf buffer) throws Exception { + public F read(final ByteBuf buffer) { final T raw = elementType.read(buffer); final T filtered = optionalElementType.read(buffer); return create(raw, filtered); } @Override - public void write(final ByteBuf buffer, final F value) throws Exception { + public void write(final ByteBuf buffer, final F value) { elementType.write(buffer, value.raw()); optionalElementType.write(buffer, value.filtered()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java index 144ea76fe..f8ba9838f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class FilterableComponent extends Filterable { - public static final Type TYPE = new FilterableType(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) { + public static final Type TYPE = new FilterableType<>(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) { @Override protected FilterableComponent create(final Tag raw, final Tag filtered) { return new FilterableComponent(raw, filtered); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java index ec11dfd29..51e945d79 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class FilterableString extends Filterable { - public static final Type TYPE = new FilterableType(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) { + public static final Type TYPE = new FilterableType<>(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) { @Override protected FilterableString create(final String raw, final String filtered) { return new FilterableString(raw, filtered); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FireworkExplosion.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FireworkExplosion.java index 72cf1e83f..789871c8c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FireworkExplosion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FireworkExplosion.java @@ -26,10 +26,10 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class FireworkExplosion { - public static final Type TYPE = new Type(FireworkExplosion.class) { +public record FireworkExplosion(int shape, int[] colors, int[] fadeColors, boolean hasTrail, boolean hasTwinkle) { + public static final Type TYPE = new Type<>(FireworkExplosion.class) { @Override - public FireworkExplosion read(final ByteBuf buffer) throws Exception { + public FireworkExplosion read(final ByteBuf buffer) { final int shape = Type.VAR_INT.readPrimitive(buffer); final int[] colors = Type.INT_ARRAY_PRIMITIVE.read(buffer); final int[] fadeColors = Type.INT_ARRAY_PRIMITIVE.read(buffer); @@ -39,7 +39,7 @@ public final class FireworkExplosion { } @Override - public void write(final ByteBuf buffer, final FireworkExplosion value) throws Exception { + public void write(final ByteBuf buffer, final FireworkExplosion value) { Type.VAR_INT.writePrimitive(buffer, value.shape); Type.INT_ARRAY_PRIMITIVE.write(buffer, value.colors); Type.INT_ARRAY_PRIMITIVE.write(buffer, value.fadeColors); @@ -49,37 +49,4 @@ public final class FireworkExplosion { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final int shape; - private final int[] colors; - private final int[] fadeColors; - private final boolean hasTrail; - private final boolean hasTwinkle; - - public FireworkExplosion(final int shape, final int[] colors, final int[] fadeColors, final boolean hasTrail, final boolean hasTwinkle) { - this.shape = shape; - this.colors = colors; - this.fadeColors = fadeColors; - this.hasTrail = hasTrail; - this.hasTwinkle = hasTwinkle; - } - - public int shape() { - return shape; - } - - public int[] colors() { - return colors; - } - - public int[] fadeColors() { - return fadeColors; - } - - public boolean hasTrail() { - return hasTrail; - } - - public boolean hasTwinkle() { - return hasTwinkle; - } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Fireworks.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Fireworks.java index 751792b4c..fba0e1c6d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Fireworks.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Fireworks.java @@ -25,36 +25,21 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class Fireworks { +public record Fireworks(int flightDuration, FireworkExplosion[] explosions) { - public static final Type TYPE = new Type(Fireworks.class) { + public static final Type TYPE = new Type<>(Fireworks.class) { @Override - public Fireworks read(final ByteBuf buffer) throws Exception { + public Fireworks read(final ByteBuf buffer) { final int flightDuration = Type.VAR_INT.readPrimitive(buffer); final FireworkExplosion[] explosions = FireworkExplosion.ARRAY_TYPE.read(buffer); return new Fireworks(flightDuration, explosions); } @Override - public void write(final ByteBuf buffer, final Fireworks value) throws Exception { + public void write(final ByteBuf buffer, final Fireworks value) { Type.VAR_INT.writePrimitive(buffer, value.flightDuration); FireworkExplosion.ARRAY_TYPE.write(buffer, value.explosions); } }; - private final FireworkExplosion[] explosions; - private final int flightDuration; - - public Fireworks(final int flightDuration, final FireworkExplosion[] explosions) { - this.flightDuration = flightDuration; - this.explosions = explosions; - } - - public int flightDuration() { - return flightDuration; - } - - public FireworkExplosion[] explosions() { - return explosions; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java index f26eeedb5..3051ce390 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodEffect.java @@ -26,37 +26,22 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class FoodEffect { +public record FoodEffect(PotionEffect effect, float probability) { - public static final Type TYPE = new Type(FoodEffect.class) { + public static final Type TYPE = new Type<>(FoodEffect.class) { @Override - public FoodEffect read(final ByteBuf buffer) throws Exception { + public FoodEffect read(final ByteBuf buffer) { final PotionEffect effect = PotionEffect.TYPE.read(buffer); final float probability = buffer.readFloat(); return new FoodEffect(effect, probability); } @Override - public void write(final ByteBuf buffer, final FoodEffect value) throws Exception { + public void write(final ByteBuf buffer, final FoodEffect value) { PotionEffect.TYPE.write(buffer, value.effect); buffer.writeFloat(value.probability); } }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final PotionEffect effect; - private final float probability; - - public FoodEffect(final PotionEffect effect, final float probability) { - this.effect = effect; - this.probability = probability; - } - - public PotionEffect effect() { - return effect; - } - - public float probability() { - return probability; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java index 4784cc005..a25cba9ea 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java @@ -25,11 +25,12 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class FoodProperties { +public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds, + FoodEffect[] possibleEffects) { - public static final Type TYPE = new Type(FoodProperties.class) { + public static final Type TYPE = new Type<>(FoodProperties.class) { @Override - public FoodProperties read(final ByteBuf buffer) throws Exception { + public FoodProperties read(final ByteBuf buffer) { final int nutrition = Type.VAR_INT.readPrimitive(buffer); final float saturationModifier = buffer.readFloat(); final boolean canAlwaysEat = buffer.readBoolean(); @@ -39,7 +40,7 @@ public final class FoodProperties { } @Override - public void write(final ByteBuf buffer, final FoodProperties value) throws Exception { + public void write(final ByteBuf buffer, final FoodProperties value) { Type.VAR_INT.writePrimitive(buffer, value.nutrition); buffer.writeFloat(value.saturationModifier); buffer.writeBoolean(value.canAlwaysEat); @@ -48,37 +49,4 @@ public final class FoodProperties { } }; - private final int nutrition; - private final float saturationModifier; - private final boolean canAlwaysEat; - private final float eatSeconds; - private final FoodEffect[] possibleEffects; - - public FoodProperties(final int nutrition, final float saturationModifier, final boolean canAlwaysEat, final float eatSeconds, final FoodEffect[] possibleEffects) { - this.nutrition = nutrition; - this.saturationModifier = saturationModifier; - this.canAlwaysEat = canAlwaysEat; - this.eatSeconds = eatSeconds; - this.possibleEffects = possibleEffects; - } - - public int nutrition() { - return nutrition; - } - - public float saturationModifier() { - return saturationModifier; - } - - public boolean canAlwaysEat() { - return canAlwaysEat; - } - - public float eatSeconds() { - return eatSeconds; - } - - public FoodEffect[] possibleEffects() { - return possibleEffects; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Instrument.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Instrument.java index eae31a242..065d73a6f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Instrument.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Instrument.java @@ -28,11 +28,11 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.misc.HolderType; import io.netty.buffer.ByteBuf; -public final class Instrument { +public record Instrument(Holder soundEvent, int useDuration, float range) { - public static final HolderType TYPE = new HolderType() { + public static final HolderType TYPE = new HolderType<>() { @Override - public Instrument readDirect(final ByteBuf buffer) throws Exception { + public Instrument readDirect(final ByteBuf buffer) { final Holder soundEvent = Type.SOUND_EVENT.read(buffer); final int useDuration = Type.VAR_INT.readPrimitive(buffer); final float range = buffer.readFloat(); @@ -40,32 +40,11 @@ public final class Instrument { } @Override - public void writeDirect(final ByteBuf buffer, final Instrument value) throws Exception { + public void writeDirect(final ByteBuf buffer, final Instrument value) { Type.SOUND_EVENT.write(buffer, value.soundEvent()); Type.VAR_INT.writePrimitive(buffer, value.useDuration()); buffer.writeFloat(value.range()); } }; - private final Holder soundEvent; - private final int useDuration; - private final float range; - - public Instrument(final Holder soundEvent, final int useDuration, final float range) { - this.soundEvent = soundEvent; - this.useDuration = useDuration; - this.range = range; - } - - public Holder soundEvent() { - return soundEvent; - } - - public int useDuration() { - return useDuration; - } - - public float range() { - return range; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/LodestoneTracker.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/LodestoneTracker.java index 997e0f092..a3e58e719 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/LodestoneTracker.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/LodestoneTracker.java @@ -27,36 +27,21 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class LodestoneTracker { +public record LodestoneTracker(@Nullable GlobalPosition position, boolean tracked) { - public static final Type TYPE = new Type(LodestoneTracker.class) { + public static final Type TYPE = new Type<>(LodestoneTracker.class) { @Override - public LodestoneTracker read(final ByteBuf buffer) throws Exception { + public LodestoneTracker read(final ByteBuf buffer) { final GlobalPosition position = Type.OPTIONAL_GLOBAL_POSITION.read(buffer); final boolean tracked = buffer.readBoolean(); return new LodestoneTracker(position, tracked); } @Override - public void write(final ByteBuf buffer, final LodestoneTracker value) throws Exception { + public void write(final ByteBuf buffer, final LodestoneTracker value) { Type.OPTIONAL_GLOBAL_POSITION.write(buffer, value.position); buffer.writeBoolean(value.tracked); } }; - private final GlobalPosition position; - private final boolean tracked; - - public LodestoneTracker(@Nullable final GlobalPosition position, final boolean tracked) { - this.position = position; - this.tracked = tracked; - } - - public @Nullable GlobalPosition pos() { - return this.position; - } - - public boolean tracked() { - return this.tracked; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecoration.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecoration.java index e2252a447..97623dde2 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecoration.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecoration.java @@ -25,11 +25,11 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class MapDecoration { +public record MapDecoration(String type, double x, double z, float rotation) { - public static final Type TYPE = new Type(MapDecoration.class) { + public static final Type TYPE = new Type<>(MapDecoration.class) { @Override - public MapDecoration read(final ByteBuf buffer) throws Exception { + public MapDecoration read(final ByteBuf buffer) { final String type = Type.STRING.read(buffer); final double x = Type.DOUBLE.readPrimitive(buffer); final double z = Type.DOUBLE.readPrimitive(buffer); @@ -38,40 +38,11 @@ public final class MapDecoration { } @Override - public void write(final ByteBuf buffer, final MapDecoration value) throws Exception { + public void write(final ByteBuf buffer, final MapDecoration value) { Type.STRING.write(buffer, value.type); buffer.writeDouble(value.x); buffer.writeDouble(value.z); buffer.writeFloat(value.rotation); } }; - - private final String type; - private final double x; - private final double z; - private final float rotation; - - public MapDecoration(final String type, final double x, final double z, final float rotation) { - this.type = type; - this.x = x; - this.z = z; - this.rotation = rotation; - } - - public String type() { - return type; - } - - public double x() { - return x; - } - - public double z() { - return z; - } - - public float rotation() { - return rotation; - } - } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecorations.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecorations.java index 6bb9f4c3c..c4e659440 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecorations.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/MapDecorations.java @@ -28,11 +28,11 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.util.Map; -public final class MapDecorations { +public record MapDecorations(Map decorations) { - public static final Type TYPE = new Type(MapDecorations.class) { + public static final Type TYPE = new Type<>(MapDecorations.class) { @Override - public MapDecorations read(final ByteBuf buffer) throws Exception { + public MapDecorations read(final ByteBuf buffer) { final Object2ObjectMap decorations = new Object2ObjectOpenHashMap<>(); final int size = Type.VAR_INT.readPrimitive(buffer); for (int i = 0; i < size; i++) { @@ -44,7 +44,7 @@ public final class MapDecorations { } @Override - public void write(final ByteBuf buffer, final MapDecorations value) throws Exception { + public void write(final ByteBuf buffer, final MapDecorations value) { Type.VAR_INT.writePrimitive(buffer, value.decorations.size()); for (final Map.Entry entry : value.decorations.entrySet()) { Type.STRING.write(buffer, entry.getKey()); @@ -52,14 +52,4 @@ public final class MapDecorations { } } }; - - private final Map decorations; - - public MapDecorations(final Map decorations) { - this.decorations = decorations; - } - - public Map decorations() { - return decorations; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java index 60827ecf9..afb6564e7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java @@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import java.util.UUID; -public final class ModifierData { +public record ModifierData(UUID uuid, String name, double amount, int operation) { - public static final Type TYPE = new Type(ModifierData.class) { + public static final Type TYPE = new Type<>(ModifierData.class) { @Override - public ModifierData read(final ByteBuf buffer) throws Exception { + public ModifierData read(final ByteBuf buffer) { final UUID uuid = Type.UUID.read(buffer); final String name = Type.STRING.read(buffer); final double amount = buffer.readDouble(); @@ -39,7 +39,7 @@ public final class ModifierData { } @Override - public void write(final ByteBuf buffer, final ModifierData value) throws Exception { + public void write(final ByteBuf buffer, final ModifierData value) { Type.UUID.write(buffer, value.uuid); Type.STRING.write(buffer, value.name); buffer.writeDouble(value.amount); @@ -47,31 +47,4 @@ public final class ModifierData { } }; - private final UUID uuid; - private final String name; - private final double amount; - private final int operation; - - public ModifierData(final UUID uuid, final String name, final double amount, final int operation) { - this.uuid = uuid; - this.name = name; - this.amount = amount; - this.operation = operation; - } - - public UUID uuid() { - return uuid; - } - - public String name() { - return name; - } - - public double amount() { - return amount; - } - - public int operation() { - return operation; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotDecorations.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotDecorations.java index 3e567ffc2..03fd81e40 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotDecorations.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotDecorations.java @@ -27,14 +27,14 @@ import io.netty.buffer.ByteBuf; public final class PotDecorations { - public static final Type TYPE = new Type(PotDecorations.class) { + public static final Type TYPE = new Type<>(PotDecorations.class) { @Override - public PotDecorations read(final ByteBuf buffer) throws Exception { + public PotDecorations read(final ByteBuf buffer) { return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer)); } @Override - public void write(final ByteBuf buffer, final PotDecorations value) throws Exception { + public void write(final ByteBuf buffer, final PotDecorations value) { Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds()); } }; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionContents.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionContents.java index f9af9a6d7..cdfad17a7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionContents.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionContents.java @@ -26,11 +26,11 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class PotionContents { +public record PotionContents(@Nullable Integer potion, @Nullable Integer customColor, PotionEffect[] customEffects) { - public static final Type TYPE = new Type(PotionContents.class) { + public static final Type TYPE = new Type<>(PotionContents.class) { @Override - public PotionContents read(final ByteBuf buffer) throws Exception { + public PotionContents read(final ByteBuf buffer) { final Integer potion = buffer.readBoolean() ? Type.VAR_INT.readPrimitive(buffer) : null; final Integer customColor = buffer.readBoolean() ? buffer.readInt() : null; final PotionEffect[] customEffects = PotionEffect.ARRAY_TYPE.read(buffer); @@ -38,7 +38,7 @@ public final class PotionContents { } @Override - public void write(final ByteBuf buffer, final PotionContents value) throws Exception { + public void write(final ByteBuf buffer, final PotionContents value) { buffer.writeBoolean(value.potion != null); if (value.potion != null) { Type.VAR_INT.writePrimitive(buffer, value.potion); @@ -52,26 +52,4 @@ public final class PotionContents { PotionEffect.ARRAY_TYPE.write(buffer, value.customEffects); } }; - - private final Integer potion; - private final Integer customColor; - private final PotionEffect[] customEffects; - - public PotionContents(@Nullable final Integer potion, @Nullable final Integer customColor, final PotionEffect[] customEffects) { - this.potion = potion; - this.customColor = customColor; - this.customEffects = customEffects; - } - - public @Nullable Integer potion() { - return potion; - } - - public @Nullable Integer customColor() { - return customColor; - } - - public PotionEffect[] customEffects() { - return customEffects; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffect.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffect.java index 59e05bc9f..6c6b6578f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffect.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffect.java @@ -26,37 +26,22 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class PotionEffect { +public record PotionEffect(int effect, PotionEffectData effectData) { - public static final Type TYPE = new Type(PotionEffect.class) { + public static final Type TYPE = new Type<>(PotionEffect.class) { @Override - public PotionEffect read(final ByteBuf buffer) throws Exception { + public PotionEffect read(final ByteBuf buffer) { final int effect = Type.VAR_INT.readPrimitive(buffer); final PotionEffectData effectData = PotionEffectData.TYPE.read(buffer); return new PotionEffect(effect, effectData); } @Override - public void write(final ByteBuf buffer, final PotionEffect value) throws Exception { + public void write(final ByteBuf buffer, final PotionEffect value) { Type.VAR_INT.writePrimitive(buffer, value.effect); PotionEffectData.TYPE.write(buffer, value.effectData); } }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final int effect; - private final PotionEffectData effectData; - - public PotionEffect(final int effect, final PotionEffectData effectData) { - this.effect = effect; - this.effectData = effectData; - } - - public int effect() { - return effect; - } - - public PotionEffectData effectData() { - return effectData; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffectData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffectData.java index ed9d5c4a5..c0fb8b9c0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffectData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/PotionEffectData.java @@ -27,11 +27,12 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class PotionEffectData { +public record PotionEffectData(int amplifier, int duration, boolean ambient, boolean showParticles, + boolean showIcon, @Nullable PotionEffectData hiddenEffect) { - public static final Type TYPE = new Type(PotionEffectData.class) { + public static final Type TYPE = new Type<>(PotionEffectData.class) { @Override - public PotionEffectData read(final ByteBuf buffer) throws Exception { + public PotionEffectData read(final ByteBuf buffer) { final int amplifier = Type.VAR_INT.readPrimitive(buffer); final int duration = Type.VAR_INT.readPrimitive(buffer); final boolean ambient = buffer.readBoolean(); @@ -42,7 +43,7 @@ public final class PotionEffectData { } @Override - public void write(final ByteBuf buffer, final PotionEffectData value) throws Exception { + public void write(final ByteBuf buffer, final PotionEffectData value) { Type.VAR_INT.writePrimitive(buffer, value.amplifier); Type.VAR_INT.writePrimitive(buffer, value.duration); buffer.writeBoolean(value.ambient); @@ -51,47 +52,6 @@ public final class PotionEffectData { OPTIONAL_TYPE.write(buffer, value.hiddenEffect); } }; - public static final Type OPTIONAL_TYPE = new OptionalType(TYPE) { + public static final Type OPTIONAL_TYPE = new OptionalType<>(TYPE) { }; - - private final int amplifier; - private final int duration; - private final boolean ambient; - private final boolean showParticles; - private final boolean showIcon; - private final PotionEffectData hiddenEffect; - - public PotionEffectData(final int amplifier, final int duration, final boolean ambient, final boolean showParticles, - final boolean showIcon, @Nullable final PotionEffectData hiddenEffect) { - this.amplifier = amplifier; - this.duration = duration; - this.ambient = ambient; - this.showParticles = showParticles; - this.showIcon = showIcon; - this.hiddenEffect = hiddenEffect; - } - - public int amplifier() { - return amplifier; - } - - public int duration() { - return duration; - } - - public boolean ambient() { - return ambient; - } - - public boolean showParticles() { - return showParticles; - } - - public boolean showIcon() { - return showIcon; - } - - public @Nullable PotionEffectData hiddenEffect() { - return hiddenEffect; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java index 820122670..479c4a1a5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java @@ -28,12 +28,12 @@ import com.viaversion.viaversion.util.Either; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class StatePropertyMatcher { +public record StatePropertyMatcher(String name, Either matcher) { // TODO Abstract Either reading - public static final Type TYPE = new Type(StatePropertyMatcher.class) { + public static final Type TYPE = new Type<>(StatePropertyMatcher.class) { @Override - public StatePropertyMatcher read(final ByteBuf buffer) throws Exception { + public StatePropertyMatcher read(final ByteBuf buffer) { final String name = Type.STRING.read(buffer); if (buffer.readBoolean()) { final String value = Type.STRING.read(buffer); @@ -46,7 +46,7 @@ public final class StatePropertyMatcher { } @Override - public void write(final ByteBuf buffer, final StatePropertyMatcher value) throws Exception { + public void write(final ByteBuf buffer, final StatePropertyMatcher value) { Type.STRING.write(buffer, value.name); if (value.matcher.isLeft()) { buffer.writeBoolean(true); @@ -60,37 +60,6 @@ public final class StatePropertyMatcher { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final String name; - private final Either matcher; - - public StatePropertyMatcher(final String name, final Either matcher) { - this.name = name; - this.matcher = matcher; - } - - public String name() { - return name; - } - - public Either matcher() { - return matcher; - } - - public static final class RangedMatcher { - private final String minValue; - private final String maxValue; - - public RangedMatcher(@Nullable final String minValue, @Nullable final String maxValue) { - this.minValue = minValue; - this.maxValue = maxValue; - } - - public @Nullable String minValue() { - return minValue; - } - - public @Nullable String maxValue() { - return maxValue; - } + public record RangedMatcher(@Nullable String minValue, @Nullable String maxValue) { } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/SuspiciousStewEffect.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/SuspiciousStewEffect.java index 52855ee48..8f30fe37e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/SuspiciousStewEffect.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/SuspiciousStewEffect.java @@ -26,9 +26,9 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; -public final class SuspiciousStewEffect { +public record SuspiciousStewEffect(int mobEffect, int duration) { - public static final Type TYPE = new Type(SuspiciousStewEffect.class) { + public static final Type TYPE = new Type<>(SuspiciousStewEffect.class) { @Override public SuspiciousStewEffect read(final ByteBuf buffer) { final int effect = Type.VAR_INT.readPrimitive(buffer); @@ -38,25 +38,10 @@ public final class SuspiciousStewEffect { @Override public void write(final ByteBuf buffer, final SuspiciousStewEffect value) { - Type.VAR_INT.writePrimitive(buffer, value.effect); + Type.VAR_INT.writePrimitive(buffer, value.mobEffect); Type.VAR_INT.writePrimitive(buffer, value.duration); } }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final int effect; - private final int duration; - - public SuspiciousStewEffect(final int effect, final int duration) { - this.effect = effect; - this.duration = duration; - } - - public int mobEffect() { - return effect; - } - - public int duration() { - return duration; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java index db692a5fc..588c14524 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolProperties.java @@ -25,11 +25,11 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class ToolProperties { +public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) { - public static final Type TYPE = new Type(ToolProperties.class) { + public static final Type TYPE = new Type<>(ToolProperties.class) { @Override - public ToolProperties read(final ByteBuf buffer) throws Exception { + public ToolProperties read(final ByteBuf buffer) { final ToolRule[] rules = ToolRule.ARRAY_TYPE.read(buffer); final float defaultMiningSpeed = buffer.readFloat(); final int damagePerBlock = Type.VAR_INT.readPrimitive(buffer); @@ -37,32 +37,11 @@ public final class ToolProperties { } @Override - public void write(final ByteBuf buffer, final ToolProperties value) throws Exception { + public void write(final ByteBuf buffer, final ToolProperties value) { ToolRule.ARRAY_TYPE.write(buffer, value.rules()); buffer.writeFloat(value.defaultMiningSpeed()); Type.VAR_INT.writePrimitive(buffer, value.damagePerBlock()); } }; - private final ToolRule[] rules; - private final float defaultMiningSpeed; - private final int damagePerBlock; - - public ToolProperties(final ToolRule[] rules, final float defaultMiningSpeed, final int damagePerBlock) { - this.rules = rules; - this.defaultMiningSpeed = defaultMiningSpeed; - this.damagePerBlock = damagePerBlock; - } - - public ToolRule[] rules() { - return rules; - } - - public float defaultMiningSpeed() { - return defaultMiningSpeed; - } - - public int damagePerBlock() { - return damagePerBlock; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java index 5bd271bc8..bed7a0a5d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ToolRule.java @@ -28,11 +28,11 @@ import com.viaversion.viaversion.api.type.types.ArrayType; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public final class ToolRule { +public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolean correctForDrops) { - public static final Type TYPE = new Type(ToolRule.class) { + public static final Type TYPE = new Type<>(ToolRule.class) { @Override - public ToolRule read(final ByteBuf buffer) throws Exception { + public ToolRule read(final ByteBuf buffer) { final HolderSet blocks = Type.HOLDER_SET.read(buffer); final Float speed = Type.OPTIONAL_FLOAT.read(buffer); final Boolean correctForDrops = Type.OPTIONAL_BOOLEAN.read(buffer); @@ -40,7 +40,7 @@ public final class ToolRule { } @Override - public void write(final ByteBuf buffer, final ToolRule value) throws Exception { + public void write(final ByteBuf buffer, final ToolRule value) { Type.HOLDER_SET.write(buffer, value.blocks); Type.OPTIONAL_FLOAT.write(buffer, value.speed); Type.OPTIONAL_BOOLEAN.write(buffer, value.correctForDrops); @@ -48,25 +48,4 @@ public final class ToolRule { }; public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - private final HolderSet blocks; - private final Float speed; - private final Boolean correctForDrops; - - public ToolRule(final HolderSet blocks, @Nullable final Float speed, @Nullable final Boolean correctForDrops) { - this.blocks = blocks; - this.speed = speed; - this.correctForDrops = correctForDrops; - } - - public HolderSet blocks() { - return blocks; - } - - public @Nullable Float speed() { - return speed; - } - - public @Nullable Boolean correctForDrops() { - return correctForDrops; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Unbreakable.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Unbreakable.java index 841506322..293c0ea6d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Unbreakable.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Unbreakable.java @@ -25,9 +25,9 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class Unbreakable { +public record Unbreakable(boolean showInTooltip) { - public static final Type TYPE = new Type(Unbreakable.class) { + public static final Type TYPE = new Type<>(Unbreakable.class) { @Override public Unbreakable read(final ByteBuf buffer) { return new Unbreakable(buffer.readBoolean()); @@ -39,13 +39,4 @@ public final class Unbreakable { } }; - private final boolean showInTooltip; - - public Unbreakable(final boolean showInTooltip) { - this.showInTooltip = showInTooltip; - } - - public boolean showInTooltip() { - return showInTooltip; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/WrittenBook.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/WrittenBook.java index 44cdcebc3..a60df78b1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/WrittenBook.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/WrittenBook.java @@ -25,11 +25,12 @@ package com.viaversion.viaversion.api.minecraft.item.data; import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; -public final class WrittenBook { +public record WrittenBook(FilterableString title, String author, int generation, FilterableComponent[] pages, + boolean resolved) { - public static final Type TYPE = new Type(WrittenBook.class) { + public static final Type TYPE = new Type<>(WrittenBook.class) { @Override - public WrittenBook read(final ByteBuf buffer) throws Exception { + public WrittenBook read(final ByteBuf buffer) { final FilterableString title = FilterableString.TYPE.read(buffer); final String author = Type.STRING.read(buffer); final int generation = Type.VAR_INT.readPrimitive(buffer); @@ -39,7 +40,7 @@ public final class WrittenBook { } @Override - public void write(final ByteBuf buffer, final WrittenBook value) throws Exception { + public void write(final ByteBuf buffer, final WrittenBook value) { FilterableString.TYPE.write(buffer, value.title); Type.STRING.write(buffer, value.author); Type.VAR_INT.writePrimitive(buffer, value.generation); @@ -48,37 +49,4 @@ public final class WrittenBook { } }; - private final FilterableString title; - private final String author; - private final int generation; - private final FilterableComponent[] pages; - private final boolean resolved; - - public WrittenBook(final FilterableString title, final String author, final int generation, final FilterableComponent[] pages, final boolean resolved) { - this.title = title; - this.author = author; - this.generation = generation; - this.pages = pages; - this.resolved = resolved; - } - - public FilterableString title() { - return title; - } - - public String author() { - return author; - } - - public int generation() { - return generation; - } - - public FilterableComponent[] pages() { - return pages; - } - - public boolean resolved() { - return resolved; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java b/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java index 62bc6acc7..7be7a21ea 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/PlatformTask.java @@ -22,22 +22,11 @@ */ package com.viaversion.viaversion.api.platform; -import org.checkerframework.checker.nullness.qual.Nullable; - /** * @param task type */ public interface PlatformTask { - /** - * Returns the actual object represented by this task/task id. - * Null if task cannot be instantly tracked. - * - * @return platform based object, or null if not tracked/cancellable - */ - @Deprecated/*(forRemoval = true)*/ - @Nullable T getObject(); - /** * Cancels the task. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java index 191b3b292..72f18d6d5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java +++ b/api/src/main/java/com/viaversion/viaversion/api/platform/ViaPlatform.java @@ -181,11 +181,6 @@ public interface ViaPlatform { */ ViaVersionConfig getConf(); - @Deprecated/*(forRemoval = true)*/ - default ConfigurationProvider getConfigurationProvider() { - return Via.getManager().getConfigurationProvider(); - } - /** * Get ViaVersions's data folder. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java index 8b7d929af..41c7dba09 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java @@ -383,7 +383,7 @@ public abstract class AbstractProtocol protocolClass) throws Exception; + void completeMappingDataLoading(Class protocolClass); /** * Shuts down the executor and uncaches mappings if all futures have been completed. diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java index e62eeeb32..379c32680 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ClientboundPacketType.java @@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet; /** * Interface to be implemented by server outgoing packet types. */ -public interface ClientboundPacketType extends PacketType { +public non-sealed interface ClientboundPacketType extends PacketType { @Override default Direction direction() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketTracker.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketTracker.java index e945733a5..6240438c6 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketTracker.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketTracker.java @@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; public class PacketTracker { private final UserConnection connection; + private boolean packetLimiterEnabled = true; private long sentPackets; private long receivedPackets; // Used for tracking pps @@ -162,4 +163,12 @@ public class PacketTracker { public void setWarnings(int warnings) { this.warnings = warnings; } + + public boolean isPacketLimiterEnabled() { + return packetLimiterEnabled; + } + + public void setPacketLimiterEnabled(boolean packetLimiterEnabled) { + this.packetLimiterEnabled = packetLimiterEnabled; + } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketType.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketType.java index 75f4eef02..02536889d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketType.java @@ -28,7 +28,7 @@ package com.viaversion.viaversion.api.protocol.packet; * @see ClientboundPacketType * @see ServerboundPacketType */ -public interface PacketType { +public sealed interface PacketType permits ClientboundPacketType, ServerboundPacketType { /** * Returns the packet id for the implemented protocol. diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketWrapper.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketWrapper.java index 23f02713a..4ca573a0c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketWrapper.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketWrapper.java @@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.InformativeException; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelFuture; @@ -83,7 +84,7 @@ public interface PacketWrapper { * @return The requested type or throws ArrayIndexOutOfBounds * @throws InformativeException If it fails to find it, an exception will be thrown. */ - T get(Type type, int index) throws Exception; + T get(Type type, int index) throws InformativeException; /** * Check if a type is at an index @@ -113,7 +114,7 @@ public interface PacketWrapper { * @param value The value of the part you wish to set it to. * @throws InformativeException If it fails to set it, an exception will be thrown. */ - void set(Type type, int index, T value) throws Exception; + void set(Type type, int index, @Nullable T value) throws InformativeException; /** * Read a type from the input. @@ -123,7 +124,7 @@ public interface PacketWrapper { * @return The requested type * @throws InformativeException If it fails to read */ - T read(Type type) throws Exception; + T read(Type type) throws InformativeException; /** * Write a type to the output. @@ -132,7 +133,7 @@ public interface PacketWrapper { * @param The return type of the type you wish to write. * @param value The value of the type to write. */ - void write(Type type, T value); + void write(Type type, @Nullable T value); /** * Take a value from the input and write to the output. @@ -140,16 +141,16 @@ public interface PacketWrapper { * @param type The type to read and write. * @param The return type of the type you wish to pass through. * @return The type which was read/written. - * @throws Exception If it failed to read or write + * @throws InformativeException If it failed to read or write */ - T passthrough(Type type) throws Exception; + T passthrough(Type type) throws InformativeException; /** * Take all the inputs and write them to the output. * - * @throws Exception If it failed to read or write + * @throws InformativeException If it failed to read or write */ - void passthroughAll() throws Exception; + void passthroughAll() throws InformativeException; /** * Write the current output to a buffer. @@ -157,7 +158,7 @@ public interface PacketWrapper { * @param buffer The buffer to write to. * @throws InformativeException Throws an exception if it fails to write a value. */ - void writeToBuffer(ByteBuf buffer) throws Exception; + void writeToBuffer(ByteBuf buffer) throws InformativeException; /** * Clear the input buffer / readable objects @@ -173,9 +174,9 @@ public interface PacketWrapper { * Send this packet to the connection on the current thread, skipping the current protocol. * * @param protocol protocol to be sent through - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - default void send(Class protocol) throws Exception { + default void send(Class protocol) throws InformativeException { send(protocol, true); } @@ -184,17 +185,17 @@ public interface PacketWrapper { * * @param protocol protocol to be sent through * @param skipCurrentPipeline whether transformation of the current protocol should be skipped - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void send(Class protocol, boolean skipCurrentPipeline) throws Exception; + void send(Class protocol, boolean skipCurrentPipeline) throws InformativeException; /** * Send this packet to the connection, submitted to netty's event loop and skipping the current protocol. * * @param protocol protocol to be sent through - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - default void scheduleSend(Class protocol) throws Exception { + default void scheduleSend(Class protocol) throws InformativeException { scheduleSend(protocol, true); } @@ -203,45 +204,33 @@ public interface PacketWrapper { * * @param protocol protocol to be sent through * @param skipCurrentPipeline whether transformation of the current protocol should be skipped - * @throws Exception if it fails to write */ - void scheduleSend(Class protocol, boolean skipCurrentPipeline) throws Exception; + void scheduleSend(Class protocol, boolean skipCurrentPipeline) throws InformativeException; /** - * Send this packet to the associated user. - * Be careful not to send packets twice. - * (Sends it after current) - * Also returns the packets ChannelFuture + * Sends this packet to the associated user. + * The ChannelFuture fails exceptionally if the packet is cancelled during construction. * * @param protocolClass the protocol class to start from in the pipeline * @return new ChannelFuture for the write operation - * @throws Exception if it fails to write */ - ChannelFuture sendFuture(Class protocolClass) throws Exception; - - /** - * @deprecated misleading; use {@link #sendRaw()}. This method will be removed in 5.0.0 - */ - @Deprecated/*(forRemoval = true)*/ - default void send() throws Exception { - sendRaw(); - } + ChannelFuture sendFuture(Class protocolClass) throws InformativeException; /** * Sends this packet to the connection. * Unlike {@link #send(Class)}, this method does not handle the pipeline with packet id and data changes. * - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void sendRaw() throws Exception; + void sendRaw() throws InformativeException; /** * Sends this packet to the associated user, submitted to netty's event loop. * Unlike {@link #send(Class)}, this method does not handle the pipeline with packet id and data changes. * - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void scheduleSendRaw() throws Exception; + void scheduleSendRaw() throws InformativeException; /** * Creates a new packet for the target of this packet. @@ -259,9 +248,8 @@ public interface PacketWrapper { * @param packetType packet type of the new packet * @param handler handler to write to the packet * @return newly created packet wrapper - * @throws Exception if it failed to write the values from the ValueCreator */ - default PacketWrapper create(PacketType packetType, PacketHandler handler) throws Exception { + default PacketWrapper create(PacketType packetType, PacketHandler handler) throws InformativeException { return create(packetType.getId(), handler); } @@ -279,9 +267,8 @@ public interface PacketWrapper { * @param packetId id of the packet * @param handler handler to write to the packet * @return newly created packet wrapper - * @throws Exception if it failed to write the values from the ValueCreator */ - PacketWrapper create(int packetId, PacketHandler handler) throws Exception; + PacketWrapper create(int packetId, PacketHandler handler) throws InformativeException; /** * Applies a pipeline from an index to the wrapper. @@ -289,23 +276,8 @@ public interface PacketWrapper { * @param direction protocol direction * @param state protocol state * @param pipeline protocol pipeline - * @throws Exception If it fails to transform a packet, exception will be thrown */ - void apply(Direction direction, State state, List pipeline) throws Exception; - - /** - * @deprecated use {@link #apply(Direction, State, List)} - */ - @Deprecated - PacketWrapper apply(Direction direction, State state, int index, List pipeline, boolean reverse) throws Exception; - - /** - * @deprecated use {@link #apply(Direction, State, List)} - */ - @Deprecated - default PacketWrapper apply(Direction direction, State state, int index, List pipeline) throws Exception { - return apply(direction, state, index, pipeline, false); - } + void apply(Direction direction, State state, List pipeline) throws InformativeException, CancelException; /** * Check if this packet is cancelled. @@ -340,41 +312,29 @@ public interface PacketWrapper { */ void resetReader(); - /** - * Send the current packet to the server. - * (Ensure the ID is suitable for viaversion) - * - * @throws Exception If it failed to write - * @deprecated misleading; use {@link #sendToServerRaw()}. This method will be removed in 5.0.0 - */ - @Deprecated/*(forRemoval = true)*/ - default void sendToServer() throws Exception { - sendToServerRaw(); - } - /** * Sends this packet to the server. * Unlike {@link #sendToServer(Class)}, this method does not handle the pipeline with packet id and data changes. * - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void sendToServerRaw() throws Exception; + void sendToServerRaw() throws InformativeException; /** * Sends this packet to the server, submitted to netty's event loop. * Unlike {@link #sendToServer(Class)}, this method does not handle the pipeline with packet id and data changes. * - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void scheduleSendToServerRaw() throws Exception; + void scheduleSendToServerRaw() throws InformativeException; /** * Send this packet to the server on the current thread, skipping the current protocol. * * @param protocol protocol to be sent through - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - default void sendToServer(Class protocol) throws Exception { + default void sendToServer(Class protocol) throws InformativeException { sendToServer(protocol, true); } @@ -383,17 +343,17 @@ public interface PacketWrapper { * * @param protocol protocol to be sent through * @param skipCurrentPipeline whether transformation of the current protocol should be skipped - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void sendToServer(Class protocol, boolean skipCurrentPipeline) throws Exception; + void sendToServer(Class protocol, boolean skipCurrentPipeline) throws InformativeException; /** * Send this packet to the server, submitted to netty's event loop and skipping the current protocol. * * @param protocol protocol to be sent through - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - default void scheduleSendToServer(Class protocol) throws Exception { + default void scheduleSendToServer(Class protocol) throws InformativeException { scheduleSendToServer(protocol, true); } @@ -402,13 +362,12 @@ public interface PacketWrapper { * * @param protocol protocol to be sent through * @param skipCurrentPipeline whether transformation of the current protocol should be skipped - * @throws Exception if it fails to write + * @throws InformativeException if it fails to write */ - void scheduleSendToServer(Class protocol, boolean skipCurrentPipeline) throws Exception; + void scheduleSendToServer(Class protocol, boolean skipCurrentPipeline) throws InformativeException; /** - * Returns the packet type. - * Currently only non-null for manually constructed packets before transformation. + * Returns the packet type, or null if not transformed or manually unset. * * @return packet type if set */ @@ -429,17 +388,6 @@ public interface PacketWrapper { */ int getId(); - /** - * Sets the packet type. - * - * @param packetType packet type - * @deprecated use {@link #setPacketType(PacketType)}. This method will be removed in 5.0.0 - */ - @Deprecated/*(forRemoval = true)*/ - default void setId(PacketType packetType) { - setPacketType(packetType); - } - /** * Sets the packet id. If set to -1, it will not be written to the buffer with {@link #writeToBuffer(ByteBuf)}. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java index 1d331d3d1..efd22fb18 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/ServerboundPacketType.java @@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet; /** * Interface to be implemented by server incoming packet types. */ -public interface ServerboundPacketType extends PacketType { +public non-sealed interface ServerboundPacketType extends PacketType { @Override default Direction direction() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/VersionedPacketTransformer.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/VersionedPacketTransformer.java index ef7d59e91..799db3720 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/VersionedPacketTransformer.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/VersionedPacketTransformer.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.protocol.packet; import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.exception.InformativeException; import java.util.function.Consumer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -43,19 +44,19 @@ public interface VersionedPacketTransformer packetWriter) throws Exception; + boolean send(UserConnection connection, C packetType, Consumer packetWriter) throws InformativeException; /** * @see #send(PacketWrapper) */ - boolean send(UserConnection connection, S packetType, Consumer packetWriter) throws Exception; + boolean send(UserConnection connection, S packetType, Consumer packetWriter) throws InformativeException; /** * Sends a packet to the user or server, depending on the packet type given by {@link PacketWrapper#getPacketType()}, submitted to the netty event loop. @@ -66,19 +67,19 @@ public interface VersionedPacketTransformer packetWriter) throws Exception; + boolean scheduleSend(UserConnection connection, C packetType, Consumer packetWriter) throws InformativeException; /** * @see #scheduleSend(PacketWrapper) */ - boolean scheduleSend(UserConnection connection, S packetType, Consumer packetWriter) throws Exception; + boolean scheduleSend(UserConnection connection, S packetType, Consumer packetWriter) throws InformativeException; /** * Transforms a packet to the protocol version of the given connection or server, or null if cancelled at some point. @@ -89,17 +90,17 @@ public interface VersionedPacketTransformer packetWriter) throws Exception; + @Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer packetWriter) throws InformativeException; /** * @see #transform(PacketWrapper) */ - @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer packetWriter) throws Exception; + @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer packetWriter) throws InformativeException; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/SimplePacketTypesProvider.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/SimplePacketTypesProvider.java index 646bdb08f..e7b18eba9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/SimplePacketTypesProvider.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/provider/SimplePacketTypesProvider.java @@ -27,41 +27,10 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import com.viaversion.viaversion.api.protocol.packet.State; import java.util.Map; -public final class SimplePacketTypesProvider implements PacketTypesProvider { - private final Map> unmappedClientboundPacketTypes; - private final Map> mappedClientboundPacketTypes; - private final Map> mappedServerboundPacketTypes; - private final Map> unmappedServerboundPacketTypes; - - public SimplePacketTypesProvider( - Map> unmappedClientboundPacketTypes, - Map> mappedClientboundPacketTypes, - Map> mappedServerboundPacketTypes, - Map> unmappedServerboundPacketTypes - ) { - this.unmappedClientboundPacketTypes = unmappedClientboundPacketTypes; - this.mappedClientboundPacketTypes = mappedClientboundPacketTypes; - this.mappedServerboundPacketTypes = mappedServerboundPacketTypes; - this.unmappedServerboundPacketTypes = unmappedServerboundPacketTypes; - } - - @Override - public Map> unmappedClientboundPacketTypes() { - return unmappedClientboundPacketTypes; - } - - @Override - public Map> mappedClientboundPacketTypes() { - return mappedClientboundPacketTypes; - } - - @Override - public Map> mappedServerboundPacketTypes() { - return mappedServerboundPacketTypes; - } - - @Override - public Map> unmappedServerboundPacketTypes() { - return unmappedServerboundPacketTypes; - } +public record SimplePacketTypesProvider( + Map> unmappedClientboundPacketTypes, + Map> mappedClientboundPacketTypes, + Map> mappedServerboundPacketTypes, + Map> unmappedServerboundPacketTypes +) implements PacketTypesProvider { } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java index 59c1cc514..582360636 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandler.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.protocol.remapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.exception.InformativeException; @FunctionalInterface public interface PacketHandler { @@ -31,9 +32,8 @@ public interface PacketHandler { * Handles a packet. * * @param wrapper packet wrapper - * @throws Exception if an error occurs during the packet handling */ - void handle(PacketWrapper wrapper) throws Exception; + void handle(PacketWrapper wrapper) throws InformativeException; /** * Returns a new packet handler that runs the provided handler after this one. diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandlers.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandlers.java index f43f17800..3acd2685a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandlers.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketHandlers.java @@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.protocol.remapper; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.exception.InformativeException; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @@ -76,7 +77,7 @@ public abstract class PacketHandlers implements PacketHandler { * @param transformer transformer to produce the new type */ public void map(Type oldType, Type newType, Function transformer) { - map(oldType, new ValueTransformer(newType) { + map(oldType, new ValueTransformer<>(newType) { @Override public T2 transform(PacketWrapper wrapper, T1 inputValue) { return transformer.apply(inputValue); @@ -173,7 +174,7 @@ public abstract class PacketHandlers implements PacketHandler { protected abstract void register(); @Override - public final void handle(PacketWrapper wrapper) throws Exception { + public final void handle(PacketWrapper wrapper) throws InformativeException { for (PacketHandler handler : packetHandlers) { handler.handle(wrapper); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketRemapper.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketRemapper.java deleted file mode 100644 index d6c21c4b4..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/PacketRemapper.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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.protocol.remapper; - -import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.exception.CancelException; -import com.viaversion.viaversion.exception.InformativeException; -import java.util.ArrayList; -import java.util.List; -import java.util.function.Function; - -/** - * @deprecated use {@link PacketHandlers} or directly implement {@link PacketHandler} - */ -@Deprecated/*(forRemoval = true)*/ -public abstract class PacketRemapper { - private final List valueRemappers = new ArrayList<>(); - - protected PacketRemapper() { - registerMap(); - } - - /** - * Reads and writes the given type. - * - * @param type type to map - */ - public void map(Type type) { - handler(wrapper -> wrapper.write(type, wrapper.read(type))); - } - - /** - * Reads the first given type and writes the second given type. - * - * @param oldType old type - * @param newType new type - */ - public void map(Type oldType, Type newType) { - handler(wrapper -> wrapper.write(newType, wrapper.read(oldType))); - } - - /** - * Maps a type from an old type to a transformed new type. - * - * @param old value type - * @param new value type - * @param oldType old type - * @param newType new type - * @param transformer transformer to produce the new type - */ - public void map(Type oldType, Type newType, Function transformer) { - map(oldType, new ValueTransformer(newType) { - @Override - public T2 transform(PacketWrapper wrapper, T1 inputValue) throws Exception { - return transformer.apply(inputValue); - } - }); - } - - /** - * Maps a type from an old type to a transformed new type based on their input type. - * - * @param old value type - * @param new value type - * @param transformer transformer to produce the new type - */ - public void map(ValueTransformer transformer) { - if (transformer.getInputType() == null) { - throw new IllegalArgumentException("Use map(Type, ValueTransformer) for value transformers without specified input type!"); - } - map(transformer.getInputType(), transformer); - } - - /** - * Maps a type from an old type to a transformed new type. - * - * @param old value type - * @param new value type - * @param oldType old type - * @param transformer transformer to produce the new type - */ - public void map(Type oldType, ValueTransformer transformer) { - map(new TypeRemapper<>(oldType), transformer); - } - - /** - * Maps a type using a basic ValueReader to a ValueWriter. - * - * @param inputReader reader to read with - * @param outputWriter writer to write with - * @param read/write type - */ - public void map(ValueReader inputReader, ValueWriter outputWriter) { - handler(wrapper -> outputWriter.write(wrapper, inputReader.read(wrapper))); - } - - /** - * Adds a packet handler. - * - * @param handler packet handler - */ - public void handler(PacketHandler handler) { - valueRemappers.add(handler); - } - - /** - * Writes a value. - * - * @param type type to write - * @param value value to write - */ - public void create(Type type, T value) { - handler(wrapper -> wrapper.write(type, value)); - } - - /** - * Reads (and thus removes) the given type. - * - * @param type type to read - */ - public void read(Type type) { - handler(wrapper -> wrapper.read(type)); - } - - /** - * Registers the handlers for this packet. - */ - public abstract void registerMap(); - - public PacketHandler asPacketHandler() { - return PacketHandlers.fromRemapper(this.valueRemappers); - } - - /** - * Processes a packet wrapper. - * - * @param packetWrapper packet wrapper to remap - * @throws InformativeException if packet reading or writing fails - * @throws CancelException if the packet should be cancelled - */ - @Deprecated - public void remap(PacketWrapper packetWrapper) throws Exception { - try { - for (PacketHandler handler : valueRemappers) { - handler.handle(packetWrapper); - } - } catch (CancelException e) { - // Pass through CancelExceptions - throw e; - } catch (InformativeException e) { - e.addSource(this.getClass()); - throw e; - } catch (Exception e) { - // Wrap other exceptions during packet handling - InformativeException ex = new InformativeException(e); - ex.addSource(this.getClass()); - throw ex; - } - } -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/TypeRemapper.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/TypeRemapper.java index 5e568d48e..0d43bfab3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/TypeRemapper.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/TypeRemapper.java @@ -24,21 +24,17 @@ package com.viaversion.viaversion.api.protocol.remapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.exception.InformativeException; -public class TypeRemapper implements ValueReader, ValueWriter { - private final Type type; - - public TypeRemapper(Type type) { - this.type = type; - } +public record TypeRemapper(Type type) implements ValueReader, ValueWriter { @Override - public T read(PacketWrapper wrapper) throws Exception { + public T read(PacketWrapper wrapper) throws InformativeException { return wrapper.read(type); } @Override - public void write(PacketWrapper output, T inputValue) { + public void write(PacketWrapper output, T inputValue) throws InformativeException { output.write(type, inputValue); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueReader.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueReader.java index e39d7cc8a..92d79ce90 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueReader.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueReader.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.protocol.remapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.exception.InformativeException; @FunctionalInterface public interface ValueReader { @@ -32,7 +33,6 @@ public interface ValueReader { * * @param wrapper The wrapper to read from * @return Returns the desired type - * @throws Exception Throws exception if it fails to read */ - T read(PacketWrapper wrapper) throws Exception; + T read(PacketWrapper wrapper) throws InformativeException; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueTransformer.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueTransformer.java index 575ee424f..c8b73ccf0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueTransformer.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueTransformer.java @@ -46,12 +46,11 @@ public abstract class ValueTransformer implements ValueWriter { * @param wrapper The current packet * @param inputValue The input value * @return The value to write to the wrapper - * @throws Exception Throws exception if it fails to transform a value */ - public abstract T2 transform(PacketWrapper wrapper, T1 inputValue) throws Exception; + public abstract T2 transform(PacketWrapper wrapper, T1 inputValue) throws InformativeException; @Override - public void write(PacketWrapper writer, T1 inputValue) throws Exception { + public void write(PacketWrapper writer, T1 inputValue) throws InformativeException { try { writer.write(outputType, transform(writer, inputValue)); } catch (InformativeException e) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueWriter.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueWriter.java index 186456eb4..476df1d58 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueWriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/remapper/ValueWriter.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.protocol.remapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.exception.InformativeException; @FunctionalInterface public interface ValueWriter { @@ -32,7 +33,6 @@ public interface ValueWriter { * * @param wrapper The packet wrapper to write to * @param inputValue The value to write - * @throws Exception Throws exception if it fails to write */ - void write(PacketWrapper wrapper, T inputValue) throws Exception; + void write(PacketWrapper wrapper, T inputValue) throws InformativeException; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java index 00e1c67b7..58f78d5e4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java @@ -43,7 +43,7 @@ public class ProtocolVersion implements Comparable { private static final List VERSION_LIST = new ArrayList<>(); public static final ProtocolVersion v1_7_2 = register(4, "1.7.2-1.7.5", new SubVersionRange("1.7", 2, 5)); - @Deprecated/*(forRemoval=true)*/ public static final ProtocolVersion v1_7_1 = v1_7_2; + @Deprecated(forRemoval=true) public static final ProtocolVersion v1_7_1 = v1_7_2; public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10", new SubVersionRange("1.7", 6, 10)); public static final ProtocolVersion v1_8 = register(47, "1.8.x", new SubVersionRange("1.8", 0, 9)); public static final ProtocolVersion v1_9 = register(107, "1.9"); @@ -163,7 +163,7 @@ public class ProtocolVersion implements Comparable { * @return internal index of the stored protocol version * @deprecated comparison should be done via the comparison methods */ - @Deprecated/*(forRemoval = true)*/ + @Deprecated(forRemoval = true) public static int getIndex(ProtocolVersion version) { return VERSION_LIST.indexOf(version); } @@ -201,20 +201,6 @@ public class ProtocolVersion implements Comparable { private final String name; private final Set includedVersions; - /** - * @param version protocol version - * @param name version name - */ - @Deprecated/*(forRemoval = true)*/ - public ProtocolVersion(int version, String name) { - this(version, -1, name, null); - } - - @Deprecated/*(forRemoval = true)*/ - public ProtocolVersion(int version, int snapshotVersion, String name, @Nullable SubVersionRange versionRange) { - this(VersionType.RELEASE, version, snapshotVersion, name, versionRange); - } - /** * Constructs a new ProtocolVersion instance. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/SubVersionRange.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/SubVersionRange.java index 26c72bbc8..8628eefcb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/SubVersionRange.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/SubVersionRange.java @@ -24,10 +24,7 @@ package com.viaversion.viaversion.api.protocol.version; import com.google.common.base.Preconditions; -public class SubVersionRange { - private final String baseVersion; - private final int rangeFrom; - private final int rangeTo; +public record SubVersionRange(String baseVersion, int rangeFrom, int rangeTo) { /** * Creates a new version range. Giving "1.7", 0, and 5 for example would represent the range from 1.7-1.7.5. @@ -36,13 +33,10 @@ public class SubVersionRange { * @param rangeFrom minor version the range begins at, must be greater than or equal to 0 * @param rangeTo minor version the range ends at, must be greater than {@code rangeFrom} */ - public SubVersionRange(String baseVersion, int rangeFrom, int rangeTo) { + public SubVersionRange { Preconditions.checkNotNull(baseVersion); Preconditions.checkArgument(rangeFrom >= 0); Preconditions.checkArgument(rangeTo > rangeFrom); - this.baseVersion = baseVersion; - this.rangeFrom = rangeFrom; - this.rangeTo = rangeTo; } /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java index 764205ca9..bdaaf95fd 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java @@ -29,7 +29,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.Protocol; import java.util.List; -public interface EntityRewriter extends Rewriter { +public interface EntityRewriter> extends Rewriter { /** * Returns the entity type from the given (mapped) type id. diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java index 3bfcd0709..b0dcaa7df 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java @@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.type.Type; import org.checkerframework.checker.nullness.qual.Nullable; -public interface ItemRewriter extends Rewriter { +public interface ItemRewriter> extends Rewriter { /** * Returns the rewritten item, which may or may not be the same given Item instance. diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/Rewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/Rewriter.java index c26e1552d..266d37d01 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/Rewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/Rewriter.java @@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.rewriter; import com.viaversion.viaversion.api.protocol.Protocol; -public interface Rewriter extends MappingDataListener { +public interface Rewriter> extends MappingDataListener { /** * Registers any packet handlers or rewrites needed. diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/RewriterBase.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/RewriterBase.java index e649c7b40..fa3fec8fb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/RewriterBase.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/RewriterBase.java @@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.rewriter; import com.viaversion.viaversion.api.protocol.Protocol; -public abstract class RewriterBase implements Rewriter { +public abstract class RewriterBase> implements Rewriter { protected final T protocol; protected RewriterBase(final T protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufReader.java b/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufReader.java index 7e84e14b7..f952945f7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufReader.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufReader.java @@ -32,7 +32,6 @@ public interface ByteBufReader { * * @param buffer buffer to read from * @return type based on the class type - * @throws Exception if it failed reading */ - T read(ByteBuf buffer) throws Exception; + T read(ByteBuf buffer); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufWriter.java b/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufWriter.java index 2facef19c..5eb9aab70 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufWriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/ByteBufWriter.java @@ -32,7 +32,6 @@ public interface ByteBufWriter { * * @param buffer buffer to write to * @param value value to write - * @throws Exception if it failed to write */ - void write(ByteBuf buffer, T value) throws Exception; + void write(ByteBuf buffer, T value); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/OptionalType.java b/api/src/main/java/com/viaversion/viaversion/api/type/OptionalType.java index 2da3c2f05..22ad59123 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/OptionalType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/OptionalType.java @@ -34,12 +34,12 @@ public abstract class OptionalType extends Type { } @Override - public @Nullable T read(ByteBuf buffer) throws Exception { + public @Nullable T read(ByteBuf buffer) { return buffer.readBoolean() ? type.read(buffer) : null; } @Override - public void write(final ByteBuf buffer, @Nullable final T value) throws Exception { + public void write(final ByteBuf buffer, @Nullable final T value) { if (value == null) { buffer.writeBoolean(false); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/PartialType.java b/api/src/main/java/com/viaversion/viaversion/api/type/PartialType.java deleted file mode 100644 index e1f50ef3a..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/type/PartialType.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.type; - -import io.netty.buffer.ByteBuf; - -@Deprecated -public abstract class PartialType extends Type { - private final X param; - - protected PartialType(X param, Class type) { - super(type); - this.param = param; - } - - protected PartialType(X param, String name, Class type) { - super(name, type); - this.param = param; - } - - public abstract T read(ByteBuf buffer, X param) throws Exception; - - public abstract void write(ByteBuf buffer, X param, T object) throws Exception; - - @Override - public final T read(ByteBuf buffer) throws Exception { - return read(buffer, this.param); - } - - @Override - public final void write(ByteBuf buffer, T object) throws Exception { - write(buffer, this.param, object); - } -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 1c652921c..78a751e99 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -165,10 +165,6 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type TAG = new TagType(); public static final Type TAG_ARRAY = new ArrayType<>(TAG); public static final Type OPTIONAL_TAG = new TagType.OptionalTagType(); - @Deprecated/*(forRemoval=true)*/ - public static final Type NBT = NAMED_COMPOUND_TAG; - @Deprecated/*(forRemoval=true)*/ - public static final Type NBT_ARRAY = NAMED_COMPOUND_TAG_ARRAY; public static final Type GLOBAL_POSITION = new GlobalPositionType(); public static final Type OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType(); @@ -215,22 +211,6 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13); public static final Type ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2); public static final Type ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2); - @Deprecated/*(forRemoval=true)*/ - public static final Type ITEM = ITEM1_8; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_ITEM = ITEM1_13; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_VAR_INT_ITEM = ITEM1_13_2; - @Deprecated/*(forRemoval=true)*/ - public static final Type ITEM_ARRAY = ITEM1_8_SHORT_ARRAY; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_ITEM_ARRAY = ITEM1_13_SHORT_ARRAY; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_VAR_INT_ITEM_ARRAY = ITEM1_13_2_SHORT_ARRAY; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_ITEM_ARRAY_VAR_INT = ITEM1_13_ARRAY; - @Deprecated/*(forRemoval=true)*/ - public static final Type FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = ITEM1_13_2_ARRAY; /* Actual Class */ private final Class outputClass; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ArrayType.java index 73e1dd0e0..15ea76d77 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ArrayType.java @@ -40,7 +40,7 @@ public class ArrayType extends Type { } @Override - public T[] read(ByteBuf buffer) throws Exception { + public T[] read(ByteBuf buffer) { int amount = Type.VAR_INT.readPrimitive(buffer); T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount); @@ -51,7 +51,7 @@ public class ArrayType extends Type { } @Override - public void write(ByteBuf buffer, T[] object) throws Exception { + public void write(ByteBuf buffer, T[] object) { Type.VAR_INT.writePrimitive(buffer, object.length); for (T o : object) { elementType.write(buffer, o); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java index 61434d492..a89ad2476 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanType.java @@ -45,8 +45,8 @@ public class BooleanType extends Type implements TypeConverter @Override public Boolean from(Object o) { - if (o instanceof Number) { - return ((Number) o).intValue() == 1; + if (o instanceof Number number) { + return number.intValue() == 1; } return (Boolean) o; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteArrayType.java index 190709ea0..07d318997 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteArrayType.java @@ -42,7 +42,7 @@ public class ByteArrayType extends Type { } @Override - public void write(final ByteBuf buffer, final byte[] object) throws Exception { + public void write(final ByteBuf buffer, final byte[] object) { if (this.length != -1) { Preconditions.checkArgument(length == object.length, "Length does not match expected length"); } else { @@ -52,7 +52,7 @@ public class ByteArrayType extends Type { } @Override - public byte[] read(final ByteBuf buffer) throws Exception { + public byte[] read(final ByteBuf buffer) { final int length = this.length == -1 ? Type.VAR_INT.readPrimitive(buffer) : this.length; Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); final byte[] array = new byte[length]; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java index e555d4e5e..da67480be 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ByteType.java @@ -53,11 +53,11 @@ public class ByteType extends Type implements TypeConverter { @Override public Byte from(Object o) { - if (o instanceof Number) { - return ((Number) o).byteValue(); - } else if (o instanceof Boolean) { - return (Boolean) o ? (byte) 1 : 0; + if (o instanceof Number number) { + return number.byteValue(); + } else if (o instanceof Boolean boo) { + return boo ? (byte) 1 : 0; } - return (Byte) o; + throw new UnsupportedOperationException(); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ComponentType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ComponentType.java index 79be960ab..c9fdc665f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ComponentType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ComponentType.java @@ -38,7 +38,7 @@ public class ComponentType extends Type { } @Override - public JsonElement read(ByteBuf buffer) throws Exception { + public JsonElement read(ByteBuf buffer) { String s = STRING_TAG.read(buffer); try { return JsonParser.parseString(s); @@ -49,7 +49,7 @@ public class ComponentType extends Type { } @Override - public void write(ByteBuf buffer, JsonElement object) throws Exception { + public void write(ByteBuf buffer, JsonElement object) { STRING_TAG.write(buffer, object.toString()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java index 6a52e6429..3aac4fa55 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/DoubleType.java @@ -60,11 +60,11 @@ public class DoubleType extends Type implements TypeConverter { @Override public Double from(Object o) { - if (o instanceof Number) { - return ((Number) o).doubleValue(); - } else if (o instanceof Boolean) { - return (Boolean) o ? (byte) 1D : 0D; + if (o instanceof Number number) { + return number.doubleValue(); + } else if (o instanceof Boolean boo) { + return boo ? (byte) 1D : 0D; } - return (Double) o; + throw new UnsupportedOperationException(); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/EmptyType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/EmptyType.java index a54b4a71d..1b4851178 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/EmptyType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/EmptyType.java @@ -33,11 +33,11 @@ public final class EmptyType extends Type { } @Override - public Unit read(final ByteBuf buffer) throws Exception { + public Unit read(final ByteBuf buffer) { return Unit.INSTANCE; } @Override - public void write(final ByteBuf buffer, final Unit value) throws Exception { + public void write(final ByteBuf buffer, final Unit value) { } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/FixedByteArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/FixedByteArrayType.java index f42ef1cad..65b362f48 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/FixedByteArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/FixedByteArrayType.java @@ -35,7 +35,7 @@ public class FixedByteArrayType extends Type { } @Override - public byte[] read(final ByteBuf byteBuf) throws Exception { + public byte[] read(final ByteBuf byteBuf) { if (byteBuf.readableBytes() < this.arrayLength) { throw new RuntimeException("Readable bytes does not match expected!"); } @@ -46,7 +46,7 @@ public class FixedByteArrayType extends Type { } @Override - public void write(final ByteBuf byteBuf, final byte[] bytes) throws Exception { + public void write(final ByteBuf byteBuf, final byte[] bytes) { byteBuf.writeBytes(bytes); } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java index f42b49c96..87569de0f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatType.java @@ -61,12 +61,12 @@ public class FloatType extends Type implements TypeConverter { @Override public Float from(Object o) { - if (o instanceof Number) { - return ((Number) o).floatValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? 1F : 0; + if (o instanceof Number number) { + return number.floatValue(); + } else if (o instanceof Boolean boo) { + return boo ? 1F : 0; } - return (Float) o; + throw new UnsupportedOperationException(); } public static final class OptionalFloatType extends OptionalType { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntArrayType.java index bc6d4adff..b44ec5a71 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntArrayType.java @@ -42,7 +42,7 @@ public class IntArrayType extends Type { } @Override - public void write(final ByteBuf buffer, final int[] object) throws Exception { + public void write(final ByteBuf buffer, final int[] object) { if (this.length != -1) { Preconditions.checkArgument(length == object.length, "Length does not match expected length"); } else { @@ -54,7 +54,7 @@ public class IntArrayType extends Type { } @Override - public int[] read(final ByteBuf buffer) throws Exception { + public int[] read(final ByteBuf buffer) { final int length = this.length == -1 ? Type.VAR_INT.readPrimitive(buffer) : this.length; Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); final int[] array = new int[length]; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java index 8c5884c10..fb6bcacbb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/IntType.java @@ -43,11 +43,11 @@ public class IntType extends Type implements TypeConverter { @Override public Integer from(Object o) { - if (o instanceof Number) { - return ((Number) o).intValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? 1 : 0; + if (o instanceof Number number) { + return number.intValue(); + } else if (o instanceof Boolean boo) { + return boo ? 1 : 0; } - return (Integer) o; + throw new UnsupportedOperationException(); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongArrayType.java index 333a7b4bc..16f687876 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongArrayType.java @@ -32,7 +32,7 @@ public class LongArrayType extends Type { } @Override - public long[] read(ByteBuf buffer) throws Exception { + public long[] read(ByteBuf buffer) { int length = Type.VAR_INT.readPrimitive(buffer); long[] array = new long[length]; for (int i = 0; i < array.length; i++) { @@ -42,7 +42,7 @@ public class LongArrayType extends Type { } @Override - public void write(ByteBuf buffer, long[] object) throws Exception { + public void write(ByteBuf buffer, long[] object) { Type.VAR_INT.writePrimitive(buffer, object.length); for (long l : object) { buffer.writeLong(l); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java index f42d58251..c0589db0c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/LongType.java @@ -52,12 +52,12 @@ public class LongType extends Type implements TypeConverter { @Override public Long from(Object o) { - if (o instanceof Number) { - return ((Number) o).longValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? 1L : 0; + if (o instanceof Number number) { + return number.longValue(); + } else if (o instanceof Boolean boo) { + return boo ? 1L : 0; } - return (Long) o; + throw new UnsupportedOperationException(); } public long readPrimitive(ByteBuf buffer) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/OptionalVarIntType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/OptionalVarIntType.java index 78605a496..5ba5be5b1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/OptionalVarIntType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/OptionalVarIntType.java @@ -32,13 +32,13 @@ public class OptionalVarIntType extends Type { } @Override - public Integer read(final ByteBuf buffer) throws Exception { + public Integer read(final ByteBuf buffer) { final int value = Type.VAR_INT.readPrimitive(buffer); return value == 0 ? null : value - 1; } @Override - public void write(final ByteBuf buffer, final Integer object) throws Exception { + public void write(final ByteBuf buffer, final Integer object) { if (object == null) { Type.VAR_INT.writePrimitive(buffer, 0); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/RegistryEntryType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/RegistryEntryType.java index 5c6aa46bc..899ce0f2b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/RegistryEntryType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/RegistryEntryType.java @@ -33,12 +33,12 @@ public class RegistryEntryType extends Type { } @Override - public RegistryEntry read(final ByteBuf buffer) throws Exception { + public RegistryEntry read(final ByteBuf buffer) { return new RegistryEntry(Type.STRING.read(buffer), Type.OPTIONAL_TAG.read(buffer)); } @Override - public void write(final ByteBuf buffer, final RegistryEntry entry) throws Exception { + public void write(final ByteBuf buffer, final RegistryEntry entry) { Type.STRING.write(buffer, entry.key()); Type.OPTIONAL_TAG.write(buffer, entry.tag()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortByteArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortByteArrayType.java index 3468aabfc..1cde4def9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortByteArrayType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortByteArrayType.java @@ -34,13 +34,13 @@ public class ShortByteArrayType extends Type { } @Override - public void write(ByteBuf buffer, byte[] object) throws Exception { + public void write(ByteBuf buffer, byte[] object) { buffer.writeShort(object.length); buffer.writeBytes(object); } @Override - public byte[] read(ByteBuf buffer) throws Exception { + public byte[] read(ByteBuf buffer) { byte[] array = new byte[buffer.readShort()]; buffer.readBytes(array); return array; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java index bb6c10faa..e950e1fc0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/ShortType.java @@ -60,11 +60,11 @@ public class ShortType extends Type implements TypeConverter { @Override public Short from(Object o) { - if (o instanceof Number) { - return ((Number) o).shortValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? (short) 1 : 0; + if (o instanceof Number number) { + return number.shortValue(); + } else if (o instanceof Boolean boo) { + return boo ? (short) 1 : 0; } - return (Short) o; + throw new UnsupportedOperationException(); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/StringType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/StringType.java index b1c804fbf..e3cb5e735 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/StringType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/StringType.java @@ -44,7 +44,7 @@ public class StringType extends Type { } @Override - public String read(ByteBuf buffer) throws Exception { + public String read(ByteBuf buffer) { int len = Type.VAR_INT.readPrimitive(buffer); Preconditions.checkArgument(len <= maxLength * MAX_CHAR_UTF_8_LENGTH, @@ -60,7 +60,7 @@ public class StringType extends Type { } @Override - public void write(ByteBuf buffer, String object) throws Exception { + public void write(ByteBuf buffer, String object) { if (object.length() > maxLength) { throw new IllegalArgumentException("Cannot send string longer than Short.MAX_VALUE characters (got " + object.length() + " characters)"); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java index bf3e9fb8e..cecc60ead 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/UnsignedByteType.java @@ -43,11 +43,11 @@ public class UnsignedByteType extends Type implements TypeConverter implements TypeConverter { } @Override - public int[] read(ByteBuf buffer) throws Exception { + public int[] read(ByteBuf buffer) { int length = Type.VAR_INT.readPrimitive(buffer); Preconditions.checkArgument(buffer.isReadable(length)); // Sanity check, at least 1 byte will be used for each varint int[] array = new int[length]; @@ -43,7 +43,7 @@ public class VarIntArrayType extends Type { } @Override - public void write(ByteBuf buffer, int[] object) throws Exception { + public void write(ByteBuf buffer, int[] object) { Type.VAR_INT.writePrimitive(buffer, object.length); for (int i : object) { Type.VAR_INT.writePrimitive(buffer, i); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarIntType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarIntType.java index 243cc021a..1c5820edb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarIntType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarIntType.java @@ -81,11 +81,11 @@ public class VarIntType extends Type implements TypeConverter @Override public Integer from(Object o) { - if (o instanceof Number) { - return ((Number) o).intValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? 1 : 0; + if (o instanceof Number number) { + return number.intValue(); + } else if (o instanceof Boolean boo) { + return boo ? 1 : 0; } - return (Integer) o; + throw new UnsupportedOperationException(); } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java index 5d359347d..c3b2a8ef9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/VarLongType.java @@ -82,11 +82,11 @@ public class VarLongType extends Type implements TypeConverter { @Override public Long from(Object o) { - if (o instanceof Number) { - return ((Number) o).longValue(); - } else if (o instanceof Boolean) { - return ((Boolean) o) ? 1L : 0L; + if (o instanceof Number number) { + return number.longValue(); + } else if (o instanceof Boolean boo) { + return boo ? 1L : 0L; } - return (Long) o; + throw new UnsupportedOperationException(); } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/VoidType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/VoidType.java deleted file mode 100644 index 9012543ca..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/VoidType.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.type.types; - -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.TypeConverter; -import io.netty.buffer.ByteBuf; - -@Deprecated -public class VoidType extends Type implements TypeConverter { - public VoidType() { - super(Void.class); - } - - @Override - public Void read(ByteBuf buffer) { - return null; - } - - @Override - public void write(ByteBuf buffer, Void object) { - - } - - @Override - public Void from(Object o) { - return null; - } -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockChangeRecordType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockChangeRecordType.java index d759c1795..8024b572e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockChangeRecordType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockChangeRecordType.java @@ -34,14 +34,14 @@ public class BlockChangeRecordType extends Type { } @Override - public BlockChangeRecord read(ByteBuf buffer) throws Exception { + public BlockChangeRecord read(ByteBuf buffer) { short position = Type.SHORT.readPrimitive(buffer); int blockId = Type.VAR_INT.readPrimitive(buffer); return new BlockChangeRecord1_8(position >> 12 & 0xF, position & 0xFF, position >> 8 & 0xF, blockId); } @Override - public void write(ByteBuf buffer, BlockChangeRecord object) throws Exception { + public void write(ByteBuf buffer, BlockChangeRecord object) { Type.SHORT.writePrimitive(buffer, (short) (object.getSectionX() << 12 | object.getSectionZ() << 8 | object.getY())); Type.VAR_INT.writePrimitive(buffer, object.getBlockId()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_18.java index 6ff055269..e2e45580c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_18.java @@ -35,7 +35,7 @@ public class BlockEntityType1_18 extends Type { } @Override - public BlockEntity read(final ByteBuf buffer) throws Exception { + public BlockEntity read(final ByteBuf buffer) { final byte xz = buffer.readByte(); final short y = buffer.readShort(); final int typeId = Type.VAR_INT.readPrimitive(buffer); @@ -44,7 +44,7 @@ public class BlockEntityType1_18 extends Type { } @Override - public void write(final ByteBuf buffer, final BlockEntity entity) throws Exception { + public void write(final ByteBuf buffer, final BlockEntity entity) { buffer.writeByte(entity.packedXZ()); buffer.writeShort(entity.y()); Type.VAR_INT.writePrimitive(buffer, entity.typeId()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_20_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_20_2.java index 764259369..46dec7d89 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_20_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/BlockEntityType1_20_2.java @@ -35,7 +35,7 @@ public class BlockEntityType1_20_2 extends Type { } @Override - public BlockEntity read(final ByteBuf buffer) throws Exception { + public BlockEntity read(final ByteBuf buffer) { final byte xz = buffer.readByte(); final short y = buffer.readShort(); final int typeId = Type.VAR_INT.readPrimitive(buffer); @@ -44,7 +44,7 @@ public class BlockEntityType1_20_2 extends Type { } @Override - public void write(final ByteBuf buffer, final BlockEntity entity) throws Exception { + public void write(final ByteBuf buffer, final BlockEntity entity) { buffer.writeByte(entity.packedXZ()); buffer.writeShort(entity.y()); Type.VAR_INT.writePrimitive(buffer, entity.typeId()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/VarLongBlockChangeRecordType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/VarLongBlockChangeRecordType.java index 4abcaf8df..8bb63c129 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/block/VarLongBlockChangeRecordType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/block/VarLongBlockChangeRecordType.java @@ -34,14 +34,14 @@ public class VarLongBlockChangeRecordType extends Type { } @Override - public BlockChangeRecord read(ByteBuf buffer) throws Exception { + public BlockChangeRecord read(ByteBuf buffer) { long data = Type.VAR_LONG.readPrimitive(buffer); short position = (short) (data & 0xFFFL); return new BlockChangeRecord1_16_2(position >>> 8 & 0xF, position & 0xF, position >>> 4 & 0xF, (int) (data >>> 12)); } @Override - public void write(ByteBuf buffer, BlockChangeRecord object) throws Exception { + public void write(ByteBuf buffer, BlockChangeRecord object) { short position = (short) (object.getSectionX() << 8 | object.getSectionZ() << 4 | object.getSectionY()); Type.VAR_LONG.writePrimitive(buffer, (long) object.getBlockId() << 12 | position); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java index 48c68b1d8..33d98f5db 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java @@ -40,7 +40,7 @@ public class BulkChunkType1_8 extends Type { } @Override - public Chunk[] read(ByteBuf input) throws Exception { + public Chunk[] read(ByteBuf input) { final boolean skyLight = input.readBoolean(); final int count = Type.VAR_INT.readPrimitive(input); final Chunk[] chunks = new Chunk[count]; @@ -61,7 +61,7 @@ public class BulkChunkType1_8 extends Type { } @Override - public void write(ByteBuf output, Chunk[] chunks) throws Exception { + public void write(ByteBuf output, Chunk[] chunks) { boolean skyLight = false; loop1: for (Chunk chunk : chunks) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_13.java index 734ac2561..6c61cf3ca 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_13.java @@ -38,7 +38,7 @@ public class ChunkSectionType1_13 extends Type { } @Override - public ChunkSection read(ByteBuf buffer) throws Exception { + public ChunkSection read(ByteBuf buffer) { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); if (bitsPerBlock > 8) { @@ -75,7 +75,7 @@ public class ChunkSectionType1_13 extends Type { } @Override - public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { + public void write(ByteBuf buffer, ChunkSection chunkSection) { int bitsPerBlock = 4; DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); while (blockPalette.size() > 1 << bitsPerBlock) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_16.java index 0bc1fec44..bb5429b2c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_16.java @@ -38,7 +38,7 @@ public class ChunkSectionType1_16 extends Type { } @Override - public ChunkSection read(ByteBuf buffer) throws Exception { + public ChunkSection read(ByteBuf buffer) { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); if (bitsPerBlock > 8) { @@ -76,7 +76,7 @@ public class ChunkSectionType1_16 extends Type { } @Override - public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { + public void write(ByteBuf buffer, ChunkSection chunkSection) { int bitsPerBlock = 4; DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); while (blockPalette.size() > 1 << bitsPerBlock) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_18.java index 90b3f1df7..3de74488d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_18.java @@ -40,7 +40,7 @@ public final class ChunkSectionType1_18 extends Type { } @Override - public ChunkSection read(final ByteBuf buffer) throws Exception { + public ChunkSection read(final ByteBuf buffer) { final ChunkSection chunkSection = new ChunkSectionImpl(); chunkSection.setNonAirBlocksCount(buffer.readShort()); chunkSection.addPalette(PaletteType.BLOCKS, blockPaletteType.read(buffer)); @@ -49,7 +49,7 @@ public final class ChunkSectionType1_18 extends Type { } @Override - public void write(final ByteBuf buffer, final ChunkSection section) throws Exception { + public void write(final ByteBuf buffer, final ChunkSection section) { buffer.writeShort(section.getNonAirBlocksCount()); blockPaletteType.write(buffer, section.palette(PaletteType.BLOCKS)); biomePaletteType.write(buffer, section.palette(PaletteType.BIOMES)); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_8.java index 9f1d446b3..0544e328d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_8.java @@ -37,7 +37,7 @@ public class ChunkSectionType1_8 extends Type { } @Override - public ChunkSection read(ByteBuf buffer) throws Exception { + public ChunkSection read(ByteBuf buffer) { ChunkSection chunkSection = new ChunkSectionImpl(true); DataPalette blocks = chunkSection.palette(PaletteType.BLOCKS); @@ -53,7 +53,7 @@ public class ChunkSectionType1_8 extends Type { } @Override - public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { + public void write(ByteBuf buffer, ChunkSection chunkSection) { DataPalette blocks = chunkSection.palette(PaletteType.BLOCKS); ByteBuf littleEndianView = buffer.order(ByteOrder.LITTLE_ENDIAN); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_9.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_9.java index 71d3e58d5..3532f6cde 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_9.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkSectionType1_9.java @@ -38,7 +38,7 @@ public class ChunkSectionType1_9 extends Type { } @Override - public ChunkSection read(ByteBuf buffer) throws Exception { + public ChunkSection read(ByteBuf buffer) { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); if (bitsPerBlock < 4) { @@ -74,7 +74,7 @@ public class ChunkSectionType1_9 extends Type { } @Override - public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { + public void write(ByteBuf buffer, ChunkSection chunkSection) { int bitsPerBlock = 4; DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); while (blockPalette.size() > 1 << bitsPerBlock) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java index c349b71e6..c6704c366 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java @@ -52,7 +52,7 @@ public class ChunkType1_13 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -89,7 +89,7 @@ public class ChunkType1_13 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java index 5511d55dd..73510f2c6 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java @@ -43,7 +43,7 @@ public class ChunkType1_14 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -75,7 +75,7 @@ public class ChunkType1_14 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java index 063756315..94034f674 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java @@ -43,7 +43,7 @@ public class ChunkType1_15 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -76,7 +76,7 @@ public class ChunkType1_15 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java index 5420fba0a..5abe4d2f6 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java @@ -43,7 +43,7 @@ public class ChunkType1_16 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -77,7 +77,7 @@ public class ChunkType1_16 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java index d241221f5..b1954e758 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java @@ -43,7 +43,7 @@ public class ChunkType1_16_2 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -74,7 +74,7 @@ public class ChunkType1_16_2 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java index 21edef47a..72d32c55b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java @@ -47,7 +47,7 @@ public final class ChunkType1_17 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -74,7 +74,7 @@ public final class ChunkType1_17 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java index 117851be9..e2e2a2a7c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java @@ -45,7 +45,7 @@ public final class ChunkType1_18 extends Type { } @Override - public Chunk read(final ByteBuf buffer) throws Exception { + public Chunk read(final ByteBuf buffer) { final int chunkX = buffer.readInt(); final int chunkZ = buffer.readInt(); final CompoundTag heightMap = Type.NAMED_COMPOUND_TAG.read(buffer); @@ -71,7 +71,7 @@ public final class ChunkType1_18 extends Type { } @Override - public void write(final ByteBuf buffer, final Chunk chunk) throws Exception { + public void write(final ByteBuf buffer, final Chunk chunk) { buffer.writeInt(chunk.getX()); buffer.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java index f75b6a1b1..dd6252f78 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java @@ -45,7 +45,7 @@ public final class ChunkType1_20_2 extends Type { } @Override - public Chunk read(final ByteBuf buffer) throws Exception { + public Chunk read(final ByteBuf buffer) { final int chunkX = buffer.readInt(); final int chunkZ = buffer.readInt(); final CompoundTag heightMap = Type.COMPOUND_TAG.read(buffer); @@ -71,7 +71,7 @@ public final class ChunkType1_20_2 extends Type { } @Override - public void write(final ByteBuf buffer, final Chunk chunk) throws Exception { + public void write(final ByteBuf buffer, final Chunk chunk) { buffer.writeInt(chunk.getX()); buffer.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java index 451d3559c..c0817604d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java @@ -52,7 +52,7 @@ public class ChunkType1_8 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { final int chunkX = input.readInt(); final int chunkZ = input.readInt(); final boolean fullChunk = input.readBoolean(); @@ -75,7 +75,7 @@ public class ChunkType1_8 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); @@ -86,7 +86,7 @@ public class ChunkType1_8 extends Type { } // Used for normal and bulk chunks - public static Chunk deserialize(final int chunkX, final int chunkZ, final boolean fullChunk, final boolean skyLight, final int bitmask, final byte[] data) throws Exception { + public static Chunk deserialize(final int chunkX, final int chunkZ, final boolean fullChunk, final boolean skyLight, final int bitmask, final byte[] data) { final ByteBuf input = Unpooled.wrappedBuffer(data); final ChunkSection[] sections = new ChunkSection[16]; @@ -125,7 +125,7 @@ public class ChunkType1_8 extends Type { } // Used for normal and bulk chunks - public static byte[] serialize(final Chunk chunk) throws Exception { + public static byte[] serialize(final Chunk chunk) { final ByteBuf output = Unpooled.buffer(); // Write blocks diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java index efb14a5fe..3ab0f6b12 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java @@ -52,7 +52,7 @@ public class ChunkType1_9_1 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -96,7 +96,7 @@ public class ChunkType1_9_1 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java index 97f922bc7..73a4c4eab 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java @@ -54,7 +54,7 @@ public class ChunkType1_9_3 extends Type { } @Override - public Chunk read(ByteBuf input) throws Exception { + public Chunk read(ByteBuf input) { int chunkX = input.readInt(); int chunkZ = input.readInt(); @@ -92,7 +92,7 @@ public class ChunkType1_9_3 extends Type { } @Override - public void write(ByteBuf output, Chunk chunk) throws Exception { + public void write(ByteBuf output, Chunk chunk) { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/PaletteType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/PaletteType1_18.java index c133fdc35..f84fa63dc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/PaletteType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/PaletteType1_18.java @@ -41,7 +41,7 @@ public final class PaletteType1_18 extends Type { } @Override - public DataPalette read(final ByteBuf buffer) throws Exception { + public DataPalette read(final ByteBuf buffer) { int bitsPerValue = buffer.readByte(); final DataPaletteImpl palette; if (bitsPerValue == 0) { @@ -83,7 +83,7 @@ public final class PaletteType1_18 extends Type { } @Override - public void write(final ByteBuf buffer, final DataPalette palette) throws Exception { + public void write(final ByteBuf buffer, final DataPalette palette) { final int size = palette.size(); if (size == 1) { // Single value palette diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemCostType1_20_5.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemCostType1_20_5.java index 2f5e694b6..c5e2f3cd3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemCostType1_20_5.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemCostType1_20_5.java @@ -33,6 +33,7 @@ import io.netty.buffer.ByteBuf; // Very similar to normal items (and just results in an item), except it allows non-positive amounts and has id/amount swapped because ??? public final class ItemCostType1_20_5 extends Type { + private static final StructuredData[] EMPTY_DATA_ARRAY = new StructuredData[0]; private final Type[]> dataArrayType; public ItemCostType1_20_5(final Type[]> dataArrayType) { @@ -41,7 +42,7 @@ public final class ItemCostType1_20_5 extends Type { } @Override - public Item read(final ByteBuf buffer) throws Exception { + public Item read(final ByteBuf buffer) { final int id = Type.VAR_INT.readPrimitive(buffer); final int amount = Type.VAR_INT.readPrimitive(buffer); final StructuredData[] dataArray = dataArrayType.read(buffer); @@ -49,10 +50,10 @@ public final class ItemCostType1_20_5 extends Type { } @Override - public void write(final ByteBuf buffer, final Item object) throws Exception { + public void write(final ByteBuf buffer, final Item object) { Type.VAR_INT.writePrimitive(buffer, object.identifier()); Type.VAR_INT.writePrimitive(buffer, object.amount()); - dataArrayType.write(buffer, object.structuredData().data().values().toArray(new StructuredData[0])); + dataArrayType.write(buffer, object.structuredData().data().values().toArray(EMPTY_DATA_ARRAY)); } public static final class OptionalItemCostType extends OptionalType { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java index 198c0cbd9..9e6e35130 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13.java @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_13 extends BaseItemArrayType { @Override - public Item[] read(ByteBuf buffer) throws Exception { + public Item[] read(ByteBuf buffer) { int amount = Type.SHORT.readPrimitive(buffer); Item[] array = new Item[amount]; for (int i = 0; i < amount; i++) { @@ -39,7 +39,7 @@ public class ItemShortArrayType1_13 extends BaseItemArrayType { } @Override - public void write(ByteBuf buffer, Item[] object) throws Exception { + public void write(ByteBuf buffer, Item[] object) { Type.SHORT.writePrimitive(buffer, (short) object.length); for (Item o : object) { Type.ITEM1_13.write(buffer, o); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java index 0a67542d3..68b199344 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_13_2 extends BaseItemArrayType { @Override - public Item[] read(ByteBuf buffer) throws Exception { + public Item[] read(ByteBuf buffer) { int amount = Type.SHORT.readPrimitive(buffer); Item[] array = new Item[amount]; for (int i = 0; i < amount; i++) { @@ -39,7 +39,7 @@ public class ItemShortArrayType1_13_2 extends BaseItemArrayType { } @Override - public void write(ByteBuf buffer, Item[] object) throws Exception { + public void write(ByteBuf buffer, Item[] object) { Type.SHORT.writePrimitive(buffer, (short) object.length); for (Item o : object) { Type.ITEM1_13_2.write(buffer, o); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java index f9c9393d5..be24179f1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_8 extends BaseItemArrayType { @Override - public Item[] read(ByteBuf buffer) throws Exception { + public Item[] read(ByteBuf buffer) { int amount = Type.SHORT.readPrimitive(buffer); Item[] array = new Item[amount]; for (int i = 0; i < amount; i++) { @@ -39,7 +39,7 @@ public class ItemShortArrayType1_8 extends BaseItemArrayType { } @Override - public void write(ByteBuf buffer, Item[] object) throws Exception { + public void write(ByteBuf buffer, Item[] object) { Type.SHORT.writePrimitive(buffer, (short) object.length); for (Item o : object) { Type.ITEM1_8.write(buffer, o); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java index 863fc62ed..2f747ae1e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java @@ -34,7 +34,7 @@ public class ItemType1_13 extends Type { } @Override - public @Nullable Item read(ByteBuf buffer) throws Exception { + public @Nullable Item read(ByteBuf buffer) { short id = buffer.readShort(); if (id < 0) { return null; @@ -48,7 +48,7 @@ public class ItemType1_13 extends Type { } @Override - public void write(ByteBuf buffer, @Nullable Item object) throws Exception { + public void write(ByteBuf buffer, @Nullable Item object) { if (object == null) { buffer.writeShort(-1); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java index 70695b40f..5497effc3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java @@ -34,7 +34,7 @@ public class ItemType1_13_2 extends Type { } @Override - public @Nullable Item read(ByteBuf buffer) throws Exception { + public @Nullable Item read(ByteBuf buffer) { boolean present = buffer.readBoolean(); if (!present) { return null; @@ -48,7 +48,7 @@ public class ItemType1_13_2 extends Type { } @Override - public void write(ByteBuf buffer, @Nullable Item object) throws Exception { + public void write(ByteBuf buffer, @Nullable Item object) { if (object == null) { buffer.writeBoolean(false); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java index a456993b1..8c8aa3277 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java @@ -35,7 +35,7 @@ public class ItemType1_20_2 extends Type { } @Override - public @Nullable Item read(final ByteBuf buffer) throws Exception { + public @Nullable Item read(final ByteBuf buffer) { if (!buffer.readBoolean()) { return null; } @@ -48,7 +48,7 @@ public class ItemType1_20_2 extends Type { } @Override - public void write(final ByteBuf buffer, @Nullable final Item object) throws Exception { + public void write(final ByteBuf buffer, @Nullable final Item object) { if (object == null) { buffer.writeBoolean(false); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java index 09fd79f27..01b55074a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java @@ -44,7 +44,7 @@ public class ItemType1_20_5 extends Type { } @Override - public @Nullable Item read(final ByteBuf buffer) throws Exception { + public @Nullable Item read(final ByteBuf buffer) { final int amount = Type.VAR_INT.readPrimitive(buffer); if (amount <= 0) { return null; @@ -55,7 +55,7 @@ public class ItemType1_20_5 extends Type { return new StructuredItem(id, amount, new StructuredDataContainer(data)); } - private Map, StructuredData> readData(final ByteBuf buffer) throws Exception { + private Map, StructuredData> readData(final ByteBuf buffer) { final int valuesSize = Type.VAR_INT.readPrimitive(buffer); final int markersSize = Type.VAR_INT.readPrimitive(buffer); if (valuesSize == 0 && markersSize == 0) { @@ -80,7 +80,7 @@ public class ItemType1_20_5 extends Type { } @Override - public void write(final ByteBuf buffer, @Nullable final Item object) throws Exception { + public void write(final ByteBuf buffer, @Nullable final Item object) { if (object == null) { Type.VAR_INT.writePrimitive(buffer, 0); return; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java index 066e6cc08..877f235b0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java @@ -35,7 +35,7 @@ public class ItemType1_8 extends Type { } @Override - public @Nullable Item read(ByteBuf buffer) throws Exception { + public @Nullable Item read(ByteBuf buffer) { short id = buffer.readShort(); if (id < 0) { return null; @@ -50,7 +50,7 @@ public class ItemType1_8 extends Type { } @Override - public void write(ByteBuf buffer, @Nullable Item object) throws Exception { + public void write(ByteBuf buffer, @Nullable Item object) { if (object == null) { buffer.writeShort(-1); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java index 56eab13a2..8269b474f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java @@ -40,13 +40,13 @@ public class StructuredDataType extends Type> { } @Override - public void write(final ByteBuf buffer, final StructuredData object) throws Exception { + public void write(final ByteBuf buffer, final StructuredData object) { Type.VAR_INT.writePrimitive(buffer, object.id()); object.write(buffer); } @Override - public StructuredData read(final ByteBuf buffer) throws Exception { + public StructuredData read(final ByteBuf buffer) { Preconditions.checkNotNull(types, "StructuredDataType has not been initialized"); final int id = Type.VAR_INT.readPrimitive(buffer); final StructuredDataKey key = this.types[id]; @@ -60,7 +60,7 @@ public class StructuredDataType extends Type> { return id >= 0 && id < types.length ? types[id] : null; } - private StructuredData readData(final ByteBuf buffer, final StructuredDataKey key, final int id) throws Exception { + private StructuredData readData(final ByteBuf buffer, final StructuredDataKey key, final int id) { return StructuredData.of(key, key.type().read(buffer), id); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/ChunkPositionType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/ChunkPositionType.java index a36ed092f..bc08262c4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/ChunkPositionType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/ChunkPositionType.java @@ -33,13 +33,13 @@ public class ChunkPositionType extends Type { } @Override - public ChunkPosition read(ByteBuf buffer) throws Exception { + public ChunkPosition read(ByteBuf buffer) { final long chunkKey = Type.LONG.readPrimitive(buffer); return new ChunkPosition(chunkKey); } @Override - public void write(ByteBuf buffer, ChunkPosition chunkPosition) throws Exception { + public void write(ByteBuf buffer, ChunkPosition chunkPosition) { Type.LONG.writePrimitive(buffer, chunkPosition.chunkKey()); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/EulerAngleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/EulerAngleType.java index bcc414fb1..3200e3b32 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/EulerAngleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/EulerAngleType.java @@ -32,7 +32,7 @@ public class EulerAngleType extends Type { } @Override - public EulerAngle read(ByteBuf buffer) throws Exception { + public EulerAngle read(ByteBuf buffer) { float x = Type.FLOAT.readPrimitive(buffer); float y = Type.FLOAT.readPrimitive(buffer); float z = Type.FLOAT.readPrimitive(buffer); @@ -41,7 +41,7 @@ public class EulerAngleType extends Type { } @Override - public void write(ByteBuf buffer, EulerAngle object) throws Exception { + public void write(ByteBuf buffer, EulerAngle object) { Type.FLOAT.writePrimitive(buffer, object.x()); Type.FLOAT.writePrimitive(buffer, object.y()); Type.FLOAT.writePrimitive(buffer, object.z()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/GlobalPositionType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/GlobalPositionType.java index 143761656..5019a7334 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/GlobalPositionType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/GlobalPositionType.java @@ -34,13 +34,13 @@ public class GlobalPositionType extends Type { } @Override - public GlobalPosition read(ByteBuf buffer) throws Exception { + public GlobalPosition read(ByteBuf buffer) { final String dimension = Type.STRING.read(buffer); return Type.POSITION1_14.read(buffer).withDimension(dimension); } @Override - public void write(ByteBuf buffer, GlobalPosition object) throws Exception { + public void write(ByteBuf buffer, GlobalPosition object) { Type.STRING.write(buffer, object.dimension()); Type.POSITION1_14.write(buffer, object); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/QuaternionType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/QuaternionType.java index 414f9a156..0c04847d7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/QuaternionType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/QuaternionType.java @@ -33,7 +33,7 @@ public class QuaternionType extends Type { } @Override - public Quaternion read(final ByteBuf buffer) throws Exception { + public Quaternion read(final ByteBuf buffer) { final float x = buffer.readFloat(); final float y = buffer.readFloat(); final float z = buffer.readFloat(); @@ -42,7 +42,7 @@ public class QuaternionType extends Type { } @Override - public void write(final ByteBuf buffer, final Quaternion object) throws Exception { + public void write(final ByteBuf buffer, final Quaternion object) { buffer.writeFloat(object.x()); buffer.writeFloat(object.y()); buffer.writeFloat(object.z()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/Vector3fType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/Vector3fType.java index 03868c761..564c3c1ad 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/Vector3fType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/Vector3fType.java @@ -33,7 +33,7 @@ public class Vector3fType extends Type { } @Override - public Vector3f read(final ByteBuf buffer) throws Exception { + public Vector3f read(final ByteBuf buffer) { final float x = buffer.readFloat(); final float y = buffer.readFloat(); final float z = buffer.readFloat(); @@ -41,7 +41,7 @@ public class Vector3fType extends Type { } @Override - public void write(final ByteBuf buffer, final Vector3f object) throws Exception { + public void write(final ByteBuf buffer, final Vector3f object) { buffer.writeFloat(object.x()); buffer.writeFloat(object.y()); buffer.writeFloat(object.z()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/VectorType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/VectorType.java index 4c295cd07..4f6ea5790 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/VectorType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/VectorType.java @@ -32,7 +32,7 @@ public class VectorType extends Type { } @Override - public Vector read(ByteBuf buffer) throws Exception { + public Vector read(ByteBuf buffer) { int x = Type.INT.read(buffer); int y = Type.INT.read(buffer); int z = Type.INT.read(buffer); @@ -41,7 +41,7 @@ public class VectorType extends Type { } @Override - public void write(ByteBuf buffer, Vector object) throws Exception { + public void write(ByteBuf buffer, Vector object) { Type.INT.write(buffer, object.blockX()); Type.INT.write(buffer, object.blockY()); Type.INT.write(buffer, object.blockZ()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/MetaListType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/MetaListType.java index 1b90120de..bf0c6eaed 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/MetaListType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/MetaListType.java @@ -38,7 +38,7 @@ public final class MetaListType extends MetaListTypeTemplate { } @Override - public List read(final ByteBuf buffer) throws Exception { + public List read(final ByteBuf buffer) { final List list = new ArrayList<>(); Metadata meta; do { @@ -51,7 +51,7 @@ public final class MetaListType extends MetaListTypeTemplate { } @Override - public void write(final ByteBuf buffer, final List object) throws Exception { + public void write(final ByteBuf buffer, final List object) { for (final Metadata metadata : object) { this.type.write(buffer, metadata); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/ModernMetaType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/ModernMetaType.java index c4d63dee6..d2a58da89 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/ModernMetaType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/ModernMetaType.java @@ -31,7 +31,7 @@ public abstract class ModernMetaType extends MetaTypeTemplate { private static final int END = 255; @Override - public Metadata read(final ByteBuf buffer) throws Exception { + public Metadata read(final ByteBuf buffer) { final short index = buffer.readUnsignedByte(); if (index == END) return null; // End of metadata final MetaType type = this.getType(Type.VAR_INT.readPrimitive(buffer)); @@ -41,7 +41,7 @@ public abstract class ModernMetaType extends MetaTypeTemplate { protected abstract MetaType getType(final int index); @Override - public void write(final ByteBuf buffer, final Metadata object) throws Exception { + public void write(final ByteBuf buffer, final Metadata object) { if (object == null) { buffer.writeByte(END); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/OldMetaType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/OldMetaType.java index ef0ef98d8..1fd0d33ce 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/OldMetaType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/metadata/OldMetaType.java @@ -31,7 +31,7 @@ public abstract class OldMetaType extends MetaTypeTemplate { private static final int END = 127; @Override - public Metadata read(final ByteBuf buffer) throws Exception { + public Metadata read(final ByteBuf buffer) { final byte index = buffer.readByte(); if (index == END) return null; // End of metadata final MetaType type = this.getType((index & 224) >> 5); @@ -41,7 +41,7 @@ public abstract class OldMetaType extends MetaTypeTemplate { protected abstract MetaType getType(final int index); @Override - public void write(final ByteBuf buffer, final Metadata object) throws Exception { + public void write(final ByteBuf buffer, final Metadata object) { if (object == null) { buffer.writeByte(END); } else { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/CompoundTagType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/CompoundTagType.java index 80d5fc7fe..4a19faaec 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/CompoundTagType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/CompoundTagType.java @@ -42,13 +42,21 @@ public class CompoundTagType extends Type { } @Override - public CompoundTag read(final ByteBuf buffer) throws IOException { - return NamedCompoundTagType.read(buffer, false); + public CompoundTag read(final ByteBuf buffer) { + try { + return NamedCompoundTagType.read(buffer, false); + } catch (final IOException e) { + throw new RuntimeException(e); + } } @Override - public void write(final ByteBuf buffer, final CompoundTag object) throws IOException { - NamedCompoundTagType.write(buffer, object, null); + public void write(final ByteBuf buffer, final CompoundTag object) { + try { + NamedCompoundTagType.write(buffer, object, null); + } catch (final IOException e) { + throw new RuntimeException(e); + } } public static final class OptionalCompoundTagType extends OptionalType { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/DynamicType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/DynamicType.java index 76d95fd70..e08824873 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/DynamicType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/DynamicType.java @@ -52,7 +52,7 @@ public abstract class DynamicType extends Type { return new DataFiller(protocol, useMappedNames); } - protected void readData(final ByteBuf buffer, final T value) throws Exception { + protected void readData(final ByteBuf buffer, final T value) { final DataReader reader = readers.get(value.id()); if (reader != null) { reader.read(buffer, value); @@ -98,8 +98,7 @@ public abstract class DynamicType extends Type { * * @param buf buffer * @param value value - * @throws Exception if an error occurs during buffer reading */ - void read(ByteBuf buf, T value) throws Exception; + void read(ByteBuf buf, T value); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/GameProfileType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/GameProfileType.java index db301e522..0458a5df4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/GameProfileType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/GameProfileType.java @@ -33,7 +33,7 @@ public final class GameProfileType extends Type { } @Override - public GameProfile read(final ByteBuf buffer) throws Exception { + public GameProfile read(final ByteBuf buffer) { final String name = Type.OPTIONAL_STRING.read(buffer); final java.util.UUID id = Type.OPTIONAL_UUID.read(buffer); final int propertyCount = Type.VAR_INT.readPrimitive(buffer); @@ -48,7 +48,7 @@ public final class GameProfileType extends Type { } @Override - public void write(final ByteBuf buffer, final GameProfile value) throws Exception { + public void write(final ByteBuf buffer, final GameProfile value) { Type.OPTIONAL_STRING.write(buffer, value.name()); Type.OPTIONAL_UUID.write(buffer, value.id()); Type.VAR_INT.writePrimitive(buffer, value.properties().length); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderSetType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderSetType.java index 9e6c081f1..bc83ac3db 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderSetType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderSetType.java @@ -34,7 +34,7 @@ public class HolderSetType extends Type { } @Override - public HolderSet read(final ByteBuf buffer) throws Exception { + public HolderSet read(final ByteBuf buffer) { final int size = Type.VAR_INT.readPrimitive(buffer) - 1; if (size == -1) { final String tag = Type.STRING.read(buffer); @@ -49,7 +49,7 @@ public class HolderSetType extends Type { } @Override - public void write(final ByteBuf buffer, final HolderSet object) throws Exception { + public void write(final ByteBuf buffer, final HolderSet object) { if (object.hasTagKey()) { Type.VAR_INT.writePrimitive(buffer, 0); Type.STRING.write(buffer, object.tagKey()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderType.java index 286c5c69d..88d645021 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/HolderType.java @@ -33,7 +33,7 @@ public abstract class HolderType extends Type> { } @Override - public Holder read(final ByteBuf buffer) throws Exception { + public Holder read(final ByteBuf buffer) { final int id = Type.VAR_INT.readPrimitive(buffer) - 1; // Normalize id if (id == -1) { return Holder.of(readDirect(buffer)); @@ -42,7 +42,7 @@ public abstract class HolderType extends Type> { } @Override - public void write(final ByteBuf buffer, final Holder object) throws Exception { + public void write(final ByteBuf buffer, final Holder object) { if (object.hasId()) { Type.VAR_INT.writePrimitive(buffer, object.id() + 1); // Normalize id } else { @@ -51,7 +51,7 @@ public abstract class HolderType extends Type> { } } - public abstract T readDirect(final ByteBuf buffer) throws Exception; + public abstract T readDirect(final ByteBuf buffer); - public abstract void writeDirect(final ByteBuf buffer, final T object) throws Exception; + public abstract void writeDirect(final ByteBuf buffer, final T object); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/NamedCompoundTagType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/NamedCompoundTagType.java index 5247c6c5e..4d09cc9af 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/NamedCompoundTagType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/NamedCompoundTagType.java @@ -43,13 +43,21 @@ public class NamedCompoundTagType extends Type { } @Override - public CompoundTag read(final ByteBuf buffer) throws IOException { - return read(buffer, true); + public CompoundTag read(final ByteBuf buffer) { + try { + return read(buffer, true); + } catch (final IOException e) { + throw new RuntimeException(e); + } } @Override - public void write(final ByteBuf buffer, final CompoundTag object) throws IOException { - write(buffer, object, ""); + public void write(final ByteBuf buffer, final CompoundTag object) { + try { + write(buffer, object, ""); + } catch (final IOException e) { + throw new RuntimeException(e); + } } public static CompoundTag read(final ByteBuf buffer, final boolean readName) throws IOException { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ParticleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ParticleType.java index 591ac82c4..f993b0fba 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ParticleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ParticleType.java @@ -39,7 +39,7 @@ public class ParticleType extends DynamicType { } @Override - public void write(final ByteBuf buffer, final Particle object) throws Exception { + public void write(final ByteBuf buffer, final Particle object) { Type.VAR_INT.writePrimitive(buffer, object.id()); for (final Particle.ParticleData data : object.getArguments()) { data.write(buffer); @@ -47,7 +47,7 @@ public class ParticleType extends DynamicType { } @Override - public Particle read(final ByteBuf buffer) throws Exception { + public Particle read(final ByteBuf buffer) { final int type = Type.VAR_INT.readPrimitive(buffer); final Particle particle = new Particle(type); readData(buffer, particle); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/PlayerMessageSignatureType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/PlayerMessageSignatureType.java index bcb0e8f4f..ef7173b28 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/PlayerMessageSignatureType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/PlayerMessageSignatureType.java @@ -34,12 +34,12 @@ public class PlayerMessageSignatureType extends Type { } @Override - public PlayerMessageSignature read(final ByteBuf buffer) throws Exception { + public PlayerMessageSignature read(final ByteBuf buffer) { return new PlayerMessageSignature(Type.UUID.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer)); } @Override - public void write(final ByteBuf buffer, final PlayerMessageSignature value) throws Exception { + public void write(final ByteBuf buffer, final PlayerMessageSignature value) { Type.UUID.write(buffer, value.uuid()); Type.BYTE_ARRAY_PRIMITIVE.write(buffer, value.signatureBytes()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ProfileKeyType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ProfileKeyType.java index 8f3934395..b61db8c1e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ProfileKeyType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/ProfileKeyType.java @@ -34,12 +34,12 @@ public class ProfileKeyType extends Type { } @Override - public ProfileKey read(final ByteBuf buffer) throws Exception { + public ProfileKey read(final ByteBuf buffer) { return new ProfileKey(buffer.readLong(), Type.BYTE_ARRAY_PRIMITIVE.read(buffer), Type.BYTE_ARRAY_PRIMITIVE.read(buffer)); } @Override - public void write(final ByteBuf buffer, final ProfileKey object) throws Exception { + public void write(final ByteBuf buffer, final ProfileKey object) { buffer.writeLong(object.expiresAt()); Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.publicKey()); Type.BYTE_ARRAY_PRIMITIVE.write(buffer, object.keySignature()); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/SoundEventType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/SoundEventType.java index 3128f4572..38f64f93f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/SoundEventType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/SoundEventType.java @@ -29,14 +29,14 @@ import io.netty.buffer.ByteBuf; public final class SoundEventType extends HolderType { @Override - public SoundEvent readDirect(final ByteBuf buffer) throws Exception { + public SoundEvent readDirect(final ByteBuf buffer) { final String resourceLocation = Type.STRING.read(buffer); final Float fixedRange = Type.OPTIONAL_FLOAT.read(buffer); return new SoundEvent(resourceLocation, fixedRange); } @Override - public void writeDirect(final ByteBuf buffer, final SoundEvent value) throws Exception { + public void writeDirect(final ByteBuf buffer, final SoundEvent value) { Type.STRING.write(buffer, value.identifier()); Type.OPTIONAL_FLOAT.write(buffer, value.fixedRange()); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/TagType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/TagType.java index b4a9e0ce5..ddd79bdcc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/TagType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/TagType.java @@ -38,19 +38,27 @@ public class TagType extends Type { } @Override - public Tag read(final ByteBuf buffer) throws IOException { + public Tag read(final ByteBuf buffer) { final byte id = buffer.readByte(); if (id == 0) { return null; } final TagLimiter tagLimiter = TagLimiter.create(NamedCompoundTagType.MAX_NBT_BYTES, NamedCompoundTagType.MAX_NESTING_LEVEL); - return TagRegistry.read(id, new ByteBufInputStream(buffer), tagLimiter, 0); + try { + return TagRegistry.read(id, new ByteBufInputStream(buffer), tagLimiter, 0); + } catch (final IOException e) { + throw new RuntimeException(e); + } } @Override - public void write(final ByteBuf buffer, final Tag tag) throws IOException { - NamedCompoundTagType.write(buffer, tag, null); + public void write(final ByteBuf buffer, final Tag tag) { + try { + NamedCompoundTagType.write(buffer, tag, null); + } catch (final IOException e) { + throw new RuntimeException(e); + } } public static final class OptionalTagType extends OptionalType { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/VillagerDataType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/VillagerDataType.java index da2fb1100..979bdd9f4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/VillagerDataType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/misc/VillagerDataType.java @@ -32,12 +32,12 @@ public class VillagerDataType extends Type { } @Override - public VillagerData read(ByteBuf buffer) throws Exception { + public VillagerData read(ByteBuf buffer) { return new VillagerData(Type.VAR_INT.readPrimitive(buffer), Type.VAR_INT.readPrimitive(buffer), Type.VAR_INT.readPrimitive(buffer)); } @Override - public void write(ByteBuf buffer, VillagerData object) throws Exception { + public void write(ByteBuf buffer, VillagerData object) { Type.VAR_INT.writePrimitive(buffer, object.type()); Type.VAR_INT.writePrimitive(buffer, object.profession()); Type.VAR_INT.writePrimitive(buffer, object.level()); diff --git a/api/src/main/java/com/viaversion/viaversion/exception/CancelDecoderException.java b/api/src/main/java/com/viaversion/viaversion/exception/CancelDecoderException.java index 6f96b1ff4..949bc69d0 100644 --- a/api/src/main/java/com/viaversion/viaversion/exception/CancelDecoderException.java +++ b/api/src/main/java/com/viaversion/viaversion/exception/CancelDecoderException.java @@ -39,7 +39,6 @@ public class CancelDecoderException extends DecoderException implements CancelCo }; public CancelDecoderException() { - super(); } public CancelDecoderException(String message, Throwable cause) { @@ -61,6 +60,6 @@ public class CancelDecoderException extends DecoderException implements CancelCo * @return a CancelDecoderException instance */ public static CancelDecoderException generate(Throwable cause) { - return Via.getManager().isDebug() ? new CancelDecoderException(cause) : CACHED; + return Via.getManager().debugHandler().enabled() ? new CancelDecoderException(cause) : CACHED; } } diff --git a/api/src/main/java/com/viaversion/viaversion/exception/CancelEncoderException.java b/api/src/main/java/com/viaversion/viaversion/exception/CancelEncoderException.java index 58551e64c..e561d6846 100644 --- a/api/src/main/java/com/viaversion/viaversion/exception/CancelEncoderException.java +++ b/api/src/main/java/com/viaversion/viaversion/exception/CancelEncoderException.java @@ -39,7 +39,6 @@ public class CancelEncoderException extends EncoderException implements CancelCo }; public CancelEncoderException() { - super(); } public CancelEncoderException(String message, Throwable cause) { @@ -61,6 +60,6 @@ public class CancelEncoderException extends EncoderException implements CancelCo * @return a CancelEncoderException instance */ public static CancelEncoderException generate(Throwable cause) { - return Via.getManager().isDebug() ? new CancelEncoderException(cause) : CACHED; + return Via.getManager().debugHandler().enabled() ? new CancelEncoderException(cause) : CACHED; } } diff --git a/api/src/main/java/com/viaversion/viaversion/exception/CancelException.java b/api/src/main/java/com/viaversion/viaversion/exception/CancelException.java index 9c284de72..46a71f055 100644 --- a/api/src/main/java/com/viaversion/viaversion/exception/CancelException.java +++ b/api/src/main/java/com/viaversion/viaversion/exception/CancelException.java @@ -63,6 +63,6 @@ public class CancelException extends Exception { * @return a CancelException instance */ public static CancelException generate() { - return Via.getManager().isDebug() ? new CancelException() : CACHED; + return Via.getManager().debugHandler().enabled() ? new CancelException() : CACHED; } } diff --git a/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java b/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java index 809f39f62..820d4762d 100644 --- a/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java +++ b/api/src/main/java/com/viaversion/viaversion/exception/InformativeException.java @@ -25,7 +25,7 @@ package com.viaversion.viaversion.exception; import java.util.HashMap; import java.util.Map; -public class InformativeException extends Exception { +public class InformativeException extends RuntimeException { private final Map info = new HashMap<>(); private boolean shouldBePrinted = true; private int sources; diff --git a/api/src/main/java/com/viaversion/viaversion/util/CompactArrayUtil.java b/api/src/main/java/com/viaversion/viaversion/util/CompactArrayUtil.java index 92ae2423f..40c61d159 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/CompactArrayUtil.java +++ b/api/src/main/java/com/viaversion/viaversion/util/CompactArrayUtil.java @@ -48,7 +48,7 @@ public final class CompactArrayUtil { }; private CompactArrayUtil() { - throw new AssertionError(); + throw new UnsupportedOperationException(); } public static long[] createCompactArrayWithPadding(int bitsPerEntry, int entries, IntToLongFunction valueGetter) { diff --git a/api/src/main/java/com/viaversion/viaversion/util/Pair.java b/api/src/main/java/com/viaversion/viaversion/util/Pair.java index dd54c9441..2786450ba 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/Pair.java +++ b/api/src/main/java/com/viaversion/viaversion/util/Pair.java @@ -22,62 +22,7 @@ */ package com.viaversion.viaversion.util; -import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; -public class Pair { - private final X key; - private Y value; - - public Pair(@Nullable X key, @Nullable Y value) { - this.key = key; - this.value = value; - } - - public @Nullable X key() { - return key; - } - - public @Nullable Y value() { - return value; - } - - @Deprecated/*(forRemoval = true)*/ - public @Nullable X getKey() { - return key; - } - - @Deprecated/*(forRemoval = true)*/ - public @Nullable Y getValue() { - return value; - } - - /** - * @deprecated don't count on this continuing to be mutable - */ - @Deprecated/*(forRemoval = true)*/ - public void setValue(@Nullable Y value) { - this.value = value; - } - - @Override - public String toString() { - return "Pair{" + key + ", " + value + '}'; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Pair pair = (Pair) o; - if (!Objects.equals(key, pair.key)) return false; - return Objects.equals(value, pair.value); - } - - @Override - public int hashCode() { - int result = key != null ? key.hashCode() : 0; - result = 31 * result + (value != null ? value.hashCode() : 0); - return result; - } +public record Pair(@Nullable X key, @Nullable Y value) { } diff --git a/api/src/main/java/com/viaversion/viaversion/util/PipelineUtil.java b/api/src/main/java/com/viaversion/viaversion/util/PipelineUtil.java index 73234bd05..34071d1ca 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/PipelineUtil.java +++ b/api/src/main/java/com/viaversion/viaversion/util/PipelineUtil.java @@ -28,6 +28,8 @@ import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToMessageDecoder; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -35,65 +37,69 @@ import java.util.List; import org.checkerframework.checker.nullness.qual.Nullable; public final class PipelineUtil { - private static final Method DECODE_METHOD; - private static final Method ENCODE_METHOD; - private static final Method MTM_DECODE; - - static { - try { - DECODE_METHOD = ByteToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class); - DECODE_METHOD.setAccessible(true); - ENCODE_METHOD = MessageToByteEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, ByteBuf.class); - ENCODE_METHOD.setAccessible(true); - MTM_DECODE = MessageToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, Object.class, List.class); - MTM_DECODE.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } + private static final MethodHandle DECODE_METHOD = privateHandleUnchecked(ByteToMessageDecoder.class, "decode", ChannelHandlerContext.class, ByteBuf.class, List.class); + private static final MethodHandle ENCODE_METHOD = privateHandleUnchecked(MessageToByteEncoder.class, "encode", ChannelHandlerContext.class, Object.class, ByteBuf.class); + private static final MethodHandle MTM_DECODE = privateHandleUnchecked(MessageToMessageDecoder.class, "decode", ChannelHandlerContext.class, Object.class, List.class); /** - * Call the decode method on a netty ByteToMessageDecoder + * Calls the decode method on a netty ByteToMessageDecoder. * - * @param decoder The decoder - * @param ctx The current context - * @param input The packet to decode - * @return A list of the decoders output - * @throws InvocationTargetException If an exception happens while executing + * @param decoder decoder + * @param ctx current context + * @param input packet to decode + * @return a list of the decoders output + * @throws Exception prapagated exception from the underlying method if thrown + * @throws InvocationTargetException wrapped throwable if a given throwable is not an exeption or error */ - public static List callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException { + public static List callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws Exception { List output = new ArrayList<>(); try { PipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output); - } catch (IllegalAccessException e) { - e.printStackTrace(); + } catch (Exception | Error e) { + throw e; // Directly propagate exceptions/errors + } catch (Throwable t) { + throw new InvocationTargetException(t); } return output; } /** - * Call the encode method on a netty MessageToByteEncoder + * Calls the encode method on a netty MessageToByteEncoder. * - * @param encoder The encoder - * @param ctx The current context - * @param msg The packet to encode - * @param output The bytebuf to write the output to - * @throws InvocationTargetException If an exception happens while executing + * @param encoder encoder + * @param ctx current context + * @param msg packet to encode + * @throws Exception prapagated exception from the underlying method if thrown + * @throws InvocationTargetException wrapped throwable if a given throwable is not an exeption or error */ - public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException { + public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws Exception { try { PipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output); - } catch (IllegalAccessException e) { - e.printStackTrace(); + } catch (Exception | Error e) { + throw e; // Directly propagate exceptions/errors + } catch (Throwable t) { + throw new InvocationTargetException(t); } } - public static List callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object msg) throws InvocationTargetException { + /** + * Calls the decode method on a netty MessageToMessageDecoder. + * + * @param decoder decoder + * @param ctx current context + * @param msg packet to decode + * @return a list of the decoders output + * @throws Exception prapagated exception from the underlying method if thrown + * @throws InvocationTargetException wrapped throwable if a given throwable is not an exeption or error + */ + public static List callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object msg) throws Exception { List output = new ArrayList<>(); try { MTM_DECODE.invoke(decoder, ctx, msg, output); - } catch (IllegalAccessException e) { - e.printStackTrace(); + } catch (Exception | Error e) { + throw e; + } catch (Throwable t) { + throw new InvocationTargetException(t); } return output; } @@ -106,13 +112,13 @@ public final class PipelineUtil { * @return True if the stack trace contained it as its cause or if t is an instance of c. */ public static boolean containsCause(Throwable t, Class c) { - while (t != null) { + do { if (c.isAssignableFrom(t.getClass())) { return true; } t = t.getCause(); - } + } while (t != null); return false; } @@ -136,25 +142,26 @@ public final class PipelineUtil { } /** - * Get the context for a the channel handler before a certain name. + * Get the context for the channel handler before a certain name. * * @param name The name of the channel handler * @param pipeline The pipeline to target * @return The ChannelHandler before the one requested. */ - public static ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipeline) { + public static @Nullable ChannelHandlerContext getContextBefore(String name, ChannelPipeline pipeline) { boolean mark = false; for (String s : pipeline.names()) { if (mark) { return pipeline.context(pipeline.get(s)); } - if (s.equalsIgnoreCase(name)) + if (s.equalsIgnoreCase(name)) { mark = true; + } } return null; } - public static ChannelHandlerContext getPreviousContext(String name, ChannelPipeline pipeline) { + public static @Nullable ChannelHandlerContext getPreviousContext(String name, ChannelPipeline pipeline) { String previous = null; for (String entry : pipeline.toMap().keySet()) { if (entry.equals(name)) { @@ -164,4 +171,18 @@ public final class PipelineUtil { } return null; } + + private static MethodHandle privateHandle(final Class clazz, final String method, final Class... parameterTypes) throws NoSuchMethodException, IllegalAccessException { + final Method decodeMethod = clazz.getDeclaredMethod(method, parameterTypes); + decodeMethod.setAccessible(true); + return MethodHandles.lookup().unreflect(decodeMethod); + } + + private static MethodHandle privateHandleUnchecked(final Class clazz, final String method, final Class... args) { + try { + return privateHandle(clazz, method, args); + } catch (final NoSuchMethodException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } } diff --git a/api/src/main/java/com/viaversion/viaversion/util/ProtocolUtil.java b/api/src/main/java/com/viaversion/viaversion/util/ProtocolUtil.java index 2a61e7393..63d8049d6 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/ProtocolUtil.java +++ b/api/src/main/java/com/viaversion/viaversion/util/ProtocolUtil.java @@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap; import java.util.Collections; import java.util.EnumMap; +import java.util.Locale; import java.util.Map; import org.checkerframework.checker.nullness.qual.Nullable; @@ -66,7 +67,7 @@ public final class ProtocolUtil { * @return packet id as a nice hex string */ public static String toNiceHex(int id) { - final String hex = Integer.toHexString(id).toUpperCase(); + final String hex = Integer.toHexString(id).toUpperCase(Locale.ROOT); return (hex.length() == 1 ? "0x0" : "0x") + hex; } } diff --git a/api/src/main/java/com/viaversion/viaversion/util/Triple.java b/api/src/main/java/com/viaversion/viaversion/util/Triple.java index 785f17b17..279d75eb6 100644 --- a/api/src/main/java/com/viaversion/viaversion/util/Triple.java +++ b/api/src/main/java/com/viaversion/viaversion/util/Triple.java @@ -22,67 +22,7 @@ */ package com.viaversion.viaversion.util; -import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; -public class Triple { - private final A first; - private final B second; - private final C third; - - public Triple(@Nullable A first, @Nullable B second, @Nullable C third) { - this.first = first; - this.second = second; - this.third = third; - } - - public @Nullable A first() { - return first; - } - - public @Nullable B second() { - return second; - } - - public @Nullable C third() { - return third; - } - - @Deprecated/*(forRemoval = true)*/ - public @Nullable A getFirst() { - return first; - } - - @Deprecated/*(forRemoval = true)*/ - public @Nullable B getSecond() { - return second; - } - - @Deprecated/*(forRemoval = true)*/ - public @Nullable C getThird() { - return third; - } - - @Override - public String toString() { - return "Triple{" + first + ", " + second + ", " + third + '}'; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Triple triple = (Triple) o; - if (!Objects.equals(first, triple.first)) return false; - if (!Objects.equals(second, triple.second)) return false; - return Objects.equals(third, triple.third); - } - - @Override - public int hashCode() { - int result = first != null ? first.hashCode() : 0; - result = 31 * result + (second != null ? second.hashCode() : 0); - result = 31 * result + (third != null ? third.hashCode() : 0); - return result; - } +public record Triple(@Nullable A first, @Nullable B second, @Nullable C third) { } diff --git a/build-logic/src/main/kotlin/via.base-conventions.gradle.kts b/build-logic/src/main/kotlin/via.base-conventions.gradle.kts index fe1f3d7ca..2fec98bf4 100644 --- a/build-logic/src/main/kotlin/via.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/via.base-conventions.gradle.kts @@ -24,7 +24,7 @@ tasks { } java { - javaTarget(8) + javaTarget(17) withSourcesJar() } diff --git a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/ArmorListener.java b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/ArmorListener.java index c7e56fec1..a790501b0 100644 --- a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/ArmorListener.java +++ b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/ArmorListener.java @@ -60,34 +60,23 @@ public class ArmorListener extends ViaBukkitListener { } PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_PROPERTIES, null, getUserConnection(player)); - try { - wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID - wrapper.write(Type.INT, 1); // only 1 property - wrapper.write(Type.STRING, "generic.armor"); - wrapper.write(Type.DOUBLE, 0D); //default 0 armor - wrapper.write(Type.VAR_INT, 1); // 1 modifier - wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid - wrapper.write(Type.DOUBLE, (double) armor); // the modifier value - wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number - - wrapper.scheduleSend(Protocol1_9To1_8.class); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send armor update", e); - } + wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID + wrapper.write(Type.INT, 1); // only 1 property + wrapper.write(Type.STRING, "generic.armor"); + wrapper.write(Type.DOUBLE, 0D); //default 0 armor + wrapper.write(Type.VAR_INT, 1); // 1 modifier + wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid + wrapper.write(Type.DOUBLE, (double) armor); // the modifier value + wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 = add number + wrapper.scheduleSend(Protocol1_9To1_8.class); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent e) { HumanEntity human = e.getWhoClicked(); - if (human instanceof Player && e.getInventory() instanceof CraftingInventory) { - final Player player = (Player) human; - if (e.getCurrentItem() != null) { - if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) { - sendDelayedArmorUpdate(player); - return; - } - } - if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) { + if (human instanceof final Player player && e.getInventory() instanceof CraftingInventory) { + if ((e.getCurrentItem() != null && ArmorType.isArmor(e.getCurrentItem().getTypeId())) + || (e.getRawSlot() >= 5 && e.getRawSlot() <= 8)) { sendDelayedArmorUpdate(player); } } @@ -95,12 +84,13 @@ public class ArmorListener extends ViaBukkitListener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInteract(PlayerInteractEvent e) { - if (e.getItem() != null) { - if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { - final Player player = e.getPlayer(); - // Due to odd bugs it's 3 ticks later - Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> sendArmorUpdate(player), 3L); - } + if (e.getItem() == null) { + return; + } + if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) { + final Player player = e.getPlayer(); + // Due to odd bugs it's 3 ticks later + Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> sendArmorUpdate(player), 3L); } } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java index 0110c623c..c3b096d76 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java @@ -46,12 +46,14 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { private static final boolean FOLIA = PaperViaInjector.hasClass("io.papermc.paper.threadedregions.RegionizedServer"); @@ -282,7 +284,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform return protocolSupport; } - @Deprecated/*(forRemoval = true)*/ + /** + * @deprecated use {@link Via#getAPI()} instead + */ + @Deprecated(forRemoval = true) public static ViaVersionPlugin getInstance() { return instance; } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/commands/BukkitCommandSender.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/commands/BukkitCommandSender.java index 2466c6f93..d0162a7a1 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/commands/BukkitCommandSender.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/commands/BukkitCommandSender.java @@ -22,12 +22,7 @@ import java.util.UUID; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; -public class BukkitCommandSender implements ViaCommandSender { - private final CommandSender sender; - - public BukkitCommandSender(CommandSender sender) { - this.sender = sender; - } +public record BukkitCommandSender(CommandSender sender) implements ViaCommandSender { @Override public boolean hasPermission(String permission) { @@ -41,8 +36,8 @@ public class BukkitCommandSender implements ViaCommandSender { @Override public UUID getUUID() { - if (sender instanceof Entity) { - return ((Entity) sender).getUniqueId(); + if (sender instanceof Entity entity) { + return entity.getUniqueId(); } else { return new UUID(0, 0); } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java index 0dff937eb..cf757ef99 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/handlers/BukkitChannelInitializer.java @@ -75,7 +75,7 @@ public final class BukkitChannelInitializer extends ChannelInitializer new ProtocolPipelineImpl(connection); if (PaperViaInjector.PAPER_PACKET_LIMITER) { - connection.setPacketLimiterEnabled(false); + connection.getPacketTracker().setPacketLimiterEnabled(false); } // Add our transformers diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java index 5fdae1672..959bd118a 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java @@ -50,11 +50,10 @@ public class JoinListener implements Listener { connectionField = findField(true, gamePacketListenerField.getType(), "NetworkManager", "Connection"); channelField = findField(connectionField.getType(), Class.forName("io.netty.channel.Channel")); } catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) { - Via.getPlatform().getLogger().log( - Level.WARNING, - "Couldn't find reflection methods/fields to access Channel from player.\n" + - "Login race condition fixer will be disabled.\n" + - " Some plugins that use ViaAPI on join event may work incorrectly.", e); + Via.getPlatform().getLogger().log(Level.WARNING, """ + Couldn't find reflection methods/fields to access Channel from player. + Login race condition fixer will be disabled. + Some plugins that use ViaAPI on join event may work incorrectly.""", e); } GET_HANDLE = getHandleMethod; CONNECTION = gamePacketListenerField; @@ -109,7 +108,7 @@ public class JoinListener implements Listener { channel = getChannel(player); } catch (Exception ex) { Via.getPlatform().getLogger().log(Level.WARNING, ex, - () -> "Could not find Channel for logging-in player " + player.getUniqueId()); + () -> "Could not find Channel for logging-in player " + player.getUniqueId()); return; } // The connection has already closed, that was a quick leave @@ -118,8 +117,8 @@ public class JoinListener implements Listener { UserConnection user = getUserConnection(channel); if (user == null) { Via.getPlatform().getLogger().log(Level.WARNING, - "Could not find UserConnection for logging-in player {0}", - player.getUniqueId()); + "Could not find UserConnection for logging-in player {0}", + player.getUniqueId()); return; } ProtocolInfo info = user.getProtocolInfo(); diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java index 7807660fb..c35bc7dad 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java @@ -49,45 +49,40 @@ public class EntityToggleGlideListener extends ViaBukkitListener { @EventHandler(priority = EventPriority.MONITOR) public void entityToggleGlide(EntityToggleGlideEvent event) { - if (!(event.getEntity() instanceof Player)) return; + if (!(event.getEntity() instanceof Player player)) return; - Player player = (Player) event.getEntity(); if (!isOnPipe(player)) return; // Cancelling can only be done by updating the player's metadata if (event.isGliding() && event.isCancelled()) { PacketWrapper packet = PacketWrapper.create(ClientboundPackets1_15.ENTITY_METADATA, null, getUserConnection(player)); - try { - packet.write(Type.VAR_INT, player.getEntityId()); + packet.write(Type.VAR_INT, player.getEntityId()); - byte bitmask = 0; - // Collect other metadata for the mitmask - if (player.getFireTicks() > 0) { - bitmask |= 0x01; - } - if (player.isSneaking()) { - bitmask |= 0x02; - } - // 0x04 is unused - if (player.isSprinting()) { - bitmask |= 0x08; - } - if (swimmingMethodExists && player.isSwimming()) { - bitmask |= 0x10; - } - if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { - bitmask |= 0x20; - } - if (player.isGlowing()) { - bitmask |= 0x40; - } - - // leave 0x80 as 0 to stop gliding - packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, Types1_14.META_TYPES.byteType, bitmask))); - packet.scheduleSend(Protocol1_15To1_14_4.class); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send entity glide fix metadata", e); + byte bitmask = 0; + // Collect other metadata for the mitmask + if (player.getFireTicks() > 0) { + bitmask |= 0x01; } + if (player.isSneaking()) { + bitmask |= 0x02; + } + // 0x04 is unused + if (player.isSprinting()) { + bitmask |= 0x08; + } + if (swimmingMethodExists && player.isSwimming()) { + bitmask |= 0x10; + } + if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { + bitmask |= 0x20; + } + if (player.isGlowing()) { + bitmask |= 0x40; + } + + // leave 0x80 as 0 to stop gliding + packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, Types1_14.META_TYPES.byteType, bitmask))); + packet.scheduleSend(Protocol1_15To1_14_4.class); } } } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java index 2852e26e4..a5fd603ee 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTask.java @@ -22,17 +22,7 @@ import com.viaversion.viaversion.api.platform.PlatformTask; import org.bukkit.scheduler.BukkitTask; import org.checkerframework.checker.nullness.qual.Nullable; -public class BukkitViaTask implements PlatformTask { - private final BukkitTask task; - - public BukkitViaTask(@Nullable BukkitTask task) { - this.task = task; - } - - @Override - public @Nullable BukkitTask getObject() { - return task; - } +public record BukkitViaTask(BukkitTask task) implements PlatformTask { @Override public void cancel() { diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTaskTask.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTaskTask.java index 2982eae1f..8e7c796d1 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTaskTask.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaTaskTask.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.bukkit.platform; import com.viaversion.viaversion.api.platform.PlatformTask; import com.viaversion.viaversion.api.scheduler.Task; -import org.checkerframework.checker.nullness.qual.Nullable; public class BukkitViaTaskTask implements PlatformTask { private final Task task; @@ -28,11 +27,6 @@ public class BukkitViaTaskTask implements PlatformTask { this.task = task; } - @Override - public @Nullable Task getObject() { - return task; - } - @Override public void cancel() { task.cancel(); diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java index af1263501..c70d7eec8 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/providers/BukkitInventoryQuickMoveProvider.java @@ -97,7 +97,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider return null; } InventoryView inv = p.getOpenInventory(); - short slotId = storage.getSlotId(); + short slotId = storage.slotId(); Inventory tinv = inv.getTopInventory(); InventoryType tinvtype = tinv == null ? null : tinv.getType(); // can this even be null? if (tinvtype != null) { @@ -125,10 +125,10 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider try { packet = windowClickPacketClass.getDeclaredConstructor().newInstance(); Object nmsItem = itemstack == null ? null : nmsItemMethod.invoke(null, itemstack); - ReflectionUtil.set(packet, "a", (int) storage.getWindowId()); + ReflectionUtil.set(packet, "a", (int) storage.windowId()); ReflectionUtil.set(packet, "slot", (int) slotId); ReflectionUtil.set(packet, "button", 0); // shift + left mouse click - ReflectionUtil.set(packet, "d", storage.getActionId()); + ReflectionUtil.set(packet, "d", storage.actionId()); ReflectionUtil.set(packet, "item", nmsItem); final ProtocolVersion protocol = Via.getAPI().getServerVersion().lowestSupportedProtocolVersion(); if (protocol.equalTo(ProtocolVersion.v1_8)) { diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java index 43cb66954..7a2b2a3e3 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandHandler.java @@ -21,6 +21,7 @@ import com.viaversion.viaversion.bungee.commands.subs.ProbeSubCmd; import com.viaversion.viaversion.commands.ViaCommandHandler; public class BungeeCommandHandler extends ViaCommandHandler { + public BungeeCommandHandler() { registerSubCommand(new ProbeSubCmd()); } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandSender.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandSender.java index 44b1516a4..a3abe64ed 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandSender.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/BungeeCommandSender.java @@ -22,12 +22,7 @@ import java.util.UUID; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; -public class BungeeCommandSender implements ViaCommandSender { - private final CommandSender sender; - - public BungeeCommandSender(CommandSender sender) { - this.sender = sender; - } +public record BungeeCommandSender(CommandSender sender) implements ViaCommandSender { @Override public boolean hasPermission(String permission) { @@ -41,8 +36,8 @@ public class BungeeCommandSender implements ViaCommandSender { @Override public UUID getUUID() { - if (sender instanceof ProxiedPlayer) { - return ((ProxiedPlayer) sender).getUniqueId(); + if (sender instanceof ProxiedPlayer player) { + return player.getUniqueId(); } else { return new UUID(0, 0); } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/subs/ProbeSubCmd.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/subs/ProbeSubCmd.java index cb0da1bb9..7c19e81f3 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/subs/ProbeSubCmd.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/commands/subs/ProbeSubCmd.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.bungee.platform.BungeeViaConfig; -public class ProbeSubCmd extends ViaSubCommand { +public class ProbeSubCmd implements ViaSubCommand { @Override public String name() { return "probe"; diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java index a39dcf641..3f7fa4421 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/handlers/BungeeServerHandler.java @@ -35,14 +35,15 @@ 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.providers.EntityIdProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.logging.Level; import java.util.stream.Collectors; @@ -54,32 +55,37 @@ import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.score.Team; import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.PluginMessage; // All of this is madness public class BungeeServerHandler implements Listener { - private static final Method getHandshake; - private static final Method getRegisteredChannels; - private static final Method getBrandMessage; - private static final Method setProtocol; - private static final Method getEntityMap; - private static final Method setVersion; - private static final Field entityRewrite; - private static final Field channelWrapper; + private static final MethodHandle GET_HANDSHAKE; + private static final MethodHandle GET_REGISTERED_CHANNELS; + private static final MethodHandle GET_BRAND_MESSAGE; + private static final MethodHandle GET_ENTITY_MAP; + private static final MethodHandle SET_VERSION; + private static final MethodHandle SET_ENTITY_REWRITE; + private static final MethodHandle GET_CHANNEL_WRAPPER; static { try { - getHandshake = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getHandshake"); - getRegisteredChannels = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getRegisteredChannels"); - getBrandMessage = Class.forName("net.md_5.bungee.connection.InitialHandler").getDeclaredMethod("getBrandMessage"); - setProtocol = Class.forName("net.md_5.bungee.protocol.packet.Handshake").getDeclaredMethod("setProtocolVersion", int.class); - getEntityMap = Class.forName("net.md_5.bungee.entitymap.EntityMap").getDeclaredMethod("getEntityMap", int.class); - setVersion = Class.forName("net.md_5.bungee.netty.ChannelWrapper").getDeclaredMethod("setVersion", int.class); - channelWrapper = Class.forName("net.md_5.bungee.UserConnection").getDeclaredField("ch"); - channelWrapper.setAccessible(true); - entityRewrite = Class.forName("net.md_5.bungee.UserConnection").getDeclaredField("entityRewrite"); - entityRewrite.setAccessible(true); - } catch (ReflectiveOperationException e) { + final MethodHandles.Lookup lookup = MethodHandles.lookup(); + final Class initialHandlerClass = Class.forName("net.md_5.bungee.connection.InitialHandler"); + GET_HANDSHAKE = lookup.findVirtual(initialHandlerClass, "getHandshake", MethodType.methodType(Handshake.class)); + GET_REGISTERED_CHANNELS = lookup.findVirtual(initialHandlerClass, "getRegisteredChannels", MethodType.methodType(Set.class)); + GET_BRAND_MESSAGE = lookup.findVirtual(initialHandlerClass, "getBrandMessage", MethodType.methodType(PluginMessage.class)); + + final Class entityMapClass = Class.forName("net.md_5.bungee.entitymap.EntityMap"); + final Class channelWrapperClass = Class.forName("net.md_5.bungee.netty.ChannelWrapper"); + GET_ENTITY_MAP = lookup.findStatic(entityMapClass, "getEntityMap", MethodType.methodType(entityMapClass, int.class)); + SET_VERSION = lookup.findVirtual(channelWrapperClass, "setVersion", MethodType.methodType(void.class, int.class)); + + final Class userConnectionClass = Class.forName("net.md_5.bungee.UserConnection"); + final MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(userConnectionClass, lookup); + GET_CHANNEL_WRAPPER = privateLookup.findGetter(userConnectionClass, "ch", channelWrapperClass); + SET_ENTITY_REWRITE = privateLookup.findSetter(userConnectionClass, "entityRewrite", entityMapClass); + } catch (final ReflectiveOperationException e) { Via.getPlatform().getLogger().severe("Error initializing BungeeServerHandler, try updating BungeeCord or ViaVersion!"); throw new RuntimeException(e); } @@ -107,9 +113,9 @@ public class BungeeServerHandler implements Listener { // Check if ViaVersion can support that version try { - Object handshake = getHandshake.invoke(event.getPlayer().getPendingConnection()); - setProtocol.invoke(handshake, protocols == null ? clientProtocolVersion.getVersion() : serverProtocolVersion.getVersion()); - } catch (InvocationTargetException | IllegalAccessException e) { + Handshake handshake = (Handshake) GET_HANDSHAKE.invoke(event.getPlayer().getPendingConnection()); + handshake.setProtocolVersion(protocols == null ? clientProtocolVersion.getVersion() : serverProtocolVersion.getVersion()); + } catch (Throwable e) { Via.getPlatform().getLogger().log(Level.SEVERE, "Error setting handshake version", e); } } @@ -118,7 +124,7 @@ public class BungeeServerHandler implements Listener { public void onServerConnected(ServerConnectedEvent event) { try { checkServerChange(event, Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId())); - } catch (Exception e) { + } catch (Throwable e) { Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to handle server switch", e); } } @@ -144,13 +150,13 @@ public class BungeeServerHandler implements Listener { // For ViaRewind for (StorableObject object : userConnection.getStoredObjects().values()) { - if (object instanceof ClientEntityIdChangeListener) { - ((ClientEntityIdChangeListener) object).setClientEntityId(playerId); + if (object instanceof ClientEntityIdChangeListener listener) { + listener.setClientEntityId(playerId); } } } - public void checkServerChange(ServerConnectedEvent event, UserConnection user) throws Exception { + public void checkServerChange(ServerConnectedEvent event, UserConnection user) throws Throwable { if (user == null) { return; } @@ -212,7 +218,7 @@ public class BungeeServerHandler implements Listener { boolean toNewId = previousServerProtocol.olderThan(ProtocolVersion.v1_13) && serverProtocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_13); boolean toOldId = previousServerProtocol.newerThanOrEqualTo(ProtocolVersion.v1_13) && serverProtocolVersion.olderThan(ProtocolVersion.v1_13); if (previousServerProtocol.isKnown() && (toNewId || toOldId)) { - Collection registeredChannels = (Collection) getRegisteredChannels.invoke(event.getPlayer().getPendingConnection()); + Collection registeredChannels = (Collection) GET_REGISTERED_CHANNELS.invoke(event.getPlayer().getPendingConnection()); if (!registeredChannels.isEmpty()) { Collection newChannels = new HashSet<>(); for (Iterator iterator = registeredChannels.iterator(); iterator.hasNext(); ) { @@ -235,7 +241,7 @@ public class BungeeServerHandler implements Listener { registeredChannels.addAll(newChannels); } - PluginMessage brandMessage = (PluginMessage) getBrandMessage.invoke(event.getPlayer().getPendingConnection()); + PluginMessage brandMessage = (PluginMessage) GET_BRAND_MESSAGE.invoke(event.getPlayer().getPendingConnection()); if (brandMessage != null) { String channel = brandMessage.getTag(); if (toNewId) { @@ -276,10 +282,10 @@ public class BungeeServerHandler implements Listener { } } - Object wrapper = channelWrapper.get(player); - setVersion.invoke(wrapper, serverProtocolVersion.getVersion()); + Object wrapper = GET_CHANNEL_WRAPPER.invoke(player); + SET_VERSION.invoke(wrapper, serverProtocolVersion.getVersion()); - Object entityMap = getEntityMap.invoke(null, serverProtocolVersion.getVersion()); - entityRewrite.set(player, entityMap); + Object entityMap = GET_ENTITY_MAP.invoke(serverProtocolVersion.getVersion()); + SET_ENTITY_REWRITE.invoke(player, entityMap); } } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/listeners/ElytraPatch.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/listeners/ElytraPatch.java index a5f560ee0..498110ee0 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/listeners/ElytraPatch.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/listeners/ElytraPatch.java @@ -44,20 +44,16 @@ public class ElytraPatch implements Listener { UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId()); if (user == null) return; - try { - if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { - EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class); - int entityId = tracker.getProvidedEntityId(); + if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { + EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class); + int entityId = tracker.getProvidedEntityId(); - PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user); + PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, null, user); - wrapper.write(Type.VAR_INT, entityId); - wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); + wrapper.write(Type.VAR_INT, entityId); + wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); - wrapper.scheduleSend(Protocol1_9To1_8.class); - } - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send elytra patch metadata packet!", e); + wrapper.scheduleSend(Protocol1_9To1_8.class); } } } diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaConfig.java index bd4673419..9a53cc525 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaConfig.java @@ -57,8 +57,8 @@ public class BungeeViaConfig extends AbstractViaConfig { // Convert any bad Protocol Ids for (Map.Entry entry : new HashSet<>(servers.entrySet())) { if (!(entry.getValue() instanceof Integer)) { - if (entry.getValue() instanceof String) { - ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue()); + if (entry.getValue() instanceof String stringValue) { + ProtocolVersion found = ProtocolVersion.getClosest(stringValue); if (found != null) { servers.put(entry.getKey(), found.getVersion()); } else { diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaInjector.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaInjector.java index 21ddb25de..db009d84e 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaInjector.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaInjector.java @@ -51,10 +51,14 @@ public class BungeeViaInjector implements ViaInjector { } @Override - @SuppressWarnings("unchecked") public void inject() throws ReflectiveOperationException { Set listeners = (Set) LISTENERS_FIELD.get(ProxyServer.getInstance()); + // Iterate through current list + for (Channel channel : listeners) { + injectChannel(channel); + } + // Inject the list Set wrapper = new SetWrapper<>(listeners, channel -> { try { @@ -65,11 +69,6 @@ public class BungeeViaInjector implements ViaInjector { }); LISTENERS_FIELD.set(ProxyServer.getInstance(), wrapper); - - // Iterate through current list - for (Channel channel : listeners) { - injectChannel(channel); - } } @Override @@ -106,18 +105,18 @@ public class BungeeViaInjector implements ViaInjector { ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); this.injectedChannels.add(channel); - } catch (NoSuchFieldException e) { + } catch (NoSuchFieldException ignored) { throw new RuntimeException("Unable to find core component 'childHandler', please check your plugins. issue: " + bootstrapAcceptor.getClass().getName()); } } @Override - public ProtocolVersion getServerProtocolVersion() throws Exception { + public ProtocolVersion getServerProtocolVersion() throws ReflectiveOperationException { return ProtocolVersion.getProtocol(getBungeeSupportedVersions().get(0)); } @Override - public SortedSet getServerProtocolVersions() throws Exception { + public SortedSet getServerProtocolVersions() throws ReflectiveOperationException { final SortedSet versions = new ObjectLinkedOpenHashSet<>(); for (final Integer version : getBungeeSupportedVersions()) { versions.add(ProtocolVersion.getProtocol(version)); @@ -125,8 +124,7 @@ public class BungeeViaInjector implements ViaInjector { return versions; } - @SuppressWarnings("unchecked") - private List getBungeeSupportedVersions() throws Exception { + private List getBungeeSupportedVersions() throws ReflectiveOperationException { return ReflectionUtil.getStatic(Class.forName("net.md_5.bungee.protocol.ProtocolConstants"), "SUPPORTED_VERSION_IDS", List.class); } @@ -157,8 +155,8 @@ public class BungeeViaInjector implements ViaInjector { try { Object child = ReflectionUtil.get(channelHandler, "childHandler", ChannelInitializer.class); handlerInfo.addProperty("childClass", child.getClass().getName()); - if (child instanceof BungeeChannelInitializer) { - handlerInfo.addProperty("oldInit", ((BungeeChannelInitializer) child).getOriginal().getClass().getName()); + if (child instanceof BungeeChannelInitializer bungeeChannelInitializer) { + handlerInfo.addProperty("oldInit", bungeeChannelInitializer.getOriginal().getClass().getName()); } } catch (ReflectiveOperationException e) { // Don't display @@ -176,8 +174,8 @@ public class BungeeViaInjector implements ViaInjector { try { Object list = LISTENERS_FIELD.get(ProxyServer.getInstance()); data.addProperty("currentList", list.getClass().getName()); - if (list instanceof SetWrapper) { - data.addProperty("wrappedList", ((SetWrapper) list).originalSet().getClass().getName()); + if (list instanceof SetWrapper wrapper) { + data.addProperty("wrappedList", wrapper.originalSet().getClass().getName()); } } catch (ReflectiveOperationException ignored) { // Ignored diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java index 53dc4b14b..7294c8110 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/platform/BungeeViaTask.java @@ -20,17 +20,7 @@ package com.viaversion.viaversion.bungee.platform; import com.viaversion.viaversion.api.platform.PlatformTask; import net.md_5.bungee.api.scheduler.ScheduledTask; -public class BungeeViaTask implements PlatformTask { - private final ScheduledTask task; - - public BungeeViaTask(ScheduledTask task) { - this.task = task; - } - - @Override - public ScheduledTask getObject() { - return task; - } +public record BungeeViaTask(ScheduledTask task) implements PlatformTask { @Override public void cancel() { diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java index 087b1d7dd..c78e8d10a 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viaversion.protocols.base.BaseVersionProvider; +import com.viaversion.viaversion.protocol.version.BaseVersionProvider; import com.viaversion.viaversion.util.ReflectionUtil; import java.util.ArrayList; import java.util.Collections; diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/service/ProtocolDetectorService.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/service/ProtocolDetectorService.java index 9cb68df8f..30cc097a9 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/service/ProtocolDetectorService.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/service/ProtocolDetectorService.java @@ -56,7 +56,7 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi } // Ensure we're the only ones writing to the config - synchronized (Via.getPlatform().getConfigurationProvider()) { + synchronized (Via.getManager().getConfigurationProvider()) { servers.put(serverName, serverPing.getVersion().getProtocol()); } config.save(); diff --git a/common/build.gradle.kts b/common/build.gradle.kts index a8d08d1c7..911d93cc3 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,6 +1,5 @@ dependencies { api(projects.viaversionApi) - api(projects.viaversionApiLegacy) api(rootProject.libs.text) { exclude("com.google.code.gson", "gson") } diff --git a/common/src/main/java/com/viaversion/viaversion/ViaListener.java b/common/src/main/java/com/viaversion/viaversion/ViaListener.java index 0447c8cc5..28763c93a 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaListener.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaListener.java @@ -24,7 +24,7 @@ import java.util.UUID; import org.checkerframework.checker.nullness.qual.Nullable; public abstract class ViaListener { - private final Class requiredPipeline; + protected final Class requiredPipeline; private boolean registered; protected ViaListener(Class requiredPipeline) { @@ -58,10 +58,6 @@ public abstract class ViaListener { */ public abstract void register(); - protected Class getRequiredPipeline() { - return requiredPipeline; - } - protected boolean isRegistered() { return registered; } diff --git a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java index 4c8262926..38e4d79e7 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/ViaCommandHandler.java @@ -115,7 +115,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand { if (args.length == 1) { if (!args[0].isEmpty()) { for (ViaSubCommand sub : allowed) { - if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT))) { + if (sub.name().toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))) { output.add(sub.name()); } } diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java index 70482ec59..9dc0982ab 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/AutoTeamSubCmd.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.util.Config; -public class AutoTeamSubCmd extends ViaSubCommand { +public class AutoTeamSubCmd implements ViaSubCommand { @Override public String name() { return "autoteam"; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DebugSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DebugSubCmd.java index 4f84542c1..d8a8f55d6 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DebugSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DebugSubCmd.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; -public class DebugSubCmd extends ViaSubCommand { +public class DebugSubCmd implements ViaSubCommand { @Override public String name() { return "debug"; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java index 0ace74614..4ad96d9e6 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DisplayLeaksSubCmd.java @@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import io.netty.util.ResourceLeakDetector; -public class DisplayLeaksSubCmd extends ViaSubCommand { +public class DisplayLeaksSubCmd implements ViaSubCommand { @Override public String name() { return "displayleaks"; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java index 63b7ea542..3e64c2ce8 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DontBugMeSubCmd.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.api.configuration.ViaVersionConfig; -public class DontBugMeSubCmd extends ViaSubCommand { +public class DontBugMeSubCmd implements ViaSubCommand { @Override public String name() { diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DumpSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DumpSubCmd.java index f0dcd6227..26c7bae7c 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DumpSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/DumpSubCmd.java @@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.util.DumpUtil; -public class DumpSubCmd extends ViaSubCommand { +public class DumpSubCmd implements ViaSubCommand { @Override public String name() { diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java index 118a55bfe..81d9002b3 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ListSubCmd.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; -public class ListSubCmd extends ViaSubCommand { +public class ListSubCmd implements ViaSubCommand { @Override public String name() { return "list"; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java index cf3da1246..a3eb9b555 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/PPSSubCmd.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; -public class PPSSubCmd extends ViaSubCommand { +public class PPSSubCmd implements ViaSubCommand { @Override public String name() { return "pps"; diff --git a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java index b011ac8d7..2c0817a66 100644 --- a/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java +++ b/common/src/main/java/com/viaversion/viaversion/commands/defaultsubs/ReloadSubCmd.java @@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; -public class ReloadSubCmd extends ViaSubCommand { +public class ReloadSubCmd implements ViaSubCommand { @Override public String name() { return "reload"; @@ -34,7 +34,7 @@ public class ReloadSubCmd extends ViaSubCommand { @Override public boolean execute(ViaCommandSender sender, String[] args) { - Via.getPlatform().getConfigurationProvider().reloadConfigs(); + Via.getManager().getConfigurationProvider().reloadConfigs(); sendMessage(sender, "&6Configuration successfully reloaded! Some features may need a restart."); return true; } diff --git a/common/src/main/java/com/viaversion/viaversion/connection/ProtocolInfoImpl.java b/common/src/main/java/com/viaversion/viaversion/connection/ProtocolInfoImpl.java index 285560329..064267cdc 100644 --- a/common/src/main/java/com/viaversion/viaversion/connection/ProtocolInfoImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/connection/ProtocolInfoImpl.java @@ -19,14 +19,12 @@ package com.viaversion.viaversion.connection; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.ProtocolInfo; -import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.ProtocolPipeline; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import java.util.UUID; public class ProtocolInfoImpl implements ProtocolInfo { - private final UserConnection connection; private State clientState = State.HANDSHAKE; private State serverState = State.HANDSHAKE; private ProtocolVersion serverProtocolVersion = ProtocolVersion.unknown; @@ -35,10 +33,6 @@ public class ProtocolInfoImpl implements ProtocolInfo { private UUID uuid; private ProtocolPipeline pipeline; - public ProtocolInfoImpl(final UserConnection connection) { - this.connection = connection; - } - @Override public State getClientState() { return clientState; @@ -115,11 +109,6 @@ public class ProtocolInfoImpl implements ProtocolInfo { this.pipeline = pipeline; } - @Override - public UserConnection getUser() { - return connection; - } - @Override public String toString() { return "ProtocolInfo{" + diff --git a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java index 38d26a890..9bd964a71 100644 --- a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java @@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.exception.InformativeException; import com.viaversion.viaversion.protocol.packet.PacketWrapperImpl; import com.viaversion.viaversion.util.ChatColorUtil; import com.viaversion.viaversion.util.PipelineUtil; @@ -37,6 +38,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.CodecException; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -58,12 +60,11 @@ public class UserConnectionImpl implements UserConnection { private final Set passthroughTokens = Collections.newSetFromMap(CacheBuilder.newBuilder() .expireAfterWrite(10, TimeUnit.SECONDS) .build().asMap()); - private final ProtocolInfo protocolInfo = new ProtocolInfoImpl(this); + private final ProtocolInfo protocolInfo = new ProtocolInfoImpl(); private final Channel channel; private final boolean clientSide; private boolean active = true; private boolean pendingDisconnect; - private boolean packetLimiterEnabled = true; /** * Creates an UserConnection. When it's a client-side connection, some method behaviors are modified. @@ -236,12 +237,8 @@ public class UserConnectionImpl implements UserConnection { if (shouldTransformPacket()) { // Bypass serverbound packet decoder transforming - try { - Type.VAR_INT.writePrimitive(buf, PacketWrapper.PASSTHROUGH_ID); - Type.UUID.write(buf, generatePassthroughToken()); - } catch (Exception shouldNotHappen) { - throw new RuntimeException(shouldNotHappen); - } + Type.VAR_INT.writePrimitive(buf, PacketWrapper.PASSTHROUGH_ID); + Type.UUID.write(buf, generatePassthroughToken()); } buf.writeBytes(packet); @@ -289,7 +286,7 @@ public class UserConnectionImpl implements UserConnection { return false; } // Increment received + Check PPS - return !packetLimiterEnabled || !packetTracker.incrementReceived() || !packetTracker.exceedsMaxPPS(); + return !packetTracker.isPacketLimiterEnabled() || !packetTracker.incrementReceived() || !packetTracker.exceedsMaxPPS(); } @Override @@ -304,17 +301,19 @@ public class UserConnectionImpl implements UserConnection { } @Override - public void transformClientbound(ByteBuf buf, Function cancelSupplier) throws Exception { + public void transformClientbound(ByteBuf buf, Function cancelSupplier) throws InformativeException, CodecException { transform(buf, Direction.CLIENTBOUND, cancelSupplier); } @Override - public void transformServerbound(ByteBuf buf, Function cancelSupplier) throws Exception { + public void transformServerbound(ByteBuf buf, Function cancelSupplier) throws InformativeException, CodecException { transform(buf, Direction.SERVERBOUND, cancelSupplier); } - private void transform(ByteBuf buf, Direction direction, Function cancelSupplier) throws Exception { - if (!buf.isReadable()) return; + private void transform(ByteBuf buf, Direction direction, Function cancelSupplier) throws InformativeException, CodecException { + if (!buf.isReadable()) { + return; + } int id = Type.VAR_INT.readPrimitive(buf); if (id == PacketWrapper.PASSTHROUGH_ID) { @@ -391,16 +390,6 @@ public class UserConnectionImpl implements UserConnection { return !clientSide; // Don't apply protocol blocking on client-side } - @Override - public boolean isPacketLimiterEnabled() { - return packetLimiterEnabled; - } - - @Override - public void setPacketLimiterEnabled(boolean packetLimiterEnabled) { - this.packetLimiterEnabled = packetLimiterEnabled; - } - @Override public UUID generatePassthroughToken() { UUID token = UUID.randomUUID(); diff --git a/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java b/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java index 304fbfcbf..62a56c2aa 100644 --- a/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java +++ b/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java @@ -20,38 +20,6 @@ package com.viaversion.viaversion.dump; import com.google.gson.JsonObject; import java.util.Map; -public class DumpTemplate { - private final VersionInfo versionInfo; - private final Map configuration; - private final JsonObject platformDump; - private final JsonObject injectionDump; - private final JsonObject playerSample; - - public DumpTemplate(VersionInfo versionInfo, Map configuration, JsonObject platformDump, JsonObject injectionDump, JsonObject playerSample) { - this.versionInfo = versionInfo; - this.configuration = configuration; - this.platformDump = platformDump; - this.injectionDump = injectionDump; - this.playerSample = playerSample; - } - - public VersionInfo getVersionInfo() { - return versionInfo; - } - - public Map getConfiguration() { - return configuration; - } - - public JsonObject getPlatformDump() { - return platformDump; - } - - public JsonObject getInjectionDump() { - return injectionDump; - } - - public JsonObject getPlayerSample() { - return playerSample; - } +public record DumpTemplate(VersionInfo versionInfo, Map configuration, + JsonObject platformDump, JsonObject injectionDump, JsonObject playerSample) { } diff --git a/common/src/main/java/com/viaversion/viaversion/dump/PluginInfo.java b/common/src/main/java/com/viaversion/viaversion/dump/PluginInfo.java index 55d25e2dd..a55a0746e 100644 --- a/common/src/main/java/com/viaversion/viaversion/dump/PluginInfo.java +++ b/common/src/main/java/com/viaversion/viaversion/dump/PluginInfo.java @@ -19,38 +19,5 @@ package com.viaversion.viaversion.dump; import java.util.List; -public class PluginInfo { - private final boolean enabled; - private final String name; - private final String version; - private final String main; - private final List authors; - - public PluginInfo(boolean enabled, String name, String version, String main, List authors) { - this.enabled = enabled; - this.name = name; - this.version = version; - this.main = main; - this.authors = authors; - } - - public boolean isEnabled() { - return enabled; - } - - public String getName() { - return name; - } - - public String getVersion() { - return version; - } - - public String getMain() { - return main; - } - - public List getAuthors() { - return authors; - } +public record PluginInfo(boolean enabled, String name, String version, String main, List authors) { } diff --git a/common/src/main/java/com/viaversion/viaversion/dump/VersionInfo.java b/common/src/main/java/com/viaversion/viaversion/dump/VersionInfo.java index 65651ee84..07ce2b3de 100644 --- a/common/src/main/java/com/viaversion/viaversion/dump/VersionInfo.java +++ b/common/src/main/java/com/viaversion/viaversion/dump/VersionInfo.java @@ -20,77 +20,10 @@ package com.viaversion.viaversion.dump; import com.viaversion.viaversion.api.protocol.version.VersionType; import java.util.Set; -public class VersionInfo { - private final String javaVersion; - private final String operatingSystem; - private final VersionType versionType; - private final int serverProtocol; - private final String serverVersion; - private final Set enabledVersions; - private final String platformName; - private final String platformVersion; - private final String pluginVersion; - private final String implementationVersion; - private final Set subPlatforms; - - public VersionInfo(String javaVersion, String operatingSystem, VersionType versionType, int serverProtocol, String serverVersion, - Set enabledVersions, String platformName, String platformVersion, String pluginVersion, String implementationVersion, - Set subPlatforms) { - this.javaVersion = javaVersion; - this.operatingSystem = operatingSystem; - this.serverProtocol = serverProtocol; - this.versionType = versionType; - this.serverVersion = serverVersion; - this.enabledVersions = enabledVersions; - this.platformName = platformName; - this.platformVersion = platformVersion; - this.pluginVersion = pluginVersion; - this.implementationVersion = implementationVersion; - this.subPlatforms = subPlatforms; - } - - public String getJavaVersion() { - return javaVersion; - } - - public String getOperatingSystem() { - return operatingSystem; - } - - public VersionType getVersionType() { - return versionType; - } - - public int getServerProtocol() { - return serverProtocol; - } - - public String getServerVersion() { - return serverVersion; - } - - public Set getEnabledVersions() { - return enabledVersions; - } - - public String getPlatformName() { - return platformName; - } - - public String getPlatformVersion() { - return platformVersion; - } - - public String getPluginVersion() { - return pluginVersion; - } - - public String getImplementationVersion() { - return implementationVersion; - } - - public Set getSubPlatforms() { - return subPlatforms; - } +public record VersionInfo(String javaVersion, String operatingSystem, VersionType versionType, + int serverProtocol, String serverVersion, + Set enabledProtocols, String platformName, + String platformVersion, String pluginVersion, + String implementationVersion, Set subPlatforms) { } diff --git a/common/src/main/java/com/viaversion/viaversion/handlers/ChannelHandlerContextWrapper.java b/common/src/main/java/com/viaversion/viaversion/handlers/ChannelHandlerContextWrapper.java index 5d6e78ff8..fe33d37ee 100644 --- a/common/src/main/java/com/viaversion/viaversion/handlers/ChannelHandlerContextWrapper.java +++ b/common/src/main/java/com/viaversion/viaversion/handlers/ChannelHandlerContextWrapper.java @@ -31,6 +31,7 @@ import io.netty.util.AttributeKey; import io.netty.util.concurrent.EventExecutor; import java.net.SocketAddress; +@Deprecated public class ChannelHandlerContextWrapper implements ChannelHandlerContext { private final ChannelHandlerContext base; private final ViaCodecHandler handler; @@ -187,16 +188,16 @@ public class ChannelHandlerContextWrapper implements ChannelHandlerContext { @Override public ChannelFuture write(Object o) { - if (o instanceof ByteBuf) { - if (transform((ByteBuf) o)) return base.newFailedFuture(new Throwable()); + if (o instanceof ByteBuf buf && transform(buf)) { + return base.newFailedFuture(new Throwable()); } return base.write(o); } @Override public ChannelFuture write(Object o, ChannelPromise channelPromise) { - if (o instanceof ByteBuf) { - if (transform((ByteBuf) o)) return base.newFailedFuture(new Throwable()); + if (o instanceof ByteBuf buf && transform(buf)) { + return base.newFailedFuture(new Throwable()); } return base.write(o, channelPromise); } diff --git a/common/src/main/java/com/viaversion/viaversion/handlers/ViaCodecHandler.java b/common/src/main/java/com/viaversion/viaversion/handlers/ViaCodecHandler.java index 9f9a938a3..1ba178f70 100644 --- a/common/src/main/java/com/viaversion/viaversion/handlers/ViaCodecHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/handlers/ViaCodecHandler.java @@ -20,6 +20,7 @@ package com.viaversion.viaversion.handlers; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +@Deprecated public interface ViaCodecHandler { void transform(ByteBuf bytebuf) throws Exception; diff --git a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java index 2e3c62813..6d4396b90 100644 --- a/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java +++ b/common/src/main/java/com/viaversion/viaversion/platform/LegacyViaInjector.java @@ -138,8 +138,8 @@ public abstract class LegacyViaInjector implements ViaInjector { try { ChannelInitializer initializer = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); - if (initializer instanceof WrappedChannelInitializer) { - ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((WrappedChannelInitializer) initializer).original()); + if (initializer instanceof WrappedChannelInitializer wrappedChannelInitializer) { + ReflectionUtil.set(bootstrapAcceptor, "childHandler", wrappedChannelInitializer.original()); } } catch (Exception e) { Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to remove injection handler, reload won't work with connections, please reboot!", e); @@ -203,8 +203,8 @@ public abstract class LegacyViaInjector implements ViaInjector { try { Object child = ReflectionUtil.get(channelHandler, "childHandler", ChannelInitializer.class); handlerInfo.addProperty("childClass", child.getClass().getName()); - if (child instanceof WrappedChannelInitializer) { - handlerInfo.addProperty("oldInit", ((WrappedChannelInitializer) child).original().getClass().getName()); + if (child instanceof WrappedChannelInitializer wrappedChannelInitializer) { + handlerInfo.addProperty("oldInit", wrappedChannelInitializer.original().getClass().getName()); } } catch (ReflectiveOperationException ignored) { // Don't display @@ -222,8 +222,8 @@ public abstract class LegacyViaInjector implements ViaInjector { // Note down the current value (could be overridden by another plugin) currentLists.addProperty(field.getName(), list.getClass().getName()); // Also, if it's not overridden we can display what's inside our list (possibly another plugin) - if (list instanceof SynchronizedListWrapper) { - wrappedLists.addProperty(field.getName(), ((SynchronizedListWrapper) list).originalList().getClass().getName()); + if (list instanceof SynchronizedListWrapper wrapper) { + wrappedLists.addProperty(field.getName(), wrapper.originalList().getClass().getName()); } } data.add("wrappedLists", wrappedLists); diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/BlockedProtocolVersionsImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/BlockedProtocolVersionsImpl.java index 0d1ffcb02..a000785f6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/BlockedProtocolVersionsImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/BlockedProtocolVersionsImpl.java @@ -21,16 +21,8 @@ import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import java.util.Set; -public class BlockedProtocolVersionsImpl implements BlockedProtocolVersions { - private final Set singleBlockedVersions; - private final ProtocolVersion blocksBelow; - private final ProtocolVersion blocksAbove; - - public BlockedProtocolVersionsImpl(final Set singleBlockedVersions, final ProtocolVersion blocksBelow, final ProtocolVersion blocksAbove) { - this.singleBlockedVersions = singleBlockedVersions; - this.blocksBelow = blocksBelow; - this.blocksAbove = blocksAbove; - } +public record BlockedProtocolVersionsImpl(Set singleBlockedVersions, ProtocolVersion blocksBelow, + ProtocolVersion blocksAbove) implements BlockedProtocolVersions { @Override public boolean contains(final ProtocolVersion protocolVersion) { @@ -38,19 +30,4 @@ public class BlockedProtocolVersionsImpl implements BlockedProtocolVersions { || blocksAbove.isKnown() && protocolVersion.newerThan(blocksAbove) || singleBlockedVersions.contains(protocolVersion); } - - @Override - public ProtocolVersion blocksBelow() { - return blocksBelow; - } - - @Override - public ProtocolVersion blocksAbove() { - return blocksAbove; - } - - @Override - public Set singleBlockedVersions() { - return singleBlockedVersions; - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java index e11d464c8..8ddbc2b22 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java @@ -106,7 +106,6 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap; import org.checkerframework.checker.nullness.qual.Nullable; -import us.myles.ViaVersion.api.protocol.ProtocolRegistry; public class ProtocolManagerImpl implements ProtocolManager { private static final Protocol BASE_PROTOCOL = new BaseProtocol(); @@ -384,8 +383,6 @@ public class ProtocolManagerImpl implements ProtocolManager { public void setServerProtocol(ServerProtocolVersion serverProtocolVersion) { this.serverProtocolVersion = serverProtocolVersion; - //noinspection deprecation - ProtocolRegistry.SERVER_PROTOCOL = serverProtocolVersion.lowestSupportedVersion(); } @Override @@ -431,13 +428,13 @@ public class ProtocolManagerImpl implements ProtocolManager { } @Override - public void completeMappingDataLoading(Class protocolClass) throws Exception { + public void completeMappingDataLoading(Class protocolClass) { if (mappingsLoaded) return; CompletableFuture future = getMappingLoaderFuture(protocolClass); if (future != null) { // Wait for completion - future.get(); + future.join(); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathEntryImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathEntryImpl.java index f758c4787..d9e972ec2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathEntryImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathEntryImpl.java @@ -20,46 +20,7 @@ package com.viaversion.viaversion.protocol; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.ProtocolPathEntry; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import java.util.Objects; -public class ProtocolPathEntryImpl implements ProtocolPathEntry { - private final ProtocolVersion outputProtocolVersion; - private final Protocol protocol; - - public ProtocolPathEntryImpl(ProtocolVersion outputProtocolVersion, Protocol protocol) { - this.outputProtocolVersion = outputProtocolVersion; - this.protocol = protocol; - } - - @Override - public ProtocolVersion outputProtocolVersion() { - return outputProtocolVersion; - } - - @Override - public Protocol protocol() { - return protocol; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final ProtocolPathEntryImpl that = (ProtocolPathEntryImpl) o; - if (outputProtocolVersion != that.outputProtocolVersion) return false; - return protocol.equals(that.protocol); - } - - @Override - public int hashCode() { - return Objects.hash(outputProtocolVersion, protocol); - } - - @Override - public String toString() { - return "ProtocolPathEntryImpl{" + - "outputProtocolVersion=" + outputProtocolVersion + - ", protocol=" + protocol + - '}'; - } +public record ProtocolPathEntryImpl(ProtocolVersion outputProtocolVersion, + Protocol protocol) implements ProtocolPathEntry { } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathKeyImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathKeyImpl.java index 9b586dc7a..98bc85747 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathKeyImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPathKeyImpl.java @@ -21,36 +21,5 @@ import com.viaversion.viaversion.api.protocol.ProtocolPathKey; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import java.util.Objects; -public class ProtocolPathKeyImpl implements ProtocolPathKey { - private final ProtocolVersion clientProtocolVersion; - private final ProtocolVersion serverProtocolVersion; - - public ProtocolPathKeyImpl(ProtocolVersion clientProtocolVersion, ProtocolVersion serverProtocolVersion) { - this.clientProtocolVersion = clientProtocolVersion; - this.serverProtocolVersion = serverProtocolVersion; - } - - @Override - public ProtocolVersion clientProtocolVersion() { - return clientProtocolVersion; - } - - @Override - public ProtocolVersion serverProtocolVersion() { - return serverProtocolVersion; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final ProtocolPathKeyImpl that = (ProtocolPathKeyImpl) o; - if (clientProtocolVersion != that.clientProtocolVersion) return false; - return serverProtocolVersion == that.serverProtocolVersion; - } - - @Override - public int hashCode() { - return Objects.hash(clientProtocolVersion, serverProtocolVersion); - } +public record ProtocolPathKeyImpl(ProtocolVersion clientProtocolVersion, ProtocolVersion serverProtocolVersion) implements ProtocolPathKey { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java index fcffa1b6e..70b521415 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolPipelineImpl.java @@ -27,6 +27,8 @@ import com.viaversion.viaversion.api.protocol.ProtocolPipeline; import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.exception.InformativeException; import com.viaversion.viaversion.util.ProtocolUtil; import java.util.ArrayList; import java.util.Collection; @@ -107,7 +109,7 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot } @Override - public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { + public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws InformativeException, CancelException { int originalID = packetWrapper.getId(); DebugHandler debugHandler = Via.getManager().debugHandler(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionRange.java b/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionRange.java index 7603d40e1..51906eb41 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionRange.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionRange.java @@ -21,29 +21,6 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import java.util.SortedSet; -public class ServerProtocolVersionRange implements ServerProtocolVersion { - private final ProtocolVersion lowestSupportedVersion; - private final ProtocolVersion highestSupportedVersion; - private final SortedSet supportedVersions; - - public ServerProtocolVersionRange(ProtocolVersion lowestSupportedVersion, ProtocolVersion highestSupportedVersion, SortedSet supportedVersions) { - this.lowestSupportedVersion = lowestSupportedVersion; - this.highestSupportedVersion = highestSupportedVersion; - this.supportedVersions = supportedVersions; - } - - @Override - public ProtocolVersion lowestSupportedProtocolVersion() { - return lowestSupportedVersion; - } - - @Override - public ProtocolVersion highestSupportedProtocolVersion() { - return highestSupportedVersion; - } - - @Override - public SortedSet supportedProtocolVersions() { - return supportedVersions; - } +public record ServerProtocolVersionRange(ProtocolVersion lowestSupportedProtocolVersion, ProtocolVersion highestSupportedProtocolVersion, + SortedSet supportedProtocolVersions) implements ServerProtocolVersion { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionSingleton.java b/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionSingleton.java index 76048d6de..685bb6a15 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionSingleton.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ServerProtocolVersionSingleton.java @@ -22,12 +22,7 @@ import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet; import java.util.SortedSet; -public class ServerProtocolVersionSingleton implements ServerProtocolVersion { - private final ProtocolVersion protocolVersion; - - public ServerProtocolVersionSingleton(ProtocolVersion protocolVersion) { - this.protocolVersion = protocolVersion; - } +public record ServerProtocolVersionSingleton(ProtocolVersion protocolVersion) implements ServerProtocolVersion { @Override public ProtocolVersion lowestSupportedProtocolVersion() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java index aab6945e5..315c328be 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java @@ -68,7 +68,7 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public T get(Type type, int index) throws Exception { + public T get(Type type, int index) throws InformativeException { int currentIndex = 0; for (PacketValue packetValue : packetValues) { if (packetValue.type() != type) { @@ -115,7 +115,7 @@ public class PacketWrapperImpl implements PacketWrapper { @Override - public void set(Type type, int index, T value) throws Exception { + public void set(Type type, int index, @Nullable T value) throws InformativeException { int currentIndex = 0; for (PacketValue packetValue : packetValues) { if (packetValue.type() != type) { @@ -131,7 +131,7 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public T read(Type type) throws Exception { + public T read(Type type) { if (readableObjects.isEmpty()) { Preconditions.checkNotNull(inputBuffer, "This packet does not have an input buffer."); // We could in the future log input read values, but honestly for things like bulk maps, mem waste D: @@ -180,14 +180,14 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public T passthrough(Type type) throws Exception { + public T passthrough(Type type) throws InformativeException { T value = read(type); write(type, value); return value; } @Override - public void passthroughAll() throws Exception { + public void passthroughAll() throws InformativeException { // Copy previous objects packetValues.addAll(readableObjects); readableObjects.clear(); @@ -198,7 +198,7 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public void writeToBuffer(ByteBuf buffer) throws Exception { + public void writeToBuffer(ByteBuf buffer) throws InformativeException { if (id != -1) { Type.VAR_INT.writePrimitive(buffer, id); } @@ -248,16 +248,16 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public void send(Class protocol, boolean skipCurrentPipeline) throws Exception { + public void send(Class protocol, boolean skipCurrentPipeline) throws InformativeException { send0(protocol, skipCurrentPipeline, true); } @Override - public void scheduleSend(Class protocol, boolean skipCurrentPipeline) throws Exception { + public void scheduleSend(Class protocol, boolean skipCurrentPipeline) throws InformativeException { send0(protocol, skipCurrentPipeline, false); } - private void send0(Class protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { + private void send0(Class protocol, boolean skipCurrentPipeline, boolean currentThread) throws InformativeException { if (isCancelled()) { return; } @@ -267,9 +267,12 @@ public class PacketWrapperImpl implements PacketWrapper { try { final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND); connection.sendRawPacket(output); - } catch (final Exception e) { + } catch (InformativeException e) { + throw e; + } catch (CancelException ignored) { + } catch (Exception e) { if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw e; + throw new InformativeException(e); } } return; @@ -279,13 +282,12 @@ public class PacketWrapperImpl implements PacketWrapper { try { final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND); connection.sendRawPacket(output); - } catch (final RuntimeException e) { + } catch (InformativeException e) { + throw e; + } catch (CancelException ignored) { + } catch (Exception e) { if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw e; - } - } catch (final Exception e) { - if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw new RuntimeException(e); + throw new InformativeException(e); } } }); @@ -297,9 +299,8 @@ public class PacketWrapperImpl implements PacketWrapper { * @param protocolClass protocol class to send the packet from, or null to go through the full pipeline * @param skipCurrentPipeline whether to start from the next protocol in the pipeline, or the provided one * @return created packet buffer - * @throws Exception if it fails to write */ - private ByteBuf constructPacket(@Nullable Class protocolClass, boolean skipCurrentPipeline, Direction direction) throws Exception { + private ByteBuf constructPacket(@Nullable Class protocolClass, boolean skipCurrentPipeline, Direction direction) throws InformativeException, CancelException { resetReader(); // Reset reader before we start final ProtocolInfo protocolInfo = user().getProtocolInfo(); @@ -315,25 +316,30 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public ChannelFuture sendFuture(Class protocolClass) throws Exception { + public ChannelFuture sendFuture(Class protocolClass) throws InformativeException { if (!isCancelled()) { - ByteBuf output = constructPacket(protocolClass, true, Direction.CLIENTBOUND); + final ByteBuf output; + try { + output = constructPacket(protocolClass, true, Direction.CLIENTBOUND); + } catch (final CancelException e) { + return user().getChannel().newFailedFuture(new RuntimeException("Cancelled packet")); + } return user().sendRawPacketFuture(output); } - return user().getChannel().newFailedFuture(new Exception("Cancelled packet")); + return user().getChannel().newFailedFuture(new RuntimeException("Tried to send cancelled packet")); } @Override - public void sendRaw() throws Exception { + public void sendRaw() throws InformativeException { sendRaw(true); } @Override - public void scheduleSendRaw() throws Exception { + public void scheduleSendRaw() throws InformativeException { sendRaw(false); } - private void sendRaw(boolean currentThread) throws Exception { + private void sendRaw(boolean currentThread) throws InformativeException { if (isCancelled()) { return; } @@ -357,14 +363,14 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public PacketWrapperImpl create(int packetId, PacketHandler handler) throws Exception { + public PacketWrapperImpl create(int packetId, PacketHandler handler) throws InformativeException { PacketWrapperImpl wrapper = create(packetId); handler.handle(wrapper); return wrapper; } @Override - public void apply(Direction direction, State state, List pipeline) throws Exception { + public void apply(Direction direction, State state, List pipeline) throws InformativeException, CancelException { // Indexed loop to allow additions to the tail for (int i = 0, size = pipeline.size(); i < size; i++) { Protocol protocol = pipeline.get(i); @@ -376,30 +382,6 @@ public class PacketWrapperImpl implements PacketWrapper { } } - @Override - @Deprecated - public PacketWrapperImpl apply(Direction direction, State state, int index, List pipeline, boolean reverse) throws Exception { - // Reset the reader after every transformation for the packetWrapper, so it can be recycled across packets - if (reverse) { - for (int i = index; i >= 0; i--) { - pipeline.get(i).transform(direction, state, this); - resetReader(); - if (this.packetType != null) { - state = this.packetType.state(); - } - } - } else { - for (int i = index; i < pipeline.size(); i++) { - pipeline.get(i).transform(direction, state, this); - resetReader(); - if (this.packetType != null) { - state = this.packetType.state(); - } - } - } - return this; - } - @Override public boolean isCancelled() { return !this.send; @@ -425,16 +407,16 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public void sendToServerRaw() throws Exception { + public void sendToServerRaw() throws InformativeException { sendToServerRaw(true); } @Override - public void scheduleSendToServerRaw() throws Exception { + public void scheduleSendToServerRaw() throws InformativeException { sendToServerRaw(false); } - private void sendToServerRaw(boolean currentThread) throws Exception { + private void sendToServerRaw(boolean currentThread) throws InformativeException { if (isCancelled()) { return; } @@ -453,16 +435,16 @@ public class PacketWrapperImpl implements PacketWrapper { } @Override - public void sendToServer(Class protocol, boolean skipCurrentPipeline) throws Exception { + public void sendToServer(Class protocol, boolean skipCurrentPipeline) throws InformativeException { sendToServer0(protocol, skipCurrentPipeline, true); } @Override - public void scheduleSendToServer(Class protocol, boolean skipCurrentPipeline) throws Exception { + public void scheduleSendToServer(Class protocol, boolean skipCurrentPipeline) throws InformativeException { sendToServer0(protocol, skipCurrentPipeline, false); } - private void sendToServer0(Class protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { + private void sendToServer0(Class protocol, boolean skipCurrentPipeline, boolean currentThread) throws InformativeException { if (isCancelled()) { return; } @@ -472,9 +454,12 @@ public class PacketWrapperImpl implements PacketWrapper { try { final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND); connection.sendRawPacketToServer(output); - } catch (final Exception e) { + } catch (InformativeException e) { + throw e; + } catch (CancelException ignored) { + } catch (Exception e) { if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw e; + throw new InformativeException(e); } } return; @@ -484,13 +469,12 @@ public class PacketWrapperImpl implements PacketWrapper { try { final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND); connection.sendRawPacketToServer(output); - } catch (final RuntimeException e) { + } catch (InformativeException e) { + throw e; + } catch (CancelException ignored) { + } catch (Exception e) { if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw e; - } - } catch (final Exception e) { - if (!PipelineUtil.containsCause(e, CancelException.class)) { - throw new RuntimeException(e); + throw new InformativeException(e); } } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/packet/VersionedPacketTransformerImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/packet/VersionedPacketTransformerImpl.java index f9d544309..4dea324a7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/packet/VersionedPacketTransformerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/packet/VersionedPacketTransformerImpl.java @@ -27,13 +27,13 @@ import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.PacketType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; -import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.VersionedPacketTransformer; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.exception.InformativeException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; public class VersionedPacketTransformerImpl implements VersionedPacketTransformer { @@ -52,51 +52,51 @@ public class VersionedPacketTransformerImpl packetWriter) throws Exception { + public boolean send(UserConnection connection, C packetType, Consumer packetWriter) throws InformativeException { return createAndSend(connection, packetType, packetWriter); } @Override - public boolean send(UserConnection connection, S packetType, Consumer packetWriter) throws Exception { + public boolean send(UserConnection connection, S packetType, Consumer packetWriter) throws InformativeException { return createAndSend(connection, packetType, packetWriter); } @Override - public boolean scheduleSend(PacketWrapper packet) throws Exception { + public boolean scheduleSend(PacketWrapper packet) throws InformativeException { validatePacket(packet); return transformAndSendPacket(packet, false); } @Override - public boolean scheduleSend(UserConnection connection, C packetType, Consumer packetWriter) throws Exception { + public boolean scheduleSend(UserConnection connection, C packetType, Consumer packetWriter) throws InformativeException { return scheduleCreateAndSend(connection, packetType, packetWriter); } @Override - public boolean scheduleSend(UserConnection connection, S packetType, Consumer packetWriter) throws Exception { + public boolean scheduleSend(UserConnection connection, S packetType, Consumer packetWriter) throws InformativeException { return scheduleCreateAndSend(connection, packetType, packetWriter); } @Override - public @Nullable PacketWrapper transform(PacketWrapper packet) throws Exception { + public @Nullable PacketWrapper transform(PacketWrapper packet) { validatePacket(packet); transformPacket(packet); return packet.isCancelled() ? null : packet; } @Override - public @Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer packetWriter) throws Exception { + public @Nullable PacketWrapper transform(UserConnection connection, C packetType, Consumer packetWriter) { return createAndTransform(connection, packetType, packetWriter); } @Override - public @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer packetWriter) throws Exception { + public @Nullable PacketWrapper transform(UserConnection connection, S packetType, Consumer packetWriter) { return createAndTransform(connection, packetType, packetWriter); } @@ -115,7 +115,7 @@ public class VersionedPacketTransformerImpl packetWriter) throws Exception { + private boolean createAndSend(UserConnection connection, PacketType packetType, Consumer packetWriter) throws InformativeException { PacketWrapper packet = PacketWrapper.create(packetType, connection); packetWriter.accept(packet); return send(packet); } - private boolean scheduleCreateAndSend(UserConnection connection, PacketType packetType, Consumer packetWriter) throws Exception { + private boolean scheduleCreateAndSend(UserConnection connection, PacketType packetType, Consumer packetWriter) throws InformativeException { PacketWrapper packet = PacketWrapper.create(packetType, connection); packetWriter.accept(packet); return scheduleSend(packet); } - private @Nullable PacketWrapper createAndTransform(UserConnection connection, PacketType packetType, Consumer packetWriter) throws Exception { + private @Nullable PacketWrapper createAndTransform(UserConnection connection, PacketType packetType, Consumer packetWriter) { PacketWrapper packet = PacketWrapper.create(packetType, connection); packetWriter.accept(packet); return transform(packet); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseVersionProvider.java b/common/src/main/java/com/viaversion/viaversion/protocol/version/BaseVersionProvider.java similarity index 96% rename from common/src/main/java/com/viaversion/viaversion/protocols/base/BaseVersionProvider.java rename to common/src/main/java/com/viaversion/viaversion/protocol/version/BaseVersionProvider.java index 5a765b93c..669145670 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseVersionProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/version/BaseVersionProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.base; +package com.viaversion.viaversion.protocol.version; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol.java b/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol.java index 4f0ea4b7f..fac997e17 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/base/BaseProtocol.java @@ -33,6 +33,9 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.VersionProvider; import com.viaversion.viaversion.api.protocol.version.VersionType; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.exception.InformativeException; +import com.viaversion.viaversion.protocol.version.BaseVersionProvider; import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket; import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider; import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket; @@ -68,7 +71,13 @@ public class BaseProtocol extends AbstractProtocol protocolPath = null; @@ -137,7 +146,7 @@ public class BaseProtocol extends AbstractProtocol protocols = null; if (info.protocolVersion().newerThanOrEqualTo(closestServerProtocol) || Via.getPlatform().isOldClientsAllowed()) { protocols = Via.getManager().getProtocolManager() @@ -198,7 +204,7 @@ public class BaseProtocol1_7 extends AbstractProtocol { - public static final ValueTransformer TO_NEW_PITCH = new ValueTransformer(Type.FLOAT) { + public static final ValueTransformer TO_NEW_PITCH = new ValueTransformer<>(Type.FLOAT) { @Override - public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception { + public Float transform(PacketWrapper wrapper, Short inputValue) { return inputValue / 63.0F; } }; - public static final ValueTransformer, List> TRANSFORM_METADATA = new ValueTransformer, List>(Types1_9.METADATA_LIST) { + public static final ValueTransformer, List> TRANSFORM_METADATA = new ValueTransformer<>(Types1_9.METADATA_LIST) { @Override - public List transform(PacketWrapper wrapper, List inputValue) throws Exception { + public List transform(PacketWrapper wrapper, List inputValue) { List metaList = new CopyOnWriteArrayList<>(inputValue); for (Metadata m : metaList) { if (m.id() >= 5) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index e733e3153..5aa91f933 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -43,9 +43,9 @@ import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.util.Pair; public class Protocol1_11To1_10 extends AbstractProtocol { - private static final ValueTransformer toOldByte = new ValueTransformer(Type.UNSIGNED_BYTE) { + private static final ValueTransformer toOldByte = new ValueTransformer<>(Type.UNSIGNED_BYTE) { @Override - public Short transform(PacketWrapper wrapper, Float inputValue) throws Exception { + public Short transform(PacketWrapper wrapper, Float inputValue) { return (short) (inputValue * 16); } }; @@ -306,7 +306,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol { - // 100 character limit on older servers + // 100-character limit on older servers String msg = wrapper.get(Type.STRING, 0); if (msg.length() > 100) { wrapper.set(Type.STRING, 0, msg.substring(0, 100)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java index 52f78fa2f..afd3f90e3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java @@ -112,19 +112,15 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter metadata) { Optional optType = EntityType.findById(numType); - if (!optType.isPresent()) { + if (optType.isEmpty()) { Via.getManager().getPlatform().getLogger().severe("Error: could not find Entity type " + numType + " with metadata: " + metadata); return null; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java index 88992adae..bd2a5d1b9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/Protocol1_12To1_11_1.java @@ -99,15 +99,11 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol { if (!Via.getConfig().is1_12NBTArrayFix()) return; - try { - final JsonElement element = wrapper.passthrough(Type.COMPONENT); - TranslateRewriter.toClient(wrapper.user(), element); - ChatItemRewriter.toClient(element); + final JsonElement element = wrapper.passthrough(Type.COMPONENT); + TranslateRewriter.toClient(wrapper.user(), element); + ChatItemRewriter.toClient(element); - wrapper.set(Type.COMPONENT, 0, element); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Error converting 1.11.2 -> 1.12 chat item", e); - } + wrapper.set(Type.COMPONENT, 0, element); }); registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/ChatItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/ChatItemRewriter.java index facac457c..6dbc6c591 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/ChatItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/ChatItemRewriter.java @@ -27,14 +27,12 @@ import com.viaversion.viaversion.util.SerializerVersion; public final class ChatItemRewriter { public static void toClient(JsonElement element) { - if (element instanceof JsonObject) { - JsonObject obj = (JsonObject) element; + if (element instanceof final JsonObject obj) { if (obj.has("hoverEvent")) { - if (!(obj.get("hoverEvent") instanceof JsonObject)) { + if (!(obj.get("hoverEvent") instanceof final JsonObject hoverEvent)) { return; } - final JsonObject hoverEvent = (JsonObject) obj.get("hoverEvent"); if (!hoverEvent.has("action") || !hoverEvent.has("value")) { return; } @@ -49,8 +47,7 @@ public final class ChatItemRewriter { } else if (obj.has("extra")) { toClient(obj.get("extra")); } - } else if (element instanceof JsonArray) { - JsonArray array = (JsonArray) element; + } else if (element instanceof final JsonArray array) { for (JsonElement value : array) { toClient(value); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/TranslateRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/TranslateRewriter.java index bcafdfc39..411c04f05 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/TranslateRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/rewriter/TranslateRewriter.java @@ -30,7 +30,7 @@ import java.util.logging.Level; public class TranslateRewriter { - private static final ComponentRewriter ACHIEVEMENT_TEXT_REWRITER = new ComponentRewriter(null, ComponentRewriter.ReadType.JSON) { + private static final ComponentRewriter ACHIEVEMENT_TEXT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) { @Override protected void handleTranslate(JsonObject object, String translate) { String text = AchievementTranslationMapping.get(translate); @@ -101,15 +101,11 @@ public class TranslateRewriter { }; public static void toClient(UserConnection connection, JsonElement element) { - if (element instanceof JsonObject) { - JsonObject obj = (JsonObject) element; + if (element instanceof JsonObject obj) { JsonElement translate = obj.get("translate"); - if (translate != null) { - if (translate.getAsString().startsWith("chat.type.achievement")) { - ACHIEVEMENT_TEXT_REWRITER.processText(connection, obj); - } + if (translate != null && translate.getAsString().startsWith("chat.type.achievement")) { + ACHIEVEMENT_TEXT_REWRITER.processText(connection, obj); } } } - -} \ No newline at end of file +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java index b9cef5971..7be16f5d4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_12to1_11_1/storage/ItemTransaction.java @@ -17,35 +17,5 @@ */ package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.storage; -public class ItemTransaction { - private final short windowId; - private final short slotId; - private final short actionId; - - public ItemTransaction(short windowId, short slotId, short actionId) { - this.windowId = windowId; - this.slotId = slotId; - this.actionId = actionId; - } - - public short getWindowId() { - return windowId; - } - - public short getSlotId() { - return slotId; - } - - public short getActionId() { - return actionId; - } - - @Override - public String toString() { - return "ItemTransaction{" + - "windowId=" + windowId + - ", slotId=" + slotId + - ", actionId=" + actionId + - '}'; - } +public record ItemTransaction(short windowId, short slotId, short actionId) { } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java index 9e2447ab0..311997da7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/Protocol1_13_1To1_13.java @@ -61,7 +61,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol(Type.STRING) { + map(Type.STRING, new ValueTransformer<>(Type.STRING) { @Override public String transform(PacketWrapper wrapper, String inputValue) { // 1.13 starts sending slash at start, so we remove it for compatibility diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java index bbf606d1c..981d43504 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/packets/InventoryPackets.java @@ -73,7 +73,7 @@ public class InventoryPackets extends ItemRewriter recipeRewriter = new RecipeRewriter(protocol) { + RecipeRewriter recipeRewriter = new RecipeRewriter<>(protocol) { @Override protected Type itemType() { return Type.ITEM1_13; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 10965fef7..be3b91170 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -219,32 +219,17 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol 2) { String category = split[1]; //TODO convert string ids (blocks, items, entities) - switch (category) { - case "mineBlock": - categoryId = 0; - break; - case "craftItem": - categoryId = 1; - break; - case "useItem": - categoryId = 2; - break; - case "breakItem": - categoryId = 3; - break; - case "pickup": - categoryId = 4; - break; - case "drop": - categoryId = 5; - break; - case "killEntity": - categoryId = 6; - break; - case "entityKilledBy": - categoryId = 7; - break; - } + categoryId = switch (category) { + case "mineBlock" -> 0; + case "craftItem" -> 1; + case "useItem" -> 2; + case "breakItem" -> 3; + case "pickup" -> 4; + case "drop" -> 5; + case "killEntity" -> 6; + case "entityKilledBy" -> 7; + default -> categoryId; + }; } if (newId != -1) remappedStats.add(new StatisticData(categoryId, newId, value)); @@ -252,9 +237,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol(Type.STRING) { + map(Type.STRING, new ValueTransformer<>(Type.STRING) { @Override public String transform(PacketWrapper wrapper, String inputValue) { wrapper.user().get(TabCompleteTracker.class).setInput(inputValue); @@ -671,9 +656,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol { - wrapper.write(Type.STRING, "MC|TrSel"); // Channel - }); + create(Type.STRING, "MC|TrSel"); // Channel map(Type.VAR_INT, Type.INT); // Slot } }); @@ -682,9 +665,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol { - wrapper.write(Type.STRING, "MC|Beacon"); // Channel - }); + create(Type.STRING, "MC|Beacon"); // Channel map(Type.VAR_INT, Type.INT); // Primary Effect map(Type.VAR_INT, Type.INT); // Secondary Effect } @@ -694,7 +675,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol wrapper.write(Type.STRING, "MC|AutoCmd")); + create(Type.STRING, "MC|AutoCmd"); // Channel handler(POS_TO_3_INT); map(Type.STRING); // Command handler(wrapper -> { @@ -721,7 +702,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol { - wrapper.write(Type.STRING, "MC|Struct"); // Channel - }); + create(Type.STRING, "MC|Struct"); // Channel handler(POS_TO_3_INT); - map(Type.VAR_INT, new ValueTransformer(Type.BYTE) { // Action + map(Type.VAR_INT, new ValueTransformer<>(Type.BYTE) { // Action @Override - public Byte transform(PacketWrapper wrapper, Integer action) throws Exception { + public Byte transform(PacketWrapper wrapper, Integer action) { return (byte) (action + 1); } }); // Action - map(Type.VAR_INT, new ValueTransformer(Type.STRING) { + map(Type.VAR_INT, new ValueTransformer<>(Type.STRING) { @Override - public String transform(PacketWrapper wrapper, Integer mode) throws Exception { + public String transform(PacketWrapper wrapper, Integer mode) { return mode == 0 ? "SAVE" : mode == 1 ? "LOAD" : mode == 2 ? "CORNER" @@ -757,17 +736,17 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol(Type.STRING) { // Mirror + map(Type.VAR_INT, new ValueTransformer<>(Type.STRING) { // Mirror @Override - public String transform(PacketWrapper wrapper, Integer mirror) throws Exception { + public String transform(PacketWrapper wrapper, Integer mirror) { return mirror == 0 ? "NONE" : mirror == 1 ? "LEFT_RIGHT" : "FRONT_BACK"; } }); - map(Type.VAR_INT, new ValueTransformer(Type.STRING) { // Rotation + map(Type.VAR_INT, new ValueTransformer<>(Type.STRING) { // Rotation @Override - public String transform(PacketWrapper wrapper, Integer rotation) throws Exception { + public String transform(PacketWrapper wrapper, Integer rotation) { return rotation == 0 ? "NONE" : rotation == 1 ? "CLOCKWISE_90" : rotation == 2 ? "CLOCKWISE_180" diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java index 82aca154d..cd8459eb4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractFenceConnectionHandler.java @@ -25,7 +25,7 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; import java.util.Arrays; -public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { +public abstract class AbstractFenceConnectionHandler implements ConnectionHandler { private static final StairConnectionHandler STAIR_CONNECTION_HANDLER = new StairConnectionHandler(); private final IntSet blockStates = new IntOpenHashSet(); private final int[] connectedBlockStates = new int[statesSize()]; @@ -61,7 +61,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { return states; } - protected byte getStates(UserConnection user, Position position, int blockState) { + protected byte getStates(UserConnection user, Position position) { byte states = 0; boolean pre1_12 = user.getProtocolInfo().serverProtocolVersion().olderThan(ProtocolVersion.v1_12); if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1; @@ -77,12 +77,12 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler { @Override public int getBlockData(UserConnection user, Position position) { - return STAIR_CONNECTION_HANDLER.connect(user, position, super.getBlockData(user, position)); + return STAIR_CONNECTION_HANDLER.connect(user, position, ConnectionHandler.super.getBlockData(user, position)); } @Override public int connect(UserConnection user, Position position, int blockState) { - final int newBlockState = connectedBlockStates[getStates(user, position, blockState)]; + final int newBlockState = connectedBlockStates[getStates(user, position)]; return newBlockState == -1 ? blockState : newBlockState; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java index 22717e18b..36eb46367 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/AbstractStempConnectionHandler.java @@ -26,7 +26,7 @@ import java.util.EnumMap; import java.util.Locale; import java.util.Map; -public abstract class AbstractStempConnectionHandler extends ConnectionHandler { +public abstract class AbstractStempConnectionHandler implements ConnectionHandler { private static final BlockFace[] BLOCK_FACES = {BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST}; private final IntSet blockId = new IntOpenHashSet(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java index e2a880f77..1f3d324a8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChestConnectionHandler.java @@ -27,7 +27,7 @@ import it.unimi.dsi.fastutil.ints.IntSet; import java.util.Arrays; import java.util.Locale; -class ChestConnectionHandler extends ConnectionHandler { +class ChestConnectionHandler implements ConnectionHandler { private static final Int2ObjectMap CHEST_FACINGS = new Int2ObjectOpenHashMap<>(); private static final int[] CONNECTED_STATES = new int[32]; private static final IntSet TRAPPED_CHESTS = new IntOpenHashSet(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java index af5dd0161..a678c2ce8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ChorusPlantConnectionHandler.java @@ -61,8 +61,8 @@ public class ChorusPlantConnectionHandler extends AbstractFenceConnectionHandler } @Override - protected byte getStates(UserConnection user, Position position, int blockState) { - byte states = super.getStates(user, position, blockState); + protected byte getStates(UserConnection user, Position position) { + byte states = super.getStates(user, position); if (connects(BlockFace.TOP, getBlockData(user, position.getRelative(BlockFace.TOP)), false)) states |= 16; if (connects(BlockFace.BOTTOM, getBlockData(user, position.getRelative(BlockFace.BOTTOM)), false)) states |= 32; return states; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index c4f800bee..d07797c21 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -64,7 +64,7 @@ public final class ConnectionData { KEY_TO_ID.defaultReturnValue(-1); } - public static void update(UserConnection user, Position position) throws Exception { + public static void update(UserConnection user, Position position) { Boolean inSync = null; for (BlockFace face : BlockFace.values()) { @@ -669,7 +669,7 @@ public final class ConnectionData { this.userBlockData = blockConnectionProvider.forUser(user); } - public void updateChunkSectionNeighbours(int chunkX, int chunkZ, int chunkSectionY) throws Exception { + public void updateChunkSectionNeighbours(int chunkX, int chunkZ, int chunkSectionY) { int chunkMinY = chunkSectionY << 4; List updates = new ArrayList<>(); for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java index 7443e6fe5..547e19e07 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionHandler.java @@ -20,11 +20,12 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnection import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; -public abstract class ConnectionHandler { +@FunctionalInterface +public interface ConnectionHandler { - public abstract int connect(UserConnection user, Position position, int blockState); + int connect(UserConnection user, Position position, int blockState); - public int getBlockData(UserConnection user, Position position) { + default int getBlockData(UserConnection user, Position position) { return ConnectionData.blockConnectionProvider.getBlockData(user, position.x(), position.y(), position.z()); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/DoorConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/DoorConnectionHandler.java index fd6cb3d11..4524de429 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/DoorConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/DoorConnectionHandler.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; -public class DoorConnectionHandler extends ConnectionHandler { +public class DoorConnectionHandler implements ConnectionHandler { private static final Int2ObjectMap DOOR_DATA_MAP = new Int2ObjectOpenHashMap<>(); private static final Map CONNECTED_STATES = new HashMap<>(); @@ -68,12 +68,12 @@ public class DoorConnectionHandler extends ConnectionHandler { private static short getStates(DoorData doorData) { short s = 0; - if (doorData.isLower()) s |= 1; - if (doorData.isOpen()) s |= 2; - if (doorData.isPowered()) s |= 4; - if (doorData.isRightHinge()) s |= 8; - s |= doorData.getFacing().ordinal() << 4; - s |= (doorData.getType() & 0x7) << 6; + if (doorData.lower()) s |= 1; + if (doorData.open()) s |= 2; + if (doorData.powered()) s |= 4; + if (doorData.rightHinge()) s |= 8; + s |= doorData.facing().ordinal() << 4; + s |= (doorData.type() & 0x7) << 6; return s; } @@ -82,64 +82,29 @@ public class DoorConnectionHandler extends ConnectionHandler { DoorData doorData = DOOR_DATA_MAP.get(blockState); if (doorData == null) return blockState; short s = 0; - s |= (doorData.getType() & 0x7) << 6; - if (doorData.isLower()) { + s |= (doorData.type() & 0x7) << 6; + if (doorData.lower()) { DoorData upperHalf = DOOR_DATA_MAP.get(getBlockData(user, position.getRelative(BlockFace.TOP))); if (upperHalf == null) return blockState; s |= 1; - if (doorData.isOpen()) s |= 2; - if (upperHalf.isPowered()) s |= 4; - if (upperHalf.isRightHinge()) s |= 8; - s |= doorData.getFacing().ordinal() << 4; + if (doorData.open()) s |= 2; + if (upperHalf.powered()) s |= 4; + if (upperHalf.rightHinge()) s |= 8; + s |= doorData.facing().ordinal() << 4; } else { DoorData lowerHalf = DOOR_DATA_MAP.get(getBlockData(user, position.getRelative(BlockFace.BOTTOM))); if (lowerHalf == null) return blockState; - if (lowerHalf.isOpen()) s |= 2; - if (doorData.isPowered()) s |= 4; - if (doorData.isRightHinge()) s |= 8; - s |= lowerHalf.getFacing().ordinal() << 4; + if (lowerHalf.open()) s |= 2; + if (doorData.powered()) s |= 4; + if (doorData.rightHinge()) s |= 8; + s |= lowerHalf.facing().ordinal() << 4; } Integer newBlockState = CONNECTED_STATES.get(s); return newBlockState == null ? blockState : newBlockState; } - private static final class DoorData { - private final boolean lower, rightHinge, powered, open; - private final BlockFace facing; - private final int type; - - private DoorData(boolean lower, boolean rightHinge, boolean powered, boolean open, BlockFace facing, int type) { - this.lower = lower; - this.rightHinge = rightHinge; - this.powered = powered; - this.open = open; - this.facing = facing; - this.type = type; - } - - public boolean isLower() { - return lower; - } - - public boolean isRightHinge() { - return rightHinge; - } - - public boolean isPowered() { - return powered; - } - - public boolean isOpen() { - return open; - } - - public BlockFace getFacing() { - return facing; - } - - public int getType() { - return type; - } + private record DoorData(boolean lower, boolean rightHinge, boolean powered, + boolean open, BlockFace facing, int type) { } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java index 418d7732b..fdb3d3e7d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FireConnectionHandler.java @@ -26,7 +26,7 @@ import it.unimi.dsi.fastutil.ints.IntSet; import java.util.HashSet; import java.util.Set; -public class FireConnectionHandler extends ConnectionHandler { +public class FireConnectionHandler implements ConnectionHandler { private static final String[] WOOD_TYPES = {"oak", "spruce", "birch", "jungle", "acacia", "dark_oak"}; private static final int[] CONNECTED_BLOCKS = new int[32]; private static final IntSet FLAMMABLE_BLOCKS = new IntOpenHashSet(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java index c1794fda1..463d8d9cc 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/FlowerConnectionHandler.java @@ -27,7 +27,7 @@ import java.util.HashSet; import java.util.Set; -public class FlowerConnectionHandler extends ConnectionHandler { +public class FlowerConnectionHandler implements ConnectionHandler { private static final Int2IntMap FLOWERS = new Int2IntOpenHashMap(); static ConnectionData.ConnectorInitAction init() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java index 40aaf9b4b..1711da5ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/GlassConnectionHandler.java @@ -54,8 +54,8 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler { } @Override - protected byte getStates(UserConnection user, Position position, int blockState) { - byte states = super.getStates(user, position, blockState); + protected byte getStates(UserConnection user, Position position) { + byte states = super.getStates(user, position); if (states != 0) return states; ProtocolInfo protocolInfo = user.getProtocolInfo(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java index 592b6c6c7..7ae2e1cef 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/RedstoneConnectionHandler.java @@ -25,7 +25,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; -public class RedstoneConnectionHandler extends ConnectionHandler { +public class RedstoneConnectionHandler implements ConnectionHandler { private static final IntSet REDSTONE = new IntOpenHashSet(); private static final Int2IntMap CONNECTED_BLOCK_STATES = new Int2IntOpenHashMap(1296); private static final Int2IntMap POWER_MAPPINGS = new Int2IntOpenHashMap(1296); @@ -57,15 +57,11 @@ public class RedstoneConnectionHandler extends ConnectionHandler { } private static int getState(String value) { - switch (value) { - case "none": - default: - return 0; - case "side": - return 1; - case "up": - return 2; - } + return switch (value) { + case "side" -> 1; + case "up" -> 2; + default -> 0; // Implicit "none" + }; } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java index cd577fe94..6fb429382 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/SnowyGrassConnectionHandler.java @@ -27,7 +27,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.util.HashSet; import java.util.Set; -public class SnowyGrassConnectionHandler extends ConnectionHandler { +public class SnowyGrassConnectionHandler implements ConnectionHandler { private static final Object2IntMap GRASS_BLOCKS = new Object2IntOpenHashMap<>(); private static final IntSet SNOWY_GRASS_BLOCKS = new IntOpenHashSet(); @@ -61,29 +61,6 @@ public class SnowyGrassConnectionHandler extends ConnectionHandler { return newId != -1 ? newId : blockState; } - private static final class GrassBlock { - private final int blockStateId; - private final boolean snowy; - - private GrassBlock(final int blockStateId, final boolean snowy) { - this.blockStateId = blockStateId; - this.snowy = snowy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final GrassBlock that = (GrassBlock) o; - if (blockStateId != that.blockStateId) return false; - return snowy == that.snowy; - } - - @Override - public int hashCode() { - int result = blockStateId; - result = 31 * result + (snowy ? 1 : 0); - return result; - } + private record GrassBlock(int blockStateId, boolean snowy) { } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/StairConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/StairConnectionHandler.java index 36cb04d63..9fe69bd73 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/StairConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/StairConnectionHandler.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; -public class StairConnectionHandler extends ConnectionHandler { +public class StairConnectionHandler implements ConnectionHandler { private static final Int2ObjectMap STAIR_DATA_MAP = new Int2ObjectOpenHashMap<>(); private static final Map CONNECTED_BLOCKS = new HashMap<>(); @@ -95,10 +95,10 @@ public class StairConnectionHandler extends ConnectionHandler { private static short getStates(StairData stairData) { short s = 0; - if (stairData.isBottom()) s |= 1; - s |= stairData.getShape() << 1; - s |= stairData.getType() << 4; - s |= stairData.getFacing().ordinal() << 9; + if (stairData.bottom()) s |= 1; + s |= stairData.shape() << 1; + s |= stairData.type() << 4; + s |= stairData.facing().ordinal() << 9; return s; } @@ -108,29 +108,29 @@ public class StairConnectionHandler extends ConnectionHandler { if (stairData == null) return blockState; short s = 0; - if (stairData.isBottom()) s |= 1; + if (stairData.bottom()) s |= 1; s |= getShape(user, position, stairData) << 1; - s |= stairData.getType() << 4; - s |= stairData.getFacing().ordinal() << 9; + s |= stairData.type() << 4; + s |= stairData.facing().ordinal() << 9; Integer newBlockState = CONNECTED_BLOCKS.get(s); return newBlockState == null ? blockState : newBlockState; } private int getShape(UserConnection user, Position position, StairData stair) { - BlockFace facing = stair.getFacing(); + BlockFace facing = stair.facing(); StairData relativeStair = STAIR_DATA_MAP.get(getBlockData(user, position.getRelative(facing))); - if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { - BlockFace facing2 = relativeStair.getFacing(); + if (relativeStair != null && relativeStair.bottom() == stair.bottom()) { + BlockFace facing2 = relativeStair.facing(); if (facing.axis() != facing2.axis() && checkOpposite(user, stair, position, facing2.opposite())) { return facing2 == rotateAntiClockwise(facing) ? 3 : 4; // outer_left : outer_right } } relativeStair = STAIR_DATA_MAP.get(getBlockData(user, position.getRelative(facing.opposite()))); - if (relativeStair != null && relativeStair.isBottom() == stair.isBottom()) { - BlockFace facing2 = relativeStair.getFacing(); + if (relativeStair != null && relativeStair.bottom() == stair.bottom()) { + BlockFace facing2 = relativeStair.facing(); if (facing.axis() != facing2.axis() && checkOpposite(user, stair, position, facing2)) { return facing2 == rotateAntiClockwise(facing) ? 1 : 2; // inner_left : inner_right } @@ -141,50 +141,19 @@ public class StairConnectionHandler extends ConnectionHandler { private boolean checkOpposite(UserConnection user, StairData stair, Position position, BlockFace face) { StairData relativeStair = STAIR_DATA_MAP.get(getBlockData(user, position.getRelative(face))); - return relativeStair == null || relativeStair.getFacing() != stair.getFacing() || relativeStair.isBottom() != stair.isBottom(); + return relativeStair == null || relativeStair.facing() != stair.facing() || relativeStair.bottom() != stair.bottom(); } private BlockFace rotateAntiClockwise(BlockFace face) { - switch (face) { - case NORTH: - return BlockFace.WEST; - case SOUTH: - return BlockFace.EAST; - case EAST: - return BlockFace.NORTH; - case WEST: - return BlockFace.SOUTH; - default: - return face; - } + return switch (face) { + case NORTH -> BlockFace.WEST; + case SOUTH -> BlockFace.EAST; + case EAST -> BlockFace.NORTH; + case WEST -> BlockFace.SOUTH; + default -> face; + }; } - private static final class StairData { - private final boolean bottom; - private final byte shape, type; - private final BlockFace facing; - - private StairData(boolean bottom, byte shape, byte type, BlockFace facing) { - this.bottom = bottom; - this.shape = shape; - this.type = type; - this.facing = facing; - } - - public boolean isBottom() { - return bottom; - } - - public byte getShape() { - return shape; - } - - public byte getType() { - return type; - } - - public BlockFace getFacing() { - return facing; - } + private record StairData(boolean bottom, byte shape, byte type, BlockFace facing) { } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java index 7cb12f378..a0c8e37cd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/TripwireConnectionHandler.java @@ -26,7 +26,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import java.util.Arrays; import java.util.Locale; -public class TripwireConnectionHandler extends ConnectionHandler { +public class TripwireConnectionHandler implements ConnectionHandler { private static final Int2ObjectMap TRIPWIRE_DATA_MAP = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap TRIPWIRE_HOOKS = new Int2ObjectArrayMap<>(); private static final int[] CONNECTED_BLOCKS = new int[128]; @@ -69,9 +69,9 @@ public class TripwireConnectionHandler extends ConnectionHandler { TripwireData tripwireData = TRIPWIRE_DATA_MAP.get(blockState); if (tripwireData == null) return blockState; byte b = 0; - if (tripwireData.isAttached()) b |= 1; - if (tripwireData.isDisarmed()) b |= 2; - if (tripwireData.isPowered()) b |= 4; + if (tripwireData.attached()) b |= 1; + if (tripwireData.disarmed()) b |= 2; + if (tripwireData.powered()) b |= 4; int east = getBlockData(user, position.getRelative(BlockFace.EAST)); int north = getBlockData(user, position.getRelative(BlockFace.NORTH)); @@ -95,25 +95,6 @@ public class TripwireConnectionHandler extends ConnectionHandler { return newBlockState == -1 ? blockState : newBlockState; } - private static final class TripwireData { - private final boolean attached, disarmed, powered; - - private TripwireData(final boolean attached, final boolean disarmed, final boolean powered) { - this.attached = attached; - this.disarmed = disarmed; - this.powered = powered; - } - - public boolean isAttached() { - return attached; - } - - public boolean isDisarmed() { - return disarmed; - } - - public boolean isPowered() { - return powered; - } + private record TripwireData(boolean attached, boolean disarmed, boolean powered) { } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java index a4e155fb9..76bd32bc1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/VineConnectionHandler.java @@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.minecraft.Position; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; -class VineConnectionHandler extends ConnectionHandler { +class VineConnectionHandler implements ConnectionHandler { private static final IntSet VINES = new IntOpenHashSet(); static ConnectionData.ConnectorInitAction init() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java index 15c4b8810..30a09476e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/WallConnectionHandler.java @@ -47,8 +47,8 @@ public class WallConnectionHandler extends AbstractFenceConnectionHandler { } @Override - protected byte getStates(UserConnection user, Position position, int blockState) { - byte states = super.getStates(user, position, blockState); + protected byte getStates(UserConnection user, Position position) { + byte states = super.getStates(user, position); if (up(user, position)) states |= 16; return states; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java index ceb22baf0..32908ba39 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/providers/BlockConnectionProvider.java @@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.platform.providers.Provider; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import org.checkerframework.checker.nullness.qual.Nullable; -public class BlockConnectionProvider implements Provider { +public abstract class BlockConnectionProvider implements Provider { public int getBlockData(UserConnection connection, int x, int y, int z) { int oldId = getWorldBlockData(connection, x, y, z); @@ -35,15 +35,12 @@ public class BlockConnectionProvider implements Provider { } public void storeBlock(UserConnection connection, int x, int y, int z, int blockState) { - } public void removeBlock(UserConnection connection, int x, int y, int z) { - } public void clearStorage(UserConnection connection) { - } public void modifiedBlock(UserConnection connection, Position position) { @@ -51,7 +48,6 @@ public class BlockConnectionProvider implements Provider { } public void unloadChunk(UserConnection connection, int x, int z) { - } public void unloadChunkSection(UserConnection connection, int chunkX, int chunkY, int chunkZ) { @@ -63,7 +59,7 @@ public class BlockConnectionProvider implements Provider { * If the client has modified the position (ie: placed or broken a block) this should return false. * * @param position The position at which block reliability should be checked, null for general-purpose - * @return true if the block & its neighbors are known to be correct + * @return true if the block and its neighbors are known to be correct */ public boolean storesBlocks(UserConnection user, @Nullable Position position) { return false; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/BlockIdData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/BlockIdData.java index 2e5c8484d..1cee38527 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/BlockIdData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/BlockIdData.java @@ -32,11 +32,12 @@ import java.util.logging.Level; public class BlockIdData { public static final String[] PREVIOUS = new String[0]; - public static Map blockIdMapping; - public static Map fallbackReverseMapping; - public static Int2ObjectMap numberIdToString; + public static final Map blockIdMapping = new HashMap<>(); + public static final Map fallbackReverseMapping = new HashMap<>(); + public static final Int2ObjectMap numberIdToString = new Int2ObjectOpenHashMap<>(); public static void init() { + // Data from https://minecraft.gamepedia.com/1.13/Flattening InputStream stream = MappingData.class.getClassLoader() .getResourceAsStream("assets/viaversion/data/blockIds1.12to1.13.json"); try (InputStreamReader reader = new InputStreamReader(stream)) { @@ -44,8 +45,7 @@ public class BlockIdData { reader, new TypeToken>() { }.getType()); - blockIdMapping = new HashMap<>(map); - fallbackReverseMapping = new HashMap<>(); + blockIdMapping.putAll(map); for (Map.Entry entry : blockIdMapping.entrySet()) { for (String val : entry.getValue()) { String[] previous = fallbackReverseMapping.get(val); @@ -65,10 +65,9 @@ public class BlockIdData { new TypeToken>() { }.getType() ); - numberIdToString = new Int2ObjectOpenHashMap<>(map); + numberIdToString.putAll(map); } catch (IOException e) { Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to load block number to string mappings (1.12.2)", e); } - // Ignored } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java index e69b18d22..34d6624af 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/EntityTypeRewriter.java @@ -117,4 +117,8 @@ public class EntityTypeRewriter { public static int getNewId(int type1_12) { return ENTITY_TYPES.getOrDefault(type1_12, type1_12); } + + public static Int2IntMap getEntityTypes() { + return ENTITY_TYPES; + } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java index c38af8f4c..b09f4284b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/ParticleRewriter.java @@ -18,16 +18,17 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ThreadLocalRandom; +import org.checkerframework.checker.nullness.qual.Nullable; public class ParticleRewriter { private static final List particles = new ArrayList<>(); @@ -159,30 +160,17 @@ public class ParticleRewriter { @FunctionalInterface interface ParticleDataHandler { + Particle handler(Particle particle, Integer[] data); } - private static class NewParticle { - private final int id; - private final ParticleDataHandler handler; - - public NewParticle(int id, ParticleDataHandler handler) { - this.id = id; - this.handler = handler; - } + private record NewParticle(int id, @Nullable ParticleDataHandler handler) { public Particle handle(Particle particle, Integer[] data) { - if (handler != null) + if (handler != null) { return handler.handler(particle, data); + } return particle; } - - public int id() { - return id; - } - - public ParticleDataHandler handler() { - return handler; - } } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/StatisticData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/StatisticData.java index e96501c8c..8c076e800 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/StatisticData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/data/StatisticData.java @@ -17,28 +17,5 @@ */ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data; -public class StatisticData { - - private final int categoryId; - private final int newId; - private final int value; - - public StatisticData(int categoryId, int newId, int value) { - this.categoryId = categoryId; - this.newId = newId; - this.value = value; - } - - public int getCategoryId() { - return categoryId; - } - - public int getNewId() { - return newId; - } - - public int getValue() { - return value; - } - +public record StatisticData(int categoryId, int newId, int value) { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java index 973e68796..a21080ef7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java @@ -83,7 +83,7 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter data = 3; // South + case 1 -> data = 4; // West // North is the same - // East - case 3: - data = 5; - break; + case 3 -> data = 5; // East } wrapper.set(Type.INT, 0, data); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 8aacf8ff0..791bf4664 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -118,7 +118,7 @@ public class InventoryPackets extends ItemRewriter finalSource = SoundSource.findBySource(originalSource); - if (!finalSource.isPresent()) { + if (finalSource.isEmpty()) { if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { Via.getPlatform().getLogger().info("Could not handle unknown sound source " + originalSource + " falling back to default: master"); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 501c5b642..420963c06 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -89,7 +89,7 @@ public class WorldPackets { Optional id = provider.getIntByIdentifier(motive); - if (!id.isPresent() && (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug())) { + if (id.isEmpty() && (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug())) { Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)"); } wrapper.write(Type.VAR_INT, id.orElse(0)); @@ -500,13 +500,13 @@ public class WorldPackets { Particle particle = ParticleRewriter.rewriteParticle(particleId, data); // Cancel if null or completely removed - if (particle == null || particle.getId() == -1) { + if (particle == null || particle.id() == -1) { wrapper.cancel(); return; } // Handle reddust particle color - if (particle.getId() == 11) { + if (particle.id() == 11) { int count = wrapper.get(Type.INT, 1); float speed = wrapper.get(Type.FLOAT, 6); // Only handle for count = 0 @@ -527,7 +527,7 @@ public class WorldPackets { } } - wrapper.set(Type.INT, 0, particle.getId()); + wrapper.set(Type.INT, 0, particle.id()); for (Particle.ParticleData particleData : particle.getArguments()) particleData.write(wrapper); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java index 2583f1d7d..56efa760c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java @@ -56,9 +56,8 @@ public class BlockEntityProvider implements Provider { * @param tag BlockEntity NBT * @param sendUpdate send a block change update * @return new block id - * @throws Exception Gotta throw that exception */ - public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { + public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) { StringTag idTag = tag.getStringTag("id"); if (idTag == null) return -1; @@ -79,7 +78,7 @@ public class BlockEntityProvider implements Provider { return newBlock; } - private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception { + private void sendBlockChange(UserConnection user, Position position, int blockId) { PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.BLOCK_CHANGE, null, user); wrapper.write(Type.POSITION1_8, position); wrapper.write(Type.VAR_INT, blockId); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 69b72b64d..95c0002b5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -188,4 +188,4 @@ public class BlockConnectionStorage implements StorableObject { return ((y & 0xF) << 8) | ((x & 0xF) << 4) | (z & 0xF); } } -} \ No newline at end of file +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/TabCompleteTracker.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/TabCompleteTracker.java index 18b024c62..52a5ef8d0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/TabCompleteTracker.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/TabCompleteTracker.java @@ -41,11 +41,7 @@ public class TabCompleteTracker implements StorableObject { wrapper.write(Type.BOOLEAN, false); final Position playerLookTarget = Via.getManager().getProviders().get(PlayerLookTargetProvider.class).getPlayerLookTarget(connection); wrapper.write(Type.OPTIONAL_POSITION1_8, playerLookTarget); - try { - wrapper.scheduleSendToServer(Protocol1_13To1_12_2.class); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send tab complete packet", e); - } + wrapper.scheduleSendToServer(Protocol1_13To1_12_2.class); lastTabComplete = null; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java index a9ca0c2f0..22f92b517 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/Protocol1_14To1_13_2.java @@ -65,7 +65,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol componentRewriter = new ComponentRewriter1_14<>(this); componentRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE); - CommandRewriter commandRewriter = new CommandRewriter(this) { + CommandRewriter commandRewriter = new CommandRewriter<>(this) { @Override public @Nullable String handleArgumentType(String argumentType) { if (argumentType.equals("minecraft:nbt")) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java index 58126668e..60b082bd0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java @@ -195,22 +195,15 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter career - switch (old) { - case 0: // farmer - return 5; - case 1: // librarian - return 9; - case 2: // priest - return 4; // cleric - case 3: // blacksmith - return 1; // armorer - case 4: // butcher - return 2; - case 5: // nitwit - return 11; - default: - return 0; // none - } + return switch (old) { + case 0 -> 5; // farmer + case 1 -> 9; // librarian + case 2 -> 4; // priest ->cleric + case 3 -> 1; // blacksmith -> armorer + case 4 -> 2; // butcher + case 5 -> 11; // nitwit + default -> 0; // none + }; } private static boolean isFallFlying(int entityFlags) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index 296e94eec..5d93883d1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -83,27 +83,15 @@ public class EntityPackets { if (type1_14.is(EntityTypes1_14.FALLING_BLOCK)) { wrapper.set(Type.INT, 0, protocol.getMappingData().getNewBlockStateId(data)); } else if (type1_14.is(EntityTypes1_14.MINECART)) { - // default is 0 = rideable minecart - switch (data) { - case 1: - typeId = EntityTypes1_14.CHEST_MINECART.getId(); - break; - case 2: - typeId = EntityTypes1_14.FURNACE_MINECART.getId(); - break; - case 3: - typeId = EntityTypes1_14.TNT_MINECART.getId(); - break; - case 4: - typeId = EntityTypes1_14.SPAWNER_MINECART.getId(); - break; - case 5: - typeId = EntityTypes1_14.HOPPER_MINECART.getId(); - break; - case 6: - typeId = EntityTypes1_14.COMMAND_BLOCK_MINECART.getId(); - break; - } + typeId = switch (data) { + case 1 -> EntityTypes1_14.CHEST_MINECART.getId(); + case 2 -> EntityTypes1_14.FURNACE_MINECART.getId(); + case 3 -> EntityTypes1_14.TNT_MINECART.getId(); + case 4 -> EntityTypes1_14.SPAWNER_MINECART.getId(); + case 5 -> EntityTypes1_14.HOPPER_MINECART.getId(); + case 6 -> EntityTypes1_14.COMMAND_BLOCK_MINECART.getId(); + default -> typeId; // default 0 = rideable minecart + }; } else if ((type1_14.is(EntityTypes1_14.ITEM) && data > 0) || type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { if (type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index 5c85e9007..d934b0798 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -48,7 +48,7 @@ import java.util.concurrent.ThreadLocalRandom; public class InventoryPackets extends ItemRewriter { private static final Set REMOVED_RECIPE_TYPES = Sets.newHashSet("crafting_special_banneraddpattern", "crafting_special_repairitem"); - private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter(null, ComponentRewriter.ReadType.JSON) { + private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) { @Override protected void handleTranslate(JsonObject object, String translate) { super.handleTranslate(object, translate); @@ -93,8 +93,7 @@ public class InventoryPackets extends ItemRewriter 0 && slots <= 54) { typeId = slots / 9 - 1; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java index cee9b7723..4182219a9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/WorldPackets.java @@ -313,7 +313,7 @@ public class WorldPackets { }); } - static void sendViewDistancePacket(UserConnection connection) throws Exception { + static void sendViewDistancePacket(UserConnection connection) { PacketWrapper setViewDistance = PacketWrapper.create(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE, connection); setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE); setViewDistance.send(Protocol1_14To1_13_2.class); @@ -395,8 +395,4 @@ public class WorldPackets { section.getLight().getBlockLightNibbleArray().set(x, y, z, blockLight); } } - - private static long getChunkIndex(int x, int z) { - return ((x & 0x3FFFFFFL) << 38) | (z & 0x3FFFFFFL); - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java index a0801d032..51fef6ee2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java @@ -109,7 +109,7 @@ public final class EntityPackets { metadataRewriter.registerRemoveEntities(ClientboundPackets1_14_4.DESTROY_ENTITIES); } - private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, EntityRewriter rewriter) throws Exception { + private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, EntityRewriter rewriter) { // Meta is no longer included in the spawn packets, but sent separately List metadata = wrapper.read(Types1_14.METADATA_LIST); if (metadata.isEmpty()) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java index 051a6ea88..e42598036 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java @@ -44,6 +44,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); @@ -80,7 +81,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol packetType = ClientboundPackets1_17.TITLE_TEXT; + case 1 -> packetType = ClientboundPackets1_17.TITLE_SUBTITLE; + case 2 -> packetType = ClientboundPackets1_17.ACTIONBAR; + case 3 -> packetType = ClientboundPackets1_17.TITLE_TIMES; + case 4 -> { packetType = ClientboundPackets1_17.CLEAR_TITLES; wrapper.write(Type.BOOLEAN, false); // Reset times - break; - case 5: + } + case 5 -> { packetType = ClientboundPackets1_17.CLEAR_TITLES; wrapper.write(Type.BOOLEAN, true); // Reset times - break; - default: - throw new IllegalArgumentException("Invalid title type received: " + type); + } + default -> throw new IllegalArgumentException("Invalid title type received: " + type); } wrapper.setPacketType(packetType); @@ -152,10 +144,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol { - // Collection length is now a var int - wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); - }); + handler(wrapper -> wrapper.write(Type.VAR_INT, wrapper.read(Type.INT))); // Collection length is now a var int } }); @@ -163,10 +152,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol { - // Angle (which Mojang just forgot to write to the buffer, lol) - wrapper.write(Type.FLOAT, 0f); - }); + handler(wrapper -> wrapper.write(Type.FLOAT, 0f)); // Angle (which Mojang just forgot to write to the buffer, lol) } }); @@ -179,9 +165,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol { - wrapper.read(Type.BOOLEAN); // Text filtering - }); + read(Type.BOOLEAN); // Text filtering } }); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java index 23c06b746..ab6a7881a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java @@ -98,10 +98,7 @@ public final class EntityPackets extends EntityRewriter { - // Collection length is now a var int - wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); - }); + handler(wrapper -> wrapper.write(Type.VAR_INT, wrapper.read(Type.INT))); // Collection length is now a var int } }); @@ -115,30 +112,19 @@ public final class EntityPackets extends EntityRewriter { - // Dismount vehicle - wrapper.write(Type.BOOLEAN, false); - }); + create(Type.BOOLEAN, false); // Dismount vehicle } }); protocol.registerClientbound(ClientboundPackets1_16_2.COMBAT_EVENT, null, wrapper -> { // Combat packet actions have been split into individual packets (the content hasn't changed) int type = wrapper.read(Type.VAR_INT); - ClientboundPacketType packetType; - switch (type) { - case 0: - packetType = ClientboundPackets1_17.COMBAT_ENTER; - break; - case 1: - packetType = ClientboundPackets1_17.COMBAT_END; - break; - case 2: - packetType = ClientboundPackets1_17.COMBAT_KILL; - break; - default: - throw new IllegalArgumentException("Invalid combat type received: " + type); - } + ClientboundPacketType packetType = switch (type) { + case 0 -> ClientboundPackets1_17.COMBAT_ENTER; + case 1 -> ClientboundPackets1_17.COMBAT_END; + case 2 -> ClientboundPackets1_17.COMBAT_KILL; + default -> throw new IllegalArgumentException("Invalid combat type received: " + type); + }; wrapper.setPacketType(packetType); }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java index b2da1f575..8de28ea72 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java @@ -50,29 +50,15 @@ public final class WorldPackets { protocol.registerClientbound(ClientboundPackets1_16_2.WORLD_BORDER, null, wrapper -> { // Border packet actions have been split into individual packets (the content hasn't changed) int type = wrapper.read(Type.VAR_INT); - ClientboundPacketType packetType; - switch (type) { - case 0: - packetType = ClientboundPackets1_17.WORLD_BORDER_SIZE; - break; - case 1: - packetType = ClientboundPackets1_17.WORLD_BORDER_LERP_SIZE; - break; - case 2: - packetType = ClientboundPackets1_17.WORLD_BORDER_CENTER; - break; - case 3: - packetType = ClientboundPackets1_17.WORLD_BORDER_INIT; - break; - case 4: - packetType = ClientboundPackets1_17.WORLD_BORDER_WARNING_DELAY; - break; - case 5: - packetType = ClientboundPackets1_17.WORLD_BORDER_WARNING_DISTANCE; - break; - default: - throw new IllegalArgumentException("Invalid world border type received: " + type); - } + ClientboundPacketType packetType = switch (type) { + case 0 -> ClientboundPackets1_17.WORLD_BORDER_SIZE; + case 1 -> ClientboundPackets1_17.WORLD_BORDER_LERP_SIZE; + case 2 -> ClientboundPackets1_17.WORLD_BORDER_CENTER; + case 3 -> ClientboundPackets1_17.WORLD_BORDER_INIT; + case 4 -> ClientboundPackets1_17.WORLD_BORDER_WARNING_DELAY; + case 5 -> ClientboundPackets1_17.WORLD_BORDER_WARNING_DISTANCE; + default -> throw new IllegalArgumentException("Invalid world border type received: " + type); + }; wrapper.setPacketType(packetType); }); @@ -97,7 +83,7 @@ public final class WorldPackets { }); } - private void writeLightArrays(PacketWrapper wrapper, int bitMask) throws Exception { + private void writeLightArrays(PacketWrapper wrapper, int bitMask) { List light = new ArrayList<>(); for (int i = 0; i < 18; i++) { if (isSet(bitMask, i)) { @@ -156,7 +142,7 @@ public final class WorldPackets { blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001); } - private static void writeMultiBlockChangePacket(PacketWrapper wrapper, Chunk chunk) throws Exception { + private static void writeMultiBlockChangePacket(PacketWrapper wrapper, Chunk chunk) { long chunkPosition = (chunk.getX() & 0x3FFFFFL) << 42; chunkPosition |= (chunk.getZ() & 0x3FFFFFL) << 20; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java index 151df0856..7bd20ab8c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18_2to1_18/Protocol1_18_2To1_18.java @@ -85,8 +85,7 @@ public final class Protocol1_18_2To1_18 extends AbstractProtocol(this).register(ClientboundPackets1_19_1.STATISTICS); - final CommandRewriter commandRewriter = new CommandRewriter(this) { + final CommandRewriter commandRewriter = new CommandRewriter<>(this) { @Override - public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { + public void handleArgument(final PacketWrapper wrapper, final String argumentType) { switch (argumentType) { - case "minecraft:item_enchantment": - wrapper.write(Type.STRING, "minecraft:enchantment"); - break; - case "minecraft:mob_effect": - wrapper.write(Type.STRING, "minecraft:mob_effect"); - break; - case "minecraft:entity_summon": - wrapper.write(Type.STRING, "minecraft:entity_type"); - break; - default: - super.handleArgument(wrapper, argumentType); - break; + case "minecraft:item_enchantment" -> wrapper.write(Type.STRING, "minecraft:enchantment"); + case "minecraft:mob_effect" -> wrapper.write(Type.STRING, "minecraft:mob_effect"); + case "minecraft:entity_summon" -> wrapper.write(Type.STRING, "minecraft:entity_type"); + default -> super.handleArgument(wrapper, argumentType); } } @Override public String handleArgumentType(final String argumentType) { - switch (argumentType) { - case "minecraft:resource": - return "minecraft:resource_key"; - case "minecraft:resource_or_tag": - return "minecraft:resource_or_tag_key"; - case "minecraft:entity_summon": - case "minecraft:item_enchantment": - case "minecraft:mob_effect": - return "minecraft:resource"; - } - return argumentType; + return switch (argumentType) { + case "minecraft:resource" -> "minecraft:resource_key"; + case "minecraft:resource_or_tag" -> "minecraft:resource_or_tag_key"; + case "minecraft:entity_summon", "minecraft:item_enchantment", "minecraft:mob_effect" -> + "minecraft:resource"; + default -> argumentType; + }; } }; commandRewriter.registerDeclareCommands1_19(ClientboundPackets1_19_1.DECLARE_COMMANDS); @@ -229,7 +218,12 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol { - signer.accept(wrapper.user().remove(NonceStorage.class).nonce()); - signer.accept(Longs.toByteArray(salt)); - }); + final byte[] signature; + try { + signature = chatSession.sign(signer -> { + signer.accept(wrapper.user().remove(NonceStorage.class).nonce()); + signer.accept(Longs.toByteArray(salt)); + }); + } catch (final SignatureException e) { + throw new RuntimeException(e); + } wrapper.write(Type.LONG, salt); // Salt wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, signature); // Signature } else { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/rewriter/RecipeRewriter1_19_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/rewriter/RecipeRewriter1_19_3.java index abef933ca..741c841ba 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/rewriter/RecipeRewriter1_19_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/rewriter/RecipeRewriter1_19_3.java @@ -45,7 +45,7 @@ public class RecipeRewriter1_19_3 extends Recip } @Override - public void handleCraftingShapeless(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShapeless(final PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.VAR_INT); // Crafting book category handleIngredients(wrapper); @@ -54,7 +54,7 @@ public class RecipeRewriter1_19_3 extends Recip } @Override - public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(final PacketWrapper wrapper) { final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.VAR_INT); // Crafting book category @@ -66,7 +66,7 @@ public class RecipeRewriter1_19_3 extends Recip } @Override - public void handleSmelting(final PacketWrapper wrapper) throws Exception { + public void handleSmelting(final PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.VAR_INT); // Crafting book category handleIngredient(wrapper); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/storage/NonceStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/storage/NonceStorage.java index 6e4878af4..59ddc85ba 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/storage/NonceStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_3to1_19_1/storage/NonceStorage.java @@ -20,15 +20,5 @@ package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.storage; import com.viaversion.viaversion.api.connection.StorableObject; import org.checkerframework.checker.nullness.qual.Nullable; -public final class NonceStorage implements StorableObject { - - private final byte[] nonce; - - public NonceStorage(final byte @Nullable [] nonce) { - this.nonce = nonce; - } - - public byte @Nullable [] nonce() { - return nonce; - } +public record NonceStorage(byte @Nullable[] nonce) implements StorableObject { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java index 34a2aab77..ccddaa697 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java @@ -62,9 +62,9 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol(this) { + new CommandRewriter<>(this) { @Override - public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { + public void handleArgument(final PacketWrapper wrapper, final String argumentType) { if (argumentType.equals("minecraft:time")) { // Minimum wrapper.write(Type.INT, 0); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java index 6826fcdb7..46ad9920a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/EntityPackets.java @@ -207,20 +207,14 @@ public final class EntityPackets extends EntityRewriter 36; // Thorned + case 36 -> 5; // Drowned + case 37 -> 27; // Burned + case 57 -> 15; // Frozen -> Poked + case 44, 2 -> 16; // Generic hurt + default -> -1; + }; } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/InventoryPackets.java index 71d6e8f23..5ff7ad369 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/packets/InventoryPackets.java @@ -94,9 +94,9 @@ public final class InventoryPackets extends ItemRewriter(protocol) { + new RecipeRewriter1_19_3<>(protocol) { @Override - public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(final PacketWrapper wrapper) { super.handleCraftingShaped(wrapper); wrapper.write(Type.BOOLEAN, true); // Show notification } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/rewriter/RecipeRewriter1_19_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/rewriter/RecipeRewriter1_19_4.java index 5471aba55..000e27551 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/rewriter/RecipeRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/rewriter/RecipeRewriter1_19_4.java @@ -30,7 +30,7 @@ public class RecipeRewriter1_19_4 extends Recip } @Override - public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(final PacketWrapper wrapper) { super.handleCraftingShaped(wrapper); wrapper.passthrough(Type.BOOLEAN); // Show notification } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index 3cebeecf3..fd9da1b84 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -273,7 +273,7 @@ public final class EntityPackets extends EntityRewriter 1; // Up/down -> Up + case 2 -> 2; // North + case 0 -> 3; // South + case 1 -> 4; // West + case 3 -> 5; // East + default -> throw new IllegalArgumentException("Unknown 2d id: " + id); + }; } private static void addMonsterSpawnData(final CompoundTag dimension) { @@ -325,7 +320,7 @@ public final class EntityPackets extends EntityRewriter { final Particle particle = (Particle) meta.getValue(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); - if (particle.getId() == particleMappings.id("vibration")) { + if (particle.id() == particleMappings.id("vibration")) { // Remove the position particle.getArguments().remove(0); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/provider/AckSequenceProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/provider/AckSequenceProvider.java index 260e5fc27..11ac77133 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/provider/AckSequenceProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/provider/AckSequenceProvider.java @@ -26,7 +26,7 @@ import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_ public class AckSequenceProvider implements Provider { - public void handleSequence(final UserConnection connection, final int sequence) throws Exception { + public void handleSequence(final UserConnection connection, final int sequence) { final PacketWrapper ackPacket = PacketWrapper.create(ClientboundPackets1_19.BLOCK_CHANGED_ACK, connection); ackPacket.write(Type.VAR_INT, sequence); ackPacket.send(Protocol1_19To1_18_2.class); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/NonceStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/NonceStorage.java index e7fbd6c3f..4ed44b754 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/NonceStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/storage/NonceStorage.java @@ -19,15 +19,5 @@ package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.storage; import com.viaversion.viaversion.api.connection.StorableObject; -public final class NonceStorage implements StorableObject { - - private final byte[] nonce; - - public NonceStorage(final byte[] nonce) { - this.nonce = nonce; - } - - public byte[] nonce() { - return nonce; - } +public record NonceStorage(byte[] nonce) implements StorableObject { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java index 9e3627b59..f86199896 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java @@ -37,6 +37,7 @@ import com.viaversion.viaversion.api.rewriter.ItemRewriter; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.exception.CancelException; +import com.viaversion.viaversion.exception.InformativeException; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; @@ -212,7 +213,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol(protocol) { + new RecipeRewriter1_19_4<>(protocol) { @Override - public void handleCraftingShapeless(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShapeless(final PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.VAR_INT); // Crafting book category handleIngredients(wrapper); @@ -270,7 +270,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter effectsTag = (ListTag) customPotionEffectsTag; + if (customPotionEffectsTag instanceof ListTag effectsTag) { item.tag().put("custom_potion_effects", customPotionEffectsTag); for (final Tag tag : effectsTag) { - if (!(tag instanceof CompoundTag)) { + if (!(tag instanceof CompoundTag effectTag)) { continue; } - final CompoundTag effectTag = (CompoundTag) tag; final Tag idTag = effectTag.remove("Id"); if (idTag instanceof NumberTag) { // Empty effect removed @@ -401,19 +399,16 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter effectsTag = (ListTag) customPotionEffectsTag; + if (customPotionEffectsTag instanceof ListTag effectsTag) { item.tag().put("CustomPotionEffects", effectsTag); for (final Tag tag : effectsTag) { - if (!(tag instanceof CompoundTag)) { + if (!(tag instanceof CompoundTag effectTag)) { continue; } - final CompoundTag effectTag = (CompoundTag) tag; - final Tag idTag = effectTag.remove("id"); - if (idTag instanceof StringTag) { - final int id = PotionEffects1_20_2.keyToId(((StringTag) idTag).getValue()); + if (effectTag.remove("id") instanceof StringTag idTag) { + final int id = PotionEffects1_20_2.keyToId(idTag.getValue()); effectTag.putInt("Id", id + 1); // Account for empty effect at id 0 } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/ConfigurationState.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/ConfigurationState.java index 4b31080d4..7261ad536 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/ConfigurationState.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/ConfigurationState.java @@ -70,11 +70,11 @@ public class ConfigurationState implements StorableObject { this.clientInformation = clientInformation; } - public void addPacketToQueue(final PacketWrapper wrapper, final boolean clientbound) throws Exception { + public void addPacketToQueue(final PacketWrapper wrapper, final boolean clientbound) { packetQueue.add(toQueuedPacket(wrapper, clientbound, false)); } - private QueuedPacket toQueuedPacket(final PacketWrapper wrapper, final boolean clientbound, final boolean skipCurrentPipeline) throws Exception { + private QueuedPacket toQueuedPacket(final PacketWrapper wrapper, final boolean clientbound, final boolean skipCurrentPipeline) { // Caching packet buffers is cursed, copy to heap buffers to make sure we don't start leaking in dumb cases final ByteBuf copy = Unpooled.buffer(); final PacketType packetType = wrapper.getPacketType(); @@ -86,7 +86,7 @@ public class ConfigurationState implements StorableObject { return new QueuedPacket(copy, clientbound, packetType, packetId, skipCurrentPipeline); } - public void setJoinGamePacket(final PacketWrapper wrapper) throws Exception { + public void setJoinGamePacket(final PacketWrapper wrapper) { this.joinGamePacket = toQueuedPacket(wrapper, true, true); queuedJoinGame = true; } @@ -106,7 +106,7 @@ public class ConfigurationState implements StorableObject { } } - public void sendQueuedPackets(final UserConnection connection) throws Exception { + public void sendQueuedPackets(final UserConnection connection) { final boolean hasJoinGamePacket = joinGamePacket != null; if (hasJoinGamePacket) { packetQueue.add(0, joinGamePacket); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastResourcePack.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastResourcePack.java index a7549c9ea..0079b461c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastResourcePack.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastResourcePack.java @@ -21,35 +21,8 @@ import com.google.gson.JsonElement; import com.viaversion.viaversion.api.connection.StorableObject; import org.checkerframework.checker.nullness.qual.Nullable; -public final class LastResourcePack implements StorableObject { - - private final String url; - private final String hash; - private final boolean required; - private final JsonElement prompt; - - public LastResourcePack(final String url, final String hash, final boolean required, @Nullable final JsonElement prompt) { - this.url = url; - this.hash = hash; - this.required = required; - this.prompt = prompt; - } - - public String url() { - return url; - } - - public String hash() { - return hash; - } - - public boolean required() { - return required; - } - - public @Nullable JsonElement prompt() { - return prompt; - } +public record LastResourcePack(String url, String hash, boolean required, + @Nullable JsonElement prompt) implements StorableObject { @Override public boolean clearOnServerSwitch() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastTags.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastTags.java index 0c3cabf41..a248b870c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastTags.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/storage/LastTags.java @@ -31,7 +31,7 @@ public class LastTags implements StorableObject { private final List registryTags = new ArrayList<>(); - public LastTags(final PacketWrapper wrapper) throws Exception { + public LastTags(final PacketWrapper wrapper) { final int length = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < length; i++) { final List tags = new ArrayList<>(); @@ -47,7 +47,7 @@ public class LastTags implements StorableObject { } } - public void sendLastTags(final UserConnection connection) throws Exception { + public void sendLastTags(final UserConnection connection) { if (registryTags.isEmpty()) { return; } @@ -65,23 +65,9 @@ public class LastTags implements StorableObject { packet.send(Protocol1_20_2To1_20.class); } - private static final class RegistryTags { - private final String registryKey; - private final List tags; - - private RegistryTags(final String registryKey, final List tags) { - this.registryKey = registryKey; - this.tags = tags; - } + private record RegistryTags(String registryKey, List tags) { } - private static final class Tag { - private final String key; - private final int[] ids; - - private Tag(final String key, final int[] ids) { - this.key = key; - this.ids = ids; - } + private record Tag(String key, int[] ids) { } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java index 544c4f64d..e9647a64e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/Protocol1_20_3To1_20_2.java @@ -335,11 +335,11 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol(protocol) { + new RecipeRewriter1_20_2<>(protocol) { @Override - public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(final PacketWrapper wrapper) { // Move width and height down final int width = wrapper.read(Type.VAR_INT); final int height = wrapper.read(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java index 409be12f6..407a43f01 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java @@ -90,7 +90,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter { final Particle particle = meta.value(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); - if (particle.getId() == particleMappings.id("vibration")) { + if (particle.id() == particleMappings.id("vibration")) { // Change the type of the resource key argument final String resourceLocation = particle.removeArgument(0).getValue(); if (Key.stripMinecraftNamespace(resourceLocation).equals("block")) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/RecipeRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/RecipeRewriter1_20_3.java index bf4589e13..9c4a0db2c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/RecipeRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_3to1_20_2/rewriter/RecipeRewriter1_20_3.java @@ -31,7 +31,7 @@ public class RecipeRewriter1_20_3 extends Recip } @Override - public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(final PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.VAR_INT); // Crafting book category final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java index 541afd6d4..bd39ce14d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/Protocol1_20_5To1_20_3.java @@ -229,7 +229,7 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol "orange"; + case 2 -> "magenta"; + case 3 -> "light_blue"; + case 4 -> "yellow"; + case 5 -> "lime"; + case 6 -> "pink"; + case 7 -> "gray"; + case 8 -> "light_gray"; + case 9 -> "cyan"; + case 10 -> "purple"; + case 11 -> "blue"; + case 12 -> "brown"; + case 13 -> "green"; + case 14 -> "red"; + case 15 -> "black"; + default -> "white"; + }; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index de0dbe27b..3843c8a36 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -320,7 +320,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter recipeRewriter = new RecipeRewriter1_20_3(protocol) { + final RecipeRewriter1_20_3 recipeRewriter = new RecipeRewriter1_20_3<>(protocol) { @Override protected Item rewrite(final UserConnection connection, @Nullable Item item) { item = super.rewrite(connection, item); @@ -704,8 +704,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter rules = new ArrayList<>(); for (final CompoundTag tag : rulesTag) { HolderSet blocks = null; - if (tag.get("blocks") instanceof StringTag) { - blocks = HolderSet.of(tag.getString("blocks")); + if (tag.get("blocks") instanceof StringTag blocksTag) { + blocks = HolderSet.of(blocksTag.getValue()); } else { final IntArrayTag blockIds = tag.getIntArrayTag("blocks"); if (blockIds != null) { @@ -912,16 +912,15 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter materialHolder; - if (materialTag instanceof StringTag) { + if (materialTag instanceof StringTag materialStringTag) { // Would technically have to be stored and retrieved from registry data, but that'd mean a lot of work - final int id = TrimMaterials1_20_3.keyToId(((StringTag) materialTag).getValue()); + final int id = TrimMaterials1_20_3.keyToId(materialStringTag.getValue()); if (id == -1) { return; } materialHolder = Holder.of(id); - } else if (materialTag instanceof CompoundTag) { - final CompoundTag materialCompoundTag = (CompoundTag) materialTag; + } else if (materialTag instanceof CompoundTag materialCompoundTag) { final StringTag assetNameTag = materialCompoundTag.getStringTag("asset_name"); final StringTag ingredientTag = materialCompoundTag.getStringTag("ingredient"); if (assetNameTag == null || ingredientTag == null) { @@ -940,12 +939,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter overrideArmorMaterials = new Int2ObjectOpenHashMap<>(); if (overrideArmorMaterialsTag != null) { for (final Map.Entry entry : overrideArmorMaterialsTag.entrySet()) { - if (!(entry.getValue() instanceof StringTag)) { + if (!(entry.getValue() instanceof StringTag valueTag)) { continue; } try { final int id = Integer.parseInt(entry.getKey()); - overrideArmorMaterials.put(id, ((StringTag) entry.getValue()).getValue()); + overrideArmorMaterials.put(id, valueTag.getValue()); } catch (NumberFormatException ignored) { } } @@ -962,15 +961,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter patternHolder; - if (patternTag instanceof StringTag) { + if (patternTag instanceof StringTag patternStringTag) { // Would technically have to be stored and retrieved from registry data, but that'd mean a lot of work - final int id = TrimPatterns1_20_3.keyToId(((StringTag) patternTag).getValue()); + final int id = TrimPatterns1_20_3.keyToId(patternStringTag.getValue()); if (id == -1) { return; } patternHolder = Holder.of(id); - } else if (patternTag instanceof CompoundTag) { - final CompoundTag patternCompoundTag = (CompoundTag) patternTag; + } else if (patternTag instanceof CompoundTag patternCompoundTag) { final String assetId = patternCompoundTag.getString("assetId"); final String templateItem = patternCompoundTag.getString("templateItem"); if (assetId == null || templateItem == null) { @@ -1014,10 +1012,10 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter entry : blockState.entrySet()) { // Only String and IntTags are valid final Tag value = entry.getValue(); - if (value instanceof StringTag) { - properties.put(entry.getKey(), ((StringTag) value).getValue()); - } else if (value instanceof IntTag) { - properties.put(entry.getKey(), Integer.toString(((NumberTag) value).asInt())); + if (value instanceof StringTag valueStringTag) { + properties.put(entry.getKey(), valueStringTag.getValue()); + } else if (value instanceof IntTag valueIntTag) { + properties.put(entry.getKey(), Integer.toString(valueIntTag.asInt())); } } data.set(StructuredDataKey.BLOCK_STATE, new BlockStateProperties(properties)); @@ -1224,13 +1222,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter properties) { for (final Map.Entry entry : propertiesTag.entrySet()) { - if (!(entry.getValue() instanceof ListTag)) { + if (!(entry.getValue() instanceof ListTag listTag)) { continue; } - for (final Tag propertyTag : (ListTag) entry.getValue()) { - if (!(propertyTag instanceof CompoundTag)) { + for (final Tag propertyTag : listTag) { + if (!(propertyTag instanceof CompoundTag compoundTag)) { continue; } - final CompoundTag compoundTag = (CompoundTag) propertyTag; final String value = compoundTag.getString("Value", ""); final String signature = compoundTag.getString("Signature"); properties.add(new GameProfile.Property( @@ -1419,20 +1415,20 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter patternsTag = tag.getListTag("Patterns", CompoundTag.class); @@ -1493,25 +1489,22 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter propertiesListTag = new ListTag<>(CompoundTag.class); - for (final Map.Entry entry : ((CompoundTag) propertiesTag).entrySet()) { - if (!(entry.getValue() instanceof ListTag)) { + for (final Map.Entry entry : propertiesTag.entrySet()) { + if (!(entry.getValue() instanceof ListTag entryValue)) { continue; } - final ListTag entryValue = (ListTag) entry.getValue(); for (final Tag propertyTag : entryValue) { - if (!(propertyTag instanceof CompoundTag)) { + if (!(propertyTag instanceof CompoundTag propertyCompoundTag)) { continue; } final CompoundTag updatedPropertyTag = new CompoundTag(); - final CompoundTag propertyCompoundTag = (CompoundTag) propertyTag; final String value = propertyCompoundTag.getString("Value", ""); final String signature = propertyCompoundTag.getString("Signature"); updatedPropertyTag.putString("name", entry.getKey()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/ComponentRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/ComponentRewriter1_20_5.java index fb693f9e4..8b9a6dd94 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/ComponentRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/ComponentRewriter1_20_5.java @@ -770,8 +770,8 @@ public class ComponentRewriter1_20_5 extends Co protected CompoundTag convertLodestoneTracker(final LodestoneTracker value) { final CompoundTag tag = new CompoundTag(); - if (value.pos() != null) { - convertGlobalPos(tag, value.pos()); + if (value.position() != null) { + convertGlobalPos(tag, value.position()); } if (!value.tracked()) { tag.putBoolean("tracked", false); @@ -1158,13 +1158,6 @@ public class ComponentRewriter1_20_5 extends Co T convert(final Tag tag); } - private static final class ConverterPair { - private final DataConverter dataConverter; - private final TagConverter tagConverter; - - ConverterPair(final DataConverter dataConverter, final TagConverter tagConverter) { - this.dataConverter = dataConverter; - this.tagConverter = tagConverter; - } + private record ConverterPair(DataConverter dataConverter, TagConverter tagConverter) { } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index 54dc1ccd4..45b9df15d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -362,7 +362,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { final CompoundTag fireworksTag = new CompoundTag(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/storage/AcknowledgedMessagesStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/storage/AcknowledgedMessagesStorage.java index ebf210f1a..33333759c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/storage/AcknowledgedMessagesStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/storage/AcknowledgedMessagesStorage.java @@ -82,7 +82,7 @@ public final class AcknowledgedMessagesStorage implements StorableObject { this.chatSession = new ChatSession(sessionId, profileKey); } - public void sendQueuedChatSession(final PacketWrapper wrapper) throws Exception { + public void sendQueuedChatSession(final PacketWrapper wrapper) { if (chatSession == null) { return; } @@ -94,22 +94,7 @@ public final class AcknowledgedMessagesStorage implements StorableObject { chatSession = null; } - public static final class ChatSession { - private final UUID sessionId; - private final ProfileKey profileKey; - - public ChatSession(final UUID sessionId, final ProfileKey profileKey) { - this.sessionId = sessionId; - this.profileKey = profileKey; - } - - public UUID sessionId() { - return sessionId; - } - - public ProfileKey profileKey() { - return profileKey; - } + public record ChatSession(UUID sessionId, ProfileKey profileKey) { } public void clear() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java index 3b05f8a92..133e0dc67 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java @@ -42,9 +42,9 @@ import java.util.List; public class Protocol1_9_3To1_9_1_2 extends AbstractProtocol { - public static final ValueTransformer ADJUST_PITCH = new ValueTransformer(Type.UNSIGNED_BYTE, Type.UNSIGNED_BYTE) { + public static final ValueTransformer ADJUST_PITCH = new ValueTransformer<>(Type.UNSIGNED_BYTE, Type.UNSIGNED_BYTE) { @Override - public Short transform(PacketWrapper wrapper, Short inputValue) throws Exception { + public Short transform(PacketWrapper wrapper, Short inputValue) { return (short) Math.round(inputValue / 63.5F * 63.0F); } }; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/ItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/ItemRewriter.java index bc917afbc..58edf33d5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -309,72 +309,53 @@ public class ItemRewriter { String id; switch (effect) { - case 1: - id = "regeneration"; - break; - case 2: - id = "swiftness"; - break; - case 3: + case 1 -> id = "regeneration"; + case 2 -> id = "swiftness"; + case 3 -> { id = "fire_resistance"; canEnhance = false; - break; - case 4: - id = "poison"; - break; - case 5: + } + case 4 -> id = "poison"; + case 5 -> { id = "healing"; canExtend = false; - break; - case 6: + } + case 6 -> { id = "night_vision"; canEnhance = false; - break; - - case 8: + } + case 8 -> { id = "weakness"; canEnhance = false; - break; - case 9: - id = "strength"; - break; - case 10: + } + case 9 -> id = "strength"; + case 10 -> { id = "slowness"; canEnhance = false; - break; - case 11: - id = "leaping"; - break; - case 12: + } + case 11 -> id = "leaping"; + case 12 -> { id = "harming"; canExtend = false; - break; - case 13: + } + case 13 -> { id = "water_breathing"; canEnhance = false; - break; - case 14: + } + case 14 -> { id = "invisibility"; canEnhance = false; - break; - - - default: + } + default -> { canEnhance = false; canExtend = false; - switch (name) { - case 0: - id = "mundane"; - break; - case 16: - id = "awkward"; - break; - case 32: - id = "thick"; - break; - default: - id = "empty"; - } + id = switch (name) { + case 0 -> "mundane"; + case 16 -> "awkward"; + case 32 -> "thick"; + default -> "empty"; + }; + } } if (effect > 0) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index 615b4846e..912f1d56e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -54,7 +54,7 @@ import com.viaversion.viaversion.util.SerializerVersion; public class Protocol1_9To1_8 extends AbstractProtocol { - public static final ValueTransformer STRING_TO_JSON = new ValueTransformer(Type.COMPONENT) { + public static final ValueTransformer STRING_TO_JSON = new ValueTransformer<>(Type.COMPONENT) { @Override public JsonElement transform(PacketWrapper wrapper, String line) { return ComponentUtil.convertJsonOrEmpty(line, SerializerVersion.V1_8, SerializerVersion.V1_9); @@ -71,16 +71,15 @@ public class Protocol1_9To1_8 extends AbstractProtocol true; + default -> false; + }; } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java index 641f50f45..036d05fc0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java @@ -106,8 +106,7 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter toNewShort = new ValueTransformer(Type.SHORT) { + public static final ValueTransformer toNewShort = new ValueTransformer<>(Type.SHORT) { @Override public Short transform(PacketWrapper wrapper, Byte inputValue) { return (short) (inputValue * 128); @@ -148,9 +148,9 @@ public class EntityPackets { public void register() { map(Type.VAR_INT); // 0 - Entity ID // 1 - Slot ID - map(Type.SHORT, new ValueTransformer(Type.VAR_INT) { + map(Type.SHORT, new ValueTransformer<>(Type.VAR_INT) { @Override - public Integer transform(PacketWrapper wrapper, Short slot) throws Exception { + public Integer transform(PacketWrapper wrapper, Short slot) { int entityId = wrapper.get(Type.VAR_INT, 0); int receiverId = wrapper.user().getEntityTracker(Protocol1_9To1_8.class).clientEntityId(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/PlayerPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index c50389ade..e8a3401c6 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -49,12 +49,8 @@ public class PlayerPackets { map(Type.BYTE); // 1 - Chat Position handler(wrapper -> { - try { - JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0); - ChatRewriter.toClient(obj, wrapper.user()); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to transform chat component", e); - } + JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0); + ChatRewriter.toClient(obj, wrapper.user()); }); } }); @@ -101,9 +97,7 @@ public class PlayerPackets { map(Type.BYTE); // 5 - Player Flags - handler(wrapper -> { - wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added - }); + create(Type.VAR_INT, 0); // 6 - Teleport ID was added } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index bc73bab4a..405b73bb7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -41,7 +41,7 @@ import java.util.List; import java.util.logging.Level; public class SpawnPackets { - public static final ValueTransformer toNewDouble = new ValueTransformer(Type.DOUBLE) { + public static final ValueTransformer toNewDouble = new ValueTransformer<>(Type.DOUBLE) { @Override public Double transform(PacketWrapper wrapper, Integer inputValue) { return inputValue / 32D; @@ -267,11 +267,7 @@ public class SpawnPackets { packet.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0)); packet.write(Type.VAR_INT, 0); packet.write(Type.ITEM1_8, new DataItem(item, (byte) 1, (short) 0, null)); - try { - packet.send(Protocol1_9To1_8.class); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.SEVERE, "Failed to send entity equipment packet", e); - } + packet.send(Protocol1_9To1_8.class); } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 1b517f8ee..e3d148d9a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -366,24 +366,12 @@ public class WorldPackets { int y = p.y(); int z = p.z(); switch (face) { - case 0: - y--; - break; - case 1: - y++; - break; - case 2: - z--; - break; - case 3: - z++; - break; - case 4: - x--; - break; - case 5: - x++; - break; + case 0 -> y--; + case 1 -> y++; + case 2 -> z--; + case 3 -> z++; + case 4 -> x--; + case 5 -> x++; } EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); tracker.addBlockInteraction(new Position(x, y, z)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/BossBarProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/BossBarProvider.java index ba7b2d127..183cccd70 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/BossBarProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/BossBarProvider.java @@ -22,11 +22,10 @@ import com.viaversion.viaversion.api.platform.providers.Provider; import java.util.UUID; public class BossBarProvider implements Provider { - public void handleAdd(UserConnection user, UUID barUUID) { + public void handleAdd(UserConnection user, UUID barUUID) { } public void handleRemove(UserConnection user, UUID barUUID) { - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java index dd8a5873a..94327cc12 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/providers/CommandBlockProvider.java @@ -31,17 +31,17 @@ import java.util.Optional; public class CommandBlockProvider implements Provider { - public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) throws Exception { + public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) { checkPermission(user); getStorage(user).addOrUpdateBlock(position, tag); } - public Optional get(UserConnection user, Position position) throws Exception { + public Optional get(UserConnection user, Position position) { checkPermission(user); return getStorage(user).getCommandBlock(position); } - public void unloadChunk(UserConnection user, int x, int z) throws Exception { + public void unloadChunk(UserConnection user, int x, int z) { checkPermission(user); getStorage(user).unloadChunk(x, z); } @@ -50,7 +50,7 @@ public class CommandBlockProvider implements Provider { return connection.get(CommandBlockStorage.class); } - public void sendPermission(UserConnection user) throws Exception { + public void sendPermission(UserConnection user) { PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_STATUS, null, user); // Entity status EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class); @@ -63,7 +63,7 @@ public class CommandBlockProvider implements Provider { } // Fix for Bungee since the join game is not sent after the first one - private void checkPermission(UserConnection user) throws Exception { + private void checkPermission(UserConnection user) { CommandBlockStorage storage = getStorage(user); if (!storage.isPermissions()) { sendPermission(user); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index 0c2899691..5215e8c1c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -64,27 +64,21 @@ public class EntityTracker1_9 extends EntityTrackerBase { .expireAfterAccess(250, TimeUnit.MILLISECONDS) .build() .asMap()); - private boolean blocking = false; - private boolean autoTeam = false; - private Position currentlyDigging = null; - private boolean teamExists = false; + private boolean blocking; + private boolean autoTeam; + private Position currentlyDigging; + private boolean teamExists; private GameMode gameMode; private String currentTeam; private int heldItemSlot; - private Item itemInSecondHand = null; + private Item itemInSecondHand; public EntityTracker1_9(UserConnection user) { super(user, EntityType.PLAYER); } public UUID getEntityUUID(int id) { - UUID uuid = uuidMap.get(id); - if (uuid == null) { - uuid = UUID.randomUUID(); - uuidMap.put(id, uuid); - } - - return uuid; + return uuidMap.computeIfAbsent(id, k -> UUID.randomUUID()); } public void setSecondHand(Item item) { @@ -96,11 +90,7 @@ public class EntityTracker1_9 extends EntityTrackerBase { wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, 1); // slot wrapper.write(Type.ITEM1_8, this.itemInSecondHand = item); - try { - wrapper.scheduleSend(Protocol1_9To1_8.class); - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send second hand item", e); - } + wrapper.scheduleSend(Protocol1_9To1_8.class); } public Item getItemInSecondHand() { @@ -221,17 +211,14 @@ public class EntityTracker1_9 extends EntityTrackerBase { && (displayNameVisible = getMetaByIndex(metadataList, 3)) != null && (boolean) displayNameVisible.getValue()) { if (!knownHolograms.contains(entityId)) { knownHolograms.add(entityId); - try { - // Send movement - PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_POSITION, null, user()); - wrapper.write(Type.VAR_INT, entityId); - wrapper.write(Type.SHORT, (short) 0); - wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D))); - wrapper.write(Type.SHORT, (short) 0); - wrapper.write(Type.BOOLEAN, true); - wrapper.scheduleSend(Protocol1_9To1_8.class); - } catch (Exception ignored) { - } + // Send movement + PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_POSITION, null, user()); + wrapper.write(Type.VAR_INT, entityId); + wrapper.write(Type.SHORT, (short) 0); + wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D))); + wrapper.write(Type.SHORT, (short) 0); + wrapper.write(Type.BOOLEAN, true); + wrapper.scheduleSend(Protocol1_9To1_8.class); } } } @@ -306,14 +293,10 @@ public class EntityTracker1_9 extends EntityTrackerBase { wrapper.write(Type.BYTE, (byte) 1); // remove team } teamExists = add; - try { - if (now) { - wrapper.send(Protocol1_9To1_8.class); - } else { - wrapper.scheduleSend(Protocol1_9To1_8.class); - } - } catch (Exception e) { - Via.getPlatform().getLogger().log(Level.WARNING, "Failed to send team packet", e); + if (now) { + wrapper.send(Protocol1_9To1_8.class); + } else { + wrapper.scheduleSend(Protocol1_9To1_8.class); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/InventoryTracker.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/InventoryTracker.java index cf702fdea..3cbf9f7df 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/InventoryTracker.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/InventoryTracker.java @@ -27,8 +27,8 @@ public class InventoryTracker implements StorableObject { private String inventory; private final Map> windowItemCache = new HashMap<>(); - private int itemIdInCursor = 0; - private boolean dragging = false; + private int itemIdInCursor; + private boolean dragging; public String getInventory() { return inventory; @@ -144,12 +144,10 @@ public class InventoryTracker implements StorableObject { break; case 5: // Mouse dragging switch (button) { - case 0: // Start left dragging - case 4: // Start right dragging + case 0, 4: // Start left/right dragging this.dragging = true; break; - case 1: // Place item during left dragging - case 5: // Place item during right dragging + case 1, 5: // Place item during left/right dragging // Check dragging mode and item on cursor if (this.dragging && this.itemIdInCursor != 0 && !isArmorOrResultSlot) { int previousItem = getItemId(windowId, hoverSlot); @@ -161,8 +159,7 @@ public class InventoryTracker implements StorableObject { this.itemIdInCursor = previousItem; } break; - case 2: // Stop left dragging - case 6: // Stop right dragging + case 2, 6: // Stop left/right dragging this.dragging = false; break; } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/BlockRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/BlockRewriter.java index f03f3159b..34aff060d 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/BlockRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/BlockRewriter.java @@ -47,11 +47,6 @@ public class BlockRewriter { private final Type positionType; private final Type compoundTagType; - @Deprecated/*(forRemoval = true)*/ - public BlockRewriter(Protocol protocol, Type positionType) { - this(protocol, positionType, Type.NAMED_COMPOUND_TAG); - } - public BlockRewriter(Protocol protocol, Type positionType, Type compoundTagType) { this.protocol = protocol; this.positionType = positionType; diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/CommandRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/CommandRewriter.java index 0fe359720..a0ac6bfac 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/CommandRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/CommandRewriter.java @@ -144,7 +144,7 @@ public class CommandRewriter { }); } - public void handleArgument(PacketWrapper wrapper, String argumentType) throws Exception { + public void handleArgument(PacketWrapper wrapper, String argumentType) { CommandArgumentConsumer handler = parserHandlers.get(argumentType); if (handler != null) { handler.accept(wrapper); @@ -189,6 +189,6 @@ public class CommandRewriter { @FunctionalInterface public interface CommandArgumentConsumer { - void accept(PacketWrapper wrapper) throws Exception; + void accept(PacketWrapper wrapper); } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java index bf81bc054..72aa8c513 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ComponentRewriter.java @@ -157,7 +157,7 @@ public class ComponentRewriter { }); } - public void passthroughAndProcess(final PacketWrapper wrapper) throws Exception { + public void passthroughAndProcess(final PacketWrapper wrapper) { switch (type) { case JSON: processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 50af9c7a6..4c3735489 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -593,7 +593,7 @@ public abstract class EntityRewriter from, Type to) throws Exception { + public void rewriteParticle(PacketWrapper wrapper, Type from, Type to) { final Particle particle = wrapper.read(from); rewriteParticle(wrapper.user(), particle); wrapper.write(to, particle); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java index 4f56befc2..26c62e1be 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java @@ -519,12 +519,12 @@ public class ItemRewriter { recipeHandlers.put("crafting_decorated_pot", this::handleSimpleRecipe); } - public void handleRecipeType(PacketWrapper wrapper, String type) throws Exception { + public void handleRecipeType(PacketWrapper wrapper, String type) { RecipeConsumer handler = recipeHandlers.get(type); if (handler != null) { handler.accept(wrapper); @@ -90,7 +90,7 @@ public class RecipeRewriter { }); } - public void handleCraftingShaped(PacketWrapper wrapper) throws Exception { + public void handleCraftingShaped(PacketWrapper wrapper) { int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); wrapper.passthrough(Type.STRING); // Group for (int i = 0; i < ingredientsNo; i++) { @@ -101,14 +101,14 @@ public class RecipeRewriter { wrapper.write(mappedItemType(), result); } - public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception { + public void handleCraftingShapeless(PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group handleIngredients(wrapper); final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); wrapper.write(mappedItemType(), result); } - public void handleSmelting(PacketWrapper wrapper) throws Exception { + public void handleSmelting(PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group handleIngredient(wrapper); final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); @@ -117,25 +117,25 @@ public class RecipeRewriter { wrapper.passthrough(Type.VAR_INT); // Cooking time } - public void handleStonecutting(PacketWrapper wrapper) throws Exception { + public void handleStonecutting(PacketWrapper wrapper) { wrapper.passthrough(Type.STRING); // Group handleIngredient(wrapper); final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); wrapper.write(mappedItemType(), result); } - public void handleSmithing(PacketWrapper wrapper) throws Exception { + public void handleSmithing(PacketWrapper wrapper) { handleIngredient(wrapper); // Base handleIngredient(wrapper); // Addition final Item result = rewrite(wrapper.user(), wrapper.read(itemType())); wrapper.write(mappedItemType(), result); } - public void handleSimpleRecipe(final PacketWrapper wrapper) throws Exception { + public void handleSimpleRecipe(final PacketWrapper wrapper) { wrapper.passthrough(Type.VAR_INT); // Crafting book category } - public void handleSmithingTransform(final PacketWrapper wrapper) throws Exception { + public void handleSmithingTransform(final PacketWrapper wrapper) { handleIngredient(wrapper); // Template handleIngredient(wrapper); // Base handleIngredient(wrapper); // Additions @@ -143,7 +143,7 @@ public class RecipeRewriter { wrapper.write(mappedItemType(), result); } - public void handleSmithingTrim(final PacketWrapper wrapper) throws Exception { + public void handleSmithingTrim(final PacketWrapper wrapper) { handleIngredient(wrapper); // Template handleIngredient(wrapper); // Base handleIngredient(wrapper); // Additions @@ -156,7 +156,7 @@ public class RecipeRewriter { return item; } - protected void handleIngredient(final PacketWrapper wrapper) throws Exception { + protected void handleIngredient(final PacketWrapper wrapper) { final Item[] items = wrapper.read(itemArrayType()); wrapper.write(mappedItemArrayType(), items); for (int i = 0; i < items.length; i++) { @@ -165,7 +165,7 @@ public class RecipeRewriter { } } - protected void handleIngredients(final PacketWrapper wrapper) throws Exception { + protected void handleIngredients(final PacketWrapper wrapper) { final int ingredients = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < ingredients; i++) { handleIngredient(wrapper); @@ -175,7 +175,7 @@ public class RecipeRewriter { @FunctionalInterface public interface RecipeConsumer { - void accept(PacketWrapper wrapper) throws Exception; + void accept(PacketWrapper wrapper); } protected Type itemType() { diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/StatisticsRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/StatisticsRewriter.java index 5f0e0cd59..ff888c869 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/StatisticsRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/StatisticsRewriter.java @@ -68,32 +68,23 @@ public class StatisticsRewriter { } protected @Nullable IdRewriteFunction getRewriter(RegistryType type) { - switch (type) { - case BLOCK: - return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null; - case ITEM: - return protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null; - case ENTITY: - return protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null; - } - throw new IllegalArgumentException("Unknown registry type in statistics packet: " + type); + return switch (type) { + case BLOCK -> + protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null; + case ITEM -> + protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null; + case ENTITY -> + protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null; + default -> throw new IllegalArgumentException("Unknown registry type in statistics packet: " + type); + }; } public @Nullable RegistryType getRegistryTypeForStatistic(int statisticsId) { - switch (statisticsId) { - case 0: - return RegistryType.BLOCK; - case 1: - case 2: - case 3: - case 4: - case 5: - return RegistryType.ITEM; - case 6: - case 7: - return RegistryType.ENTITY; - default: - return null; - } + return switch (statisticsId) { + case 0 -> RegistryType.BLOCK; + case 1, 2, 3, 4, 5 -> RegistryType.ITEM; + case 6, 7 -> RegistryType.ENTITY; + default -> null; + }; } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java index df3f5fd95..c07032987 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java @@ -163,11 +163,11 @@ public class TagRewriter implements com.viavers }; } - public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List newTags) throws Exception { + public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List newTags) { handle(wrapper, rewriteFunction, newTags, null); } - public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List newTags, @Nullable Map tagsToRename) throws Exception { + public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List newTags, @Nullable Map tagsToRename) { int tagsSize = wrapper.read(Type.VAR_INT); wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count @@ -220,17 +220,14 @@ public class TagRewriter implements com.viavers public @Nullable IdRewriteFunction getRewriter(RegistryType tagType) { MappingData mappingData = protocol.getMappingData(); - switch (tagType) { - case BLOCK: - return mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null; - case ITEM: - return mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null; - case ENTITY: - return protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null; - case FLUID: - case GAME_EVENT: - default: - return null; - } + return switch (tagType) { + case BLOCK -> + mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null; + case ITEM -> + mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null; + case ENTITY -> + protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null; + case FLUID, GAME_EVENT -> null; + }; } } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaFilter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaFilter.java index 9a66ce8c4..9f7567156 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaFilter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/meta/MetaFilter.java @@ -27,20 +27,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectFunction; import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; -public class MetaFilter { - private final MetaHandler handler; - private final EntityType type; - private final MetaType metaType; - private final int index; - private final boolean filterFamily; +public record MetaFilter(@Nullable EntityType type, boolean filterFamily, + @Nullable MetaType metaType, int index, MetaHandler handler) { - public MetaFilter(@Nullable EntityType type, boolean filterFamily, @Nullable MetaType metaType, int index, MetaHandler handler) { + public MetaFilter { Preconditions.checkNotNull(handler, "MetaHandler cannot be null"); - this.type = type; - this.metaType = metaType; - this.filterFamily = filterFamily; - this.index = index; - this.handler = handler; } /** diff --git a/common/src/main/java/com/viaversion/viaversion/update/Version.java b/common/src/main/java/com/viaversion/viaversion/update/Version.java index b35765706..0c92d2a4a 100644 --- a/common/src/main/java/com/viaversion/viaversion/update/Version.java +++ b/common/src/main/java/com/viaversion/viaversion/update/Version.java @@ -100,7 +100,7 @@ public class Version implements Comparable { @Override public boolean equals(Object that) { - return that instanceof Version && equals(this, (Version) that); + return that instanceof Version version && equals(this, version); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/util/CipherUtil.java b/common/src/main/java/com/viaversion/viaversion/util/CipherUtil.java index dab2c9c89..48f837831 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/CipherUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/CipherUtil.java @@ -36,11 +36,15 @@ public final class CipherUtil { } } - public static byte[] encryptNonce(final byte[] publicKeyBytes, final byte[] nonceBytes) throws Exception { - final EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); - final PublicKey key = RSA_FACTORY.generatePublic(keySpec); - final Cipher cipher = Cipher.getInstance(key.getAlgorithm()); - cipher.init(Cipher.ENCRYPT_MODE, key); - return cipher.doFinal(nonceBytes); + public static byte[] encryptNonce(final byte[] publicKeyBytes, final byte[] nonceBytes) { + try { + final EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKeyBytes); + final PublicKey key = RSA_FACTORY.generatePublic(keySpec); + final Cipher cipher = Cipher.getInstance(key.getAlgorithm()); + cipher.init(Cipher.ENCRYPT_MODE, key); + return cipher.doFinal(nonceBytes); + } catch (final Exception e) { + throw new RuntimeException(e); + } } } diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index 53908e8d1..dd0cf2928 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -226,8 +226,7 @@ public abstract class Config { public List getListSafe(String key, Class type, String invalidValueMessage) { Object o = this.config.get(key); - if (o instanceof List) { - List list = (List) o; + if (o instanceof List list) { List filteredValues = new ArrayList<>(); for (Object o1 : list) { if (type.isInstance(o1)) { diff --git a/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java b/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java index 14909a6fa..fb7d78801 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/DumpUtil.java @@ -87,7 +87,7 @@ public final class DumpUtil { try { con.setRequestProperty("Content-Type", "application/json"); - con.addRequestProperty("User-Agent", "ViaVersion-" + platform.getPlatformName() + "/" + version.getPluginVersion()); + con.addRequestProperty("User-Agent", "ViaVersion-" + platform.getPlatformName() + "/" + version.pluginVersion()); con.setRequestMethod("POST"); con.setDoOutput(true); diff --git a/common/src/main/java/com/viaversion/viaversion/util/ReflectionUtil.java b/common/src/main/java/com/viaversion/viaversion/util/ReflectionUtil.java index 2cc5d8244..1fe56131d 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/ReflectionUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/ReflectionUtil.java @@ -20,12 +20,8 @@ package com.viaversion.viaversion.util; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -public class ReflectionUtil { +public final class ReflectionUtil { public static Object invokeStatic(Class clazz, String method) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Method m = clazz.getDeclaredMethod(method); @@ -78,74 +74,4 @@ public class ReflectionUtil { field.setAccessible(true); field.set(o, value); } - - public static final class ClassReflection { - private final Class handle; - private final Map fields = new ConcurrentHashMap<>(); - private final Map methods = new ConcurrentHashMap<>(); - - public ClassReflection(Class handle) { - this(handle, true); - } - - public ClassReflection(Class handle, boolean recursive) { - this.handle = handle; - scanFields(handle, recursive); - scanMethods(handle, recursive); - } - - private void scanFields(Class host, boolean recursive) { - if (recursive && host.getSuperclass() != null && host.getSuperclass() != Object.class) { - scanFields(host.getSuperclass(), true); - } - - for (Field field : host.getDeclaredFields()) { - field.setAccessible(true); - fields.put(field.getName(), field); - } - } - - private void scanMethods(Class host, boolean recursive) { - if (recursive && host.getSuperclass() != null && host.getSuperclass() != Object.class) { - scanMethods(host.getSuperclass(), true); - } - - for (Method method : host.getDeclaredMethods()) { - method.setAccessible(true); - methods.put(method.getName(), method); - } - } - - public Object newInstance() throws ReflectiveOperationException { - return handle.getConstructor().newInstance(); - } - - public Field getField(String name) { - return fields.get(name); - } - - public void setFieldValue(String fieldName, Object instance, Object value) throws IllegalAccessException { - getField(fieldName).set(instance, value); - } - - public T getFieldValue(String fieldName, Object instance, Class type) throws IllegalAccessException { - return type.cast(getField(fieldName).get(instance)); - } - - public T invokeMethod(Class type, String methodName, Object instance, Object... args) throws InvocationTargetException, IllegalAccessException { - return type.cast(getMethod(methodName).invoke(instance, args)); - } - - public Method getMethod(String name) { - return methods.get(name); - } - - public Collection getFields() { - return Collections.unmodifiableCollection(fields.values()); - } - - public Collection getMethods() { - return Collections.unmodifiableCollection(methods.values()); - } - } } diff --git a/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java b/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java index 8b5a95940..74e44a3cb 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/TagUtil.java @@ -67,14 +67,13 @@ public final class TagUtil { } private static Tag handleDeep(@Nullable final String key, final Tag tag, final TagUpdater consumer) { - if (tag instanceof CompoundTag) { - final CompoundTag compoundTag = (CompoundTag) tag; + if (tag instanceof final CompoundTag compoundTag) { for (final Map.Entry entry : compoundTag.entrySet()) { final Tag updatedTag = handleDeep(entry.getKey(), entry.getValue(), consumer); entry.setValue(updatedTag); } - } else if (tag instanceof ListTag) { - handleListTag((ListTag) tag, consumer); + } else if (tag instanceof ListTag listTag) { + handleListTag(listTag, consumer); } return consumer.update(key, tag); } diff --git a/common/src/main/resources/assets/viaversion/data/en_US.properties b/common/src/main/resources/assets/viaversion/data/en_US.properties index a5afd07c8..dd044d8d6 100644 --- a/common/src/main/resources/assets/viaversion/data/en_US.properties +++ b/common/src/main/resources/assets/viaversion/data/en_US.properties @@ -1523,7 +1523,6 @@ effect.unluck=Bad Luck effect.levitation=Levitation tipped_arrow.effect.empty=Uncraftable Tipped Arrow -tipped_arrow.effect.water=Tipped Arrow tipped_arrow.effect.mundane=Tipped Arrow tipped_arrow.effect.thick=Tipped Arrow tipped_arrow.effect.awkward=Tipped Arrow diff --git a/common/src/test/java/com/viaversion/viaversion/common/protocol/ProtocolVersionTest.java b/common/src/test/java/com/viaversion/viaversion/common/protocol/ProtocolVersionTest.java index 23bdd5a64..f1ef70976 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/protocol/ProtocolVersionTest.java +++ b/common/src/test/java/com/viaversion/viaversion/common/protocol/ProtocolVersionTest.java @@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersionRange; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class ProtocolVersionTest { +class ProtocolVersionTest { @Test void testVersionWildcard() { diff --git a/common/src/test/java/com/viaversion/viaversion/common/type/ItemTypeTest.java b/common/src/test/java/com/viaversion/viaversion/common/type/ItemTypeTest.java index a9c00b750..eca2eac36 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/type/ItemTypeTest.java +++ b/common/src/test/java/com/viaversion/viaversion/common/type/ItemTypeTest.java @@ -24,9 +24,10 @@ import io.netty.buffer.Unpooled; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class ItemTypeTest { +class ItemTypeTest { + @Test - public void testEmptyItemRead() throws Exception { + void testEmptyItemRead() { // Test empty item read Assertions.assertNull(Type.ITEM1_8.read(Unpooled.wrappedBuffer(new byte[]{-1, -1}))); Assertions.assertNull(Type.ITEM1_13.read(Unpooled.wrappedBuffer(new byte[]{-1, -1}))); @@ -34,8 +35,7 @@ public class ItemTypeTest { } @Test - public void testNormalItemRead() throws Exception { - + void testNormalItemRead() { // Test item read Assertions.assertEquals( new DataItem(Short.MAX_VALUE, (byte) -128, (short) 257, null), @@ -66,7 +66,7 @@ public class ItemTypeTest { } @Test - public void testEmptyItemWrite() throws Exception { + void testEmptyItemWrite() { ByteBuf buf = Unpooled.buffer(); // Test item empty write @@ -79,7 +79,7 @@ public class ItemTypeTest { } @Test - public void testNormalItemWrite() throws Exception { + void testNormalItemWrite() { ByteBuf buf = Unpooled.buffer(); // Test item write diff --git a/common/src/test/java/com/viaversion/viaversion/common/type/StringTypeTest.java b/common/src/test/java/com/viaversion/viaversion/common/type/StringTypeTest.java index 361e9e7a6..580658025 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/type/StringTypeTest.java +++ b/common/src/test/java/com/viaversion/viaversion/common/type/StringTypeTest.java @@ -24,9 +24,9 @@ import io.netty.buffer.Unpooled; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class StringTypeTest { +class StringTypeTest { @Test - public void testStringWrite() throws Exception { + void testStringWrite() { // Write final ByteBuf buf = Unpooled.buffer(); Type.STRING.write(buf, "\uD83E\uDDFD"); // Sponge Emoji @@ -34,7 +34,7 @@ public class StringTypeTest { } @Test - public void testStringRead() throws Exception { + void testStringRead() throws Exception { // Write final ByteBuf buf = Unpooled.buffer(); Type.STRING.write(buf, new String(new char[Short.MAX_VALUE])); @@ -48,7 +48,7 @@ public class StringTypeTest { } @Test - public void testStringReadOverflowException() { + void testStringReadOverflowException() { // Read exception final ByteBuf buf = Unpooled.buffer(); Type.VAR_INT.writePrimitive(buf, (Short.MAX_VALUE + 1) * 4); @@ -59,7 +59,7 @@ public class StringTypeTest { } @Test - public void testStringWriteOverflowException() { + void testStringWriteOverflowException() { // Write exceptions final ByteBuf buf = Unpooled.buffer(); Assertions.assertThrows(IllegalArgumentException.class, () -> Type.STRING.write(buf, new String(new char[Short.MAX_VALUE / 2 + 1]).replace("\0", "\uD83E\uDDFD"))); diff --git a/gradle.properties b/gradle.properties index 43997dd42..9eb00301b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project properties - we put these here so they can be modified without causing a recompile of the build scripts -projectVersion=4.10.3-SNAPSHOT +projectVersion=5.0.0-SNAPSHOT # Smile emoji mcVersions=1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d825aa128..75b394cca 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ junit = "5.9.3" checkerQual = "3.39.0" # Platforms -paper = "1.16.5-R0.1-SNAPSHOT" +paper = "1.17.1-R0.1-SNAPSHOT" legacyBukkit = "1.8.8-R0.1-SNAPSHOT" bungee = "1.19-R0.1-SNAPSHOT" sponge = "8.0.0" @@ -41,7 +41,7 @@ jupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version. jupiterEngine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" } checkerQual = { group = "org.checkerframework", name = "checker-qual", version.ref = "checkerQual" } -paper = { group = "com.destroystokyo.paper", name = "paper-api", version.ref = "paper" } +paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "paper" } legacyBukkit = { group = "org.bukkit", name = "bukkit", version.ref = "legacyBukkit" } bungee = { group = "net.md-5", name = "bungeecord-api", version.ref = "bungee" } sponge = { group = "org.spongepowered", name = "spongeapi", version.ref = "sponge" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5e0f402c9..2ed77abe1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,7 +30,6 @@ includeBuild("build-logic") include("compat", "compat:snakeyaml-compat-common", "compat:snakeyaml2-compat", "compat:snakeyaml1-compat", "compat:protocolsupport-compat") setupViaSubproject("api") -setupViaSubproject("api-legacy") setupViaSubproject("common") setupViaSubproject("bukkit") setupViaSubproject("bukkit-legacy") diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandHandler.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandHandler.java index d8fda2ed2..9a1d34c05 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandHandler.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandHandler.java @@ -33,7 +33,7 @@ public class SpongeCommandHandler extends ViaCommandHandler implements Command.R @Override public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) { - String[] args = arguments.input().length() > 0 ? arguments.input().split(" ") : new String[0]; + String[] args = !arguments.input().isEmpty() ? arguments.input().split(" ") : new String[0]; onCommand(new SpongeCommandSender(cause), args); return CommandResult.success(); } diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandSender.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandSender.java index 78ff277f7..d5b088030 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandSender.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/commands/SpongeCommandSender.java @@ -43,8 +43,8 @@ public class SpongeCommandSender implements ViaCommandSender { @Override public UUID getUUID() { - if (source instanceof Identifiable) { - return ((Identifiable) source).uniqueId(); + if (source instanceof Identifiable identifiable) { + return identifiable.uniqueId(); } else { return new UUID(0, 0); } diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeDecodeHandler.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeDecodeHandler.java index c8f97c89b..39900886f 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeDecodeHandler.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeDecodeHandler.java @@ -24,7 +24,6 @@ import com.viaversion.viaversion.util.PipelineUtil; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; -import java.lang.reflect.InvocationTargetException; import java.util.List; public class SpongeDecodeHandler extends ByteToMessageDecoder { @@ -51,15 +50,7 @@ public class SpongeDecodeHandler extends ByteToMessageDecoder { info.transformServerbound(transformedBuf, CancelDecoderException::generate); } - try { - list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf)); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof Exception) { - throw (Exception) e.getCause(); - } else if (e.getCause() instanceof Error) { - throw (Error) e.getCause(); - } - } + list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, transformedBuf == null ? bytebuf : transformedBuf)); } finally { if (transformedBuf != null) { transformedBuf.release(); diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeEncodeHandler.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeEncodeHandler.java index 279f9f978..095ee4b1c 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeEncodeHandler.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/handlers/SpongeEncodeHandler.java @@ -40,19 +40,19 @@ public class SpongeEncodeHandler extends MessageToByteEncoder implements @Override protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception { // handle the packet type - if (!(o instanceof ByteBuf)) { + if (!(o instanceof ByteBuf buf)) { // call minecraft encoder try { PipelineUtil.callEncode(this.minecraftEncoder, new ChannelHandlerContextWrapper(ctx, this), o, bytebuf); } catch (InvocationTargetException e) { - if (e.getCause() instanceof Exception) { - throw (Exception) e.getCause(); - } else if (e.getCause() instanceof Error) { - throw (Error) e.getCause(); + if (e.getCause() instanceof Exception cause) { + throw cause; + } else if (e.getCause() instanceof Error cause) { + throw cause; } } } else { - bytebuf.writeBytes((ByteBuf) o); + bytebuf.writeBytes(buf); } transform(bytebuf); } diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java index fa6db14ad..b507321cf 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaTask.java @@ -20,17 +20,7 @@ package com.viaversion.viaversion.sponge.platform; import com.viaversion.viaversion.api.platform.PlatformTask; import org.spongepowered.api.scheduler.ScheduledTask; -public class SpongeViaTask implements PlatformTask { - private final ScheduledTask task; - - public SpongeViaTask(ScheduledTask task) { - this.task = task; - } - - @Override - public ScheduledTask getObject() { - return task; - } +public record SpongeViaTask(ScheduledTask task) implements PlatformTask { @Override public void cancel() { diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/command/VelocityCommandSender.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/command/VelocityCommandSender.java index da030a4d0..825844d1d 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/command/VelocityCommandSender.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/command/VelocityCommandSender.java @@ -23,12 +23,7 @@ import com.viaversion.viaversion.VelocityPlugin; import com.viaversion.viaversion.api.command.ViaCommandSender; import java.util.UUID; -public class VelocityCommandSender implements ViaCommandSender { - private final CommandSource source; - - public VelocityCommandSender(CommandSource source) { - this.source = source; - } +public record VelocityCommandSender(CommandSource source) implements ViaCommandSender { @Override public boolean hasPermission(String permission) { @@ -42,16 +37,16 @@ public class VelocityCommandSender implements ViaCommandSender { @Override public UUID getUUID() { - if (source instanceof Player) { - return ((Player) source).getUniqueId(); + if (source instanceof Player player) { + return player.getUniqueId(); } return new UUID(0, 0); } @Override public String getName() { - if (source instanceof Player) { - return ((Player) source).getUsername(); + if (source instanceof Player player) { + return player.getUsername(); } return "?"; // :( } diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/command/subs/ProbeSubCmd.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/command/subs/ProbeSubCmd.java index 775def07e..00b5b866e 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/command/subs/ProbeSubCmd.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/command/subs/ProbeSubCmd.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaSubCommand; import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; -public class ProbeSubCmd extends ViaSubCommand { +public class ProbeSubCmd implements ViaSubCommand { @Override public String name() { return "probe"; diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java index 2a4ce1ed0..b930061eb 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java @@ -48,16 +48,16 @@ public class VelocityViaConfig extends AbstractViaConfig { protected void handleConfig(Map config) { // Parse servers Map servers; - if (!(config.get("velocity-servers") instanceof Map)) { - servers = new HashMap<>(); + if (config.get("velocity-servers") instanceof Map velocityServers) { + servers = velocityServers; } else { - servers = (Map) config.get("velocity-servers"); + servers = new HashMap<>(); } // Convert any bad Protocol Ids for (Map.Entry entry : new HashSet<>(servers.entrySet())) { if (!(entry.getValue() instanceof Integer)) { - if (entry.getValue() instanceof String) { - ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue()); + if (entry.getValue() instanceof String protocol) { + ProtocolVersion found = ProtocolVersion.getClosest(protocol); if (found != null) { servers.put(entry.getKey(), found.getVersion()); } else { diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java index 14b608069..f405bd31a 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaTask.java @@ -20,17 +20,7 @@ package com.viaversion.viaversion.velocity.platform; import com.velocitypowered.api.scheduler.ScheduledTask; import com.viaversion.viaversion.api.platform.PlatformTask; -public class VelocityViaTask implements PlatformTask { - private final ScheduledTask task; - - public VelocityViaTask(ScheduledTask task) { - this.task = task; - } - - @Override - public ScheduledTask getObject() { - return task; - } +public record VelocityViaTask(ScheduledTask task) implements PlatformTask { @Override public void cancel() { diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/providers/VelocityVersionProvider.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/providers/VelocityVersionProvider.java index 1e7e850f4..69a6c4fef 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/providers/VelocityVersionProvider.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/providers/VelocityVersionProvider.java @@ -22,7 +22,7 @@ import com.viaversion.viaversion.VelocityPlugin; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viaversion.protocols.base.BaseVersionProvider; +import com.viaversion.viaversion.api.protocol.version.VersionProvider; import com.viaversion.viaversion.velocity.platform.VelocityViaInjector; import io.netty.channel.ChannelHandler; import java.lang.reflect.Method; @@ -31,7 +31,7 @@ import java.util.logging.Level; import java.util.stream.IntStream; import org.jetbrains.annotations.Nullable; -public class VelocityVersionProvider extends BaseVersionProvider { +public class VelocityVersionProvider implements VersionProvider { private static final Method GET_ASSOCIATION = getAssociationMethod(); private static @Nullable Method getAssociationMethod() { diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java index 043508892..212e80242 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/service/ProtocolDetectorService.java @@ -73,7 +73,7 @@ public final class ProtocolDetectorService extends AbstractProtocolDetectorServi } // Ensure we're the only ones writing to the config - synchronized (Via.getPlatform().getConfigurationProvider()) { + synchronized (Via.getManager().getConfigurationProvider()) { servers.put(serverName, serverPing.getVersion().getProtocol()); } config.save();