From 16c5ff8c89f90f285deece9c845868b8bf84df31 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Mon, 14 Dec 2020 18:37:46 +0100 Subject: [PATCH] really big refactoring Enums now use a static array to ordinal mapping (values()) More structure (static final instead of final static) Write constants in CAPS --- .idea/codeStyles/Project.xml | 14 + .idea/codeStyles/codeStyleConfig.xml | 1 - .idea/encodings.xml | 7 + .idea/inspectionProfiles/Project_Default.xml | 27 ++ .../java/de/bixilon/minosoft/Minosoft.java | 39 +-- .../minosoft/config/Configuration.java | 49 ++- .../minosoft/config/ConfigurationPaths.java | 2 +- .../minosoft/config/StaticConfiguration.java | 8 +- .../minosoft/data/ChangeableIdentifier.java | 10 +- .../minosoft/data/ChatTextPositions.java | 4 +- .../bixilon/minosoft/data/Difficulties.java | 4 +- .../de/bixilon/minosoft/data/Directions.java | 4 +- .../de/bixilon/minosoft/data/GameModes.java | 4 +- .../de/bixilon/minosoft/data/LevelTypes.java | 2 +- .../java/de/bixilon/minosoft/data/MapSet.java | 4 +- .../java/de/bixilon/minosoft/data/Player.java | 50 +-- .../minosoft/data/PlayerPropertyData.java | 4 +- .../minosoft/data/SoundCategories.java | 4 +- .../java/de/bixilon/minosoft/data/Tag.java | 4 +- .../java/de/bixilon/minosoft/data/Trade.java | 18 +- .../minosoft/data/VersionValueMap.java | 8 +- .../minosoft/data/assets/AssetsManager.java | 24 +- .../data/commands/CommandArgumentNode.java | 16 +- .../data/commands/CommandLiteralNode.java | 4 +- .../minosoft/data/commands/CommandNode.java | 36 +- .../data/commands/parser/FloatParser.java | 1 - .../IdentifierSelectorArgumentParser.java | 1 - .../entity/RangeSelectorArgumentParser.java | 8 +- .../exceptions/CommandParseException.java | 9 +- .../properties/DoubleParserProperties.java | 12 +- .../properties/EntityParserProperties.java | 8 +- .../properties/FloatParserProperties.java | 12 +- .../properties/IntegerParserProperties.java | 12 +- .../properties/RangeParserProperties.java | 4 +- .../ScoreHolderParserProperties.java | 4 +- .../properties/StringParserProperties.java | 16 +- .../data/entities/EntityInformation.java | 4 +- .../data/entities/EntityMetaData.java | 12 +- .../data/entities/EntityMetaDataFields.java | 7 +- .../data/entities/EntityProperty.java | 4 +- .../data/entities/EntityPropertyKeys.java | 8 +- .../data/entities/EntityPropertyModifier.java | 2 +- .../minosoft/data/entities/Objects.java | 10 +- .../bixilon/minosoft/data/entities/Poses.java | 4 +- .../minosoft/data/entities/Rotation.kt | 2 +- .../minosoft/data/entities/VillagerData.kt | 18 + .../entities/block/BedEntityMetaData.java | 8 +- .../block/CampfireBlockEntityMetaData.java | 6 +- .../data/entities/entities/AgeableMob.java | 2 +- .../data/entities/entities/Entity.java | 56 ++-- .../data/entities/entities/ExperienceOrb.java | 4 +- .../data/entities/entities/LivingEntity.java | 14 +- .../minosoft/data/entities/entities/Mob.java | 2 +- .../data/entities/entities/TamableAnimal.java | 4 +- .../data/entities/entities/ambient/Bat.java | 2 +- .../data/entities/entities/animal/Bee.java | 4 +- .../data/entities/entities/animal/Cat.java | 16 +- .../data/entities/entities/animal/Fox.java | 8 +- .../entities/entities/animal/IronGolem.java | 2 +- .../entities/entities/animal/Mooshroom.java | 2 +- .../data/entities/entities/animal/Ocelot.java | 2 +- .../data/entities/entities/animal/Panda.java | 19 +- .../data/entities/entities/animal/Parrot.java | 10 +- .../data/entities/entities/animal/Pig.java | 4 +- .../entities/entities/animal/PolarBear.java | 2 +- .../data/entities/entities/animal/Rabbit.java | 2 +- .../data/entities/entities/animal/Sheep.java | 4 +- .../entities/entities/animal/SnowGolem.java | 2 +- .../entities/entities/animal/Strider.java | 6 +- .../data/entities/entities/animal/Turtle.java | 12 +- .../data/entities/entities/animal/Wolf.java | 14 +- .../entities/animal/hoglin/Hoglin.java | 2 +- .../animal/horse/AbstractChestedHorse.java | 2 +- .../entities/animal/horse/AbstractHorse.java | 4 +- .../entities/entities/animal/horse/Horse.java | 16 +- .../entities/entities/animal/horse/Llama.java | 6 +- .../entities/animal/water/AbstractFish.java | 2 +- .../entities/animal/water/Dolphin.java | 6 +- .../entities/animal/water/PufferFish.java | 2 +- .../entities/animal/water/TropicalFish.java | 2 +- .../boss/enderdragon/EnderDragon.java | 10 +- .../entities/boss/wither/WitherBoss.java | 8 +- .../entities/decoration/ArmorStand.java | 14 +- .../entities/decoration/ItemFrame.java | 5 +- .../entities/decoration/Painting.java | 8 +- .../entities/entities/item/ItemEntity.java | 2 +- .../entities/entities/item/PrimedTNT.java | 2 +- .../data/entities/entities/monster/Blaze.java | 2 +- .../entities/entities/monster/Creeper.java | 6 +- .../entities/entities/monster/Enderman.java | 10 +- .../data/entities/entities/monster/Ghast.java | 2 +- .../entities/entities/monster/Guardian.java | 4 +- .../entities/entities/monster/Phantom.java | 2 +- .../entities/entities/monster/Shulker.java | 8 +- .../data/entities/entities/monster/Slime.java | 2 +- .../entities/entities/monster/Spider.java | 2 +- .../data/entities/entities/monster/Vex.java | 3 +- .../entities/entities/monster/Zoglin.java | 2 +- .../entities/entities/monster/Zombie.java | 6 +- .../entities/monster/ZombieVillager.java | 4 +- .../monster/piglin/AbstractPiglin.java | 2 +- .../entities/monster/piglin/Piglin.java | 11 +- .../entities/monster/raid/Pillager.java | 2 +- .../entities/monster/raid/Raider.java | 2 +- .../monster/raid/SpellcasterIllager.java | 10 +- .../entities/entities/monster/raid/Witch.java | 4 +- .../entities/npc/AbstractVillager.java | 2 +- .../data/entities/entities/npc/Villager.java | 2 +- .../entities/player/PlayerEntity.java | 18 +- .../entities/projectile/AbstractArrow.java | 6 +- .../entities/entities/projectile/Arrow.java | 2 +- .../entities/projectile/Fireball.java | 2 +- .../projectile/ThrowableItemProjectile.java | 2 +- .../entities/projectile/ThrownEyeOfEnder.java | 2 +- .../entities/projectile/ThrownPotion.java | 4 +- .../entities/vehicle/AbstractMinecart.java | 12 +- .../data/entities/entities/vehicle/Boat.java | 10 +- .../vehicle/MinecartCommandBlock.java | 4 +- .../entities/vehicle/MinecartFurnace.java | 2 +- .../minosoft/data/inventory/Inventory.java | 12 +- .../data/inventory/InventoryActions.java | 6 +- .../data/inventory/InventoryProperties.java | 8 +- .../data/inventory/InventorySlots.java | 16 +- .../data/inventory/InventoryTypes.java | 57 ++-- .../bixilon/minosoft/data/inventory/Slot.java | 100 +++--- .../minosoft/data/locale/Language.java | 8 +- .../locale/minecraft/MinecraftLanguage.java | 8 +- .../minosoft/data/mappings/Dimension.java | 2 +- .../minosoft/data/mappings/ModIdentifier.java | 8 +- .../minosoft/data/mappings/blocks/Block.java | 20 +- .../data/mappings/blocks/BlockProperties.java | 14 +- .../data/mappings/blocks/BlockRotations.java | 7 +- .../mappings/blocks/actions/BellAction.java | 12 +- .../mappings/blocks/actions/ChestAction.java | 2 +- .../blocks/actions/NoteBlockAction.java | 10 +- .../mappings/blocks/actions/PistonAction.java | 6 +- .../particle/data/BlockParticleData.java | 4 +- .../particle/data/DustParticleData.java | 10 +- .../particle/data/ItemParticleData.java | 4 +- .../mappings/particle/data/ParticleData.java | 2 +- .../data/mappings/recipes/Recipe.java | 32 +- .../data/mappings/recipes/RecipeTypes.java | 2 +- .../data/mappings/recipes/Recipes.java | 49 ++- .../statistics/StatisticCategories.java | 4 +- .../data/mappings/versions/Version.java | 28 +- .../mappings/versions/VersionMapping.java | 231 +++++++------ .../bixilon/minosoft/data/player/Hands.java | 4 +- .../minosoft/data/player/PlayerListItem.java | 18 +- .../data/player/PlayerListItemBulk.java | 26 +- .../data/player/PlayerProperties.java | 2 +- .../minosoft/data/player/PlayerProperty.java | 8 +- .../data/player/advancements/Advancement.java | 8 +- .../advancements/AdvancementDisplay.java | 24 +- .../advancements/CriterionProgress.java | 4 +- .../data/scoreboard/ScoreboardManager.java | 12 +- .../data/scoreboard/ScoreboardObjective.java | 20 +- .../data/scoreboard/ScoreboardScore.java | 6 +- .../minosoft/data/scoreboard/Team.java | 22 +- .../minosoft/data/text/BaseComponent.java | 44 +-- .../minosoft/data/text/ChatColors.java | 14 +- .../data/text/ChatFormattingCodes.java | 8 +- .../minosoft/data/text/ClickEvent.java | 4 +- .../minosoft/data/text/HoverEvent.java | 4 +- .../data/text/MultiChatComponent.java | 4 +- .../data/text/PostChatFormattingCodes.java | 10 +- .../data/text/PreChatFormattingCodes.java | 10 +- .../bixilon/minosoft/data/text/RGBColor.java | 24 +- .../minosoft/data/text/TextComponent.java | 60 ++-- .../data/text/TranslatableComponent.java | 14 +- .../de/bixilon/minosoft/data/world/Chunk.java | 17 +- .../minosoft/data/world/ChunkSection.java | 24 +- .../de/bixilon/minosoft/data/world/World.java | 22 +- .../data/world/palette/DirectPalette.java | 6 +- .../data/world/palette/IndirectPalette.java | 10 +- .../minosoft/gui/main/AccountListCell.java | 38 +-- .../minosoft/gui/main/AccountWindow.java | 11 +- .../bixilon/minosoft/gui/main/GUITools.java | 16 +- .../bixilon/minosoft/gui/main/Launcher.java | 6 +- .../bixilon/minosoft/gui/main/MainWindow.java | 35 +- .../de/bixilon/minosoft/gui/main/Server.java | 53 ++- .../minosoft/gui/main/ServerListCell.java | 177 +++++----- .../minosoft/gui/main/SessionListCell.java | 22 +- .../minosoft/gui/main/SessionsWindow.java | 12 +- .../minosoft/gui/main/SettingsWindow.java | 14 +- .../gui/main/StartProgressWindow.java | 12 +- .../java/de/bixilon/minosoft/logging/Log.java | 17 +- .../de/bixilon/minosoft/modding/Logger.java | 2 +- .../bixilon/minosoft/modding/MinosoftMod.java | 8 +- .../channels/DefaultPluginChannels.java | 2 +- .../minosoft/modding/event/EventInvoker.java | 4 +- .../modding/event/EventInvokerCallback.java | 7 +- .../modding/event/EventInvokerMethod.java | 12 +- .../minosoft/modding/event/EventManager.java | 8 +- .../event/address/HostnameValidator.java | 6 +- .../modding/event/address/PortValidator.java | 10 +- .../modding/event/address/RegexValidator.java | 8 +- .../event/address/SimpleAddressValidator.java | 6 +- .../event/events/BlockActionEvent.java | 4 +- .../events/BlockBreakAnimationEvent.java | 6 +- .../event/events/BlockChangeEvent.java | 4 +- .../BlockEntityMetaDataChangeEvent.java | 6 +- .../event/events/BossBarChangeEvent.java | 20 +- .../modding/event/events/CancelableEvent.java | 4 +- .../event/events/ChangeGameStateEvent.java | 4 +- .../events/ChatMessageReceivingEvent.java | 4 +- .../event/events/ChatMessageSendingEvent.java | 2 +- .../event/events/ChunkDataChangeEvent.java | 6 +- .../event/events/CloseWindowEvent.java | 4 +- .../events/CollectItemAnimationEvent.java | 6 +- .../modding/event/events/ConnectionEvent.java | 2 +- .../events/ConnectionStateChangeEvent.java | 4 +- .../modding/event/events/DisconnectEvent.java | 2 +- .../modding/event/events/EffectEvent.java | 8 +- .../event/events/EntityDespawnEvent.java | 8 +- .../events/EntityEquipmentChangeEvent.java | 6 +- .../event/events/EntitySpawnEvent.java | 2 +- .../event/events/EntitySpectateEvent.java | 2 +- .../event/events/ExperienceChangeEvent.java | 6 +- .../modding/event/events/JoinGameEvent.java | 24 +- .../event/events/LightningBoltSpawnEvent.java | 2 +- .../event/events/LoginDisconnectEvent.java | 2 +- .../LoginPluginMessageRequestEvent.java | 6 +- .../event/events/MultiBlockChangeEvent.java | 4 +- .../event/events/MultiSlotChangeEvent.java | 4 +- .../event/events/OpenSignEditorEvent.java | 2 +- .../event/events/PacketReceiveEvent.java | 2 +- .../modding/event/events/PacketSendEvent.java | 2 +- .../event/events/ParticleSpawnEvent.java | 16 +- .../events/PlayerListInfoChangeEvent.java | 4 +- .../events/PlayerListItemChangeEvent.java | 2 +- .../events/PluginMessageReceiveEvent.java | 4 +- .../event/events/ResourcePackChangeEvent.java | 4 +- .../modding/event/events/RespawnEvent.java | 8 +- .../events/ServerListPingArriveEvent.java | 2 +- .../event/events/SingleSlotChangeEvent.java | 6 +- .../events/SpawnLocationChangeEvent.java | 2 +- .../modding/event/events/StatusPongEvent.java | 2 +- .../event/events/StatusResponseEvent.java | 2 +- .../modding/event/events/TimeChangeEvent.java | 4 +- .../event/events/TitleChangeEvent.java | 12 +- .../event/events/UpdateHealthEvent.java | 6 +- .../minosoft/modding/loading/LoadingInfo.java | 2 +- .../modding/loading/ModDependency.java | 26 +- .../minosoft/modding/loading/ModInfo.java | 32 +- .../minosoft/modding/loading/ModLoader.java | 31 +- .../minosoft/modding/loading/Priorities.java | 8 +- .../minosoft/protocol/network/Connection.java | 201 +++++------ .../network/socket/SocketNetwork.java | 126 +++---- .../login/PacketEncryptionRequest.java | 12 +- .../login/PacketLoginDisconnect.java | 6 +- .../login/PacketLoginPluginRequest.java | 16 +- .../login/PacketLoginSetCompression.java | 6 +- .../clientbound/login/PacketLoginSuccess.java | 14 +- .../play/PacketAcknowledgePlayerDigging.java | 18 +- .../clientbound/play/PacketAdvancements.java | 20 +- .../clientbound/play/PacketAttachEntity.java | 8 +- .../clientbound/play/PacketBlockAction.java | 12 +- .../play/PacketBlockBreakAnimation.java | 16 +- .../clientbound/play/PacketBlockChange.java | 14 +- .../play/PacketBlockEntityMetadata.java | 24 +- .../clientbound/play/PacketBossBar.java | 72 ++-- .../clientbound/play/PacketCamera.java | 6 +- .../play/PacketChangeGameState.java | 14 +- .../play/PacketChatMessageReceiving.java | 16 +- .../clientbound/play/PacketChunkBulk.java | 8 +- .../clientbound/play/PacketChunkData.java | 24 +- .../play/PacketCloseWindowReceiving.java | 4 +- .../clientbound/play/PacketCollectItem.java | 16 +- .../clientbound/play/PacketCombatEvent.java | 26 +- .../PacketConfirmTransactionReceiving.java | 8 +- .../play/PacketCraftRecipeResponse.java | 14 +- .../play/PacketDeclareCommands.java | 4 +- .../play/PacketDeclareRecipes.java | 6 +- .../clientbound/play/PacketDestroyEntity.java | 8 +- .../clientbound/play/PacketDisconnect.java | 6 +- .../clientbound/play/PacketEffect.java | 30 +- .../play/PacketEntityAnimation.java | 10 +- .../clientbound/play/PacketEntityEffect.java | 26 +- .../play/PacketEntityEquipment.java | 22 +- .../clientbound/play/PacketEntityEvent.java | 6 +- .../play/PacketEntityHeadRotation.java | 6 +- .../play/PacketEntityInitialisation.java | 6 +- .../play/PacketEntityMetadata.java | 8 +- .../play/PacketEntityMovement.java | 6 +- .../play/PacketEntityMovementAndRotation.java | 12 +- .../play/PacketEntityProperties.java | 12 +- .../play/PacketEntityRotation.java | 10 +- .../play/PacketEntitySoundEffect.java | 22 +- .../play/PacketEntityTeleport.java | 10 +- .../play/PacketEntityVelocity.java | 6 +- .../clientbound/play/PacketExplosion.java | 32 +- .../clientbound/play/PacketFacePlayer.java | 22 +- .../play/PacketHeldItemChangeReceiving.java | 6 +- .../clientbound/play/PacketJoinGame.java | 78 ++--- .../clientbound/play/PacketKeepAlive.java | 10 +- .../clientbound/play/PacketMapData.java | 66 ++-- .../play/PacketMultiBlockChange.java | 20 +- .../play/PacketNBTQueryResponse.java | 10 +- .../play/PacketNamedSoundEffect.java | 30 +- .../clientbound/play/PacketOpenBook.java | 8 +- .../play/PacketOpenHorseWindow.java | 8 +- .../play/PacketOpenSignEditor.java | 8 +- .../clientbound/play/PacketOpenWindow.java | 24 +- .../clientbound/play/PacketParticle.java | 60 ++-- .../play/PacketPlayerAbilitiesReceiving.java | 34 +- .../play/PacketPlayerListItem.java | 12 +- .../play/PacketPlayerPositionAndRotation.java | 20 +- .../play/PacketPluginMessageReceiving.java | 12 +- .../play/PacketRemoveEntityEffect.java | 8 +- .../play/PacketResourcePackSend.java | 16 +- .../clientbound/play/PacketRespawn.java | 38 +-- .../PacketScoreboardDisplayScoreboard.java | 10 +- .../play/PacketScoreboardObjective.java | 35 +- .../play/PacketScoreboardUpdateScore.java | 30 +- .../play/PacketSelectAdvancementTab.java | 8 +- .../play/PacketServerDifficulty.java | 8 +- .../play/PacketSetCompression.java | 6 +- .../clientbound/play/PacketSetCooldown.java | 10 +- .../clientbound/play/PacketSetExperience.java | 18 +- .../clientbound/play/PacketSetPassenger.java | 12 +- .../clientbound/play/PacketSetSlot.java | 8 +- .../clientbound/play/PacketSoundEffect.java | 28 +- .../play/PacketSpawnExperienceOrb.java | 6 +- .../clientbound/play/PacketSpawnLocation.java | 8 +- .../clientbound/play/PacketSpawnMob.java | 12 +- .../clientbound/play/PacketSpawnObject.java | 12 +- .../clientbound/play/PacketSpawnPainting.java | 6 +- .../clientbound/play/PacketSpawnPlayer.java | 8 +- .../play/PacketSpawnWeatherEntity.java | 6 +- .../clientbound/play/PacketStatistics.java | 8 +- .../clientbound/play/PacketStopSound.java | 14 +- .../play/PacketTabCompleteReceiving.java | 18 +- .../play/PacketTabHeaderAndFooter.java | 12 +- .../packets/clientbound/play/PacketTags.java | 10 +- .../packets/clientbound/play/PacketTeams.java | 74 +++-- .../clientbound/play/PacketTimeUpdate.java | 10 +- .../packets/clientbound/play/PacketTitle.java | 42 +-- .../clientbound/play/PacketTradeList.java | 30 +- .../clientbound/play/PacketUnloadChunk.java | 6 +- .../clientbound/play/PacketUnlockRecipes.java | 89 ++--- .../clientbound/play/PacketUpdateHealth.java | 16 +- .../clientbound/play/PacketUpdateLight.java | 4 +- .../play/PacketUpdateSignReceiving.java | 12 +- .../play/PacketUpdateViewDistance.java | 4 +- .../play/PacketUpdateViewPosition.java | 4 +- .../clientbound/play/PacketUseBed.java | 12 +- .../play/PacketVehicleMovement.java | 14 +- .../clientbound/play/PacketWindowItems.java | 14 +- .../play/PacketWindowProperty.java | 8 +- .../clientbound/play/PacketWorldBorder.java | 70 ++-- .../clientbound/status/PacketStatusPong.java | 2 +- .../status/PacketStatusResponse.java | 4 +- .../handshaking/PacketHandshake.java | 10 +- .../login/PacketEncryptionResponse.java | 6 +- .../login/PacketLoginPluginResponse.java | 10 +- .../serverbound/login/PacketLoginStart.java | 6 +- .../play/PacketAdvancementTab.java | 14 +- .../serverbound/play/PacketAnimation.java | 4 +- .../play/PacketChatMessageSending.java | 4 +- .../serverbound/play/PacketClickWindow.java | 14 +- .../play/PacketClientSettings.java | 8 +- .../serverbound/play/PacketClientStatus.java | 10 +- .../play/PacketCloseWindowSending.java | 6 +- .../play/PacketConfirmTeleport.java | 4 +- .../play/PacketConfirmTransactionSending.java | 8 +- .../play/PacketCraftingBookData.java | 34 +- .../play/PacketCraftingRecipeRequest.java | 6 +- .../play/PacketCreativeInventoryAction.java | 6 +- .../serverbound/play/PacketEntityAction.java | 16 +- .../play/PacketGenerateStructure.java | 8 +- .../play/PacketHeldItemChangeSending.java | 4 +- .../play/PacketInteractEntity.java | 26 +- .../play/PacketKeepAliveResponse.java | 8 +- .../serverbound/play/PacketNameItem.java | 4 +- .../play/PacketPlayerAbilitiesSending.java | 4 +- .../play/PacketPlayerBlockPlacement.java | 30 +- .../serverbound/play/PacketPlayerDigging.java | 20 +- ...acketPlayerPositionAndRotationSending.java | 16 +- .../play/PacketPlayerPositionSending.java | 12 +- .../play/PacketPlayerRotationSending.java | 8 +- .../play/PacketPluginMessageSending.java | 10 +- .../play/PacketQueryEntityNBT.java | 6 +- .../play/PacketRecipeBookState.java | 12 +- .../play/PacketResourcePackStatus.java | 6 +- .../serverbound/play/PacketSelectTrade.java | 4 +- .../play/PacketSetBeaconEffect.java | 6 +- .../play/PacketSetDisplayedRecipe.java | 4 +- .../serverbound/play/PacketSpectate.java | 4 +- .../serverbound/play/PacketSteerBoat.java | 6 +- .../serverbound/play/PacketSteerVehicle.java | 14 +- .../play/PacketTabCompleteSending.java | 16 +- .../play/PacketUpdateCommandBlock.java | 18 +- .../PacketUpdateCommandBlockMinecart.java | 8 +- .../play/PacketUpdateJigsawBlock.java | 20 +- .../play/PacketUpdateSignSending.java | 10 +- .../play/PacketUpdateStructureBlock.java | 50 +-- .../serverbound/play/PacketUseItem.java | 4 +- .../play/PacketVehicleMovement.java | 12 +- .../play/PacketWindowClickButton.java | 6 +- .../serverbound/status/PacketStatusPing.java | 4 +- .../minosoft/protocol/ping/ForgeModInfo.java | 8 +- .../protocol/ping/ServerListPing.java | 30 +- .../minosoft/protocol/ping/ServerModItem.java | 6 +- .../protocol/protocol/ConnectionPing.java | 6 +- .../protocol/protocol/ConnectionStates.java | 4 +- .../protocol/protocol/InByteBuffer.java | 66 ++-- .../protocol/protocol/InPacketBuffer.java | 4 +- .../protocol/protocol/LANServerListener.java | 32 +- .../protocol/protocol/OutByteBuffer.java | 40 +-- .../protocol/protocol/OutPacketBuffer.java | 2 +- .../protocol/protocol/PacketHandler.java | 311 +++++++++--------- .../protocol/protocol/PacketSender.java | 46 +-- .../minosoft/protocol/protocol/Packets.java | 6 +- .../protocol/protocol/ProtocolDefinition.java | 1 + .../de/bixilon/minosoft/util/BitByte.java | 2 +- .../minosoft/util/CountUpAndDownLatch.java | 52 +-- .../util/MinosoftCommandLineArguments.java | 20 +- .../bixilon/minosoft/util/ServerAddress.java | 8 +- .../java/de/bixilon/minosoft/util/Util.java | 6 +- .../util/buffers/ImprovedStringReader.java | 30 +- .../util/mojang/api/MojangAccount.java | 34 +- .../MojangAccountAuthenticationAttempt.java | 6 +- .../minosoft/util/mojang/api/MojangURLs.java | 4 +- .../minosoft/util/nbt/tag/ByteArrayTag.java | 12 +- .../minosoft/util/nbt/tag/ByteTag.java | 8 +- .../minosoft/util/nbt/tag/CompoundTag.java | 62 ++-- .../minosoft/util/nbt/tag/DoubleTag.java | 6 +- .../minosoft/util/nbt/tag/FloatTag.java | 6 +- .../minosoft/util/nbt/tag/IntArrayTag.java | 8 +- .../bixilon/minosoft/util/nbt/tag/IntTag.java | 8 +- .../minosoft/util/nbt/tag/ListTag.java | 36 +- .../minosoft/util/nbt/tag/LongArrayTag.java | 12 +- .../minosoft/util/nbt/tag/LongTag.java | 8 +- .../bixilon/minosoft/util/nbt/tag/NBTTag.java | 4 +- .../minosoft/util/nbt/tag/ShortTag.java | 8 +- .../minosoft/util/nbt/tag/StringTag.java | 10 +- .../minosoft/util/nbt/tag/TagTypes.java | 6 +- .../minosoft/util/task/AsyncTaskWorker.java | 24 +- .../de/bixilon/minosoft/util/task/Task.java | 12 +- 439 files changed, 3332 insertions(+), 3158 deletions(-) create mode 100644 .idea/encodings.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index c4b1ab3b7..e8986929f 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -12,6 +12,20 @@ + + + + + GETTERS_AND_SETTERS + KEEP + + + OVERRIDDEN_METHODS + BY_NAME + + + + diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 6e6eec114..79ee123c2 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,6 +1,5 @@ \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..aa00ffab7 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 5f0e05cea..219e2b586 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,11 +1,28 @@ \ No newline at end of file diff --git a/src/main/java/de/bixilon/minosoft/Minosoft.java b/src/main/java/de/bixilon/minosoft/Minosoft.java index 18481a8d2..af18fcaa5 100644 --- a/src/main/java/de/bixilon/minosoft/Minosoft.java +++ b/src/main/java/de/bixilon/minosoft/Minosoft.java @@ -13,7 +13,6 @@ package de.bixilon.minosoft; -import com.google.common.collect.HashBiMap; import com.jfoenix.controls.JFXAlert; import com.jfoenix.controls.JFXDialogLayout; import de.bixilon.minosoft.config.Configuration; @@ -43,13 +42,12 @@ import javafx.scene.text.Text; import javafx.stage.Stage; import java.io.IOException; -import java.util.ArrayList; import java.util.HashSet; import java.util.UUID; public final class Minosoft { - public static final HashSet eventManagers = new HashSet<>(); - private static final CountUpAndDownLatch startStatusLatch = new CountUpAndDownLatch(1); + public static final HashSet EVENT_MANAGERS = new HashSet<>(); + private static final CountUpAndDownLatch START_STATUS_LATCH = new CountUpAndDownLatch(1); public static MojangAccount selectedAccount; public static Configuration config; @@ -65,10 +63,10 @@ public final class Minosoft { return; } try { - if (StartProgressWindow.toolkitLatch.getCount() == 2) { + if (StartProgressWindow.TOOLKIT_LATCH.getCount() == 2) { StartProgressWindow.start(); } - StartProgressWindow.toolkitLatch.await(); + StartProgressWindow.TOOLKIT_LATCH.await(); } catch (InterruptedException e) { e.printStackTrace(); System.exit(1); @@ -117,20 +115,6 @@ public final class Minosoft { progress.countDown(); }, "Configuration", String.format("Load config file (%s)", StaticConfiguration.CONFIG_FILENAME), Priorities.HIGHEST, TaskImportance.REQUIRED)); - taskWorker.addTask(new Task((progress) -> { - if (StaticConfiguration.HEADLESS_MODE) { - return; - } - StartProgressWindow.start(); - }, "JavaFX Toolkit", "Initialize JavaFX", Priorities.HIGHEST)); - - taskWorker.addTask(new Task((progress) -> { - if (StaticConfiguration.HEADLESS_MODE) { - return; - } - StartProgressWindow.show(startStatusLatch); - }, "Progress Window", "Display progress window", Priorities.HIGH, TaskImportance.OPTIONAL, "JavaFX Toolkit", "Configuration")); - taskWorker.addTask(new Task(progress -> { progress.countUp(); LocaleManager.load(config.getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE)); @@ -179,9 +163,14 @@ public final class Minosoft { progress.countDown(); }, "LAN Server Listener", "Listener for LAN Servers", Priorities.LOWEST, TaskImportance.OPTIONAL, "Configuration")); - taskWorker.work(startStatusLatch); + if (!StaticConfiguration.HEADLESS_MODE) { + taskWorker.addTask(new Task((progress) -> StartProgressWindow.start(), "JavaFX Toolkit", "Initialize JavaFX", Priorities.HIGHEST)); + + taskWorker.addTask(new Task((progress) -> StartProgressWindow.show(START_STATUS_LATCH), "Progress Window", "Display progress window", Priorities.HIGH, TaskImportance.OPTIONAL, "JavaFX Toolkit", "Configuration")); + } + taskWorker.work(START_STATUS_LATCH); try { - startStatusLatch.waitUntilZero(); + START_STATUS_LATCH.waitUntilZero(); } catch (InterruptedException e) { e.printStackTrace(); } @@ -209,7 +198,7 @@ public final class Minosoft { MojangAccount.RefreshStates refreshState = account.refreshToken(); if (refreshState == MojangAccount.RefreshStates.ERROR) { account.delete(); - AccountListCell.listView.getItems().remove(account); + AccountListCell.MOJANG_ACCOUNT_LIST_VIEW.getItems().remove(account); selectedAccount = null; return; } @@ -232,13 +221,13 @@ public final class Minosoft { */ public static void waitForStartup() { try { - startStatusLatch.waitUntilZero(); + START_STATUS_LATCH.waitUntilZero(); } catch (InterruptedException e) { e.printStackTrace(); } } public static CountUpAndDownLatch getStartStatusLatch() { - return startStatusLatch; + return START_STATUS_LATCH; } } diff --git a/src/main/java/de/bixilon/minosoft/config/Configuration.java b/src/main/java/de/bixilon/minosoft/config/Configuration.java index 95f185485..c3514089c 100644 --- a/src/main/java/de/bixilon/minosoft/config/Configuration.java +++ b/src/main/java/de/bixilon/minosoft/config/Configuration.java @@ -28,7 +28,7 @@ import java.util.Map; public class Configuration { public static final int LATEST_CONFIG_VERSION = 1; - private final static JsonObject DEFAULT_CONFIGURATION = JsonParser.parseReader(new InputStreamReader(Configuration.class.getResourceAsStream("/config/" + StaticConfiguration.CONFIG_FILENAME))).getAsJsonObject(); + private static final JsonObject DEFAULT_CONFIGURATION = JsonParser.parseReader(new InputStreamReader(Configuration.class.getResourceAsStream("/config/" + StaticConfiguration.CONFIG_FILENAME))).getAsJsonObject(); private final HashMap config = new HashMap<>(); private final HashBiMap accountList = HashBiMap.create(); private final HashBiMap serverList = HashBiMap.create(); @@ -52,7 +52,6 @@ public class Configuration { JsonObject json = Util.readJsonFromFile(file.getAbsolutePath()); - int configVersion = (int) getData(json, ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION); if (configVersion > LATEST_CONFIG_VERSION) { throw new ConfigMigrationException(String.format("Configuration was migrated to newer config format (version=%d, expected=%d). Downgrading the config file is unsupported!", configVersion, LATEST_CONFIG_VERSION)); @@ -62,27 +61,27 @@ public class Configuration { } for (ConfigurationPaths.ConfigurationPath path : ConfigurationPaths.ALL_PATHS) { - config.put(path, getData(json, path)); + this.config.put(path, getData(json, path)); } // servers for (Map.Entry entry : json.getAsJsonObject("servers").getAsJsonObject("entries").entrySet()) { - serverList.put(Integer.parseInt(entry.getKey()), Server.deserialize(entry.getValue().getAsJsonObject())); + this.serverList.put(Integer.parseInt(entry.getKey()), Server.deserialize(entry.getValue().getAsJsonObject())); } // accounts for (Map.Entry entry : json.getAsJsonObject("accounts").getAsJsonObject("entries").entrySet()) { MojangAccount account = MojangAccount.deserialize(entry.getValue().getAsJsonObject()); - accountList.put(account.getUserId(), account); + this.accountList.put(account.getUserId(), account); } final File finalFile = file; new Thread(() -> { while (true) { // wait for interrupt - synchronized (lock) { + synchronized (this.lock) { try { - lock.wait(); + this.lock.wait(); } catch (InterruptedException ignored) { } } @@ -97,23 +96,23 @@ public class Configuration { return; } JsonObject jsonObject = DEFAULT_CONFIGURATION.deepCopy(); - synchronized (config) { + synchronized (this.config) { // accounts JsonObject accountsEntriesJson = jsonObject.getAsJsonObject("servers").getAsJsonObject("entries"); - for (Map.Entry entry : serverList.entrySet()) { + for (Map.Entry entry : this.serverList.entrySet()) { accountsEntriesJson.add(String.valueOf(entry.getKey()), entry.getValue().serialize()); } // servers JsonObject serversEntriesJson = jsonObject.getAsJsonObject("accounts").getAsJsonObject("entries"); - for (Map.Entry entry : accountList.entrySet()) { + for (Map.Entry entry : this.accountList.entrySet()) { serversEntriesJson.add(entry.getKey(), entry.getValue().serialize()); } // rest of data for (ConfigurationPaths.ConfigurationPath path : ConfigurationPaths.ALL_PATHS) { - saveData(jsonObject, path, config.get(path)); + saveData(jsonObject, path, this.config.get(path)); } } gson.toJson(jsonObject, writer); @@ -137,57 +136,57 @@ public class Configuration { } public boolean getBoolean(ConfigurationPaths.BooleanPaths path) { - return (boolean) config.get(path); + return (boolean) this.config.get(path); } public void putBoolean(ConfigurationPaths.BooleanPaths path, boolean value) { - config.put(path, value); + this.config.put(path, value); } public int getInt(ConfigurationPaths.IntegerPaths path) { - return (int) config.get(path); + return (int) this.config.get(path); } public void putInt(ConfigurationPaths.IntegerPaths path, int value) { - config.put(path, value); + this.config.put(path, value); } public String getString(ConfigurationPaths.StringPaths path) { - return (String) config.get(path); + return (String) this.config.get(path); } public void putString(ConfigurationPaths.StringPaths path, String value) { - config.put(path, value); + this.config.put(path, value); } public void putMojangAccount(MojangAccount account) { - accountList.put(account.getUserId(), account); + this.accountList.put(account.getUserId(), account); } public void putServer(Server server) { - serverList.put(server.getId(), server); + this.serverList.put(server.getId(), server); } public void removeServer(Server server) { - serverList.remove(server.getId()); + this.serverList.remove(server.getId()); } public void saveToFile() { - synchronized (lock) { - lock.notifyAll(); + synchronized (this.lock) { + this.lock.notifyAll(); } } public void removeAccount(MojangAccount account) { - accountList.remove(account.getUserId()); + this.accountList.remove(account.getUserId()); } public HashBiMap getServerList() { - return serverList; + return this.serverList; } public HashBiMap getAccountList() { - return accountList; + return this.accountList; } private void migrateConfiguration() throws ConfigMigrationException { diff --git a/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java b/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java index 492674eac..211d21233 100644 --- a/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java +++ b/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java @@ -17,7 +17,7 @@ import java.util.Arrays; import java.util.HashSet; public abstract class ConfigurationPaths { - static HashSet ALL_PATHS = new HashSet<>(); + public static final HashSet ALL_PATHS = new HashSet<>(); static { ALL_PATHS.addAll(Arrays.asList(StringPaths.values())); diff --git a/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java b/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java index 0f6b27e12..11975a39e 100644 --- a/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java +++ b/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java @@ -22,11 +22,11 @@ public class StaticConfiguration { public static final boolean DEBUG_MODE = false; // if true, additional checks will be made to validate data, ... Decreases performance public static final boolean DEBUG_SLOW_LOADING = false; // if true, many Thread.sleep will be executed and the start will be delayed (by a lot) public static String CONFIG_FILENAME = "config.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config) - public static boolean SKIP_MOJANG_AUTHENTICATION = false; // disables all connections to mojang + public static boolean SKIP_MOJANG_AUTHENTICATION; // disables all connections to mojang public static boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components) - public static boolean LOG_RELATIVE_TIME = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time - public static boolean VERBOSE_ENTITY_META_DATA_LOGGING = false; // if true, the entity meta data is getting serialized - public static boolean HEADLESS_MODE = false; // if true, no gui, rendering or whatever will be loaded or shown + public static boolean LOG_RELATIVE_TIME; // prefix all log messages with the relative start time in milliseconds instead of the formatted time + public static boolean VERBOSE_ENTITY_META_DATA_LOGGING; // if true, the entity meta data is getting serialized + public static boolean HEADLESS_MODE; // if true, no gui, rendering or whatever will be loaded or shown public static String HOME_DIRECTORY; public static final String TEMPORARY_FOLDER = System.getProperty("java.io.tmpdir", HOME_DIRECTORY + "/tmp/") + "/"; diff --git a/src/main/java/de/bixilon/minosoft/data/ChangeableIdentifier.java b/src/main/java/de/bixilon/minosoft/data/ChangeableIdentifier.java index a0b56f4c5..16007af36 100644 --- a/src/main/java/de/bixilon/minosoft/data/ChangeableIdentifier.java +++ b/src/main/java/de/bixilon/minosoft/data/ChangeableIdentifier.java @@ -22,13 +22,13 @@ public class ChangeableIdentifier extends VersionValueMap { String mod = ProtocolDefinition.DEFAULT_MOD; public ChangeableIdentifier(String legacy, String water) { - values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), legacy); - values.put(ProtocolDefinition.FLATTING_VERSION_ID, water); + this.values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), legacy); + this.values.put(ProtocolDefinition.FLATTING_VERSION_ID, water); } public ChangeableIdentifier(String legacy, String water, String mod) { - values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), legacy); - values.put(ProtocolDefinition.FLATTING_VERSION_ID, water); + this.values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), legacy); + this.values.put(ProtocolDefinition.FLATTING_VERSION_ID, water); this.mod = mod; } @@ -48,7 +48,7 @@ public class ChangeableIdentifier extends VersionValueMap { name = name.toLowerCase(); if (name.indexOf(":") != 0) { String[] splitName = name.split(":", 2); - if (!mod.equals(splitName[0])) { + if (!this.mod.equals(splitName[0])) { // mod is not correct return false; } diff --git a/src/main/java/de/bixilon/minosoft/data/ChatTextPositions.java b/src/main/java/de/bixilon/minosoft/data/ChatTextPositions.java index ae071b80e..eb85c5526 100644 --- a/src/main/java/de/bixilon/minosoft/data/ChatTextPositions.java +++ b/src/main/java/de/bixilon/minosoft/data/ChatTextPositions.java @@ -18,7 +18,9 @@ public enum ChatTextPositions { SYSTEM_MESSAGE, ABOVE_HOTBAR; + private static final ChatTextPositions[] CHAT_TEXT_POSITIONS = values(); + public static ChatTextPositions byId(int id) { - return values()[id]; + return CHAT_TEXT_POSITIONS[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/Difficulties.java b/src/main/java/de/bixilon/minosoft/data/Difficulties.java index 4ef0832f2..648f9cb6e 100644 --- a/src/main/java/de/bixilon/minosoft/data/Difficulties.java +++ b/src/main/java/de/bixilon/minosoft/data/Difficulties.java @@ -19,7 +19,9 @@ public enum Difficulties { NORMAL, HARD; + private static final Difficulties[] DIFFICULTIES = values(); + public static Difficulties byId(int id) { - return values()[id]; + return DIFFICULTIES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/Directions.java b/src/main/java/de/bixilon/minosoft/data/Directions.java index f1573fd2d..2e214235e 100644 --- a/src/main/java/de/bixilon/minosoft/data/Directions.java +++ b/src/main/java/de/bixilon/minosoft/data/Directions.java @@ -21,7 +21,9 @@ public enum Directions { WEST, EAST; + private static final Directions[] DIRECTIONS = values(); + public static Directions byId(int id) { - return values()[id]; + return DIRECTIONS[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/GameModes.java b/src/main/java/de/bixilon/minosoft/data/GameModes.java index 08a40bdc9..3fa4baeb3 100644 --- a/src/main/java/de/bixilon/minosoft/data/GameModes.java +++ b/src/main/java/de/bixilon/minosoft/data/GameModes.java @@ -19,7 +19,9 @@ public enum GameModes { ADVENTURE, SPECTATOR; + private static final GameModes[] GAME_MODES = values(); + public static GameModes byId(int id) { - return values()[id]; + return GAME_MODES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/LevelTypes.java b/src/main/java/de/bixilon/minosoft/data/LevelTypes.java index 7c6c91c69..bf0b08810 100644 --- a/src/main/java/de/bixilon/minosoft/data/LevelTypes.java +++ b/src/main/java/de/bixilon/minosoft/data/LevelTypes.java @@ -39,6 +39,6 @@ public enum LevelTypes { } public String getId() { - return type; + return this.type; } } diff --git a/src/main/java/de/bixilon/minosoft/data/MapSet.java b/src/main/java/de/bixilon/minosoft/data/MapSet.java index 87dceca08..2b089faf8 100644 --- a/src/main/java/de/bixilon/minosoft/data/MapSet.java +++ b/src/main/java/de/bixilon/minosoft/data/MapSet.java @@ -26,12 +26,12 @@ public class MapSet implements Map.Entry { @Override public K getKey() { - return key; + return this.key; } @Override public V getValue() { - return value; + return this.value; } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/Player.java b/src/main/java/de/bixilon/minosoft/data/Player.java index 3f3506904..75ed6cfc8 100644 --- a/src/main/java/de/bixilon/minosoft/data/Player.java +++ b/src/main/java/de/bixilon/minosoft/data/Player.java @@ -45,7 +45,7 @@ public class Player { int level; int totalExperience; PlayerEntity entity; - boolean spawnConfirmed = false; + boolean spawnConfirmed; ChatComponent tabHeader; ChatComponent tabFooter; @@ -53,15 +53,15 @@ public class Player { public Player(MojangAccount account) { this.account = account; // create our own inventory without any properties - inventories.put(PLAYER_INVENTORY_ID, new Inventory(null)); + this.inventories.put(PLAYER_INVENTORY_ID, new Inventory(null)); } public String getPlayerName() { - return account.getPlayerName(); + return this.account.getPlayerName(); } public UUID getPlayerUUID() { - return account.getUUID(); + return this.account.getUUID(); } public MojangAccount getAccount() { @@ -69,7 +69,7 @@ public class Player { } public float getHealth() { - return health; + return this.health; } public void setHealth(float health) { @@ -77,7 +77,7 @@ public class Player { } public int getFood() { - return food; + return this.food; } public void setFood(int food) { @@ -85,7 +85,7 @@ public class Player { } public float getSaturation() { - return saturation; + return this.saturation; } public void setSaturation(float saturation) { @@ -93,7 +93,7 @@ public class Player { } public BlockPosition getSpawnLocation() { - return spawnLocation; + return this.spawnLocation; } public void setSpawnLocation(BlockPosition spawnLocation) { @@ -101,7 +101,7 @@ public class Player { } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public void setGameMode(GameModes gameMode) { @@ -109,11 +109,11 @@ public class Player { } public World getWorld() { - return world; + return this.world; } public byte getSelectedSlot() { - return selectedSlot; + return this.selectedSlot; } public void setSelectedSlot(byte selectedSlot) { @@ -121,7 +121,7 @@ public class Player { } public int getLevel() { - return level; + return this.level; } public void setLevel(int level) { @@ -129,7 +129,7 @@ public class Player { } public int getTotalExperience() { - return totalExperience; + return this.totalExperience; } public void setTotalExperience(int totalExperience) { @@ -151,11 +151,11 @@ public class Player { } public void setSlot(int windowId, int slot, Slot data) { - inventories.get(windowId).setSlot(slot, data); + this.inventories.get(windowId).setSlot(slot, data); } public Inventory getInventory(int id) { - return inventories.get(id); + return this.inventories.get(id); } public Slot getSlot(int windowId, InventorySlots.InventoryInterface slot, int versionId) { @@ -163,7 +163,7 @@ public class Player { } public Slot getSlot(int windowId, int slot) { - return inventories.get(windowId).getSlot(slot); + return this.inventories.get(windowId).getSlot(slot); } public void setSlot(int windowId, InventorySlots.InventoryInterface slot, int versionId, Slot data) { @@ -171,15 +171,15 @@ public class Player { } public void createInventory(InventoryProperties properties) { - inventories.put(properties.getWindowId(), new Inventory(properties)); + this.inventories.put(properties.getWindowId(), new Inventory(properties)); } public void deleteInventory(int windowId) { - inventories.remove(windowId); + this.inventories.remove(windowId); } public boolean isSpawnConfirmed() { - return spawnConfirmed; + return this.spawnConfirmed; } public void setSpawnConfirmed(boolean spawnConfirmed) { @@ -187,16 +187,16 @@ public class Player { } public ScoreboardManager getScoreboardManager() { - return scoreboardManager; + return this.scoreboardManager; } public HashMap getPlayerList() { - return playerList; + return this.playerList; } public PlayerListItem getPlayerListItem(String name) { // only legacy - for (PlayerListItem listItem : playerList.values()) { + for (PlayerListItem listItem : this.playerList.values()) { if (listItem.getName().equals(name)) { return listItem; } @@ -205,7 +205,7 @@ public class Player { } public ChatComponent getTabHeader() { - return tabHeader; + return this.tabHeader; } public void setTabHeader(ChatComponent tabHeader) { @@ -213,7 +213,7 @@ public class Player { } public ChatComponent getTabFooter() { - return tabFooter; + return this.tabFooter; } public void setTabFooter(ChatComponent tabFooter) { @@ -221,7 +221,7 @@ public class Player { } public PlayerEntity getEntity() { - return entity; + return this.entity; } public void setEntity(PlayerEntity entity) { diff --git a/src/main/java/de/bixilon/minosoft/data/PlayerPropertyData.java b/src/main/java/de/bixilon/minosoft/data/PlayerPropertyData.java index 26944f4d2..96f2adea7 100644 --- a/src/main/java/de/bixilon/minosoft/data/PlayerPropertyData.java +++ b/src/main/java/de/bixilon/minosoft/data/PlayerPropertyData.java @@ -29,11 +29,11 @@ public class PlayerPropertyData { } public String getValue() { - return value; + return this.value; } public String getSignature() { - return signature; + return this.signature; } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/SoundCategories.java b/src/main/java/de/bixilon/minosoft/data/SoundCategories.java index 85cee6b36..c217e198d 100644 --- a/src/main/java/de/bixilon/minosoft/data/SoundCategories.java +++ b/src/main/java/de/bixilon/minosoft/data/SoundCategories.java @@ -25,7 +25,9 @@ public enum SoundCategories { AMBIENT, VOICE; + private static final SoundCategories[] SOUND_CATEGORIES = values(); + public static SoundCategories byId(int id) { - return values()[id]; + return SOUND_CATEGORIES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/Tag.java b/src/main/java/de/bixilon/minosoft/data/Tag.java index 5217bbcd3..11154f0cd 100644 --- a/src/main/java/de/bixilon/minosoft/data/Tag.java +++ b/src/main/java/de/bixilon/minosoft/data/Tag.java @@ -23,10 +23,10 @@ public class Tag { } public String getIdentifier() { - return identifier; + return this.identifier; } public int[] getIdList() { - return idList; + return this.idList; } } diff --git a/src/main/java/de/bixilon/minosoft/data/Trade.java b/src/main/java/de/bixilon/minosoft/data/Trade.java index 6576a3c7b..12a354e5a 100644 --- a/src/main/java/de/bixilon/minosoft/data/Trade.java +++ b/src/main/java/de/bixilon/minosoft/data/Trade.java @@ -39,38 +39,38 @@ public class Trade { } public Slot getInput1() { - return input1; + return this.input1; } public Slot getInput2() { - return input2; + return this.input2; } public boolean isEnabled() { - return enabled; + return this.enabled; } public int getUsages() { - return usages; + return this.usages; } public int getMaxUsages() { - return maxUsages; + return this.maxUsages; } public int getXp() { - return xp; + return this.xp; } public int getSpecialPrice() { - return specialPrice; + return this.specialPrice; } public float getPriceMultiplier() { - return priceMultiplier; + return this.priceMultiplier; } public int getDemand() { - return demand; + return this.demand; } } diff --git a/src/main/java/de/bixilon/minosoft/data/VersionValueMap.java b/src/main/java/de/bixilon/minosoft/data/VersionValueMap.java index 043bdf90d..233b9d41f 100644 --- a/src/main/java/de/bixilon/minosoft/data/VersionValueMap.java +++ b/src/main/java/de/bixilon/minosoft/data/VersionValueMap.java @@ -26,16 +26,16 @@ public class VersionValueMap { public VersionValueMap(MapSet[] sets, boolean unused) { for (MapSet set : sets) { - values.put(set.getKey(), set.getValue()); + this.values.put(set.getKey(), set.getValue()); } } public VersionValueMap(V value) { - values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), value); + this.values.put(Versions.LOWEST_VERSION_SUPPORTED.getVersionId(), value); } public V get(int versionId) { - Map.Entry value = values.lowerEntry(versionId); + Map.Entry value = this.values.lowerEntry(versionId); if (value == null) { return null; } @@ -53,6 +53,6 @@ public class VersionValueMap { } public TreeMap getAll() { - return values; + return this.values; } } diff --git a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java index 385f5ed3c..9e50986b6 100644 --- a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java +++ b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java @@ -44,7 +44,7 @@ public class AssetsManager { public static final String ASSETS_CLIENT_JAR_HASH = "f6581c4fd25cde00eecf003354cedc450390eb82"; // sha1 hash of file generated by minosoft (client jar file mappings: name -> hash) public static final String[] RELEVANT_ASSETS = {"minecraft/lang/", "minecraft/sounds/", "minecraft/textures/", "minecraft/font/"}; - private static final HashMap assets = new HashMap<>(); + private static final HashMap ASSETS_MAP = new HashMap<>(); public static void downloadAssetsIndex() throws IOException { Util.downloadFileAsGz(String.format("https://launchermeta.mojang.com/v1/packages/%s/%s.json", ASSETS_INDEX_HASH, ASSETS_INDEX_VERSION), getAssetDiskPath(ASSETS_INDEX_HASH)); @@ -71,7 +71,7 @@ public class AssetsManager { } public static void downloadAllAssets(CountUpAndDownLatch latch) throws IOException { - if (assets.size() > 0) { + if (!ASSETS_MAP.isEmpty()) { return; } try { @@ -80,12 +80,12 @@ public class AssetsManager { Log.printException(e, LogLevels.DEBUG); Log.warn("Could not download assets index. Please check your internet connection"); } - assets.putAll(verifyAssets(AssetsSource.MOJANG, latch, parseAssetsIndex(ASSETS_INDEX_HASH))); - assets.putAll(verifyAssets(AssetsSource.MINOSOFT_GIT, latch, parseAssetsIndex(Util.readJsonAsset("mapping/resources.json")))); + ASSETS_MAP.putAll(verifyAssets(AssetsSource.MOJANG, latch, parseAssetsIndex(ASSETS_INDEX_HASH))); + ASSETS_MAP.putAll(verifyAssets(AssetsSource.MINOSOFT_GIT, latch, parseAssetsIndex(Util.readJsonAsset("mapping/resources.json")))); latch.addCount(1); // client jar // download assets generateJarAssets(); - assets.putAll(parseAssetsIndex(ASSETS_CLIENT_JAR_HASH)); + ASSETS_MAP.putAll(parseAssetsIndex(ASSETS_CLIENT_JAR_HASH)); latch.countDown(); } @@ -99,7 +99,7 @@ public class AssetsManager { Thread.sleep(100L); } if (!verifyAssetHash(hash, compressed)) { - AssetsManager.downloadAsset(source, hash); + downloadAsset(source, hash); } latch.countDown(); } catch (Exception e) { @@ -111,23 +111,23 @@ public class AssetsManager { } public static boolean doesAssetExist(String name) { - return assets.containsKey(name); + return ASSETS_MAP.containsKey(name); } - public static HashMap getAssets() { - return assets; + public static HashMap getAssetsMap() { + return ASSETS_MAP; } public static InputStreamReader readAsset(String name) throws IOException { - return readAssetByHash(assets.get(name)); + return readAssetByHash(ASSETS_MAP.get(name)); } public static InputStream readAssetAsStream(String name) throws IOException { - return readAssetAsStreamByHash(assets.get(name)); + return readAssetAsStreamByHash(ASSETS_MAP.get(name)); } public static JsonElement readJsonAsset(String name) throws IOException { - return readJsonAssetByHash(assets.get(name)); + return readJsonAssetByHash(ASSETS_MAP.get(name)); } private static void downloadAsset(AssetsSource source, String hash) throws Exception { diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java index 81fa9eb19..b38e7760e 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandArgumentNode.java @@ -31,11 +31,11 @@ public class CommandArgumentNode extends CommandLiteralNode { public CommandArgumentNode(byte flags, InByteBuffer buffer) { super(flags, buffer); - parser = CommandParsers.INSTANCE.getParserInstance(buffer.readIdentifier()); - properties = parser.readParserProperties(buffer); + this.parser = CommandParsers.INSTANCE.getParserInstance(buffer.readIdentifier()); + this.properties = this.parser.readParserProperties(buffer); if (BitByte.isBitMask(flags, 0x10)) { String fullIdentifier = buffer.readIdentifier().getFullIdentifier(); - suggestionType = switch (fullIdentifier) { + this.suggestionType = switch (fullIdentifier) { case "minecraft:ask_server" -> CommandArgumentNode.SuggestionTypes.ASK_SERVER; case "minecraft:all_recipes" -> CommandArgumentNode.SuggestionTypes.ALL_RECIPES; case "minecraft:available_sounds" -> CommandArgumentNode.SuggestionTypes.AVAILABLE_SOUNDS; @@ -44,26 +44,26 @@ public class CommandArgumentNode extends CommandLiteralNode { default -> throw new IllegalStateException("Unexpected value: " + fullIdentifier); }; } else { - suggestionType = null; + this.suggestionType = null; } } public CommandParser getParser() { - return parser; + return this.parser; } @Nullable public ParserProperties getProperties() { - return properties; + return this.properties; } public SuggestionTypes getSuggestionType() { - return suggestionType; + return this.suggestionType; } @Override public void isSyntaxCorrect(Connection connection, ImprovedStringReader stringReader) throws CommandParseException { - parser.isParsable(connection, properties, stringReader); + this.parser.isParsable(connection, this.properties, stringReader); super.isSyntaxCorrect(connection, stringReader); } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java index 92c6f9ffe..f7ab24fcc 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandLiteralNode.java @@ -20,10 +20,10 @@ public class CommandLiteralNode extends CommandNode { public CommandLiteralNode(byte flags, InByteBuffer buffer) { super(flags, buffer); - name = buffer.readString(); + this.name = buffer.readString(); } public String getName() { - return name; + return this.name; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java b/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java index 66f3c2665..d40858357 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/CommandNode.java @@ -36,28 +36,28 @@ public abstract class CommandNode { public CommandNode(byte flags, InByteBuffer buffer) { this.isExecutable = BitByte.isBitMask(flags, 0x04); - childrenIds = buffer.readVarIntArray(); + this.childrenIds = buffer.readVarIntArray(); if (BitByte.isBitMask(flags, 0x08)) { - redirectNodeId = buffer.readVarInt(); + this.redirectNodeId = buffer.readVarInt(); } else { - redirectNodeId = -1; + this.redirectNodeId = -1; } } public boolean isExecutable() { - return isExecutable; + return this.isExecutable; } public HashMap getLiteralChildren() { - return literalChildren; + return this.literalChildren; } public HashSet getArgumentsChildren() { - return argumentsChildren; + return this.argumentsChildren; } public CommandNode getRedirectNode() { - return redirectNode; + return this.redirectNode; } @DoNotCall @@ -70,29 +70,29 @@ public abstract class CommandNode { @DoNotCall public int getRedirectNodeId() { - return redirectNodeId; + return this.redirectNodeId; } @DoNotCall public int[] getChildrenIds() { - return childrenIds; + return this.childrenIds; } public void isSyntaxCorrect(Connection connection, ImprovedStringReader stringReader) throws CommandParseException { String nextArgument = stringReader.getUntilNextCommandArgument(); - if (nextArgument.length() == 0) { - if (isExecutable) { + if (nextArgument.isEmpty()) { + if (this.isExecutable) { return; } throw new RequiresMoreArgumentsCommandParseException(stringReader); } - if (literalChildren.containsKey(nextArgument)) { + if (this.literalChildren.containsKey(nextArgument)) { stringReader.skip(nextArgument.length() + ProtocolDefinition.COMMAND_SEPARATOR.length()); - literalChildren.get(nextArgument).isSyntaxCorrect(connection, stringReader); + this.literalChildren.get(nextArgument).isSyntaxCorrect(connection, stringReader); return; } CommandParseException lastException = null; - for (CommandArgumentNode argumentNode : argumentsChildren) { + for (CommandArgumentNode argumentNode : this.argumentsChildren) { int currentPosition = stringReader.getPosition(); try { argumentNode.isSyntaxCorrect(connection, stringReader); @@ -119,6 +119,12 @@ public abstract class CommandNode { public enum NodeTypes { ROOT, LITERAL, - ARGUMENT + ARGUMENT; + + private static final NodeTypes[] NODE_TYPES = values(); + + public static NodeTypes byId(int id) { + return NODE_TYPES[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java index bdf2f1fec..6a349fbe4 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/FloatParser.java @@ -25,7 +25,6 @@ import de.bixilon.minosoft.util.buffers.ImprovedStringReader; public class FloatParser extends CommandParser { public static final FloatParser FLOAT_PARSER = new FloatParser(); - @Override public ParserProperties readParserProperties(InByteBuffer buffer) { return new FloatParserProperties(buffer); diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/IdentifierSelectorArgumentParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/IdentifierSelectorArgumentParser.java index cd1c033c4..c7f3dda3c 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/IdentifierSelectorArgumentParser.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/IdentifierSelectorArgumentParser.java @@ -24,7 +24,6 @@ import de.bixilon.minosoft.util.buffers.ImprovedStringReader; public class IdentifierSelectorArgumentParser extends EntitySelectorArgumentParser { public static final IdentifierSelectorArgumentParser ENTITY_TYPE_IDENTIFIER_SELECTOR_ARGUMENT_PARSER = new IdentifierSelectorArgumentParser(); - @Override public void isParsable(Connection connection, ImprovedStringReader stringReader) throws CommandParseException { Pair match = readNextArgument(stringReader); diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/RangeSelectorArgumentParser.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/RangeSelectorArgumentParser.java index b62ae3dbe..5dc79b7e3 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/RangeSelectorArgumentParser.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/entity/RangeSelectorArgumentParser.java @@ -35,15 +35,15 @@ public class RangeSelectorArgumentParser extends EntitySelectorArgumentParser { } public int getMinValue() { - return minValue; + return this.minValue; } public int getMaxValue() { - return maxValue; + return this.maxValue; } public boolean isDecimal() { - return decimal; + return this.decimal; } @Override @@ -70,7 +70,7 @@ public class RangeSelectorArgumentParser extends EntitySelectorArgumentParser { } if (min < getMinValue() || max > getMaxValue()) { - throw new ValueOutOfRangeCommandParseException(stringReader, minValue, maxValue, match.getKey()); + throw new ValueOutOfRangeCommandParseException(stringReader, this.minValue, this.maxValue, match.getKey()); } if (min > max) { throw new MinimumBiggerAsMaximumCommandParseException(stringReader, match.getKey()); diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/CommandParseException.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/CommandParseException.java index 89712a5e6..c550865ae 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/CommandParseException.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/exceptions/CommandParseException.java @@ -13,7 +13,6 @@ package de.bixilon.minosoft.data.commands.parser.exceptions; - import de.bixilon.minosoft.util.buffers.ImprovedStringReader; public class CommandParseException extends Exception { @@ -47,18 +46,18 @@ public class CommandParseException extends Exception { } public String getErrorMessage() { - return errorMessage; + return this.errorMessage; } public ImprovedStringReader getCommand() { - return command; + return this.command; } public int getStartIndex() { - return startIndex; + return this.startIndex; } public int getEndIndex() { - return endIndex; + return this.endIndex; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java index bfed21e55..83caedbbe 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/DoubleParserProperties.java @@ -23,22 +23,22 @@ public class DoubleParserProperties implements ParserProperties { public DoubleParserProperties(InByteBuffer buffer) { byte flags = buffer.readByte(); if (BitByte.isBitMask(flags, 0x01)) { - minValue = buffer.readDouble(); + this.minValue = buffer.readDouble(); } else { - minValue = Double.MIN_VALUE; + this.minValue = Double.MIN_VALUE; } if (BitByte.isBitMask(flags, 0x02)) { - maxValue = buffer.readDouble(); + this.maxValue = buffer.readDouble(); } else { - maxValue = Double.MAX_VALUE; + this.maxValue = Double.MAX_VALUE; } } public double getMinValue() { - return minValue; + return this.minValue; } public double getMaxValue() { - return maxValue; + return this.maxValue; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java index 510703937..e3c92d850 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/EntityParserProperties.java @@ -22,15 +22,15 @@ public class EntityParserProperties implements ParserProperties { public EntityParserProperties(InByteBuffer buffer) { byte flags = buffer.readByte(); - onlySingleEntity = BitByte.isBitMask(flags, 0x01); - onlyPlayers = BitByte.isBitMask(flags, 0x02); + this.onlySingleEntity = BitByte.isBitMask(flags, 0x01); + this.onlyPlayers = BitByte.isBitMask(flags, 0x02); } public boolean isOnlySingleEntity() { - return onlySingleEntity; + return this.onlySingleEntity; } public boolean isOnlyPlayers() { - return onlyPlayers; + return this.onlyPlayers; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java index d656078da..bbd803f53 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/FloatParserProperties.java @@ -23,22 +23,22 @@ public class FloatParserProperties implements ParserProperties { public FloatParserProperties(InByteBuffer buffer) { byte flags = buffer.readByte(); if (BitByte.isBitMask(flags, 0x01)) { - minValue = buffer.readFloat(); + this.minValue = buffer.readFloat(); } else { - minValue = Float.MIN_VALUE; + this.minValue = Float.MIN_VALUE; } if (BitByte.isBitMask(flags, 0x02)) { - maxValue = buffer.readFloat(); + this.maxValue = buffer.readFloat(); } else { - maxValue = Float.MAX_VALUE; + this.maxValue = Float.MAX_VALUE; } } public float getMinValue() { - return minValue; + return this.minValue; } public float getMaxValue() { - return maxValue; + return this.maxValue; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java index 05954cc6e..b63c69ad7 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/IntegerParserProperties.java @@ -23,23 +23,23 @@ public class IntegerParserProperties implements ParserProperties { public IntegerParserProperties(InByteBuffer buffer) { byte flags = buffer.readByte(); if (BitByte.isBitMask(flags, 0x01)) { - minValue = buffer.readInt(); + this.minValue = buffer.readInt(); } else { - minValue = Integer.MIN_VALUE; + this.minValue = Integer.MIN_VALUE; } if (BitByte.isBitMask(flags, 0x02)) { - maxValue = buffer.readInt(); + this.maxValue = buffer.readInt(); } else { - maxValue = Integer.MAX_VALUE; + this.maxValue = Integer.MAX_VALUE; } } public int getMinValue() { - return minValue; + return this.minValue; } public int getMaxValue() { - return maxValue; + return this.maxValue; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java index cbcb347c6..da05236d6 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/RangeParserProperties.java @@ -20,10 +20,10 @@ public class RangeParserProperties implements ParserProperties { private final boolean allowDecimals; public RangeParserProperties(InByteBuffer buffer) { - allowDecimals = BitByte.isBitMask(buffer.readByte(), 0x01); + this.allowDecimals = BitByte.isBitMask(buffer.readByte(), 0x01); } public boolean isAllowDecimals() { - return allowDecimals; + return this.allowDecimals; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java index 9c139a7e8..a152ff723 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/ScoreHolderParserProperties.java @@ -20,10 +20,10 @@ public class ScoreHolderParserProperties implements ParserProperties { private final boolean allowMultiple; public ScoreHolderParserProperties(InByteBuffer buffer) { - allowMultiple = BitByte.isBitMask(buffer.readByte(), 0x01); + this.allowMultiple = BitByte.isBitMask(buffer.readByte(), 0x01); } public boolean isAllowMultiple() { - return allowMultiple; + return this.allowMultiple; } } diff --git a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java index 6ce0fc796..25961db54 100644 --- a/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/commands/parser/properties/StringParserProperties.java @@ -20,8 +20,8 @@ public class StringParserProperties implements ParserProperties { private final boolean allowEmptyString; public StringParserProperties(InByteBuffer buffer) { - setting = StringSettings.values()[buffer.readVarInt()]; - allowEmptyString = false; + this.setting = StringSettings.byId(buffer.readVarInt()); + this.allowEmptyString = false; } public StringParserProperties(StringSettings setting, boolean allowEmptyString) { @@ -30,16 +30,22 @@ public class StringParserProperties implements ParserProperties { } public StringSettings getSetting() { - return setting; + return this.setting; } public boolean isAllowEmptyString() { - return allowEmptyString; + return this.allowEmptyString; } public enum StringSettings { SINGLE_WORD, QUOTABLE_PHRASE, - GREEDY_PHRASE + GREEDY_PHRASE; + + private static final StringSettings[] STRING_SETTINGS = values(); + + public static StringSettings byId(int id) { + return STRING_SETTINGS[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityInformation.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityInformation.java index 3093bf887..6e81b4da1 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityInformation.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityInformation.java @@ -35,10 +35,10 @@ public class EntityInformation extends ModIdentifier { } public float getWidth() { - return width; + return this.width; } public float getHeight() { - return height; + return this.height; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaData.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaData.java index 58fb3368d..4bb4fdbb8 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaData.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaData.java @@ -78,7 +78,7 @@ public class EntityMetaData { case POSE -> buffer.readPose(); case BLOCK_ID -> buffer.getConnection().getMapping().getBlockById(buffer.readVarInt()); case OPT_VAR_INT -> buffer.readVarInt() - 1; - case VILLAGER_DATA -> new VillagerData(VillagerData.VillagerTypes.values()[buffer.readVarInt()], VillagerData.VillagerProfessions.byId(buffer.readVarInt(), buffer.getVersionId()), VillagerData.VillagerLevels.values()[buffer.readVarInt()]); + case VILLAGER_DATA -> new VillagerData(VillagerData.VillagerTypes.byId(buffer.readVarInt()), VillagerData.VillagerProfessions.byId(buffer.readVarInt(), buffer.getVersionId()), VillagerData.VillagerLevels.byId(buffer.readVarInt())); case OPT_BLOCK_ID -> { int blockId = buffer.readVarInt(); if (blockId == 0) { @@ -90,7 +90,7 @@ public class EntityMetaData { } public MetaDataHashMap getSets() { - return sets; + return this.sets; } public enum EntityMetaDataValueTypes { @@ -121,11 +121,11 @@ public class EntityMetaData { final VersionValueMap valueMap; EntityMetaDataValueTypes(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } EntityMetaDataValueTypes(int id) { - valueMap = new VersionValueMap<>(id); + this.valueMap = new VersionValueMap<>(id); } public static EntityMetaDataValueTypes byId(int id, int versionId) { @@ -138,7 +138,7 @@ public class EntityMetaData { } public int getId(Integer versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } @@ -206,7 +206,7 @@ public class EntityMetaData { @SuppressWarnings("unchecked") public K get(EntityMetaDataFields field) { - Integer index = connection.getMapping().getEntityMetaDataIndex(field); + Integer index = EntityMetaData.this.connection.getMapping().getEntityMetaDataIndex(field); if (index == null) { // ups, index not found. Index not available in this version?, mappings broken or mappings not available return field.getDefaultValue(); diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaDataFields.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaDataFields.java index 1e2bf3c64..6ceaf24a3 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaDataFields.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityMetaDataFields.java @@ -58,7 +58,6 @@ public enum EntityMetaDataFields { ABSTRACT_ARROW_PIERCE_LEVEL((byte) 0), ABSTRACT_ARROW_OWNER_UUID, - FISHING_HOOK_HOOKED_ENTITY(0), FISHING_HOOK_CATCHABLE(false), @@ -67,7 +66,6 @@ public enum EntityMetaDataFields { THROWN_TRIDENT_LOYALTY_LEVEL(0), THROWN_TRIDENT_FOIL(false), - BOAT_HURT(0), BOAT_HURT_DIRECTION(1), BOAT_DAMAGE_TAKEN(0f), @@ -267,7 +265,6 @@ public enum EntityMetaDataFields { THROWN_EYE_OF_ENDER_ITEM, - // pretty old stuff here. 1.8 mostly (or even after, I don't know and I don't care) LEGACY_SKELETON_TYPE((byte) 0), LEGACY_ENDERMAN_CARRIED_BLOCK(0), @@ -287,7 +284,7 @@ public enum EntityMetaDataFields { private final Object defaultValue; EntityMetaDataFields() { - defaultValue = null; + this.defaultValue = null; } EntityMetaDataFields(Object defaultValue) { @@ -296,6 +293,6 @@ public enum EntityMetaDataFields { @SuppressWarnings("unchecked") public K getDefaultValue() { - return (K) defaultValue; + return (K) this.defaultValue; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityProperty.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityProperty.java index 536cbbeb4..3d7f5eda7 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityProperty.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityProperty.java @@ -25,10 +25,10 @@ public class EntityProperty { } public double getValue() { - return value; + return this.value; } public HashMap getModifiers() { - return modifiers; + return this.modifiers; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java index 6b0974ca4..7f5115aa9 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyKeys.java @@ -24,11 +24,11 @@ public enum EntityPropertyKeys { HORSE_JUMP_STRENGTH("horse.jumpStrength"), ZOMBIE_SPAWN_REINFORCEMENT("zombie.spawnReinforcements"); - final static HashBiMap keys = HashBiMap.create(); + private static final HashBiMap KEYS = HashBiMap.create(); static { for (EntityPropertyKeys key : values()) { - keys.put(key.getIdentifier(), key); + KEYS.put(key.getIdentifier(), key); } } @@ -39,10 +39,10 @@ public enum EntityPropertyKeys { } public static EntityPropertyKeys byName(String name) { - return keys.get(name); + return KEYS.get(name); } public String getIdentifier() { - return identifier; + return this.identifier; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyModifier.java b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyModifier.java index 5fd8d920b..5fc9fbdcc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyModifier.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/EntityPropertyModifier.java @@ -21,7 +21,7 @@ public class EntityPropertyModifier { } public double getAmount() { - return amount; + return this.amount; } public void setAmount(double amount) { diff --git a/src/main/java/de/bixilon/minosoft/data/entities/Objects.java b/src/main/java/de/bixilon/minosoft/data/entities/Objects.java index 861400aa9..302a4ebdc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/Objects.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/Objects.java @@ -58,11 +58,11 @@ public enum Objects { DRAGON_FIREBALL(93, DragonFireball.class), TRIDENT(94, ThrownTrident.class); - final static HashBiMap objects = HashBiMap.create(); + private static final HashBiMap ID_OBJECT_MAP = HashBiMap.create(); static { for (Objects object : values()) { - objects.put(object.getId(), object); + ID_OBJECT_MAP.put(object.getId(), object); } } @@ -75,14 +75,14 @@ public enum Objects { } public static Objects byId(int id) { - return objects.get(id); + return ID_OBJECT_MAP.get(id); } public int getId() { - return id; + return this.id; } public Class getClazz() { - return clazz; + return this.clazz; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/Poses.java b/src/main/java/de/bixilon/minosoft/data/entities/Poses.java index 57097ee9c..3426d91a8 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/Poses.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/Poses.java @@ -22,7 +22,9 @@ public enum Poses { SNEAKING, DYING; + private static final Poses[] POSES = values(); + public static Poses byId(int id) { - return values()[id]; + return POSES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt b/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt index 0738dd054..9e57b6f8e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/Rotation.kt @@ -12,7 +12,7 @@ */ package de.bixilon.minosoft.data.entities -class Rotation(val yaw: Int, val pitch: Int) { +data class Rotation(val yaw: Int, val pitch: Int) { override fun toString(): String { return String.format("raw=%d, pitch=%d", yaw, pitch) diff --git a/src/main/java/de/bixilon/minosoft/data/entities/VillagerData.kt b/src/main/java/de/bixilon/minosoft/data/entities/VillagerData.kt index 620c4ed9d..0033e4c05 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/VillagerData.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/VillagerData.kt @@ -63,9 +63,27 @@ data class VillagerData(val type: VillagerTypes, val profession: VillagerProfess enum class VillagerTypes { DESSERT, JUNGLE, PLAINS, SAVANNA, SNOW, SWAMP, TAIGA; + + companion object { + private val VILLAGER_TYPES: Array = values() + + @JvmStatic + fun byId(id: Int): VillagerTypes { + return VILLAGER_TYPES[id] + } + } } enum class VillagerLevels { NOVICE, APPRENTICE, JOURNEYMAN, EXPERT, MASTER; + + companion object { + private val VILLAGER_LEVELS: Array = values() + + @JvmStatic + fun byId(id: Int): VillagerLevels { + return VILLAGER_LEVELS[id] + } + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java b/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java index 9ed2700f4..eb35a9043 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/BedEntityMetaData.java @@ -28,15 +28,15 @@ public class BedEntityMetaData extends BlockEntityMetaData { public BedEntityMetaData(NBTTag nbt) { if (nbt == null) { - color = ChatColors.RED; + this.color = ChatColors.RED; return; } if (nbt instanceof StringTag stringTag) { // yes, we support bed rgb colors :D - color = new RGBColor(stringTag.getValue()); + this.color = new RGBColor(stringTag.getValue()); return; } - color = switch (((IntTag) nbt).getValue()) { + this.color = switch (((IntTag) nbt).getValue()) { case 0 -> new RGBColor(255, 255, 255); // white case 1 -> new RGBColor(234, 103, 3); // orange case 2 -> new RGBColor(199, 78, 189); // magenta @@ -58,6 +58,6 @@ public class BedEntityMetaData extends BlockEntityMetaData { } public RGBColor getColor() { - return color; + return this.color; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/block/CampfireBlockEntityMetaData.java b/src/main/java/de/bixilon/minosoft/data/entities/block/CampfireBlockEntityMetaData.java index de6404862..cd365edcd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/block/CampfireBlockEntityMetaData.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/block/CampfireBlockEntityMetaData.java @@ -26,13 +26,13 @@ public class CampfireBlockEntityMetaData extends BlockEntityMetaData { } public CampfireBlockEntityMetaData(ListTag nbt) { - items = new Slot[4]; + this.items = new Slot[4]; for (CompoundTag tag : nbt.getValue()) { - items[tag.getByteTag("Slot").getValue()] = new Slot(new Item(tag.getStringTag("id").getValue()), tag.getByteTag("Count").getValue()); + this.items[tag.getByteTag("Slot").getValue()] = new Slot(new Item(tag.getStringTag("id").getValue()), tag.getByteTag("Count").getValue()); } } public Slot[] getItems() { - return items; + return this.items; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/AgeableMob.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/AgeableMob.java index cfd9613fc..362a7637f 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/AgeableMob.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/AgeableMob.java @@ -27,6 +27,6 @@ public abstract class AgeableMob extends PathfinderMob { @EntityMetaDataFunction(identifier = "isBaby") public boolean isBaby() { - return metaData.getSets().getBoolean(EntityMetaDataFields.AGEABLE_IS_BABY); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.AGEABLE_IS_BABY); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java index 4b47fdc1c..8f7cd5965 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/Entity.java @@ -55,11 +55,11 @@ public abstract class Entity { } public int getEntityId() { - return entityId; + return this.entityId; } public Location getLocation() { - return location; + return this.location; } public void setLocation(Location location) { @@ -67,33 +67,33 @@ public abstract class Entity { } public void setLocation(RelativeLocation relativeLocation) { - location = new Location(location.getX() + relativeLocation.getX(), location.getY() + relativeLocation.getY(), location.getZ() + relativeLocation.getZ()); + this.location = new Location(this.location.getX() + relativeLocation.getX(), this.location.getY() + relativeLocation.getY(), this.location.getZ() + relativeLocation.getZ()); } public void setEquipment(HashMap slots) { - equipment.putAll(slots); + this.equipment.putAll(slots); } public Slot getEquipment(InventorySlots.EntityInventorySlots slot) { - return equipment.get(slot); + return this.equipment.get(slot); } public UUID getUUID() { - return uuid; + return this.uuid; } public HashSet getEffectList() { - return effectList; + return this.effectList; } public void addEffect(StatusEffect effect) { // effect already applied, maybe the duration or the amplifier changed? - effectList.removeIf(listEffect -> listEffect.getEffect() == effect.getEffect()); - effectList.add(effect); + this.effectList.removeIf(listEffect -> listEffect.getEffect() == effect.getEffect()); + this.effectList.add(effect); } public void removeEffect(MobEffect effect) { - effectList.removeIf(listEffect -> listEffect.getEffect() == effect); + this.effectList.removeIf(listEffect -> listEffect.getEffect() == effect); } public void attachTo(int vehicleId) { @@ -101,19 +101,19 @@ public abstract class Entity { } public boolean isAttached() { - return attachedTo != -1; + return this.attachedTo != -1; } public int getAttachedEntity() { - return attachedTo; + return this.attachedTo; } public void detach() { - attachedTo = -1; + this.attachedTo = -1; } public EntityRotation getRotation() { - return rotation; + return this.rotation; } public void setRotation(EntityRotation rotation) { @@ -121,7 +121,7 @@ public abstract class Entity { } public void setRotation(int yaw, int pitch) { - this.rotation = new EntityRotation(yaw, pitch, rotation.getHeadYaw()); + this.rotation = new EntityRotation(yaw, pitch, this.rotation.getHeadYaw()); } public void setRotation(int yaw, int pitch, int headYaw) { @@ -129,12 +129,12 @@ public abstract class Entity { } public void setHeadRotation(int headYaw) { - this.rotation = new EntityRotation(rotation.getYaw(), rotation.getPitch(), headYaw); + this.rotation = new EntityRotation(this.rotation.getYaw(), this.rotation.getPitch(), headYaw); } @Unsafe public EntityMetaData getMetaData() { - return metaData; + return this.metaData; } @Unsafe @@ -146,11 +146,11 @@ public abstract class Entity { } public EntityInformation getEntityInformation() { - return information; + return this.information; } private boolean getEntityFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.ENTITY_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.ENTITY_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "onFire") @@ -187,28 +187,28 @@ public abstract class Entity { @EntityMetaDataFunction(identifier = "airSupply") private int getAirSupply() { - return metaData.getSets().getInt(EntityMetaDataFields.ENTITY_AIR_SUPPLY); + return this.metaData.getSets().getInt(EntityMetaDataFields.ENTITY_AIR_SUPPLY); } @EntityMetaDataFunction(identifier = "customName") @Nullable private ChatComponent getCustomName() { - return metaData.getSets().getChatComponent(EntityMetaDataFields.ENTITY_CUSTOM_NAME); + return this.metaData.getSets().getChatComponent(EntityMetaDataFields.ENTITY_CUSTOM_NAME); } @EntityMetaDataFunction(identifier = "customNameVisible") public boolean isCustomNameVisible() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_CUSTOM_NAME_VISIBLE); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_CUSTOM_NAME_VISIBLE); } @EntityMetaDataFunction(identifier = "isSilent") public boolean isSilent() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_SILENT); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_SILENT); } @EntityMetaDataFunction(identifier = "hasNoGravity") public boolean hasNoGravity() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_NO_GRAVITY); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ENTITY_NO_GRAVITY); } @EntityMetaDataFunction(identifier = "pose") @@ -222,20 +222,20 @@ public abstract class Entity { if (isFlyingWithElytra()) { return Poses.FLYING; } - return metaData.getSets().getPose(EntityMetaDataFields.ENTITY_POSE); + return this.metaData.getSets().getPose(EntityMetaDataFields.ENTITY_POSE); } @EntityMetaDataFunction(identifier = "ticksFrozen") public int getTicksFrozen() { - return metaData.getSets().getInt(EntityMetaDataFields.ENTITY_TICKS_FROZEN); + return this.metaData.getSets().getInt(EntityMetaDataFields.ENTITY_TICKS_FROZEN); } @Override public String toString() { - if (information == null) { + if (this.information == null) { return this.getClass().getCanonicalName(); } - return String.format("%s:%s", information.getMod(), information.getIdentifier()); + return String.format("%s:%s", this.information.getMod(), this.information.getIdentifier()); } public String getEntityMetaDataAsString() { diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/ExperienceOrb.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/ExperienceOrb.java index 3cef7fdb0..ebdac36b3 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/ExperienceOrb.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/ExperienceOrb.java @@ -24,7 +24,7 @@ public class ExperienceOrb extends Entity { public ExperienceOrb(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) { super(connection, entityId, uuid, location, rotation); - count = 0; + this.count = 0; } public ExperienceOrb(Connection connection, int entityId, Location location, int count) { @@ -34,6 +34,6 @@ public class ExperienceOrb extends Entity { @EntityMetaDataFunction(identifier = "count") public int getCount() { - return count; + return this.count; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.java index 03a487221..81ce7bedd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.java @@ -29,7 +29,7 @@ public abstract class LivingEntity extends Entity { } private boolean getLivingEntityFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.LIVING_ENTITY_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.LIVING_ENTITY_FLAGS, bitMask); } // = isUsingItem @@ -50,33 +50,33 @@ public abstract class LivingEntity extends Entity { @EntityMetaDataFunction(identifier = "health") public float getHealth() { - return metaData.getSets().getFloat(EntityMetaDataFields.LIVING_ENTITY_HEALTH); + return this.metaData.getSets().getFloat(EntityMetaDataFields.LIVING_ENTITY_HEALTH); } @EntityMetaDataFunction(identifier = "effectColor") public int getEffectColor() { - return metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_EFFECT_COLOR); + return this.metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_EFFECT_COLOR); } @EntityMetaDataFunction(identifier = "isEffectAmbient") public boolean getEffectAmbient() { - return metaData.getSets().getBoolean(EntityMetaDataFields.LIVING_ENTITY_EFFECT_AMBIENCE); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.LIVING_ENTITY_EFFECT_AMBIENCE); } @EntityMetaDataFunction(identifier = "arrowsInEntity") public int getArrowCount() { - return metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_ARROW_COUNT); + return this.metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_ARROW_COUNT); } @EntityMetaDataFunction(identifier = "absorptionHearts") public int getAbsorptionHearts() { - return metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_ABSORPTION_HEARTS); + return this.metaData.getSets().getInt(EntityMetaDataFields.LIVING_ENTITY_ABSORPTION_HEARTS); } @EntityMetaDataFunction(identifier = "bedLocation") @Nullable public BlockPosition getBedLocation() { - return metaData.getSets().getPosition(EntityMetaDataFields.LIVING_ENTITY_BED_POSITION); + return this.metaData.getSets().getPosition(EntityMetaDataFields.LIVING_ENTITY_BED_POSITION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/Mob.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/Mob.java index 3d6f46e49..a345bc6ac 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/Mob.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/Mob.java @@ -26,7 +26,7 @@ public abstract class Mob extends LivingEntity { } private boolean getMobFlags(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.MOB_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.MOB_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isNoAI") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/TamableAnimal.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/TamableAnimal.java index 208123a3d..da0328bdd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/TamableAnimal.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/TamableAnimal.java @@ -28,7 +28,7 @@ public abstract class TamableAnimal extends Animal { } private boolean getTameableFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.TAMABLE_ENTITY_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.TAMABLE_ENTITY_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isSitting") @@ -44,6 +44,6 @@ public abstract class TamableAnimal extends Animal { @EntityMetaDataFunction(identifier = "ownerUUID") @Nullable public UUID getOwner() { - return metaData.getSets().getUUID(EntityMetaDataFields.TAMABLE_ENTITY_OWNER_UUID); + return this.metaData.getSets().getUUID(EntityMetaDataFields.TAMABLE_ENTITY_OWNER_UUID); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/ambient/Bat.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/ambient/Bat.java index 34b8c2593..f322c12a5 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/ambient/Bat.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/ambient/Bat.java @@ -28,7 +28,7 @@ public class Bat extends AmbientCreature { } private boolean getBatFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.BAT_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.BAT_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "hanging") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Bee.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Bee.java index 4ffb3a66b..1c0ed25be 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Bee.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Bee.java @@ -28,7 +28,7 @@ public class Bee extends Animal { } private boolean getBeeFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.BEE_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.BEE_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isAngry") @@ -48,6 +48,6 @@ public class Bee extends Animal { @EntityMetaDataFunction(identifier = "remainingAngerTime") public int getRemainingAngerTimer() { - return metaData.getSets().getInt(EntityMetaDataFields.BEE_REMAINING_ANGER_TIME); + return this.metaData.getSets().getInt(EntityMetaDataFields.BEE_REMAINING_ANGER_TIME); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Cat.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Cat.java index 21f58de6e..92b6a7ad1 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Cat.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Cat.java @@ -32,22 +32,22 @@ public class Cat extends TamableAnimal { @EntityMetaDataFunction(identifier = "variant") public CatVariants getVariant() { - return CatVariants.values()[metaData.getSets().getInt(EntityMetaDataFields.CAT_VARIANT)]; + return CatVariants.byId(this.metaData.getSets().getInt(EntityMetaDataFields.CAT_VARIANT)); } @EntityMetaDataFunction(identifier = "lying") public boolean isLying() { - return metaData.getSets().getBoolean(EntityMetaDataFields.CAT_IS_LYING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.CAT_IS_LYING); } @EntityMetaDataFunction(identifier = "relaxed") public boolean isRelaxed() { - return metaData.getSets().getBoolean(EntityMetaDataFields.CAT_IS_RELAXED); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.CAT_IS_RELAXED); } @EntityMetaDataFunction(identifier = "collarColor") public RGBColor getCollarColor() { - return ChatColors.getColorById(metaData.getSets().getInt(EntityMetaDataFields.CAT_GET_COLLAR_COLOR)); + return ChatColors.getColorById(this.metaData.getSets().getInt(EntityMetaDataFields.CAT_GET_COLLAR_COLOR)); } public enum CatVariants { @@ -59,6 +59,12 @@ public class Cat extends TamableAnimal { CALICO, PERSIAN, RAGDOLL, - ALL_BLACK + ALL_BLACK; + + private static final CatVariants[] CAT_VARIANTS = values(); + + public static CatVariants byId(int id) { + return CAT_VARIANTS[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Fox.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Fox.java index 1a687fa34..042051138 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Fox.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Fox.java @@ -30,11 +30,11 @@ public class Fox extends Animal { @EntityMetaDataFunction(identifier = "variant") public int getVariant() { - return metaData.getSets().getInt(EntityMetaDataFields.FOX_VARIANT); + return this.metaData.getSets().getInt(EntityMetaDataFields.FOX_VARIANT); } private boolean getFoxFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.FOX_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.FOX_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isSitting") @@ -75,12 +75,12 @@ public class Fox extends Animal { @EntityMetaDataFunction(identifier = "trusted1") @Nullable public UUID getFirstTrusted() { - return metaData.getSets().getUUID(EntityMetaDataFields.FOX_TRUSTED_1); + return this.metaData.getSets().getUUID(EntityMetaDataFields.FOX_TRUSTED_1); } @EntityMetaDataFunction(identifier = "trusted2") @Nullable public UUID getSecondTrusted() { - return metaData.getSets().getUUID(EntityMetaDataFields.FOX_TRUSTED_2); + return this.metaData.getSets().getUUID(EntityMetaDataFields.FOX_TRUSTED_2); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/IronGolem.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/IronGolem.java index 21a63c4a5..763e4d32f 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/IronGolem.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/IronGolem.java @@ -28,7 +28,7 @@ public class IronGolem extends AbstractGolem { } private boolean getIronGolemFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.IRON_GOLEM_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.IRON_GOLEM_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isPlayerCreated") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Mooshroom.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Mooshroom.java index 369df3501..5e17b1c6a 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Mooshroom.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Mooshroom.java @@ -29,6 +29,6 @@ public class Mooshroom extends Cow { @EntityMetaDataFunction(identifier = "variant") public String getVariant() { - return metaData.getSets().getString(EntityMetaDataFields.MOOSHROOM_VARIANT); + return this.metaData.getSets().getString(EntityMetaDataFields.MOOSHROOM_VARIANT); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Ocelot.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Ocelot.java index c1152bb50..e3b6caeb8 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Ocelot.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Ocelot.java @@ -29,6 +29,6 @@ public class Ocelot extends Animal { @EntityMetaDataFunction(identifier = "trusting") public boolean isTrusting() { - return metaData.getSets().getBoolean(EntityMetaDataFields.OCELOT_IS_TRUSTING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.OCELOT_IS_TRUSTING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Panda.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Panda.java index 467910125..53ac99978 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Panda.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Panda.java @@ -29,31 +29,31 @@ public class Panda extends Animal { @EntityMetaDataFunction(identifier = "unhappyTimer") public int getUnhappyTimer() { - return metaData.getSets().getInt(EntityMetaDataFields.PANDA_UNHAPPY_TIMER); + return this.metaData.getSets().getInt(EntityMetaDataFields.PANDA_UNHAPPY_TIMER); } @EntityMetaDataFunction(identifier = "sneezeTimer") public int getSneezeTimer() { - return metaData.getSets().getInt(EntityMetaDataFields.PANDA_SNEEZE_TIMER); + return this.metaData.getSets().getInt(EntityMetaDataFields.PANDA_SNEEZE_TIMER); } @EntityMetaDataFunction(identifier = "eatTimer") public int getEatTimer() { - return metaData.getSets().getInt(EntityMetaDataFields.PANDA_EAT_TIMER); + return this.metaData.getSets().getInt(EntityMetaDataFields.PANDA_EAT_TIMER); } @EntityMetaDataFunction(identifier = "mainGene") public Genes getMainGene() { - return Genes.values()[metaData.getSets().getInt(EntityMetaDataFields.PANDA_MAIN_GENE)]; + return Genes.byId(this.metaData.getSets().getInt(EntityMetaDataFields.PANDA_MAIN_GENE)); } @EntityMetaDataFunction(identifier = "hiddenGene") public Genes getHiddenGene() { - return Genes.values()[metaData.getSets().getInt(EntityMetaDataFields.PANDA_HIDDEN_GAME)]; + return Genes.byId(this.metaData.getSets().getInt(EntityMetaDataFields.PANDA_HIDDEN_GAME)); } private boolean getPandaFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.PANDA_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.PANDA_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isSneezing") @@ -83,6 +83,11 @@ public class Panda extends Animal { PLAYFUL, BROWN, WEAK, - AGGRESSIVE + AGGRESSIVE; + private static final Genes[] GENES = values(); + + public static Genes byId(int id) { + return GENES[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Parrot.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Parrot.java index 2fd40b63a..eabafd0cd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Parrot.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Parrot.java @@ -29,7 +29,7 @@ public class Parrot extends ShoulderRidingAnimal { @EntityMetaDataFunction(identifier = "variant") public ParrotVariants getVariant() { - return ParrotVariants.values()[metaData.getSets().getInt(EntityMetaDataFields.PARROT_VARIANT)]; + return ParrotVariants.byId(this.metaData.getSets().getInt(EntityMetaDataFields.PARROT_VARIANT)); } public enum ParrotVariants { @@ -37,6 +37,12 @@ public class Parrot extends ShoulderRidingAnimal { BLUE, GREEN, YELLOW_BLUE, - GREY + GREY; + + private static final ParrotVariants[] PARROT_VARIANTS = values(); + + public static ParrotVariants byId(int id) { + return PARROT_VARIANTS[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Pig.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Pig.java index 4c3ca1a18..3536e69b5 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Pig.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Pig.java @@ -29,11 +29,11 @@ public class Pig extends Animal { @EntityMetaDataFunction(identifier = "hasSaddle") public boolean hasSaddle() { - return metaData.getSets().getBoolean(EntityMetaDataFields.PIG_HAS_SADDLE); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PIG_HAS_SADDLE); } @EntityMetaDataFunction(identifier = "boostTime") public int getBoostTime() { - return metaData.getSets().getInt(EntityMetaDataFields.PIG_BOOST_TIME); + return this.metaData.getSets().getInt(EntityMetaDataFields.PIG_BOOST_TIME); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/PolarBear.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/PolarBear.java index c10152f24..1a11105ce 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/PolarBear.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/PolarBear.java @@ -29,6 +29,6 @@ public class PolarBear extends Animal { @EntityMetaDataFunction(identifier = "isStanding") public boolean isStanding() { - return metaData.getSets().getBoolean(EntityMetaDataFields.POLAR_BEAR_STANDING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.POLAR_BEAR_STANDING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Rabbit.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Rabbit.java index 4de82083f..266eede8e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Rabbit.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Rabbit.java @@ -29,6 +29,6 @@ public class Rabbit extends Animal { @EntityMetaDataFunction(identifier = "variant") public int getVariant() { - return metaData.getSets().getInt(EntityMetaDataFields.RABBIT_VARIANT); + return this.metaData.getSets().getInt(EntityMetaDataFields.RABBIT_VARIANT); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Sheep.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Sheep.java index a993c6d99..2d6a2fe84 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Sheep.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Sheep.java @@ -31,11 +31,11 @@ public class Sheep extends Animal { @EntityMetaDataFunction(identifier = "color") private RGBColor getColor() { - return ChatColors.getColorById(metaData.getSets().getByte(EntityMetaDataFields.SHEEP_FLAGS) & 0xF); + return ChatColors.getColorById(this.metaData.getSets().getByte(EntityMetaDataFields.SHEEP_FLAGS) & 0xF); } @EntityMetaDataFunction(identifier = "isSheared") private boolean isSheared() { - return metaData.getSets().getBitMask(EntityMetaDataFields.SHEEP_FLAGS, 0x10); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.SHEEP_FLAGS, 0x10); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/SnowGolem.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/SnowGolem.java index 845105c6d..164688ccd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/SnowGolem.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/SnowGolem.java @@ -28,7 +28,7 @@ public class SnowGolem extends AbstractGolem { } private boolean getPumpkinFlags(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.SNOW_GOLEM_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.SNOW_GOLEM_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "pumpkinHat") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Strider.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Strider.java index 7c9372f7e..782767103 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Strider.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Strider.java @@ -29,16 +29,16 @@ public class Strider extends Animal { @EntityMetaDataFunction(identifier = "boostTime") private int getBoostTime() { - return metaData.getSets().getInt(EntityMetaDataFields.STRIDER_TIME_TO_BOOST); + return this.metaData.getSets().getInt(EntityMetaDataFields.STRIDER_TIME_TO_BOOST); } @EntityMetaDataFunction(identifier = "isSuffocating") private boolean isSuffocating() { - return metaData.getSets().getBoolean(EntityMetaDataFields.STRIDER_IS_SUFFOCATING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.STRIDER_IS_SUFFOCATING); } @EntityMetaDataFunction(identifier = "hasSaddle") private boolean hasSaddle() { - return metaData.getSets().getBoolean(EntityMetaDataFields.STRIDER_HAS_SADDLE); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.STRIDER_HAS_SADDLE); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Turtle.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Turtle.java index f5d0f95ae..ed3462b9c 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Turtle.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Turtle.java @@ -32,32 +32,32 @@ public class Turtle extends Animal { @EntityMetaDataFunction(identifier = "homePosition") @Nullable public BlockPosition getHomePosition() { - return metaData.getSets().getPosition(EntityMetaDataFields.TURTLE_HOME_POSITION); + return this.metaData.getSets().getPosition(EntityMetaDataFields.TURTLE_HOME_POSITION); } @EntityMetaDataFunction(identifier = "hasEgg") public boolean hasEgg() { - return metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_HAS_EGG); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_HAS_EGG); } @EntityMetaDataFunction(identifier = "isLayingEgg") public boolean isLayingEgg() { - return metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_LAYING_EGG); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_LAYING_EGG); } @EntityMetaDataFunction(identifier = "travelPosition") @Nullable public BlockPosition getTravelPosition() { - return metaData.getSets().getPosition(EntityMetaDataFields.TURTLE_TRAVEL_POSITION); + return this.metaData.getSets().getPosition(EntityMetaDataFields.TURTLE_TRAVEL_POSITION); } @EntityMetaDataFunction(identifier = "isGoingHome") public boolean isGoingHome() { - return metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_GOING_HOME); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_GOING_HOME); } @EntityMetaDataFunction(identifier = "isTraveling") public boolean isTraveling() { - return metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_TRAVELING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.TURTLE_IS_TRAVELING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Wolf.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Wolf.java index dcf3d0898..741fbc9d5 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Wolf.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/Wolf.java @@ -32,28 +32,28 @@ public class Wolf extends TamableAnimal { @EntityMetaDataFunction(identifier = "isBegging") public boolean isBegging() { - return metaData.getSets().getBoolean(EntityMetaDataFields.WOLF_IS_BEGGING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.WOLF_IS_BEGGING); } @EntityMetaDataFunction(identifier = "collarColor") public RGBColor getCollarColor() { - return ChatColors.getColorById(metaData.getSets().getInt(EntityMetaDataFields.WOLF_COLLAR_COLOR)); + return ChatColors.getColorById(this.metaData.getSets().getInt(EntityMetaDataFields.WOLF_COLLAR_COLOR)); } @EntityMetaDataFunction(identifier = "angerTime") public int getAngerTime() { - if (versionId <= 47) {// ToDo - return metaData.getSets().getBitMask(EntityMetaDataFields.TAMABLE_ENTITY_FLAGS, 0x02) ? 1 : 0; + if (this.versionId <= 47) {// ToDo + return this.metaData.getSets().getBitMask(EntityMetaDataFields.TAMABLE_ENTITY_FLAGS, 0x02) ? 1 : 0; } - return metaData.getSets().getInt(EntityMetaDataFields.WOLF_ANGER_TIME); + return this.metaData.getSets().getInt(EntityMetaDataFields.WOLF_ANGER_TIME); } @EntityMetaDataFunction(identifier = "health") @Override public float getHealth() { - if (versionId > 562) { + if (this.versionId > 562) { return super.getHealth(); } - return metaData.getSets().getFloat(EntityMetaDataFields.WOLF_HEALTH); + return this.metaData.getSets().getFloat(EntityMetaDataFields.WOLF_HEALTH); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/hoglin/Hoglin.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/hoglin/Hoglin.java index e6b2094d2..8b4cff4a3 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/hoglin/Hoglin.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/hoglin/Hoglin.java @@ -30,6 +30,6 @@ public class Hoglin extends Animal { @EntityMetaDataFunction(identifier = "immuneToZombification") public boolean isImmuneToZombification() { - return metaData.getSets().getBoolean(EntityMetaDataFields.HOGLIN_IMMUNE_TO_ZOMBIFICATION); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.HOGLIN_IMMUNE_TO_ZOMBIFICATION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractChestedHorse.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractChestedHorse.java index 212512cec..be86b03b3 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractChestedHorse.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractChestedHorse.java @@ -28,6 +28,6 @@ public abstract class AbstractChestedHorse extends AbstractHorse { @EntityMetaDataFunction(identifier = "hasChest") public boolean hasChest() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_CHESTED_HORSE_HAS_CHEST); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_CHESTED_HORSE_HAS_CHEST); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractHorse.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractHorse.java index 39f405066..52ebff186 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractHorse.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/AbstractHorse.java @@ -29,7 +29,7 @@ public abstract class AbstractHorse extends Animal { } private boolean getAbstractHorseFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_HORSE_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_HORSE_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isTame") @@ -64,6 +64,6 @@ public abstract class AbstractHorse extends Animal { @Nullable public UUID getOwner() { - return metaData.getSets().getUUID(EntityMetaDataFields.ABSTRACT_HORSE_OWNER_UUID); + return this.metaData.getSets().getUUID(EntityMetaDataFields.ABSTRACT_HORSE_OWNER_UUID); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Horse.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Horse.java index f00c05400..01101bd0f 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Horse.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Horse.java @@ -33,11 +33,11 @@ public class Horse extends AbstractHorse { } private boolean getAbstractHorseFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_HORSE_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_HORSE_FLAGS, bitMask); } private int getVariant() { - return metaData.getSets().getInt(EntityMetaDataFields.HORSE_VARIANT); + return this.metaData.getSets().getInt(EntityMetaDataFields.HORSE_VARIANT); } @EntityMetaDataFunction(identifier = "color") @@ -53,10 +53,10 @@ public class Horse extends AbstractHorse { @EntityMetaDataFunction(identifier = "armor") @Nullable public Item getArmor() { - if (versionId <= 47) { // ToDo + if (this.versionId <= 47) { // ToDo return null; } - return switch (metaData.getSets().getInt(EntityMetaDataFields.LEGACY_HORSE_ARMOR)) { + return switch (this.metaData.getSets().getInt(EntityMetaDataFields.LEGACY_HORSE_ARMOR)) { default -> null; case 1 -> LEGACY_IRON_ARMOR; case 2 -> LEGACY_GOLD_ARMOR; @@ -73,8 +73,10 @@ public class Horse extends AbstractHorse { GRAY, DARK_BROWN; + private static final HorseColors[] HORSE_COLORS = values(); + public static HorseColors byId(int id) { - return values()[id]; + return HORSE_COLORS[id]; } } @@ -85,8 +87,10 @@ public class Horse extends AbstractHorse { WHITE_DOTS, BLACK_DOTS; + private static final HorseDots[] HORSE_DOTS = values(); + public static HorseDots byId(int id) { - return values()[id]; + return HORSE_DOTS[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Llama.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Llama.java index 5b6fde513..c665fe1dd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Llama.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/horse/Llama.java @@ -29,16 +29,16 @@ public class Llama extends AbstractChestedHorse { @EntityMetaDataFunction(identifier = "strength") public int getStrength() { - return metaData.getSets().getInt(EntityMetaDataFields.LLAMA_STRENGTH); + return this.metaData.getSets().getInt(EntityMetaDataFields.LLAMA_STRENGTH); } @EntityMetaDataFunction(identifier = "carpetColor") public int getCarpetColor() { - return metaData.getSets().getInt(EntityMetaDataFields.LLAMA_CARPET_COLOR); + return this.metaData.getSets().getInt(EntityMetaDataFields.LLAMA_CARPET_COLOR); } @EntityMetaDataFunction(identifier = "variant") public int getVariant() { - return metaData.getSets().getInt(EntityMetaDataFields.LLAMA_VARIANT); + return this.metaData.getSets().getInt(EntityMetaDataFields.LLAMA_VARIANT); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/AbstractFish.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/AbstractFish.java index a43874e0f..bf326a21e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/AbstractFish.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/AbstractFish.java @@ -28,7 +28,7 @@ public abstract class AbstractFish extends WaterAnimal { @EntityMetaDataFunction(identifier = "isFromBucket") public boolean isFromBucket() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_FISH_FROM_BUCKET); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_FISH_FROM_BUCKET); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/Dolphin.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/Dolphin.java index fc74d26ea..6c775184d 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/Dolphin.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/Dolphin.java @@ -32,17 +32,17 @@ public class Dolphin extends WaterAnimal { @EntityMetaDataFunction(identifier = "treasurePosition") @Nullable public BlockPosition getTreasurePosition() { - return metaData.getSets().getPosition(EntityMetaDataFields.DOLPHIN_TREASURE_POSITION); + return this.metaData.getSets().getPosition(EntityMetaDataFields.DOLPHIN_TREASURE_POSITION); } @EntityMetaDataFunction(identifier = "hasFish") public boolean hasFish() { - return metaData.getSets().getBoolean(EntityMetaDataFields.DOLPHIN_HAS_FISH); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.DOLPHIN_HAS_FISH); } @EntityMetaDataFunction(identifier = "moistnessLevel") public int getMoistnessLevel() { - return metaData.getSets().getInt(EntityMetaDataFields.DOLPHIN_MOISTNESS_LEVEL); + return this.metaData.getSets().getInt(EntityMetaDataFields.DOLPHIN_MOISTNESS_LEVEL); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/PufferFish.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/PufferFish.java index 8d1414ac0..0af782d73 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/PufferFish.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/PufferFish.java @@ -29,6 +29,6 @@ public class PufferFish extends AbstractFish { @EntityMetaDataFunction(identifier = "puffState") public int getPuffState() { - return metaData.getSets().getInt(EntityMetaDataFields.PUFFERFISH_PUFF_STATE); + return this.metaData.getSets().getInt(EntityMetaDataFields.PUFFERFISH_PUFF_STATE); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/TropicalFish.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/TropicalFish.java index f77d853cd..1a79d928e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/TropicalFish.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/animal/water/TropicalFish.java @@ -29,6 +29,6 @@ public class TropicalFish extends AbstractSchoolingFish { @EntityMetaDataFunction(identifier = "variant") public int getVariant() { - return metaData.getSets().getInt(EntityMetaDataFields.TROPICAL_FISH_VARIANT); + return this.metaData.getSets().getInt(EntityMetaDataFields.TROPICAL_FISH_VARIANT); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/enderdragon/EnderDragon.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/enderdragon/EnderDragon.java index 140317ce1..6e0dfc182 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/enderdragon/EnderDragon.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/enderdragon/EnderDragon.java @@ -30,7 +30,7 @@ public class EnderDragon extends Mob { @EntityMetaDataFunction(identifier = "phase") public DragonPhases getPhase() { - return DragonPhases.values()[metaData.getSets().getInt(EntityMetaDataFields.ENDER_DRAGON_PHASE)]; + return DragonPhases.byId(this.metaData.getSets().getInt(EntityMetaDataFields.ENDER_DRAGON_PHASE)); } public enum DragonPhases { @@ -44,6 +44,12 @@ public class EnderDragon extends Mob { SITTING_ATTACKING, CHARGE_PLAYER, DEATH, - HOVER + HOVER; + + private static final DragonPhases[] DRAGON_PHASES = values(); + + public static DragonPhases byId(int id) { + return DRAGON_PHASES[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/wither/WitherBoss.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/wither/WitherBoss.java index d29e66e3a..084a67e9f 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/wither/WitherBoss.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/boss/wither/WitherBoss.java @@ -30,21 +30,21 @@ public class WitherBoss extends Monster { @EntityMetaDataFunction(identifier = "centerHeadTargetEntityId") public int getCenterHeadTargetEntityId() { - return metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_CENTER_HEAD_TARGET_ENTITY_ID); + return this.metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_CENTER_HEAD_TARGET_ENTITY_ID); } @EntityMetaDataFunction(identifier = "leftHeadTargetEntityId") public int getLeftHeadTargetEntityId() { - return metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_LEFT_HEAD_TARGET_ENTITY_ID); + return this.metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_LEFT_HEAD_TARGET_ENTITY_ID); } @EntityMetaDataFunction(identifier = "rightHeadTargetEntityId") public int getRightHeadTargetEntityId() { - return metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_RIGHT_HEAD_TARGET_ENTITY_ID); + return this.metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_RIGHT_HEAD_TARGET_ENTITY_ID); } @EntityMetaDataFunction(identifier = "invulnerableTime") public int getInvulnerableTime() { - return metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_INVULNERABLE_TIME); + return this.metaData.getSets().getInt(EntityMetaDataFields.WITHER_BOSS_INVULNERABLE_TIME); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ArmorStand.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ArmorStand.java index f294de408..16462debd 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ArmorStand.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ArmorStand.java @@ -29,7 +29,7 @@ public class ArmorStand extends LivingEntity { } private boolean getArmorStandFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.ARMOR_STAND_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.ARMOR_STAND_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isSmall") @@ -54,32 +54,32 @@ public class ArmorStand extends LivingEntity { @EntityMetaDataFunction(identifier = "headRotation") public EntityRotation getHeadRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_HEAD_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_HEAD_ROTATION); } @EntityMetaDataFunction(identifier = "bodyRotation") public EntityRotation getBodyRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_BODY_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_BODY_ROTATION); } @EntityMetaDataFunction(identifier = "leftArmRotation") public EntityRotation getLeftArmRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_LEFT_ARM_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_LEFT_ARM_ROTATION); } @EntityMetaDataFunction(identifier = "rightArmRotation") public EntityRotation getRightArmRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_RIGHT_ARM_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_RIGHT_ARM_ROTATION); } @EntityMetaDataFunction(identifier = "leftLegRotation") public EntityRotation getLeftLegRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_LEFT_LAG_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_LEFT_LAG_ROTATION); } @EntityMetaDataFunction(identifier = "leftRightRotation") public EntityRotation getRightLegRotation() { - return metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_RIGHT_LAG_ROTATION); + return this.metaData.getSets().getRotation(EntityMetaDataFields.ARMOR_STAND_RIGHT_LAG_ROTATION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.java index 226763197..6e6fe38a4 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.java @@ -29,16 +29,15 @@ public class ItemFrame extends HangingEntity { super(connection, entityId, uuid, location, rotation); } - @EntityMetaDataFunction(identifier = "item") @Nullable public Slot getItem() { - return metaData.getSets().getSlot(EntityMetaDataFields.ITEM_FRAME_ITEM); + return this.metaData.getSets().getSlot(EntityMetaDataFields.ITEM_FRAME_ITEM); } @EntityMetaDataFunction(identifier = "itemRotationLevel") public int get() { - return metaData.getSets().getInt(EntityMetaDataFields.ITEM_FRAME_ROTATION); + return this.metaData.getSets().getInt(EntityMetaDataFields.ITEM_FRAME_ROTATION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/Painting.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/Painting.java index 1dc0e54cc..7418921fc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/Painting.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/Painting.java @@ -30,8 +30,8 @@ public class Painting extends Entity { public Painting(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) { super(connection, entityId, uuid, location, rotation); - direction = Directions.NORTH; - motive = new Motive("kebab"); + this.direction = Directions.NORTH; + this.motive = new Motive("kebab"); } public Painting(Connection connection, int entityId, UUID uuid, BlockPosition position, Directions direction, Motive motive) { @@ -42,11 +42,11 @@ public class Painting extends Entity { @EntityMetaDataFunction(identifier = "direction") public Directions getDirection() { - return direction; + return this.direction; } @EntityMetaDataFunction(identifier = "motive") public Motive getMotive() { - return motive; + return this.motive; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/item/ItemEntity.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/item/ItemEntity.java index cbc94aecc..942d630eb 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/item/ItemEntity.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/item/ItemEntity.java @@ -33,7 +33,7 @@ public class ItemEntity extends Entity { @EntityMetaDataFunction(identifier = "item") @Nullable public Slot getItem() { - return metaData.getSets().getSlot(EntityMetaDataFields.ITEM_ITEM); + return this.metaData.getSets().getSlot(EntityMetaDataFields.ITEM_ITEM); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/item/PrimedTNT.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/item/PrimedTNT.java index 29a292ab4..0588eadec 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/item/PrimedTNT.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/item/PrimedTNT.java @@ -30,6 +30,6 @@ public class PrimedTNT extends Entity { @EntityMetaDataFunction(identifier = "fuseTime") public int getFuseTime() { - return metaData.getSets().getInt(EntityMetaDataFields.PRIMED_TNT_FUSE_TIME); + return this.metaData.getSets().getInt(EntityMetaDataFields.PRIMED_TNT_FUSE_TIME); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Blaze.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Blaze.java index b199cf5ef..ad6b175fc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Blaze.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Blaze.java @@ -28,7 +28,7 @@ public class Blaze extends Monster { } private boolean getFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.BLAZE_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.BLAZE_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isBurning") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Creeper.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Creeper.java index a01e89b51..478a16fbc 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Creeper.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Creeper.java @@ -29,16 +29,16 @@ public class Creeper extends Monster { @EntityMetaDataFunction(identifier = "state") public int getState() { - return metaData.getSets().getInt(EntityMetaDataFields.CREEPER_STATE); + return this.metaData.getSets().getInt(EntityMetaDataFields.CREEPER_STATE); } @EntityMetaDataFunction(identifier = "isCharged") public boolean isCharged() { - return metaData.getSets().getBoolean(EntityMetaDataFields.CREEPER_IS_CHARGED); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.CREEPER_IS_CHARGED); } @EntityMetaDataFunction(identifier = "isIgnited") public boolean isIgnited() { - return metaData.getSets().getBoolean(EntityMetaDataFields.CREEPER_IS_IGNITED); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.CREEPER_IS_IGNITED); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Enderman.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Enderman.java index edd1b6376..680cdad7c 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Enderman.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Enderman.java @@ -32,19 +32,19 @@ public class Enderman extends AbstractSkeleton { @EntityMetaDataFunction(identifier = "carriedBlock") @Nullable public Block getCarriedBlock() { - if (versionId <= 47) { // ToDo: No clue here - return connection.getMapping().getBlockById(metaData.getSets().getInt(EntityMetaDataFields.LEGACY_ENDERMAN_CARRIED_BLOCK) << 4 | metaData.getSets().getInt(EntityMetaDataFields.LEGACY_ENDERMAN_CARRIED_BLOCK_DATA)); + if (this.versionId <= 47) { // ToDo: No clue here + return this.connection.getMapping().getBlockById(this.metaData.getSets().getInt(EntityMetaDataFields.LEGACY_ENDERMAN_CARRIED_BLOCK) << 4 | this.metaData.getSets().getInt(EntityMetaDataFields.LEGACY_ENDERMAN_CARRIED_BLOCK_DATA)); } - return metaData.getSets().getBlock(EntityMetaDataFields.ENDERMAN_CARRIED_BLOCK); + return this.metaData.getSets().getBlock(EntityMetaDataFields.ENDERMAN_CARRIED_BLOCK); } @EntityMetaDataFunction(identifier = "isScreaming") public boolean isScreaming() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ENDERMAN_IS_SCREAMING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ENDERMAN_IS_SCREAMING); } @EntityMetaDataFunction(identifier = "isStarring") public boolean isStarring() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ENDERMAN_IS_STARRING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ENDERMAN_IS_STARRING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Ghast.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Ghast.java index 25840cb14..8f63fb0bb 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Ghast.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Ghast.java @@ -30,6 +30,6 @@ public class Ghast extends FlyingMob { @EntityMetaDataFunction(identifier = "isAttacking") public boolean isAttacking() { - return metaData.getSets().getBoolean(EntityMetaDataFields.GHAST_IS_ATTACKING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.GHAST_IS_ATTACKING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Guardian.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Guardian.java index 9094a0529..da64fd47a 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Guardian.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Guardian.java @@ -29,11 +29,11 @@ public class Guardian extends Monster { @EntityMetaDataFunction(identifier = "isMoving") public boolean isMoving() { - return metaData.getSets().getBoolean(EntityMetaDataFields.GUARDIAN_IS_MOVING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.GUARDIAN_IS_MOVING); } @EntityMetaDataFunction(identifier = "attackedEntityId") public int getAttackEntityId() { - return metaData.getSets().getInt(EntityMetaDataFields.GUARDIAN_TARGET_ENTITY_ID); + return this.metaData.getSets().getInt(EntityMetaDataFields.GUARDIAN_TARGET_ENTITY_ID); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Phantom.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Phantom.java index e23c21789..ef2aa35ca 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Phantom.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Phantom.java @@ -30,6 +30,6 @@ public class Phantom extends FlyingMob { @EntityMetaDataFunction(identifier = "size") public int getSize() { - return metaData.getSets().getInt(EntityMetaDataFields.PHANTOM_SIZE); + return this.metaData.getSets().getInt(EntityMetaDataFields.PHANTOM_SIZE); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Shulker.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Shulker.java index 7e3b6d37c..6c924ef4e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Shulker.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Shulker.java @@ -35,22 +35,22 @@ public class Shulker extends AbstractGolem { @EntityMetaDataFunction(identifier = "attachmentFace") public Directions getAttachmentFace() { - return metaData.getSets().getDirection(EntityMetaDataFields.SHULKER_ATTACH_FACE); + return this.metaData.getSets().getDirection(EntityMetaDataFields.SHULKER_ATTACH_FACE); } @EntityMetaDataFunction(identifier = "attachmentPosition") @Nullable public BlockPosition getAttachmentPosition() { - return metaData.getSets().getPosition(EntityMetaDataFields.SHULKER_ATTACHMENT_POSITION); + return this.metaData.getSets().getPosition(EntityMetaDataFields.SHULKER_ATTACHMENT_POSITION); } @EntityMetaDataFunction(identifier = "peek") public byte getPeek() { - return metaData.getSets().getByte(EntityMetaDataFields.SHULKER_PEEK); + return this.metaData.getSets().getByte(EntityMetaDataFields.SHULKER_PEEK); } @EntityMetaDataFunction(identifier = "color") public RGBColor getColor() { - return ChatColors.getColorById(metaData.getSets().getByte(EntityMetaDataFields.SHULKER_COLOR)); + return ChatColors.getColorById(this.metaData.getSets().getByte(EntityMetaDataFields.SHULKER_COLOR)); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Slime.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Slime.java index e42a55e2d..09a97f4c1 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Slime.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Slime.java @@ -30,6 +30,6 @@ public class Slime extends Mob { @EntityMetaDataFunction(identifier = "size") public int getSize() { - return metaData.getSets().getInt(EntityMetaDataFields.SLIME_SIZE); + return this.metaData.getSets().getInt(EntityMetaDataFields.SLIME_SIZE); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Spider.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Spider.java index f77469c49..6ab531f29 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Spider.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Spider.java @@ -28,7 +28,7 @@ public class Spider extends Monster { } private boolean getSpiderFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.SPIDER_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.SPIDER_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isClimbing") diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Vex.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Vex.java index cd23675df..16cc03c54 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Vex.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Vex.java @@ -28,10 +28,9 @@ public class Vex extends Monster { } private boolean getVexFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.VEX_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.VEX_FLAGS, bitMask); } - @EntityMetaDataFunction(identifier = "isAttacking") public boolean isAttacking() { return getVexFlag(0x01); diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zoglin.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zoglin.java index 9eca4c1c5..3f4781ab4 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zoglin.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zoglin.java @@ -29,6 +29,6 @@ public class Zoglin extends Monster { @EntityMetaDataFunction(identifier = "isBaby") public boolean isBaby() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ZOGLIN_IS_BABY); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ZOGLIN_IS_BABY); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zombie.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zombie.java index 47861c8a9..8da76de94 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zombie.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/Zombie.java @@ -29,17 +29,17 @@ public class Zombie extends Monster { @EntityMetaDataFunction(identifier = "isBaby") public boolean isBaby() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_IS_BABY); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_IS_BABY); } @EntityMetaDataFunction(identifier = "specialType") public int getSpecialType() { - return metaData.getSets().getInt(EntityMetaDataFields.ZOMBIE_SPECIAL_TYPE); + return this.metaData.getSets().getInt(EntityMetaDataFields.ZOMBIE_SPECIAL_TYPE); } @EntityMetaDataFunction(identifier = "isConvertingToDrowned") public boolean isConvertingToDrowned() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_DROWNING_CONVERSION); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_DROWNING_CONVERSION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/ZombieVillager.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/ZombieVillager.java index 57128c0e1..c034ec4de 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/ZombieVillager.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/ZombieVillager.java @@ -30,12 +30,12 @@ public class ZombieVillager extends Zombie { @EntityMetaDataFunction(identifier = "isConverting") public boolean isConverting() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_VILLAGER_IS_CONVERTING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ZOMBIE_VILLAGER_IS_CONVERTING); } @EntityMetaDataFunction(identifier = "villagerData") public VillagerData getVillagerData() { - return metaData.getSets().getVillagerData(EntityMetaDataFields.ZOMBIE_VILLAGER_DATA); + return this.metaData.getSets().getVillagerData(EntityMetaDataFields.ZOMBIE_VILLAGER_DATA); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/AbstractPiglin.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/AbstractPiglin.java index 90c6b8ee1..6355f812e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/AbstractPiglin.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/AbstractPiglin.java @@ -29,7 +29,7 @@ public abstract class AbstractPiglin extends Monster { @EntityMetaDataFunction(identifier = "isImmuneToZombification") public boolean isImmuneToZombification() { - return metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_PIGLIN_IMMUNE_TO_ZOMBIFICATION); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.ABSTRACT_PIGLIN_IMMUNE_TO_ZOMBIFICATION); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/Piglin.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/Piglin.java index db5983973..adebcb026 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/Piglin.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/piglin/Piglin.java @@ -30,26 +30,25 @@ public class Piglin extends AbstractPiglin { @EntityMetaDataFunction(identifier = "isImmuneToZombification") @Override public boolean isImmuneToZombification() { - if (versionId < 738) { + if (this.versionId < 738) { return super.isImmuneToZombification(); } - return metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IMMUNE_TO_ZOMBIFICATION); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IMMUNE_TO_ZOMBIFICATION); } @EntityMetaDataFunction(identifier = "isBaby") public boolean isBaby() { - return metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_BABY); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_BABY); } @EntityMetaDataFunction(identifier = "isChargingCrossbow") public boolean isChargingCrossbow() { - return metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_CHARGING_CROSSBOW); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_CHARGING_CROSSBOW); } @EntityMetaDataFunction(identifier = "isDancing") public boolean isDancing() { - return metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_DANCING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PIGLIN_IS_DANCING); } - } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Pillager.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Pillager.java index c87d5e726..00e1bef46 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Pillager.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Pillager.java @@ -29,6 +29,6 @@ public class Pillager extends AbstractIllager { @EntityMetaDataFunction(identifier = "isChargingCrossbow") public boolean isChargingCrossbow() { - return metaData.getSets().getBoolean(EntityMetaDataFields.PILLAGER_IS_CHARGING_CROSSBOW); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.PILLAGER_IS_CHARGING_CROSSBOW); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Raider.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Raider.java index faf7fe5e4..360d10b3d 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Raider.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Raider.java @@ -29,6 +29,6 @@ public abstract class Raider extends PatrollingMonster { @EntityMetaDataFunction(identifier = "isCelebrating") public boolean isCelebrating() { - return metaData.getSets().getBoolean(EntityMetaDataFields.RAIDER_IS_CELEBRATING); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.RAIDER_IS_CELEBRATING); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/SpellcasterIllager.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/SpellcasterIllager.java index 2edfdc60c..9fe03b54b 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/SpellcasterIllager.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/SpellcasterIllager.java @@ -29,7 +29,7 @@ public class SpellcasterIllager extends AbstractIllager { @EntityMetaDataFunction(identifier = "spell") public Spells getSpell() { - return Spells.values()[metaData.getSets().getInt(EntityMetaDataFields.SPELLCASTER_ILLAGER_SPELL)]; + return Spells.byId(this.metaData.getSets().getInt(EntityMetaDataFields.SPELLCASTER_ILLAGER_SPELL)); } public enum Spells { @@ -38,6 +38,12 @@ public class SpellcasterIllager extends AbstractIllager { ATTACK, WOLOLO, DISAPPEAR, - BLINDNESS + BLINDNESS; + + private static final Spells[] SPELLS = values(); + + public static Spells byId(int id) { + return SPELLS[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Witch.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Witch.java index 6e8dab743..08100cadf 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Witch.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/monster/raid/Witch.java @@ -29,10 +29,10 @@ public class Witch extends Raider { @EntityMetaDataFunction(identifier = "isDrinkingPotion") public boolean isDrinkingPotion() { - return metaData.getSets().getBoolean(EntityMetaDataFields.WITCH_IS_DRINKING_POTION); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.WITCH_IS_DRINKING_POTION); } public boolean isAggressive() { - return metaData.getSets().getBoolean(EntityMetaDataFields.LEGACY_WITCH_IS_AGGRESSIVE); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.LEGACY_WITCH_IS_AGGRESSIVE); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/AbstractVillager.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/AbstractVillager.java index c862ebe21..476f1b97a 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/AbstractVillager.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/AbstractVillager.java @@ -29,6 +29,6 @@ public abstract class AbstractVillager extends AgeableMob { @EntityMetaDataFunction(identifier = "unhappyTimer") public int getUnhappyTimer() { - return metaData.getSets().getInt(EntityMetaDataFields.ABSTRACT_VILLAGER_UNHAPPY_TIMER); + return this.metaData.getSets().getInt(EntityMetaDataFields.ABSTRACT_VILLAGER_UNHAPPY_TIMER); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/Villager.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/Villager.java index d8a0a1ace..3b2110023 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/Villager.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/npc/Villager.java @@ -29,6 +29,6 @@ public class Villager extends AbstractVillager { @EntityMetaDataFunction(identifier = "villagerData") public VillagerData getVillagerDate() { - return metaData.getSets().getVillagerData(EntityMetaDataFields.VILLAGER_VILLAGER_DATA); + return this.metaData.getSets().getVillagerData(EntityMetaDataFields.VILLAGER_VILLAGER_DATA); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.java index 9677f7926..961368db6 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/player/PlayerEntity.java @@ -48,49 +48,49 @@ public class PlayerEntity extends LivingEntity { @EntityMetaDataFunction(identifier = "absorptionHearts") public float getPlayerAbsorptionHearts() { - return metaData.getSets().getFloat(EntityMetaDataFields.PLAYER_ABSORPTION_HEARTS); + return this.metaData.getSets().getFloat(EntityMetaDataFields.PLAYER_ABSORPTION_HEARTS); } @EntityMetaDataFunction(identifier = "score") public int getScore() { - return metaData.getSets().getInt(EntityMetaDataFields.PLAYER_SCORE); + return this.metaData.getSets().getInt(EntityMetaDataFields.PLAYER_SCORE); } private boolean getSkinPartsFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.PLAYER_SKIN_PARTS_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.PLAYER_SKIN_PARTS_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "mainHand") public Hands getMainHand() { - return metaData.getSets().getByte(EntityMetaDataFields.PLAYER_SKIN_MAIN_HAND) == 0x01 ? Hands.OFF_HAND : Hands.MAIN_HAND; + return this.metaData.getSets().getByte(EntityMetaDataFields.PLAYER_SKIN_MAIN_HAND) == 0x01 ? Hands.OFF_HAND : Hands.MAIN_HAND; } @EntityMetaDataFunction(identifier = "leftShoulderEntityData") @Nullable public CompoundTag getLeftShoulderData() { - return metaData.getSets().getNBT(EntityMetaDataFields.PLAYER_LEFT_SHOULDER_DATA); + return this.metaData.getSets().getNBT(EntityMetaDataFields.PLAYER_LEFT_SHOULDER_DATA); } @EntityMetaDataFunction(identifier = "rightShoulderEntityData") @Nullable public CompoundTag getRightShoulderData() { - return metaData.getSets().getNBT(EntityMetaDataFields.PLAYER_RIGHT_SHOULDER_DATA); + return this.metaData.getSets().getNBT(EntityMetaDataFields.PLAYER_RIGHT_SHOULDER_DATA); } @EntityMetaDataFunction(identifier = "name") public String getName() { - return name; + return this.name; } @EntityMetaDataFunction(identifier = "properties") @Nullable public HashSet getProperties() { - return properties; + return this.properties; } @Deprecated public Item getCurrentItem() { - return currentItem; + return this.currentItem; } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/AbstractArrow.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/AbstractArrow.java index 079be8c6c..aca11bccb 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/AbstractArrow.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/AbstractArrow.java @@ -27,7 +27,7 @@ public abstract class AbstractArrow extends Projectile { } private boolean getAbstractArrowFlag(int bitMask) { - return metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_ARROW_FLAGS, bitMask); + return this.metaData.getSets().getBitMask(EntityMetaDataFields.ABSTRACT_ARROW_FLAGS, bitMask); } @EntityMetaDataFunction(identifier = "isCritical") @@ -42,12 +42,12 @@ public abstract class AbstractArrow extends Projectile { @EntityMetaDataFunction(identifier = "piercingLevel") public byte getPiercingLevel() { - return metaData.getSets().getByte(EntityMetaDataFields.ABSTRACT_ARROW_PIERCE_LEVEL); + return this.metaData.getSets().getByte(EntityMetaDataFields.ABSTRACT_ARROW_PIERCE_LEVEL); } @EntityMetaDataFunction(identifier = "ownerUUID") public UUID getOwnerUUID() { - return metaData.getSets().getUUID(EntityMetaDataFields.ABSTRACT_ARROW_OWNER_UUID); + return this.metaData.getSets().getUUID(EntityMetaDataFields.ABSTRACT_ARROW_OWNER_UUID); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Arrow.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Arrow.java index d13f49243..e23a88995 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Arrow.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Arrow.java @@ -28,6 +28,6 @@ public class Arrow extends AbstractArrow { @EntityMetaDataFunction(identifier = "effectColor") public int getEffectColor() { - return metaData.getSets().getInt(EntityMetaDataFields.ARROW_EFFECT_COLOR); + return this.metaData.getSets().getInt(EntityMetaDataFields.ARROW_EFFECT_COLOR); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Fireball.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Fireball.java index 4cc4d8c6b..c05f1a830 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Fireball.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/Fireball.java @@ -31,7 +31,7 @@ public abstract class Fireball extends AbstractHurtingProjectile { @EntityMetaDataFunction(identifier = "item") @Nullable private Slot getItem() { - Slot slot = metaData.getSets().getSlot(EntityMetaDataFields.FIREBALL_ITEM); + Slot slot = this.metaData.getSets().getSlot(EntityMetaDataFields.FIREBALL_ITEM); if (slot == null) { return getDefaultItem(); } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrowableItemProjectile.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrowableItemProjectile.java index e4c38cb40..bf0eccb74 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrowableItemProjectile.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrowableItemProjectile.java @@ -29,7 +29,7 @@ public abstract class ThrowableItemProjectile extends ThrowableProjectile { @EntityMetaDataFunction(identifier = "item") public Slot getItem() { - Slot slot = metaData.getSets().getSlot(EntityMetaDataFields.THROWABLE_ITEM_PROJECTILE_ITEM); + Slot slot = this.metaData.getSets().getSlot(EntityMetaDataFields.THROWABLE_ITEM_PROJECTILE_ITEM); if (slot == null) { return getDefaultItem(); } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownEyeOfEnder.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownEyeOfEnder.java index 78165c020..d30277942 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownEyeOfEnder.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownEyeOfEnder.java @@ -33,7 +33,7 @@ public class ThrownEyeOfEnder extends Entity { @EntityMetaDataFunction(identifier = "item") public Slot getItem() { - Slot slot = metaData.getSets().getSlot(EntityMetaDataFields.THROWN_EYE_OF_ENDER_ITEM); + Slot slot = this.metaData.getSets().getSlot(EntityMetaDataFields.THROWN_EYE_OF_ENDER_ITEM); if (slot == null) { return DEFAULT_ITEM; } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownPotion.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownPotion.java index 339df5201..50a087c21 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownPotion.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/ThrownPotion.java @@ -32,10 +32,10 @@ public class ThrownPotion extends ThrowableItemProjectile { @EntityMetaDataFunction(identifier = "item") @Override public Slot getItem() { - if (versionId > 704) { + if (this.versionId > 704) { return super.getItem(); } - Slot slot = metaData.getSets().getSlot(EntityMetaDataFields.THROWN_POTION_ITEM); + Slot slot = this.metaData.getSets().getSlot(EntityMetaDataFields.THROWN_POTION_ITEM); if (slot == null) { return getDefaultItem(); } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/AbstractMinecart.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/AbstractMinecart.java index 4bbb0b222..aac5d752b 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/AbstractMinecart.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/AbstractMinecart.java @@ -29,31 +29,31 @@ public abstract class AbstractMinecart extends Entity { @EntityMetaDataFunction(identifier = "shakingPower") public int getShakingPower() { - return metaData.getSets().getInt(EntityMetaDataFields.MINECART_HURT); + return this.metaData.getSets().getInt(EntityMetaDataFields.MINECART_HURT); } @EntityMetaDataFunction(identifier = "shakingDirection") public int getShakingDirection() { - return metaData.getSets().getInt(EntityMetaDataFields.MINECART_HURT_DIRECTION); + return this.metaData.getSets().getInt(EntityMetaDataFields.MINECART_HURT_DIRECTION); } @EntityMetaDataFunction(identifier = "shakingMultiplier") public float getShakingMultiplier() { - return metaData.getSets().getInt(EntityMetaDataFields.MINECART_DAMAGE_TAKEN); + return this.metaData.getSets().getInt(EntityMetaDataFields.MINECART_DAMAGE_TAKEN); } @EntityMetaDataFunction(identifier = "blockId") public int getBlockId() { - return metaData.getSets().getInt(EntityMetaDataFields.MINECART_BLOCK_ID); + return this.metaData.getSets().getInt(EntityMetaDataFields.MINECART_BLOCK_ID); } @EntityMetaDataFunction(identifier = "blockYOffset") public int getBlockYOffset() { - return metaData.getSets().getInt(EntityMetaDataFields.MINECART_BLOCK_Y_OFFSET); + return this.metaData.getSets().getInt(EntityMetaDataFields.MINECART_BLOCK_Y_OFFSET); } @EntityMetaDataFunction(identifier = "isShowingBlock") public boolean isShowingBlock() { - return metaData.getSets().getBoolean(EntityMetaDataFields.MINECART_SHOW_BLOCK); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.MINECART_SHOW_BLOCK); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/Boat.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/Boat.java index bc981aeb6..f1c34fd1e 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/Boat.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/Boat.java @@ -45,7 +45,7 @@ public class Boat extends Entity { @EntityMetaDataFunction(identifier = "material") public BoatMaterials getMaterial() { - return BoatMaterials.values()[getMetaData().getSets().getInt(EntityMetaDataFields.BOAT_MATERIAL)]; + return BoatMaterials.byId(getMetaData().getSets().getInt(EntityMetaDataFields.BOAT_MATERIAL)); } @EntityMetaDataFunction(identifier = "leftPaddleTurning") @@ -69,7 +69,13 @@ public class Boat extends Entity { BIRCH, JUNGLE, ACACIA, - DARK_OAK + DARK_OAK; + + private static final BoatMaterials[] BOAT_MATERIALS = values(); + + public static BoatMaterials byId(int id) { + return BOAT_MATERIALS[id]; + } } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartCommandBlock.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartCommandBlock.java index 87eddf675..bcc95bab1 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartCommandBlock.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartCommandBlock.java @@ -30,11 +30,11 @@ public class MinecartCommandBlock extends AbstractMinecart { @EntityMetaDataFunction(identifier = "command") public String getCommand() { - return metaData.getSets().getString(EntityMetaDataFields.MINECART_COMMAND_BLOCK_COMMAND); + return this.metaData.getSets().getString(EntityMetaDataFields.MINECART_COMMAND_BLOCK_COMMAND); } @EntityMetaDataFunction(identifier = "lastOutput") public ChatComponent getLastOutput() { - return metaData.getSets().getChatComponent(EntityMetaDataFields.MINECART_COMMAND_BLOCK_LAST_OUTPUT); + return this.metaData.getSets().getChatComponent(EntityMetaDataFields.MINECART_COMMAND_BLOCK_LAST_OUTPUT); } } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartFurnace.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartFurnace.java index a8c6dfb19..d92fc168a 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartFurnace.java +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/vehicle/MinecartFurnace.java @@ -29,6 +29,6 @@ public class MinecartFurnace extends AbstractMinecartContainer { @EntityMetaDataFunction(identifier = "hasFuel") public boolean hasFuel() { - return metaData.getSets().getBoolean(EntityMetaDataFields.MINECART_FURNACE_HAS_FUEL); + return this.metaData.getSets().getBoolean(EntityMetaDataFields.MINECART_FURNACE_HAS_FUEL); } } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/Inventory.java b/src/main/java/de/bixilon/minosoft/data/inventory/Inventory.java index f636143ba..d7bae8865 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/Inventory.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/Inventory.java @@ -42,26 +42,26 @@ public class Inventory { } public Slot getSlot(int slot) { - return slots.get(slot); + return this.slots.get(slot); } public void setSlot(int slot, Slot data) { - slots.put(slot, data); + this.slots.put(slot, data); } public void setSlot(InventorySlots.InventoryInterface slot, int versionId, Slot data) { - slots.put(slot.getId(versionId), data); + this.slots.put(slot.getId(versionId), data); } public void clear() { - slots.clear(); + this.slots.clear(); } public HashMap getSlots() { - return slots; + return this.slots; } public InventoryProperties getProperties() { - return properties; + return this.properties; } } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryActions.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryActions.java index 153798dca..dd0b90eda 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryActions.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryActions.java @@ -67,14 +67,14 @@ public enum InventoryActions { } public byte getButton() { - return button; + return this.button; } public byte getMode() { - return mode; + return this.mode; } public boolean hasSlot() { - return hasSlot; + return this.hasSlot; } } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java index 60fadff1d..b94592618 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryProperties.java @@ -29,18 +29,18 @@ public class InventoryProperties { } public int getWindowId() { - return windowId; + return this.windowId; } public InventoryTypes getType() { - return type; + return this.type; } public ChatComponent getTitle() { - return title; + return this.title; } public byte getSlotCount() { - return slotCount; + return this.slotCount; } } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventorySlots.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventorySlots.java index 4beac8d54..ddd030ce2 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventorySlots.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/InventorySlots.java @@ -67,12 +67,14 @@ public class InventorySlots { HOTBAR_9, OFF_HAND; - public static PlayerInventorySlots byId(int id, int versionId) { - return values()[id]; - } + private static final PlayerInventorySlots[] INVENTORY_SLOTS = values(); public static PlayerInventorySlots byId(int id) { - return values()[id]; + return INVENTORY_SLOTS[id]; + } + + public static PlayerInventorySlots byId(int id, int versionId) { + return byId(id); } @Override @@ -92,11 +94,11 @@ public class InventorySlots { final VersionValueMap valueMap; EntityInventorySlots(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } EntityInventorySlots(int id) { - valueMap = new VersionValueMap<>(id); + this.valueMap = new VersionValueMap<>(id); } public static EntityInventorySlots byId(int id, int versionId) { @@ -110,7 +112,7 @@ public class InventorySlots { @Override public int getId(int versionId) { - Integer value = valueMap.get(versionId); + Integer value = this.valueMap.get(versionId); if (value == null) { return Integer.MIN_VALUE; } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java index c9205b089..8078ca283 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/InventoryTypes.java @@ -13,40 +13,47 @@ package de.bixilon.minosoft.data.inventory; +import com.google.common.collect.HashBiMap; +import de.bixilon.minosoft.data.mappings.ModIdentifier; + public enum InventoryTypes { - CHEST("minecraft:chest"), - WORKBENCH("minecraft:crafting_table"), - FURNACE("minecraft:furnace"), - DISPENSER("minecraft:dispenser "), - ENCHANTMENT_TABLE("minecraft:enchanting_table "), - BREWING_STAND("minecraft:brewing_stand "), - NPC_TRACE("minecraft:villager "), - BEACON("minecraft:beacon "), - ANVIL("minecraft:anvil "), - HOPPER("minecraft:hopper "), - DROPPER("minecraft:dropper "), - HORSE("EntityHorse"); + CHEST(new ModIdentifier("minecraft:chest")), + WORKBENCH(new ModIdentifier("minecraft:crafting_table")), + FURNACE(new ModIdentifier("minecraft:furnace")), + DISPENSER(new ModIdentifier("minecraft:dispenser")), + ENCHANTMENT_TABLE(new ModIdentifier("minecraft:enchanting_table")), + BREWING_STAND(new ModIdentifier("minecraft:brewing_stand")), + NPC_TRACE(new ModIdentifier("minecraft:villager")), + BEACON(new ModIdentifier("minecraft:beacon")), + ANVIL(new ModIdentifier("minecraft:anvil")), + HOPPER(new ModIdentifier("minecraft:hopper")), + DROPPER(new ModIdentifier("minecraft:dropper")), + HORSE(new ModIdentifier("EntityHorse")); - final String name; + private static final InventoryTypes[] INVENTORY_TYPES = values(); + private static final HashBiMap IDENTIFIER_TYPE_MAP = HashBiMap.create(); - InventoryTypes(String name) { - this.name = name; + static { + for (InventoryTypes type : INVENTORY_TYPES) { + IDENTIFIER_TYPE_MAP.put(type.getIdentifier(), type); + } + } + + private final ModIdentifier identifier; + + InventoryTypes(ModIdentifier identifier) { + this.identifier = identifier; } public static InventoryTypes byId(int id) { - return values()[id]; + return INVENTORY_TYPES[id]; } - public static InventoryTypes byName(String name) { - for (InventoryTypes type : values()) { - if (type.getName().equals(name)) { - return type; - } - } - return null; + public static InventoryTypes byIdentifier(ModIdentifier identifier) { + return IDENTIFIER_TYPE_MAP.get(identifier); } - public String getName() { - return name; + public ModIdentifier getIdentifier() { + return this.identifier; } } diff --git a/src/main/java/de/bixilon/minosoft/data/inventory/Slot.java b/src/main/java/de/bixilon/minosoft/data/inventory/Slot.java index ff00fb247..97e7c888d 100644 --- a/src/main/java/de/bixilon/minosoft/data/inventory/Slot.java +++ b/src/main/java/de/bixilon/minosoft/data/inventory/Slot.java @@ -91,11 +91,11 @@ public class Slot { if (nbt.containsKey("Enchantments")) { for (CompoundTag enchantment : nbt.getListTag("Enchantments").getValue()) { String[] spilittedIdentifier = enchantment.getStringTag("id").getValue().split(":"); - enchantments.put(new Enchantment(spilittedIdentifier[0], spilittedIdentifier[1]), enchantment.getNumberTag("lvl").getAsInt()); + this.enchantments.put(new Enchantment(spilittedIdentifier[0], spilittedIdentifier[1]), enchantment.getNumberTag("lvl").getAsInt()); } } else if (nbt.containsKey("ench")) { for (CompoundTag enchantment : nbt.getListTag("ench").getValue()) { - enchantments.put(mapping.getEnchantmentById(enchantment.getNumberTag("id").getAsInt()), enchantment.getNumberTag("lvl").getAsInt()); + this.enchantments.put(mapping.getEnchantmentById(enchantment.getNumberTag("id").getAsInt()), enchantment.getNumberTag("lvl").getAsInt()); } } } @@ -103,33 +103,33 @@ public class Slot { public CompoundTag getNbt(VersionMapping mapping) { CompoundTag nbt = new CompoundTag(); - if (repairCost != 0) { - nbt.writeTag("RepairCost", new IntTag(repairCost)); + if (this.repairCost != 0) { + nbt.writeTag("RepairCost", new IntTag(this.repairCost)); } CompoundTag display = new CompoundTag(); - if (customDisplayName != null) { - display.writeTag("Name", new StringTag(customDisplayName.getLegacyText())); + if (this.customDisplayName != null) { + display.writeTag("Name", new StringTag(this.customDisplayName.getLegacyText())); } - if (lore.size() > 0) { - display.writeTag("Lore", new ListTag(TagTypes.STRING, lore.stream().map(ChatComponent::getLegacyText).map(StringTag::new).toArray(StringTag[]::new))); + if (!this.lore.isEmpty()) { + display.writeTag("Lore", new ListTag(TagTypes.STRING, this.lore.stream().map(ChatComponent::getLegacyText).map(StringTag::new).toArray(StringTag[]::new))); } if (display.size() > 0) { nbt.writeTag("display", display); } - if (unbreakable) { + if (this.unbreakable) { nbt.writeTag("unbreakable", new ByteTag(true)); } - if (skullOwner != null) { + if (this.skullOwner != null) { // nbt.writeTag("SkullOwner", new StringTag(skullOwner)); // ToDo } - if (hideFlags != 0) { - nbt.writeTag("HideFlags", new IntTag(hideFlags)); + if (this.hideFlags != 0) { + nbt.writeTag("HideFlags", new IntTag(this.hideFlags)); } - if (enchantments.size() > 0) { + if (!this.enchantments.isEmpty()) { if (mapping.getVersion().isFlattened()) { ListTag enchantmentList = new ListTag(TagTypes.COMPOUND, new ArrayList<>()); - enchantments.forEach((id, level) -> { + this.enchantments.forEach((id, level) -> { CompoundTag tag = new CompoundTag(); tag.writeTag("id", new StringTag(id.toString())); tag.writeTag("lvl", new ShortTag(level.shortValue())); @@ -138,7 +138,7 @@ public class Slot { nbt.writeTag("Enchantments", enchantmentList); } else { ListTag enchantmentList = new ListTag(TagTypes.COMPOUND, new ArrayList<>()); - enchantments.forEach((id, level) -> { + this.enchantments.forEach((id, level) -> { CompoundTag tag = new CompoundTag(); tag.writeTag("id", new ShortTag((short) (int) mapping.getIdByEnchantment(id))); tag.writeTag("lvl", new ShortTag(level.shortValue())); @@ -163,11 +163,11 @@ public class Slot { } public Item getItem() { - return item; + return this.item; } public int getItemCount() { - return itemCount; + return this.itemCount; } public void setItemCount(int itemCount) { @@ -175,7 +175,7 @@ public class Slot { } public short getItemMetadata() { - return itemMetadata; + return this.itemMetadata; } public void setItemMetadata(short itemMetadata) { @@ -192,23 +192,23 @@ public class Slot { if (customName != null) { return customName.getANSIColoredMessage(); } - return (item == null ? "AIR" : getLanguageName()); + return (this.item == null ? "AIR" : getLanguageName()); } public String getLanguageName() { // ToDo: What if an item identifier changed between versions? oOo - String[] keys = new String[]{String.format("item.%s.%s", item.getMod(), item.getIdentifier()), String.format("block.%s.%s", item.getMod(), item.getIdentifier())}; + String[] keys = {String.format("item.%s.%s", this.item.getMod(), this.item.getIdentifier()), String.format("block.%s.%s", this.item.getMod(), this.item.getIdentifier())}; for (String key : keys) { if (MinecraftLocaleManager.getLanguage().canTranslate(key)) { return MinecraftLocaleManager.translate(key); } } - return item.getFullIdentifier(); + return this.item.getFullIdentifier(); } @Nullable public ChatComponent getCustomDisplayName() { - return customDisplayName; + return this.customDisplayName; } public void setCustomDisplayName(ChatComponent customDisplayName) { @@ -216,7 +216,7 @@ public class Slot { } public int getRepairCost() { - return repairCost; + return this.repairCost; } public void setRepairCost(int repairCost) { @@ -224,7 +224,7 @@ public class Slot { } public int getDurability() { - return durability; + return this.durability; } public void setDurability(int durability) { @@ -232,7 +232,7 @@ public class Slot { } public boolean isUnbreakable() { - return unbreakable; + return this.unbreakable; } public void setUnbreakable(boolean unbreakable) { @@ -240,45 +240,45 @@ public class Slot { } public boolean shouldHideEnchantments() { - return BitByte.isBitSet(hideFlags, 0); + return BitByte.isBitSet(this.hideFlags, 0); } public boolean shouldHideModifiers() { - return BitByte.isBitSet(hideFlags, 1); + return BitByte.isBitSet(this.hideFlags, 1); } public boolean shouldHideUnbreakable() { - return BitByte.isBitSet(hideFlags, 2); + return BitByte.isBitSet(this.hideFlags, 2); } public boolean shouldHideCanDestroy() { - return BitByte.isBitSet(hideFlags, 3); + return BitByte.isBitSet(this.hideFlags, 3); } public boolean shouldHideCanPlaceOn() { - return BitByte.isBitSet(hideFlags, 4); + return BitByte.isBitSet(this.hideFlags, 4); } /** * @return hides other information, including potion effects, shield pattern info, "StoredEnchantments", written book "generation" and "author", "Explosion", "Fireworks", and map tooltips */ public boolean shouldHideOtherInformation() { - return BitByte.isBitSet(hideFlags, 5); + return BitByte.isBitSet(this.hideFlags, 5); } public boolean shouldHideLeatherDyeColor() { - return BitByte.isBitSet(hideFlags, 6); + return BitByte.isBitSet(this.hideFlags, 6); } public HashMap getEnchantments() { - return enchantments; + return this.enchantments; } public String getSkullOwner() { - if (!item.getMod().equals(ProtocolDefinition.DEFAULT_MOD) || !item.getIdentifier().equals("skull")) { + if (!this.item.getMod().equals(ProtocolDefinition.DEFAULT_MOD) || !this.item.getIdentifier().equals("skull")) { throw new IllegalArgumentException("Item is not a skull!"); } - return skullOwner; + return this.skullOwner; } public void setSkullOwner(String skullOwner) { @@ -286,45 +286,45 @@ public class Slot { } public ArrayList getLore() { - return lore; + return this.lore; } public void setShouldHideEnchantments(boolean hideEnchantments) { if (hideEnchantments) { - hideFlags |= 1; + this.hideFlags |= 1; } else - hideFlags &= ~(1); + this.hideFlags &= ~(1); } public void setShouldHideModifiers(boolean hideModifiers) { if (hideModifiers) { - hideFlags |= 1 << 1; + this.hideFlags |= 1 << 1; } else { - hideFlags &= ~(1 << 1); + this.hideFlags &= ~(1 << 1); } } public void setShouldHideUnbreakable(boolean hideUnbreakable) { if (hideUnbreakable) { - hideFlags |= 1 << 2; + this.hideFlags |= 1 << 2; } else { - hideFlags &= ~(1 << 2); + this.hideFlags &= ~(1 << 2); } } public void setShouldHideCanDestroy(boolean hideCanDestroy) { if (hideCanDestroy) { - hideFlags |= 1 << 3; + this.hideFlags |= 1 << 3; } else { - hideFlags &= ~(1 << 3); + this.hideFlags &= ~(1 << 3); } } public void setShouldHideCanPlaceOn(boolean hideCanPlaceOn) { if (hideCanPlaceOn) { - hideFlags |= 1 << 4; + this.hideFlags |= 1 << 4; } else { - hideFlags &= ~(1 << 4); + this.hideFlags &= ~(1 << 4); } } @@ -333,17 +333,17 @@ public class Slot { */ public void setShouldHideOtherInformation(boolean hideOtherInformation) { if (hideOtherInformation) { - hideFlags |= 1 << 5; + this.hideFlags |= 1 << 5; } else { - hideFlags &= ~(1 << 5); + this.hideFlags &= ~(1 << 5); } } public void setShouldHideLeatherDyeColor(boolean hideLeatherDyeColor) { if (hideLeatherDyeColor) { - hideFlags |= 1 << 6; + this.hideFlags |= 1 << 6; } else { - hideFlags &= ~(1 << 6); + this.hideFlags &= ~(1 << 6); } } } diff --git a/src/main/java/de/bixilon/minosoft/data/locale/Language.java b/src/main/java/de/bixilon/minosoft/data/locale/Language.java index 2a1565a29..2c4466636 100644 --- a/src/main/java/de/bixilon/minosoft/data/locale/Language.java +++ b/src/main/java/de/bixilon/minosoft/data/locale/Language.java @@ -24,15 +24,15 @@ public class Language { protected Language(String language, JsonObject json) { this.language = language; - json.keySet().forEach((key) -> data.put(Strings.valueOf(key.toUpperCase()), json.get(key).getAsString())); + json.keySet().forEach((key) -> this.data.put(Strings.valueOf(key.toUpperCase()), json.get(key).getAsString())); } public String getLanguage() { - return language; + return this.language; } public boolean canTranslate(Strings key) { - return data.containsKey(key); + return this.data.containsKey(key); } public String translate(Strings key, Object... data) { @@ -41,6 +41,6 @@ public class Language { @Override public String toString() { - return language; + return this.language; } } diff --git a/src/main/java/de/bixilon/minosoft/data/locale/minecraft/MinecraftLanguage.java b/src/main/java/de/bixilon/minosoft/data/locale/minecraft/MinecraftLanguage.java index 74ce4c272..9fddcec51 100644 --- a/src/main/java/de/bixilon/minosoft/data/locale/minecraft/MinecraftLanguage.java +++ b/src/main/java/de/bixilon/minosoft/data/locale/minecraft/MinecraftLanguage.java @@ -23,15 +23,15 @@ public class MinecraftLanguage { protected MinecraftLanguage(String language, JsonObject json) { this.language = language; - json.keySet().forEach((key) -> data.put(key.toLowerCase(), json.get(key).getAsString())); + json.keySet().forEach((key) -> this.data.put(key.toLowerCase(), json.get(key).getAsString())); } public String getLanguage() { - return language; + return this.language; } public boolean canTranslate(String key) { - return data.containsKey(key); + return this.data.containsKey(key); } public String translate(String key, Object... data) { @@ -40,6 +40,6 @@ public class MinecraftLanguage { @Override public String toString() { - return language; + return this.language; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/Dimension.java b/src/main/java/de/bixilon/minosoft/data/mappings/Dimension.java index f861f4b89..6964fdd89 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/Dimension.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/Dimension.java @@ -22,7 +22,7 @@ public class Dimension extends ModIdentifier { } public boolean hasSkyLight() { - return hasSkyLight; + return this.hasSkyLight; } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java b/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java index e7a462d6a..343d5133e 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/ModIdentifier.java @@ -36,15 +36,15 @@ public class ModIdentifier { } public String getMod() { - return mod; + return this.mod; } public String getIdentifier() { - return identifier; + return this.identifier; } public String getFullIdentifier() { - return String.format("%s:%s", mod, identifier); + return String.format("%s:%s", this.mod, this.identifier); } @Override @@ -54,7 +54,7 @@ public class ModIdentifier { @Override public int hashCode() { - return mod.hashCode() * identifier.hashCode(); + return this.mod.hashCode() * this.identifier.hashCode(); } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.java index 8a2bd1cde..bc7aa0777 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.java @@ -52,31 +52,31 @@ public class Block extends ModIdentifier { } public BlockRotations getRotation() { - return rotation; + return this.rotation; } public HashSet getProperties() { - return properties; + return this.properties; } @Override public String toString() { StringBuilder out = new StringBuilder(); - if (rotation != BlockRotations.NONE) { + if (this.rotation != BlockRotations.NONE) { out.append(" ("); out.append("rotation="); out.append(getRotation()); } - if (properties.size() > 0) { - if (out.length() > 0) { + if (!this.properties.isEmpty()) { + if (!out.isEmpty()) { out.append(", "); } else { out.append(" ("); } out.append("properties="); - out.append(properties); + out.append(this.properties); } - if (out.length() > 0) { + if (!out.isEmpty()) { out.append(")"); } return String.format("%s:%s%s", getMod(), getIdentifier(), out); @@ -84,9 +84,9 @@ public class Block extends ModIdentifier { @Override public int hashCode() { - int ret = mod.hashCode() * identifier.hashCode() * rotation.hashCode(); - if (properties.size() > 0) { - ret *= properties.hashCode(); + int ret = this.mod.hashCode() * this.identifier.hashCode() * this.rotation.hashCode(); + if (!this.properties.isEmpty()) { + ret *= this.properties.hashCode(); } return ret; } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockProperties.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockProperties.java index d1f472c61..b73218035 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockProperties.java @@ -32,7 +32,6 @@ public enum BlockProperties { GENERAL_WATERLOGGED_YES, GENERAL_WATERLOGGED_NO, - // stairs STAIR_DIRECTIONAL_STRAIGHT("shape", "straight"), STAIR_DIRECTIONAL_INNER_LEFT("shape", "inner_left"), @@ -47,7 +46,6 @@ public enum BlockProperties { SLAB_TYPE_BOTTOM, SLAB_TYPE_DOUBLE, - // farmland FARMLAND_MOISTURE_LEVEL_0, FARMLAND_MOISTURE_LEVEL_1, @@ -419,7 +417,6 @@ public enum BlockProperties { BUTTON_FACE_WALL, BUTTON_FACE_CEILING, - POINTED_DRIPSTONE_THICKNESS_TIP_MERGE("thickness", "tip_merge"), POINTED_DRIPSTONE_THICKNESS_TIP("thickness", "tip"), POINTED_DRIPSTONE_THICKNESS_FRUSTUM("thickness", "frustum"), @@ -439,7 +436,6 @@ public enum BlockProperties { SCULK_SENSOR_PHASE_ACTIVE("sculk_sensor_phase", "active"), SCULK_SENSOR_PHASE_COOLDOWN("sculk_sensor_phase", "cooldown"); - public static final HashMap> PROPERTIES_MAPPING = new HashMap<>(); static { @@ -462,12 +458,12 @@ public enum BlockProperties { if (name.contains("LEVEL")) { // level with int values int levelIndex = split.indexOf("LEVEL"); - group = split.get(levelIndex - 1).toLowerCase(); + this.group = split.get(levelIndex - 1).toLowerCase(); } else if (split.size() == 3) { // TYPE_NAME_VALUE - group = split.get(1).toLowerCase(); + this.group = split.get(1).toLowerCase(); } else if (name.endsWith("YES") || name.endsWith("NO")) { - group = split.get(split.size() - 2).toLowerCase(); + this.group = split.get(split.size() - 2).toLowerCase(); } else { throw new IllegalArgumentException(String.format("Could not find group automatically: %s", name)); } @@ -501,10 +497,10 @@ public enum BlockProperties { } public String getGroup() { - return group; + return this.group; } public String getValue() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockRotations.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockRotations.java index 11cdccca7..731c93b39 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockRotations.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/BlockRotations.java @@ -37,7 +37,6 @@ public enum BlockRotations { SOUTH_EAST("14"), SOUTH_SOUTH_EAST("15"), - // stairs? NORTH_SOUTH, EAST_WEST, @@ -80,14 +79,14 @@ public enum BlockRotations { private final HashSet aliases; BlockRotations() { - aliases = new HashSet<>(); + this.aliases = new HashSet<>(); } BlockRotations(String... alias) { - aliases = new HashSet<>(Arrays.asList(alias)); + this.aliases = new HashSet<>(Arrays.asList(alias)); } public HashSet getAliases() { - return aliases; + return this.aliases; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/BellAction.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/BellAction.java index 9a18f0bc7..ee18a6623 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/BellAction.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/BellAction.java @@ -13,21 +13,21 @@ package de.bixilon.minosoft.data.mappings.blocks.actions; -import com.sun.javafx.scene.traversal.Direction; +import de.bixilon.minosoft.data.Directions; public class BellAction implements BlockAction { - private final Direction direction; + private final Directions direction; public BellAction(short unused, short direction) { - this.direction = Direction.values()[direction]; + this.direction = Directions.byId(direction); } - public Direction getDirection() { - return direction; + public Directions getDirection() { + return this.direction; } @Override public String toString() { - return String.format("BELL_HIT_%s", direction); + return String.format("BELL_HIT_%s", this.direction); } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/ChestAction.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/ChestAction.java index fc9e1efa3..7ef1de84a 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/ChestAction.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/ChestAction.java @@ -22,6 +22,6 @@ public class ChestAction implements BlockAction { @Override public String toString() { - return playersLookingInChest > 0 ? String.format("CHEST_OPEN (%d)", playersLookingInChest) : "CHEST_CLOSE"; + return this.playersLookingInChest > 0 ? String.format("CHEST_OPEN (%d)", this.playersLookingInChest) : "CHEST_CLOSE"; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/NoteBlockAction.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/NoteBlockAction.java index 30189ba35..3c1e6b65c 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/NoteBlockAction.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/NoteBlockAction.java @@ -14,8 +14,8 @@ package de.bixilon.minosoft.data.mappings.blocks.actions; public class NoteBlockAction implements BlockAction { - final Instruments instrument; - final short pitch; + private final Instruments instrument; + private final short pitch; public NoteBlockAction(short instrument, short pitch) { this.instrument = Instruments.byId(instrument); @@ -24,7 +24,7 @@ public class NoteBlockAction implements BlockAction { @Override public String toString() { - return String.format("NOTEBLOCK_%s:%d", instrument, pitch); + return String.format("NOTEBLOCK_%s:%d", this.instrument, this.pitch); } public enum Instruments { @@ -34,8 +34,10 @@ public class NoteBlockAction implements BlockAction { CLICKS_STICKS, BASS_DRUM; + private static final Instruments[] INSTRUMENTS = values(); + public static Instruments byId(int id) { - return values()[id]; + return INSTRUMENTS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/PistonAction.java b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/PistonAction.java index c17c87627..7987fd235 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/PistonAction.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/actions/PistonAction.java @@ -26,15 +26,17 @@ public class PistonAction implements BlockAction { @Override public String toString() { - return String.format("PISTON_%s:%s", status, direction); + return String.format("PISTON_%s:%s", this.status, this.direction); } public enum PistonStates { PUSH, PULL; + private static final PistonStates[] PISTON_STATES = values(); + public static PistonStates byId(int id) { - return values()[id]; + return PISTON_STATES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/BlockParticleData.java b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/BlockParticleData.java index e98787c57..0749404be 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/BlockParticleData.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/BlockParticleData.java @@ -30,9 +30,9 @@ public class BlockParticleData extends ParticleData { @Override public String toString() { - if (block == null) { + if (this.block == null) { return null; } - return block.toString(); + return this.block.toString(); } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/DustParticleData.java b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/DustParticleData.java index b6adc72cc..fd8efc949 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/DustParticleData.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/DustParticleData.java @@ -30,23 +30,23 @@ public class DustParticleData extends ParticleData { } public float getRed() { - return red; + return this.red; } public float getGreen() { - return green; + return this.green; } public float getBlue() { - return blue; + return this.blue; } public float getScale() { - return scale; + return this.scale; } @Override public String toString() { - return String.format("{red=%s, green=%s, blue=%s, scale=%s)", red, green, blue, scale); + return String.format("{red=%s, green=%s, blue=%s, scale=%s)", this.red, this.green, this.blue, this.scale); } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ItemParticleData.java b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ItemParticleData.java index 758ed37f1..e6166d405 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ItemParticleData.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ItemParticleData.java @@ -25,11 +25,11 @@ public class ItemParticleData extends ParticleData { } public Slot getSlot() { - return slot; + return this.slot; } @Override public String toString() { - return slot.toString(); + return this.slot.toString(); } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ParticleData.java b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ParticleData.java index 1653eab2c..7806c513f 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ParticleData.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/particle/data/ParticleData.java @@ -23,7 +23,7 @@ public class ParticleData { } public Particle getType() { - return type; + return this.type; } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipe.java b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipe.java index 3c6afebe9..0684ab0cf 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipe.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipe.java @@ -16,14 +16,14 @@ package de.bixilon.minosoft.data.mappings.recipes; import de.bixilon.minosoft.data.inventory.Slot; public class Recipe { - final RecipeTypes type; - Slot result; - String group; - Ingredient[] ingredients; - int height; - int width; - float experience; - int cookingTime; + private final RecipeTypes type; + private Slot result; + private String group; + private Ingredient[] ingredients; + private int height; + private int width; + private float experience; + private int cookingTime; public Recipe(RecipeTypes type, String group, Ingredient[] ingredients, Slot result) { this.type = type; @@ -68,34 +68,34 @@ public class Recipe { } public RecipeTypes getType() { - return type; + return this.type; } public Slot getResult() { - return result; + return this.result; } public String getGroup() { - return group; + return this.group; } public Ingredient[] getIngredients() { - return ingredients; + return this.ingredients; } public int getWidth() { - return width; + return this.width; } public int getHeight() { - return height; + return this.height; } public float getExperience() { - return experience; + return this.experience; } public int getCookingTime() { - return cookingTime; + return this.cookingTime; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/RecipeTypes.java b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/RecipeTypes.java index 6209bddcd..0578ab01b 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/RecipeTypes.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/RecipeTypes.java @@ -56,6 +56,6 @@ public enum RecipeTypes { } public String getName() { - return name; + return this.name; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java index 2f8ee5984..b4f7fd4c8 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/recipes/Recipes.java @@ -17,31 +17,13 @@ import com.google.common.collect.HashBiMap; import de.bixilon.minosoft.data.inventory.Slot; import de.bixilon.minosoft.data.mappings.ModIdentifier; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; public class Recipes { - final static ArrayList recipeList = new ArrayList<>(); - final static HashBiMap recipeIdMap = HashBiMap.create(); // ids for version <= VERSION_1_12_2 - final static HashBiMap recipeNameMap = HashBiMap.create(); - - public static Recipe getRecipeById(int id) { - return recipeIdMap.get(id); - } - - public static Recipe getRecipe(ModIdentifier identifier) { - return recipeNameMap.get(identifier); - } - - public static Recipe getRecipe(RecipeTypes property, Slot result, String group, Ingredient[] ingredients) { - for (Recipe recipe : recipeList) { - if (recipe.getType() == property && recipe.getResult().equals(result) && recipe.getGroup().equals(group) && ingredientsEquals(recipe.getIngredients(), ingredients)) { - return recipe; - } - } - return null; - } + private final HashSet recipeList = new HashSet<>(); + private final HashBiMap recipeIdMap = HashBiMap.create(); // ids for version <= VERSION_1_12_2 + private final HashBiMap recipeNameMap = HashBiMap.create(); public static boolean ingredientsEquals(Ingredient[] one, Ingredient[] two) { if (one.length != two.length) { @@ -53,11 +35,28 @@ public class Recipes { } // we don't want that recipes from 1 server will appear on an other. You must call this function before reconnecting do avoid issues - public static void removeCustomRecipes() { - recipeNameMap.clear(); + public void removeCustomRecipes() { + this.recipeNameMap.clear(); } - public static void registerCustomRecipes(HashBiMap recipes) { - recipeNameMap.putAll(recipes); + public void registerCustomRecipes(HashBiMap recipes) { + this.recipeNameMap.putAll(recipes); + } + + public Recipe getRecipeById(int id) { + return this.recipeIdMap.get(id); + } + + public Recipe getRecipe(ModIdentifier identifier) { + return this.recipeNameMap.get(identifier); + } + + public Recipe getRecipe(RecipeTypes property, Slot result, String group, Ingredient[] ingredients) { + for (Recipe recipe : this.recipeList) { + if (recipe.getType() == property && recipe.getResult().equals(result) && recipe.getGroup().equals(group) && ingredientsEquals(recipe.getIngredients(), ingredients)) { + return recipe; + } + } + return null; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/statistics/StatisticCategories.java b/src/main/java/de/bixilon/minosoft/data/mappings/statistics/StatisticCategories.java index 956031a13..98450e1e5 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/statistics/StatisticCategories.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/statistics/StatisticCategories.java @@ -53,10 +53,10 @@ public enum StatisticCategories { } public ChangeableIdentifier getChangeableIdentifier() { - return changeableIdentifier; + return this.changeableIdentifier; } public int getId() { - return id; + return this.id; } } diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.java b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.java index 161a90634..a5edf6a36 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Version.java @@ -38,29 +38,29 @@ public class Version { } public Packets.Clientbound getPacketByCommand(ConnectionStates state, int command) { - if (clientboundPacketMapping.containsKey(state) && clientboundPacketMapping.get(state).containsValue(command)) { - return clientboundPacketMapping.get(state).inverse().get(command); + if (this.clientboundPacketMapping.containsKey(state) && this.clientboundPacketMapping.get(state).containsValue(command)) { + return this.clientboundPacketMapping.get(state).inverse().get(command); } return null; } public Integer getCommandByPacket(Packets.Serverbound packet) { - if (serverboundPacketMapping.containsKey(packet.getState()) && serverboundPacketMapping.get(packet.getState()).containsKey(packet)) { - return serverboundPacketMapping.get(packet.getState()).get(packet); + if (this.serverboundPacketMapping.containsKey(packet.getState()) && this.serverboundPacketMapping.get(packet.getState()).containsKey(packet)) { + return this.serverboundPacketMapping.get(packet.getState()).get(packet); } return null; } public HashMap> getClientboundPacketMapping() { - return clientboundPacketMapping; + return this.clientboundPacketMapping; } public HashMap> getServerboundPacketMapping() { - return serverboundPacketMapping; + return this.serverboundPacketMapping; } public VersionMapping getMapping() { - return mapping; + return this.mapping; } public void setMapping(VersionMapping mapping) { @@ -68,19 +68,19 @@ public class Version { } public boolean isGettingLoaded() { - return isGettingLoaded; + return this.isGettingLoaded; } public void setGettingLoaded(boolean gettingLoaded) { - isGettingLoaded = gettingLoaded; + this.isGettingLoaded = gettingLoaded; } public boolean isFlattened() { - return versionId >= ProtocolDefinition.FLATTING_VERSION_ID; + return this.versionId >= ProtocolDefinition.FLATTING_VERSION_ID; } public String getVersionName() { - return versionName; + return this.versionName; } public void setVersionName(String versionName) { @@ -88,7 +88,7 @@ public class Version { } public int getVersionId() { - return versionId; + return this.versionId; } @Override @@ -97,7 +97,7 @@ public class Version { } public int getProtocolId() { - return protocolId; + return this.protocolId; } public boolean isLoaded() { @@ -115,7 +115,7 @@ public class Version { if (hashCode() != obj.hashCode()) { return false; } - return getVersionName().equals(versionName); + return getVersionName().equals(this.versionName); } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java index a249393f5..bdc214f12 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.java @@ -67,90 +67,90 @@ public class VersionMapping { } public Motive getMotiveByIdentifier(String identifier) { - if (parentMapping != null) { - Motive motive = parentMapping.getMotiveByIdentifier(identifier); + if (this.parentMapping != null) { + Motive motive = this.parentMapping.getMotiveByIdentifier(identifier); if (motive != null) { return motive; } } - return motiveIdentifierMap.get(identifier); + return this.motiveIdentifierMap.get(identifier); } public Statistic getStatisticByIdentifier(String identifier) { - if (parentMapping != null) { - Statistic statistic = parentMapping.getStatisticByIdentifier(identifier); + if (this.parentMapping != null) { + Statistic statistic = this.parentMapping.getStatisticByIdentifier(identifier); if (statistic != null) { return statistic; } } - return statisticIdentifierMap.get(identifier); + return this.statisticIdentifierMap.get(identifier); } public Particle getParticleByIdentifier(String identifier) { - if (parentMapping != null) { - Particle particle = parentMapping.getParticleByIdentifier(identifier); + if (this.parentMapping != null) { + Particle particle = this.parentMapping.getParticleByIdentifier(identifier); if (particle != null) { return particle; } } - return particleIdentifierMap.get(identifier); + return this.particleIdentifierMap.get(identifier); } public Item getItemById(int versionId) { - if (!version.isFlattened()) { + if (!this.version.isFlattened()) { return getItemByLegacy(versionId >>> 16, versionId & 0xFFFF); } return getItemByIdIgnoreFlattened(versionId); } private Item getItemByIdIgnoreFlattened(int versionId) { - if (parentMapping != null) { - Item item = parentMapping.getItemById(versionId); + if (this.parentMapping != null) { + Item item = this.parentMapping.getItemById(versionId); if (item != null) { return item; } } - return itemMap.get(versionId); + return this.itemMap.get(versionId); } public Integer getItemId(Item item) { - if (parentMapping != null) { - Integer itemId = parentMapping.getItemId(item); + if (this.parentMapping != null) { + Integer itemId = this.parentMapping.getItemId(item); if (item != null) { return itemId; } } - return itemMap.inverse().get(item); + return this.itemMap.inverse().get(item); } public Motive getMotiveById(int versionId) { - if (parentMapping != null) { - Motive motive = parentMapping.getMotiveById(versionId); + if (this.parentMapping != null) { + Motive motive = this.parentMapping.getMotiveById(versionId); if (motive != null) { return motive; } } - return motiveIdMap.get(versionId); + return this.motiveIdMap.get(versionId); } public MobEffect getMobEffectById(int versionId) { - if (parentMapping != null) { - MobEffect mobEffect = parentMapping.getMobEffectById(versionId); + if (this.parentMapping != null) { + MobEffect mobEffect = this.parentMapping.getMobEffectById(versionId); if (mobEffect != null) { return mobEffect; } } - return mobEffectMap.get(versionId); + return this.mobEffectMap.get(versionId); } public Dimension getDimensionById(int versionId) { - if (parentMapping != null) { - Dimension dimension = parentMapping.getDimensionById(versionId); + if (this.parentMapping != null) { + Dimension dimension = this.parentMapping.getDimensionById(versionId); if (dimension != null) { return dimension; } } - return dimensionMap.get(versionId); + return this.dimensionMap.get(versionId); } @Nullable @@ -158,111 +158,111 @@ public class VersionMapping { if (versionId == ProtocolDefinition.NULL_BLOCK_ID) { return null; } - if (parentMapping != null) { - Block block = parentMapping.getBlockById(versionId); + if (this.parentMapping != null) { + Block block = this.parentMapping.getBlockById(versionId); if (block != null) { return block; } } - return blockMap.get(versionId); + return this.blockMap.get(versionId); } public BlockId getBlockIdById(int versionId) { - if (parentMapping != null) { - BlockId blockId = parentMapping.getBlockIdById(versionId); + if (this.parentMapping != null) { + BlockId blockId = this.parentMapping.getBlockIdById(versionId); if (blockId != null) { return blockId; } } - return blockIdMap.get(versionId); + return this.blockIdMap.get(versionId); } public Enchantment getEnchantmentById(int versionId) { - if (parentMapping != null) { - Enchantment enchantment = parentMapping.getEnchantmentById(versionId); + if (this.parentMapping != null) { + Enchantment enchantment = this.parentMapping.getEnchantmentById(versionId); if (enchantment != null) { return enchantment; } } - return enchantmentMap.get(versionId); + return this.enchantmentMap.get(versionId); } public Particle getParticleById(int versionId) { - if (parentMapping != null) { - Particle particle = parentMapping.getParticleById(versionId); + if (this.parentMapping != null) { + Particle particle = this.parentMapping.getParticleById(versionId); if (particle != null) { return particle; } } - return particleIdMap.get(versionId); + return this.particleIdMap.get(versionId); } public Statistic getStatisticById(int versionId) { - if (parentMapping != null) { - Statistic statistic = parentMapping.getStatisticById(versionId); + if (this.parentMapping != null) { + Statistic statistic = this.parentMapping.getStatisticById(versionId); if (statistic != null) { return statistic; } } - return statisticIdMap.get(versionId); + return this.statisticIdMap.get(versionId); } public Integer getIdByEnchantment(Enchantment enchantment) { - if (parentMapping != null) { - Integer enchantmentId = parentMapping.getIdByEnchantment(enchantment); + if (this.parentMapping != null) { + Integer enchantmentId = this.parentMapping.getIdByEnchantment(enchantment); if (enchantmentId != null) { return enchantmentId; } } - return enchantmentMap.inverse().get(enchantment); + return this.enchantmentMap.inverse().get(enchantment); } public EntityInformation getEntityInformation(Class clazz) { - if (parentMapping != null) { - EntityInformation information = parentMapping.getEntityInformation(clazz); + if (this.parentMapping != null) { + EntityInformation information = this.parentMapping.getEntityInformation(clazz); if (information != null) { return information; } } - return entityInformationMap.get(clazz); + return this.entityInformationMap.get(clazz); } public Integer getEntityMetaDataIndex(EntityMetaDataFields field) { - if (parentMapping != null) { - Integer metaDataIndex = parentMapping.getEntityMetaDataIndex(field); + if (this.parentMapping != null) { + Integer metaDataIndex = this.parentMapping.getEntityMetaDataIndex(field); if (metaDataIndex != null) { return metaDataIndex; } } - return entityMetaIndexMap.get(field); + return this.entityMetaIndexMap.get(field); } public Class getEntityClassById(int id) { - if (parentMapping != null) { - Class clazz = parentMapping.getEntityClassById(id); + if (this.parentMapping != null) { + Class clazz = this.parentMapping.getEntityClassById(id); if (clazz != null) { return clazz; } } - return entityIdClassMap.get(id); + return this.entityIdClassMap.get(id); } public Dimension getDimensionByIdentifier(String identifier) { - if (parentMapping != null) { - Dimension dimension = parentMapping.getDimensionByIdentifier(identifier); + if (this.parentMapping != null) { + Dimension dimension = this.parentMapping.getDimensionByIdentifier(identifier); if (dimension != null) { return dimension; } } String[] split = identifier.split(":", 2); - if (dimensionIdentifierMap.containsKey(split[0]) && dimensionIdentifierMap.get(split[0]).containsKey(split[1])) { - return dimensionIdentifierMap.get(split[0]).get(split[1]); + if (this.dimensionIdentifierMap.containsKey(split[0]) && this.dimensionIdentifierMap.get(split[0]).containsKey(split[1])) { + return this.dimensionIdentifierMap.get(split[0]).get(split[1]); } return null; } public void setDimensions(HashMap> dimensions) { - dimensionIdentifierMap = dimensions; + this.dimensionIdentifierMap = dimensions; } public Item getItemByLegacy(int itemId, int metaData) { @@ -278,23 +278,22 @@ public class VersionMapping { return item; } - public void load(Mappings type, String mod, @Nullable JsonObject data, Version version) { switch (type) { case REGISTRIES -> { if (!version.isFlattened() && version.getVersionId() != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) { // clone all values - itemMap = Versions.PRE_FLATTENING_MAPPING.itemMap; - enchantmentMap = Versions.PRE_FLATTENING_MAPPING.enchantmentMap; - statisticIdMap = Versions.PRE_FLATTENING_MAPPING.statisticIdMap; - statisticIdentifierMap = Versions.PRE_FLATTENING_MAPPING.statisticIdentifierMap; - blockIdMap = Versions.PRE_FLATTENING_MAPPING.blockIdMap; - motiveIdMap = Versions.PRE_FLATTENING_MAPPING.motiveIdMap; - motiveIdentifierMap = Versions.PRE_FLATTENING_MAPPING.motiveIdentifierMap; - particleIdMap = Versions.PRE_FLATTENING_MAPPING.particleIdMap; - particleIdentifierMap = Versions.PRE_FLATTENING_MAPPING.particleIdentifierMap; - mobEffectMap = Versions.PRE_FLATTENING_MAPPING.mobEffectMap; - dimensionMap = Versions.PRE_FLATTENING_MAPPING.dimensionMap; + this.itemMap = Versions.PRE_FLATTENING_MAPPING.itemMap; + this.enchantmentMap = Versions.PRE_FLATTENING_MAPPING.enchantmentMap; + this.statisticIdMap = Versions.PRE_FLATTENING_MAPPING.statisticIdMap; + this.statisticIdentifierMap = Versions.PRE_FLATTENING_MAPPING.statisticIdentifierMap; + this.blockIdMap = Versions.PRE_FLATTENING_MAPPING.blockIdMap; + this.motiveIdMap = Versions.PRE_FLATTENING_MAPPING.motiveIdMap; + this.motiveIdentifierMap = Versions.PRE_FLATTENING_MAPPING.motiveIdentifierMap; + this.particleIdMap = Versions.PRE_FLATTENING_MAPPING.particleIdMap; + this.particleIdentifierMap = Versions.PRE_FLATTENING_MAPPING.particleIdentifierMap; + this.mobEffectMap = Versions.PRE_FLATTENING_MAPPING.mobEffectMap; + this.dimensionMap = Versions.PRE_FLATTENING_MAPPING.dimensionMap; break; } @@ -314,81 +313,81 @@ public class VersionMapping { itemId |= identifierJSON.get("meta").getAsInt(); } } - itemMap.put(itemId, item); + this.itemMap.put(itemId, item); } JsonObject enchantmentJson = data.getAsJsonObject("enchantment").getAsJsonObject("entries"); for (String identifier : enchantmentJson.keySet()) { Enchantment enchantment = new Enchantment(mod, identifier); - enchantmentMap.put(enchantmentJson.getAsJsonObject(identifier).get("id").getAsInt(), enchantment); + this.enchantmentMap.put(enchantmentJson.getAsJsonObject(identifier).get("id").getAsInt(), enchantment); } JsonObject statisticJson = data.getAsJsonObject("custom_stat").getAsJsonObject("entries"); for (String identifier : statisticJson.keySet()) { Statistic statistic = new Statistic(mod, identifier); if (statisticJson.getAsJsonObject(identifier).has("id")) { - statisticIdMap.put(statisticJson.getAsJsonObject(identifier).get("id").getAsInt(), statistic); + this.statisticIdMap.put(statisticJson.getAsJsonObject(identifier).get("id").getAsInt(), statistic); } - statisticIdentifierMap.put(identifier, statistic); + this.statisticIdentifierMap.put(identifier, statistic); } JsonObject blockIdJson = data.getAsJsonObject("block").getAsJsonObject("entries"); for (String identifier : blockIdJson.keySet()) { BlockId blockId = new BlockId(mod, identifier); - blockIdMap.put(blockIdJson.getAsJsonObject(identifier).get("id").getAsInt(), blockId); + this.blockIdMap.put(blockIdJson.getAsJsonObject(identifier).get("id").getAsInt(), blockId); } JsonObject motiveJson = data.getAsJsonObject("motive").getAsJsonObject("entries"); for (String identifier : motiveJson.keySet()) { Motive motive = new Motive(mod, identifier); if (motiveJson.getAsJsonObject(identifier).has("id")) { - motiveIdMap.put(motiveJson.getAsJsonObject(identifier).get("id").getAsInt(), motive); + this.motiveIdMap.put(motiveJson.getAsJsonObject(identifier).get("id").getAsInt(), motive); } - motiveIdentifierMap.put(identifier, motive); + this.motiveIdentifierMap.put(identifier, motive); } JsonObject particleJson = data.getAsJsonObject("particle_type").getAsJsonObject("entries"); for (String identifier : particleJson.keySet()) { Particle particle = new Particle(mod, identifier); if (particleJson.getAsJsonObject(identifier).has("id")) { - particleIdMap.put(particleJson.getAsJsonObject(identifier).get("id").getAsInt(), particle); + this.particleIdMap.put(particleJson.getAsJsonObject(identifier).get("id").getAsInt(), particle); } - particleIdentifierMap.put(identifier, particle); + this.particleIdentifierMap.put(identifier, particle); } JsonObject mobEffectJson = data.getAsJsonObject("mob_effect").getAsJsonObject("entries"); for (String identifier : mobEffectJson.keySet()) { MobEffect mobEffect = new MobEffect(mod, identifier); - mobEffectMap.put(mobEffectJson.getAsJsonObject(identifier).get("id").getAsInt(), mobEffect); + this.mobEffectMap.put(mobEffectJson.getAsJsonObject(identifier).get("id").getAsInt(), mobEffect); } if (data.has("dimension_type")) { - dimensionMap = HashBiMap.create(); + this.dimensionMap = HashBiMap.create(); JsonObject dimensionJson = data.getAsJsonObject("dimension_type").getAsJsonObject("entries"); for (String identifier : dimensionJson.keySet()) { Dimension dimension = new Dimension(mod, identifier, dimensionJson.getAsJsonObject(identifier).get("has_skylight").getAsBoolean()); - dimensionMap.put(dimensionJson.getAsJsonObject(identifier).get("id").getAsInt(), dimension); + this.dimensionMap.put(dimensionJson.getAsJsonObject(identifier).get("id").getAsInt(), dimension); } } } case BLOCKS -> { if (!version.isFlattened() && version.getVersionId() != ProtocolDefinition.PRE_FLATTENING_VERSION_ID) { // clone all values - blockMap = Versions.PRE_FLATTENING_MAPPING.blockMap; + this.blockMap = Versions.PRE_FLATTENING_MAPPING.blockMap; break; } if (data == null) { break; } - blockMap = Blocks.load(mod, data, !version.isFlattened()); + this.blockMap = Blocks.load(mod, data, !version.isFlattened()); } case ENTITIES -> { if (data == null) { break; } for (String identifier : data.keySet()) { - if (entityMetaIndexOffsetParentMapping.containsKey(identifier)) { + if (this.entityMetaIndexOffsetParentMapping.containsKey(identifier)) { continue; } loadEntityMapping(mod, identifier, data); } } } - loaded.add(type); + this.loaded.add(type); } private void loadEntityMapping(String mod, String identifier, JsonObject fullModData) { @@ -397,10 +396,10 @@ public class VersionMapping { EntityInformation information = EntityInformation.deserialize(mod, identifier, data); if (information != null) { // not abstract, has id and attributes - entityInformationMap.put(clazz, information); + this.entityInformationMap.put(clazz, information); if (data.has("id")) { - entityIdClassMap.put(data.get("id").getAsInt(), clazz); + this.entityIdClassMap.put(data.get("id").getAsInt(), clazz); } } String parent = null; @@ -409,12 +408,12 @@ public class VersionMapping { parent = data.get("extends").getAsString(); // check if parent has been loaded - Pair metaParent = entityMetaIndexOffsetParentMapping.get(parent); + Pair metaParent = this.entityMetaIndexOffsetParentMapping.get(parent); if (metaParent == null) { loadEntityMapping(mod, parent, fullModData); } - metaDataIndexOffset += entityMetaIndexOffsetParentMapping.get(parent).getValue(); + metaDataIndexOffset += this.entityMetaIndexOffsetParentMapping.get(parent).getValue(); } // meta data index if (data.has("data")) { @@ -422,45 +421,45 @@ public class VersionMapping { if (metaDataJson instanceof JsonArray metaDataJsonArray) { for (JsonElement jsonElement : metaDataJsonArray) { String field = jsonElement.getAsString(); - entityMetaIndexMap.put(EntityMetaDataFields.valueOf(field), metaDataIndexOffset++); + this.entityMetaIndexMap.put(EntityMetaDataFields.valueOf(field), metaDataIndexOffset++); } } else if (metaDataJson instanceof JsonObject metaDataJsonObject) { for (String key : metaDataJsonObject.keySet()) { - entityMetaIndexMap.put(EntityMetaDataFields.valueOf(key), metaDataJsonObject.get(key).getAsInt()); + this.entityMetaIndexMap.put(EntityMetaDataFields.valueOf(key), metaDataJsonObject.get(key).getAsInt()); metaDataIndexOffset++; } } else { throw new RuntimeException("entities.json is invalid"); } } - entityMetaIndexOffsetParentMapping.put(identifier, new Pair<>(parent, metaDataIndexOffset)); + this.entityMetaIndexOffsetParentMapping.put(identifier, new Pair<>(parent, metaDataIndexOffset)); } public void unload() { - motiveIdentifierMap.clear(); - particleIdentifierMap.clear(); - statisticIdentifierMap.clear(); - itemMap.clear(); - motiveIdMap.clear(); - mobEffectMap.clear(); - dimensionMap.clear(); - blockMap.clear(); - blockIdMap.clear(); - enchantmentMap.clear(); - particleIdMap.clear(); - statisticIdMap.clear(); - entityInformationMap.clear(); - entityMetaIndexMap.clear(); - entityMetaIndexOffsetParentMapping.clear(); - entityIdClassMap.clear(); + this.motiveIdentifierMap.clear(); + this.particleIdentifierMap.clear(); + this.statisticIdentifierMap.clear(); + this.itemMap.clear(); + this.motiveIdMap.clear(); + this.mobEffectMap.clear(); + this.dimensionMap.clear(); + this.blockMap.clear(); + this.blockIdMap.clear(); + this.enchantmentMap.clear(); + this.particleIdMap.clear(); + this.statisticIdMap.clear(); + this.entityInformationMap.clear(); + this.entityMetaIndexMap.clear(); + this.entityMetaIndexOffsetParentMapping.clear(); + this.entityIdClassMap.clear(); } public boolean isFullyLoaded() { - if (loaded.size() == Mappings.values().length) { + if (this.loaded.size() == Mappings.values().length) { return true; } for (Mappings mapping : Mappings.values()) { - if (!loaded.contains(mapping)) { + if (!this.loaded.contains(mapping)) { return false; } } @@ -468,7 +467,7 @@ public class VersionMapping { } public Version getVersion() { - return version; + return this.version; } public void setVersion(Version version) { @@ -476,7 +475,7 @@ public class VersionMapping { } public VersionMapping getParentMapping() { - return parentMapping; + return this.parentMapping; } public void setParentMapping(VersionMapping parentMapping) { @@ -484,15 +483,15 @@ public class VersionMapping { } public HashSet getAvailableFeatures() { - return loaded; + return this.loaded; } public boolean doesItemExist(ModIdentifier identifier) { - if (parentMapping != null) { - if (parentMapping.doesItemExist(identifier)) { + if (this.parentMapping != null) { + if (this.parentMapping.doesItemExist(identifier)) { return true; } } - return itemMap.containsValue(new Item(identifier.getFullIdentifier())); + return this.itemMap.containsValue(new Item(identifier.getFullIdentifier())); } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/Hands.java b/src/main/java/de/bixilon/minosoft/data/player/Hands.java index 397e28ad3..b31c9bd1b 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/Hands.java +++ b/src/main/java/de/bixilon/minosoft/data/player/Hands.java @@ -17,7 +17,9 @@ public enum Hands { OFF_HAND, // left MAIN_HAND; // right + private static final Hands[] HANDS = values(); + public static Hands byId(int id) { - return values()[id]; + return HANDS[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/PlayerListItem.java b/src/main/java/de/bixilon/minosoft/data/player/PlayerListItem.java index 53448c96e..d41e72ab4 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/PlayerListItem.java +++ b/src/main/java/de/bixilon/minosoft/data/player/PlayerListItem.java @@ -55,15 +55,15 @@ public class PlayerListItem { } public UUID getUUID() { - return uuid; + return this.uuid; } public String getName() { - return name; + return this.name; } public int getPing() { - return ping; + return this.ping; } public void setPing(int ping) { @@ -71,7 +71,7 @@ public class PlayerListItem { } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public void setGameMode(GameModes gameMode) { @@ -79,7 +79,7 @@ public class PlayerListItem { } public ChatComponent getDisplayName() { - return (hasDisplayName() ? displayName : ChatComponent.valueOf(name)); + return (hasDisplayName() ? this.displayName : ChatComponent.valueOf(this.name)); } public void setDisplayName(ChatComponent displayName) { @@ -87,18 +87,18 @@ public class PlayerListItem { } public boolean hasDisplayName() { - return displayName != null; + return this.displayName != null; } public HashMap getProperties() { - return properties; + return this.properties; } public PlayerProperty getProperty(PlayerProperties property) { - return properties.get(property); + return this.properties.get(property); } public boolean isLegacy() { - return legacy; + return this.legacy; } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/PlayerListItemBulk.java b/src/main/java/de/bixilon/minosoft/data/player/PlayerListItemBulk.java index fc0a51e06..b7c20da63 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/PlayerListItemBulk.java +++ b/src/main/java/de/bixilon/minosoft/data/player/PlayerListItemBulk.java @@ -38,9 +38,9 @@ public class PlayerListItemBulk { this.uuid = UUID.randomUUID(); this.name = name; this.ping = ping; - gameMode = null; - displayName = null; - properties = null; + this.gameMode = null; + this.displayName = null; + this.properties = null; this.legacy = true; } @@ -56,43 +56,43 @@ public class PlayerListItemBulk { } public UUID getUUID() { - return uuid; + return this.uuid; } public String getName() { - return name; + return this.name; } public int getPing() { - return ping; + return this.ping; } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public ChatComponent getDisplayName() { - return (hasDisplayName() ? displayName : ChatComponent.valueOf(name)); + return (hasDisplayName() ? this.displayName : ChatComponent.valueOf(this.name)); } public boolean hasDisplayName() { - return displayName != null; + return this.displayName != null; } public HashMap getProperties() { - return properties; + return this.properties; } public PlayerProperty getProperty(PlayerProperties property) { - return properties.get(property); + return this.properties.get(property); } public boolean isLegacy() { - return legacy; + return this.legacy; } public PacketPlayerListItem.PlayerListItemActions getAction() { - return action; + return this.action; } @Override diff --git a/src/main/java/de/bixilon/minosoft/data/player/PlayerProperties.java b/src/main/java/de/bixilon/minosoft/data/player/PlayerProperties.java index 1036bf1d6..aca370a7e 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/PlayerProperties.java +++ b/src/main/java/de/bixilon/minosoft/data/player/PlayerProperties.java @@ -33,6 +33,6 @@ public enum PlayerProperties { } public String getName() { - return name; + return this.name; } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/PlayerProperty.java b/src/main/java/de/bixilon/minosoft/data/player/PlayerProperty.java index 4d46f13f8..45e8e79f9 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/PlayerProperty.java +++ b/src/main/java/de/bixilon/minosoft/data/player/PlayerProperty.java @@ -31,19 +31,19 @@ public class PlayerProperty { } public PlayerProperties getProperty() { - return property; + return this.property; } public String getValue() { - return value; + return this.value; } public boolean isSigned() { // ToDo check signature - return signature != null; + return this.signature != null; } public String getSignature() { - return signature; + return this.signature; } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/advancements/Advancement.java b/src/main/java/de/bixilon/minosoft/data/player/advancements/Advancement.java index 36ca99c07..660db350f 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/advancements/Advancement.java +++ b/src/main/java/de/bixilon/minosoft/data/player/advancements/Advancement.java @@ -29,18 +29,18 @@ public class Advancement { } public String getParentName() { - return parentName; + return this.parentName; } public AdvancementDisplay getDisplay() { - return display; + return this.display; } public ArrayList getCriteria() { - return criteria; + return this.criteria; } public ArrayList getRequirements() { - return requirements; + return this.requirements; } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/advancements/AdvancementDisplay.java b/src/main/java/de/bixilon/minosoft/data/player/advancements/AdvancementDisplay.java index c25045902..fc5622036 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/advancements/AdvancementDisplay.java +++ b/src/main/java/de/bixilon/minosoft/data/player/advancements/AdvancementDisplay.java @@ -50,43 +50,43 @@ public class AdvancementDisplay { } public ChatComponent getTitle() { - return title; + return this.title; } public ChatComponent getDescription() { - return description; + return this.description; } public Slot getIcon() { - return icon; + return this.icon; } public AdvancementFrameTypes getFrameType() { - return frameType; + return this.frameType; } public boolean hasBackgroundTexture() { - return BitByte.isBitMask(flags, 0x01); + return BitByte.isBitMask(this.flags, 0x01); } public boolean showToast() { - return BitByte.isBitMask(flags, 0x02); + return BitByte.isBitMask(this.flags, 0x02); } public boolean isHidden() { - return BitByte.isBitMask(flags, 0x04); + return BitByte.isBitMask(this.flags, 0x04); } public String getBackgroundTexture() { - return backgroundTexture; + return this.backgroundTexture; } public float getX() { - return x; + return this.x; } public float getY() { - return y; + return this.y; } public enum AdvancementFrameTypes { @@ -94,8 +94,10 @@ public class AdvancementDisplay { CHALLENGE, GOAL; + private static final AdvancementFrameTypes[] ADVANCEMENT_FRAME_TYPES = values(); + public static AdvancementFrameTypes byId(int id) { - return values()[id]; + return ADVANCEMENT_FRAME_TYPES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/data/player/advancements/CriterionProgress.java b/src/main/java/de/bixilon/minosoft/data/player/advancements/CriterionProgress.java index 411da29a4..1e04f6ec6 100644 --- a/src/main/java/de/bixilon/minosoft/data/player/advancements/CriterionProgress.java +++ b/src/main/java/de/bixilon/minosoft/data/player/advancements/CriterionProgress.java @@ -23,10 +23,10 @@ public class CriterionProgress { } public boolean isArchived() { - return archived; + return this.archived; } public Long getArchiveTime() { - return archiveTime; + return this.archiveTime; } } diff --git a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardManager.java b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardManager.java index 64dd136cc..0aa877730 100644 --- a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardManager.java +++ b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardManager.java @@ -20,26 +20,26 @@ public class ScoreboardManager { final HashMap objectives = new HashMap<>(); public void addTeam(Team team) { - teams.put(team.getName(), team); + this.teams.put(team.getName(), team); } public Team getTeam(String name) { - return teams.get(name); + return this.teams.get(name); } public void removeTeam(String name) { - teams.remove(name); + this.teams.remove(name); } public void addObjective(ScoreboardObjective objective) { - objectives.put(objective.getObjectiveName(), objective); + this.objectives.put(objective.getObjectiveName(), objective); } public void removeObjective(String name) { - objectives.remove(name); + this.objectives.remove(name); } public ScoreboardObjective getObjective(String objective) { - return objectives.get(objective); + return this.objectives.get(objective); } } diff --git a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardObjective.java b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardObjective.java index e73c9eeec..ea2e0e912 100644 --- a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardObjective.java +++ b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardObjective.java @@ -28,36 +28,36 @@ public class ScoreboardObjective { } public String getObjectiveName() { - return objectiveName; + return this.objectiveName; } public ChatComponent getObjectiveValue() { - return objectiveValue; + return this.objectiveValue; } public HashMap getScores() { - return scores; + return this.scores; } public void addScore(ScoreboardScore score) { - if (scores.containsKey(score.getItemName())) { + if (this.scores.containsKey(score.getItemName())) { // update - scores.get(score.getItemName()).setScoreName(score.getScoreName()); - scores.get(score.getItemName()).setScore(score.getScore()); + this.scores.get(score.getItemName()).setScoreName(score.getScoreName()); + this.scores.get(score.getItemName()).setScore(score.getScore()); return; } - scores.put(score.getItemName(), score); + this.scores.put(score.getItemName(), score); } public void removeScore(String itemName) { - scores.remove(itemName); + this.scores.remove(itemName); } public ScoreboardScore getScore(String itemName) { - return scores.get(itemName); + return this.scores.get(itemName); } public void setValue(ChatComponent value) { - objectiveValue = value; + this.objectiveValue = value; } } diff --git a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardScore.java b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardScore.java index 881ec2d27..e8880b2e0 100644 --- a/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardScore.java +++ b/src/main/java/de/bixilon/minosoft/data/scoreboard/ScoreboardScore.java @@ -25,11 +25,11 @@ public class ScoreboardScore { } public String getItemName() { - return itemName; + return this.itemName; } public String getScoreName() { - return scoreName; + return this.scoreName; } public void setScoreName(String scoreName) { @@ -37,7 +37,7 @@ public class ScoreboardScore { } public int getScore() { - return score; + return this.score; } public void setScore(int score) { diff --git a/src/main/java/de/bixilon/minosoft/data/scoreboard/Team.java b/src/main/java/de/bixilon/minosoft/data/scoreboard/Team.java index a271fec77..817b747b4 100644 --- a/src/main/java/de/bixilon/minosoft/data/scoreboard/Team.java +++ b/src/main/java/de/bixilon/minosoft/data/scoreboard/Team.java @@ -47,46 +47,46 @@ public class Team { } public String getName() { - return name; + return this.name; } public ChatComponent getDisplayName() { - return displayName; + return this.displayName; } public ChatComponent getPrefix() { - return prefix; + return this.prefix; } public ChatComponent getSuffix() { - return suffix; + return this.suffix; } public boolean isFriendlyFireEnabled() { - return friendlyFire; + return this.friendlyFire; } public boolean isSeeingFriendlyInvisibles() { - return seeFriendlyInvisibles; + return this.seeFriendlyInvisibles; } public void addPlayers(List list) { - players.addAll(list); + this.players.addAll(list); } public void addPlayer(String name) { - players.add(name); + this.players.add(name); } public void removePlayers(List list) { - players.removeAll(list); + this.players.removeAll(list); } public void removePlayer(String name) { - players.remove(name); + this.players.remove(name); } public ArrayList getPlayers() { - return players; + return this.players; } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/BaseComponent.java b/src/main/java/de/bixilon/minosoft/data/text/BaseComponent.java index 2f1a44b7b..262a1c055 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/BaseComponent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/BaseComponent.java @@ -29,7 +29,7 @@ import java.text.StringCharacterIterator; import java.util.ArrayList; public class BaseComponent extends ChatComponent { - private final static String LEGACY_RESET_SUFFIX = String.valueOf(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR) + PostChatFormattingCodes.RESET.getChar(); + private static final String LEGACY_RESET_SUFFIX = String.valueOf(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR) + PostChatFormattingCodes.RESET.getChar(); private final ArrayList parts = new ArrayList<>(); public BaseComponent() { @@ -58,8 +58,8 @@ public class BaseComponent extends ChatComponent { RGBColor nextColor = ChatColors.getColorByFormattingChar(nextFormattingChar); if (nextColor != null) { // color change, add text part - if (currentText.length() > 0) { - parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); + if (!currentText.isEmpty()) { + this.parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); currentText = new StringBuilder(); } color = nextColor; @@ -68,8 +68,8 @@ public class BaseComponent extends ChatComponent { } ChatFormattingCode nextFormattingCode = ChatFormattingCodes.getChatFormattingCodeByChar(nextFormattingChar); if (nextFormattingCode != null) { - if (currentText.length() > 0) { - parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); + if (!currentText.isEmpty()) { + this.parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); currentText = new StringBuilder(); color = null; formattingCodes = new BetterHashSet<>(); @@ -77,9 +77,9 @@ public class BaseComponent extends ChatComponent { formattingCodes.add(nextFormattingCode); if (nextFormattingCode == PostChatFormattingCodes.RESET) { // special rule here - if (currentText.length() > 0) { + if (!currentText.isEmpty()) { // color change, add text part - parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); + this.parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); currentText = new StringBuilder(); } color = null; @@ -87,8 +87,8 @@ public class BaseComponent extends ChatComponent { } } } - if (currentText.length() > 0) { - parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); + if (!currentText.isEmpty()) { + this.parts.add(new TextComponent(currentText.toString(), color, formattingCodes)); } } @@ -104,7 +104,7 @@ public class BaseComponent extends ChatComponent { String text = json.get("text").getAsString(); if (text.contains(String.valueOf(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR))) { // legacy text component - parts.add(new BaseComponent(text)); + this.parts.add(new BaseComponent(text)); return; } RGBColor color; @@ -154,20 +154,20 @@ public class BaseComponent extends ChatComponent { } if (thisTextComponent != null) { - parts.add(thisTextComponent); + this.parts.add(thisTextComponent); } final TextComponent parentParameter = thisTextComponent == null ? parent : thisTextComponent; if (json.has("extra")) { JsonArray extras = json.getAsJsonArray("extra"); - extras.forEach((extra -> parts.add(new BaseComponent(parentParameter, extra)))); + extras.forEach((extra -> this.parts.add(new BaseComponent(parentParameter, extra)))); } if (json.has("translate")) { - parts.add(new TranslatableComponent(parentParameter, json.get("translate").getAsString(), json.getAsJsonArray("with"))); + this.parts.add(new TranslatableComponent(parentParameter, json.get("translate").getAsString(), json.getAsJsonArray("with"))); } } else if (data instanceof JsonPrimitive primitive) { - parts.add(new BaseComponent(parent, primitive.getAsString())); + this.parts.add(new BaseComponent(parent, primitive.getAsString())); } } @@ -179,14 +179,14 @@ public class BaseComponent extends ChatComponent { @Override public String getANSIColoredMessage() { StringBuilder builder = new StringBuilder(); - parts.forEach((chatPart -> builder.append(chatPart.getANSIColoredMessage()))); + this.parts.forEach((chatPart -> builder.append(chatPart.getANSIColoredMessage()))); return builder.toString(); } @Override public String getLegacyText() { StringBuilder builder = new StringBuilder(); - parts.forEach((chatPart -> builder.append(chatPart.getLegacyText()))); + this.parts.forEach((chatPart -> builder.append(chatPart.getLegacyText()))); String string = builder.toString(); if (string.endsWith(LEGACY_RESET_SUFFIX)) { string = string.substring(0, string.length() - LEGACY_RESET_SUFFIX.length()); @@ -197,32 +197,32 @@ public class BaseComponent extends ChatComponent { @Override public String getMessage() { StringBuilder builder = new StringBuilder(); - parts.forEach((chatPart -> builder.append(chatPart.getMessage()))); + this.parts.forEach((chatPart -> builder.append(chatPart.getMessage()))); return builder.toString(); } @Override public ObservableList getJavaFXText(ObservableList nodes) { - parts.forEach((chatPart) -> chatPart.getJavaFXText(nodes)); + this.parts.forEach((chatPart) -> chatPart.getJavaFXText(nodes)); return nodes; } @Unsafe public ArrayList getParts() { - return parts; + return this.parts; } public BaseComponent append(ChatComponent component) { - parts.add(component); + this.parts.add(component); return this; } public BaseComponent append(String message) { - parts.add(new BaseComponent(message)); + this.parts.add(new BaseComponent(message)); return this; } public boolean isEmpty() { - return parts.isEmpty(); + return this.parts.isEmpty(); } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java b/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java index 7d6a5eb8f..e9b77b483 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java +++ b/src/main/java/de/bixilon/minosoft/data/text/ChatColors.java @@ -33,12 +33,12 @@ public final class ChatColors { public static final RGBColor YELLOW = new RGBColor(255, 255, 85); public static final RGBColor WHITE = new RGBColor(255, 255, 255); - private static final HashBiMap colorIntMap = HashBiMap.create(); - private static final RGBColor[] colors = {BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE}; + private static final HashBiMap COLOR_ID_MAP = HashBiMap.create(); + private static final RGBColor[] COLORS = {BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE}; static { - for (int i = 0; i < colors.length; i++) { - colorIntMap.put(colors[i], i); + for (int i = 0; i < COLORS.length; i++) { + COLOR_ID_MAP.put(COLORS[i], i); } } @@ -74,17 +74,17 @@ public final class ChatColors { return null; } if (id <= 15) { - return colors[id]; + return COLORS[id]; } return null; } public static Integer getColorId(RGBColor color) { - return colorIntMap.get(color); + return COLOR_ID_MAP.get(color); } public static String getColorChar(RGBColor color) { - return String.format("%x", colorIntMap.get(color)); + return String.format("%x", COLOR_ID_MAP.get(color)); } public static RGBColor getColorByName(String name) { diff --git a/src/main/java/de/bixilon/minosoft/data/text/ChatFormattingCodes.java b/src/main/java/de/bixilon/minosoft/data/text/ChatFormattingCodes.java index cda138c13..9003ec292 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/ChatFormattingCodes.java +++ b/src/main/java/de/bixilon/minosoft/data/text/ChatFormattingCodes.java @@ -19,14 +19,14 @@ import java.util.Arrays; public final class ChatFormattingCodes { - private static final HashBiMap formattingCodes = HashBiMap.create(); + private static final HashBiMap FORMATTING_CODES = HashBiMap.create(); static { - Arrays.stream(PreChatFormattingCodes.values()).forEach(chatFormattingCodes -> formattingCodes.put(chatFormattingCodes.getChar(), chatFormattingCodes)); - Arrays.stream(PostChatFormattingCodes.values()).forEach(chatFormattingCodes -> formattingCodes.put(chatFormattingCodes.getChar(), chatFormattingCodes)); + Arrays.stream(PreChatFormattingCodes.values()).forEach(chatFormattingCodes -> FORMATTING_CODES.put(chatFormattingCodes.getChar(), chatFormattingCodes)); + Arrays.stream(PostChatFormattingCodes.values()).forEach(chatFormattingCodes -> FORMATTING_CODES.put(chatFormattingCodes.getChar(), chatFormattingCodes)); } public static ChatFormattingCode getChatFormattingCodeByChar(char nextFormattingChar) { - return formattingCodes.get(nextFormattingChar); + return FORMATTING_CODES.get(nextFormattingChar); } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/ClickEvent.java b/src/main/java/de/bixilon/minosoft/data/text/ClickEvent.java index fe2fb6214..86cf09fd3 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/ClickEvent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/ClickEvent.java @@ -36,11 +36,11 @@ public class ClickEvent { } public ClickEventActions getAction() { - return action; + return this.action; } public Object getValue() { - return value; + return this.value; } public enum ClickEventActions { diff --git a/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java b/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java index ae7697740..8ba7932a0 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/HoverEvent.java @@ -36,7 +36,7 @@ public class HoverEvent { data = json.get("contents"); } json.get("value"); - value = switch (action) { // ToDo + this.value = switch (this.action) { // ToDo case SHOW_TEXT -> ChatComponent.valueOf(data); case SHOW_ENTITY -> EntityHoverData.deserialize(data); default -> null; @@ -52,7 +52,7 @@ public class HoverEvent { } public Object getValue() { - return value; + return this.value; } public enum HoverEventActions { diff --git a/src/main/java/de/bixilon/minosoft/data/text/MultiChatComponent.java b/src/main/java/de/bixilon/minosoft/data/text/MultiChatComponent.java index 28eb15e3c..3bb89ca8e 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/MultiChatComponent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/MultiChatComponent.java @@ -38,7 +38,7 @@ public class MultiChatComponent extends TextComponent { } public ClickEvent getClickEvent() { - return clickEvent; + return this.clickEvent; } public void setClickEvent(ClickEvent clickEvent) { @@ -46,7 +46,7 @@ public class MultiChatComponent extends TextComponent { } public HoverEvent getHoverEvent() { - return hoverEvent; + return this.hoverEvent; } public void setHoverEvent(HoverEvent hoverEvent) { diff --git a/src/main/java/de/bixilon/minosoft/data/text/PostChatFormattingCodes.java b/src/main/java/de/bixilon/minosoft/data/text/PostChatFormattingCodes.java index a3452ab77..e99336576 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/PostChatFormattingCodes.java +++ b/src/main/java/de/bixilon/minosoft/data/text/PostChatFormattingCodes.java @@ -25,16 +25,16 @@ public enum PostChatFormattingCodes implements ChatFormattingCode { } public char getChar() { - return c; + return this.c; + } + + public String getANSI() { + return this.ansi; } @Override public String toString() { return getANSI(); } - - public String getANSI() { - return ansi; - } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/PreChatFormattingCodes.java b/src/main/java/de/bixilon/minosoft/data/text/PreChatFormattingCodes.java index 1860f33bb..fb4207e9a 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/PreChatFormattingCodes.java +++ b/src/main/java/de/bixilon/minosoft/data/text/PreChatFormattingCodes.java @@ -20,7 +20,6 @@ public enum PreChatFormattingCodes implements ChatFormattingCode { UNDERLINED('n', "\u001b[4m"), ITALIC('o', "\u001b[3m"); - final char c; final String ansi; @@ -30,17 +29,16 @@ public enum PreChatFormattingCodes implements ChatFormattingCode { } public char getChar() { - return c; + return this.c; } + public String getANSI() { + return this.ansi; + } @Override public String toString() { return getANSI(); } - - public String getANSI() { - return ansi; - } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/RGBColor.java b/src/main/java/de/bixilon/minosoft/data/text/RGBColor.java index 05159cf19..a2e81f34e 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/RGBColor.java +++ b/src/main/java/de/bixilon/minosoft/data/text/RGBColor.java @@ -32,28 +32,28 @@ public final class RGBColor implements ChatCode { if (colorString.startsWith("#")) { colorString = colorString.substring(1); } - color = Integer.parseInt(colorString, 16); + this.color = Integer.parseInt(colorString, 16); } public int getAlpha() { - return (color >> 24) & 0xFF; + return (this.color >> 24) & 0xFF; } public int getRed() { - return (color >> 16) & 0xFF; + return (this.color >> 16) & 0xFF; } public int getGreen() { - return (color >> 8) & 0xFF; + return (this.color >> 8) & 0xFF; } public int getBlue() { - return color & 0xFF; + return this.color & 0xFF; } @Override public int hashCode() { - return color; + return this.color; } @Override @@ -65,15 +65,15 @@ public final class RGBColor implements ChatCode { return getColor() == their.getColor(); } - public int getColor() { - return color; - } - @Override public String toString() { if (getAlpha() > 0) { - return String.format("#%08X", color); + return String.format("#%08X", this.color); } - return String.format("#%06X", (0xFFFFFF & color)); + return String.format("#%06X", (0xFFFFFF & this.color)); + } + + public int getColor() { + return this.color; } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/TextComponent.java b/src/main/java/de/bixilon/minosoft/data/text/TextComponent.java index a9a607247..465859a00 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/TextComponent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/TextComponent.java @@ -47,37 +47,37 @@ public class TextComponent extends ChatComponent { } public TextComponent setObfuscated(boolean obfuscated) { - formatting.addOrRemove(PreChatFormattingCodes.OBFUSCATED, obfuscated); + this.formatting.addOrRemove(PreChatFormattingCodes.OBFUSCATED, obfuscated); return this; } public TextComponent setBold(boolean bold) { - formatting.addOrRemove(PreChatFormattingCodes.BOLD, bold); + this.formatting.addOrRemove(PreChatFormattingCodes.BOLD, bold); return this; } public TextComponent setStrikethrough(boolean strikethrough) { - formatting.addOrRemove(PreChatFormattingCodes.STRIKETHROUGH, strikethrough); + this.formatting.addOrRemove(PreChatFormattingCodes.STRIKETHROUGH, strikethrough); return this; } public TextComponent setUnderlined(boolean underlined) { - formatting.addOrRemove(PreChatFormattingCodes.UNDERLINED, underlined); + this.formatting.addOrRemove(PreChatFormattingCodes.UNDERLINED, underlined); return this; } public TextComponent setItalic(boolean italic) { - formatting.addOrRemove(PreChatFormattingCodes.ITALIC, italic); + this.formatting.addOrRemove(PreChatFormattingCodes.ITALIC, italic); return this; } public TextComponent setReset(boolean reset) { - formatting.addOrRemove(PostChatFormattingCodes.RESET, reset); + this.formatting.addOrRemove(PostChatFormattingCodes.RESET, reset); return this; } public RGBColor getColor() { - return color; + return this.color; } public TextComponent setColor(RGBColor color) { @@ -86,7 +86,7 @@ public class TextComponent extends ChatComponent { } public BetterHashSet getFormatting() { - return formatting; + return this.formatting; } public TextComponent setFormatting(BetterHashSet formatting) { @@ -94,6 +94,11 @@ public class TextComponent extends ChatComponent { return this; } + @Override + public int hashCode() { + return Objects.hash(this.text, this.color, this.formatting); + } + @Override public boolean equals(Object obj) { if (super.equals(obj)) { @@ -103,30 +108,30 @@ public class TextComponent extends ChatComponent { return false; } TextComponent their = (TextComponent) obj; - return text.equals(their.getMessage()) && color.equals(their.getColor()) && formatting.equals(their.getFormatting()); + return this.text.equals(their.getMessage()) && this.color.equals(their.getColor()) && this.formatting.equals(their.getFormatting()); } @Override - public int hashCode() { - return Objects.hash(text, color, formatting); + public String toString() { + return getANSIColoredMessage(); } @Override public String getANSIColoredMessage() { StringBuilder builder = new StringBuilder(); - if (color != null) { - builder.append(ChatColors.getANSIColorByRGBColor(color)); + if (this.color != null) { + builder.append(ChatColors.getANSIColorByRGBColor(this.color)); } - if (formatting != null) { - formatting.forEach((chatFormattingCodes -> { + if (this.formatting != null) { + this.formatting.forEach((chatFormattingCodes -> { if (chatFormattingCodes instanceof PreChatFormattingCodes code) { builder.append(code.getANSI()); } })); } - builder.append(text); - if (formatting != null) { - formatting.forEach((chatFormattingCodes -> { + builder.append(this.text); + if (this.formatting != null) { + this.formatting.forEach((chatFormattingCodes -> { if (chatFormattingCodes instanceof PostChatFormattingCodes code) { builder.append(code.getANSI()); } @@ -139,30 +144,30 @@ public class TextComponent extends ChatComponent { @Override public String getLegacyText() { StringBuilder output = new StringBuilder(); - Integer colorChar = ChatColors.getColorId(color); + Integer colorChar = ChatColors.getColorId(this.color); if (colorChar != null) { output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(Integer.toHexString(colorChar)); } - formatting.forEach((chatFormattingCode -> output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(chatFormattingCode.getChar()))); - output.append(text); + this.formatting.forEach((chatFormattingCode -> output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(chatFormattingCode.getChar()))); + output.append(this.text); output.append(ProtocolDefinition.TEXT_COMPONENT_SPECIAL_PREFIX_CHAR).append(PostChatFormattingCodes.RESET.getChar()); return output.toString(); } @Override public String getMessage() { - return text; + return this.text; } @Override public ObservableList getJavaFXText(ObservableList nodes) { Text text = new Text(this.text); - if (color == null) { + if (this.color == null) { text.setFill(Color.WHITE); } else { - text.setFill(Color.web(color.toString())); + text.setFill(Color.web(this.color.toString())); } - formatting.forEach((chatFormattingCode -> { + this.formatting.forEach((chatFormattingCode -> { if (chatFormattingCode instanceof PreChatFormattingCodes code) { switch (code) { case OBFUSCATED -> { @@ -180,9 +185,4 @@ public class TextComponent extends ChatComponent { nodes.add(text); return nodes; } - - @Override - public String toString() { - return getANSIColoredMessage(); - } } diff --git a/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponent.java b/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponent.java index af905d4a4..f36b97cc7 100644 --- a/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponent.java +++ b/src/main/java/de/bixilon/minosoft/data/text/TranslatableComponent.java @@ -76,15 +76,15 @@ public class TranslatableComponent extends ChatComponent { for (int i = 0; i < this.data.size(); i++) { data[i] = this.data.get(i).getClass().getMethod(methodName).invoke(this.data.get(i)); } - if (parent != null) { + if (this.parent != null) { StringBuilder builder = new StringBuilder(); if (methodName.equals("getANSIColoredMessage")) { - builder.append(ChatColors.getANSIColorByRGBColor(parent.getColor())); + builder.append(ChatColors.getANSIColorByRGBColor(this.parent.getColor())); } else if (methodName.equals("getLegacyText")) { - builder.append(ChatColors.getColorChar(parent.getColor())); + builder.append(ChatColors.getColorChar(this.parent.getColor())); } - for (ChatFormattingCode code : parent.getFormatting()) { + for (ChatFormattingCode code : this.parent.getFormatting()) { if (code instanceof PreChatFormattingCodes preCode) { builder.append(switch (methodName) { case "getANSIColoredMessage" -> preCode.getANSI(); @@ -93,8 +93,8 @@ public class TranslatableComponent extends ChatComponent { }); } } - builder.append(MinecraftLocaleManager.translate(key, data)); - for (ChatFormattingCode code : parent.getFormatting()) { + builder.append(MinecraftLocaleManager.translate(this.key, data)); + for (ChatFormattingCode code : this.parent.getFormatting()) { if (code instanceof PostChatFormattingCodes postCode) { builder.append(switch (methodName) { case "getANSIColoredMessage" -> postCode.getANSI(); @@ -105,7 +105,7 @@ public class TranslatableComponent extends ChatComponent { } return builder.toString(); } - return MinecraftLocaleManager.translate(key, data); + return MinecraftLocaleManager.translate(this.key, data); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/de/bixilon/minosoft/data/world/Chunk.java b/src/main/java/de/bixilon/minosoft/data/world/Chunk.java index 42fcef1e4..c8f3e651e 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/Chunk.java +++ b/src/main/java/de/bixilon/minosoft/data/world/Chunk.java @@ -37,22 +37,22 @@ public class Chunk { throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z)); } byte section = (byte) (y / 16); - if (!sections.containsKey(section)) { + if (!this.sections.containsKey(section)) { return null; } - return sections.get(section).getBlock(x, y % 16, z); + return this.sections.get(section).getBlock(x, y % 16, z); } public void setBlock(int x, int y, int z, Block block) { byte section = (byte) (y / 16); createSection(section); - sections.get(section).setBlock(x, y % 16, z, block); + this.sections.get(section).setBlock(x, y % 16, z, block); } void createSection(byte section) { - if (sections.get(section) == null) { + if (this.sections.get(section) == null) { // section was empty before, creating it - sections.put(section, new ChunkSection()); + this.sections.put(section, new ChunkSection()); } } @@ -63,12 +63,11 @@ public class Chunk { public void setBlock(InChunkLocation location, Block block) { byte section = (byte) (location.getY() / 16); createSection(section); - sections.get(section).setBlock(location.getInChunkSectionLocation(), block); + this.sections.get(section).setBlock(location.getInChunkSectionLocation(), block); } - public void setBlockEntityData(InChunkLocation position, BlockEntityMetaData data) { - ChunkSection section = sections.get((byte) (position.getY() / 16)); + ChunkSection section = this.sections.get((byte) (position.getY() / 16)); if (section == null) { return; } @@ -76,7 +75,7 @@ public class Chunk { } public BlockEntityMetaData getBlockEntityData(InChunkLocation position) { - ChunkSection section = sections.get((byte) (position.getY() / 16)); + ChunkSection section = this.sections.get((byte) (position.getY() / 16)); if (section == null) { return null; } diff --git a/src/main/java/de/bixilon/minosoft/data/world/ChunkSection.java b/src/main/java/de/bixilon/minosoft/data/world/ChunkSection.java index 194b2fae0..ba1eda6ab 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/ChunkSection.java +++ b/src/main/java/de/bixilon/minosoft/data/world/ChunkSection.java @@ -46,7 +46,7 @@ public class ChunkSection { } public Block getBlock(InChunkSectionLocation loc) { - return blocks.get(loc); + return this.blocks.get(loc); } public void setBlock(int x, int y, int z, Block block) { @@ -55,40 +55,40 @@ public class ChunkSection { public void setBlock(InChunkSectionLocation location, Block block) { if (block == null) { - blocks.remove(location); - blockEntityMeta.remove(location); + this.blocks.remove(location); + this.blockEntityMeta.remove(location); return; } - blocks.put(location, block); - blockEntityMeta.remove(location); + this.blocks.put(location, block); + this.blockEntityMeta.remove(location); } public void setBlockEntityData(InChunkSectionLocation position, BlockEntityMetaData data) { // ToDo check if block is really a block entity (command block, spawner, skull, flower pot) - blockEntityMeta.put(position, data); + this.blockEntityMeta.put(position, data); } public HashMap getBlocks() { - return blocks; + return this.blocks; } public HashMap getBlockEntityMeta() { - return blockEntityMeta; + return this.blockEntityMeta; } public HashMap getLight() { - return light; + return this.light; } public HashMap getSkyLight() { - return skyLight; + return this.skyLight; } public BlockEntityMetaData getBlockEntityData(InChunkSectionLocation position) { - return blockEntityMeta.get(position); + return this.blockEntityMeta.get(position); } public void setBlockEntityData(HashMap blockEntities) { - blockEntities.forEach(blockEntityMeta::put); + blockEntities.forEach(this.blockEntityMeta::put); } } diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.java b/src/main/java/de/bixilon/minosoft/data/world/World.java index 401dda0c9..591901a44 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.java +++ b/src/main/java/de/bixilon/minosoft/data/world/World.java @@ -32,7 +32,7 @@ public class World { Dimension dimension; // used for sky color, etc public HashMap getAllChunks() { - return chunks; + return this.chunks; } @Nullable @@ -45,7 +45,7 @@ public class World { } public Chunk getChunk(ChunkLocation loc) { - return chunks.get(loc); + return this.chunks.get(loc); } public void setBlock(BlockPosition pos, Block block) { @@ -56,19 +56,19 @@ public class World { } public void unloadChunk(ChunkLocation location) { - chunks.remove(location); + this.chunks.remove(location); } public void setChunk(ChunkLocation location, Chunk chunk) { - chunks.put(location, chunk); + this.chunks.put(location, chunk); } public void setChunks(HashMap chunkMap) { - chunkMap.forEach(chunks::put); + chunkMap.forEach(this.chunks::put); } public boolean isHardcore() { - return hardcore; + return this.hardcore; } public void setHardcore(boolean hardcore) { @@ -76,7 +76,7 @@ public class World { } public boolean isRaining() { - return raining; + return this.raining; } public void setRaining(boolean raining) { @@ -88,7 +88,7 @@ public class World { } public Entity getEntity(int id) { - return entities.get(id); + return this.entities.get(id); } public void removeEntity(Entity entity) { @@ -100,7 +100,7 @@ public class World { } public Dimension getDimension() { - return dimension; + return this.dimension; } public void setDimension(Dimension dimension) { @@ -108,7 +108,7 @@ public class World { } public void setBlockEntityData(BlockPosition position, BlockEntityMetaData data) { - Chunk chunk = chunks.get(position.getChunkLocation()); + Chunk chunk = this.chunks.get(position.getChunkLocation()); if (chunk == null) { return; } @@ -116,7 +116,7 @@ public class World { } public BlockEntityMetaData getBlockEntityData(BlockPosition position) { - Chunk chunk = chunks.get(position.getChunkLocation()); + Chunk chunk = this.chunks.get(position.getChunkLocation()); if (chunk == null) { return null; } diff --git a/src/main/java/de/bixilon/minosoft/data/world/palette/DirectPalette.java b/src/main/java/de/bixilon/minosoft/data/world/palette/DirectPalette.java index 0ec71b544..7daa3ddc2 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/palette/DirectPalette.java +++ b/src/main/java/de/bixilon/minosoft/data/world/palette/DirectPalette.java @@ -23,12 +23,12 @@ public class DirectPalette implements Palette { @Override public Block byId(int id) { - return mapping.getBlockById(id); + return this.mapping.getBlockById(id); } @Override public byte getBitsPerBlock() { - if (versionId < 367) { + if (this.versionId < 367) { return 13; } return 14; @@ -37,7 +37,7 @@ public class DirectPalette implements Palette { @Override public void read(InByteBuffer buffer) { this.versionId = buffer.getVersionId(); - mapping = buffer.getConnection().getMapping(); + this.mapping = buffer.getConnection().getMapping(); if (buffer.getVersionId() < 346) { buffer.readVarInt(); } diff --git a/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.java b/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.java index ba690c0dc..12cc7f067 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.java +++ b/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.java @@ -34,15 +34,15 @@ public class IndirectPalette implements Palette { @Override public Block byId(int id) { - int blockId = map.getOrDefault(id, id); - Block block = mapping.getBlockById(blockId); + int blockId = this.map.getOrDefault(id, id); + Block block = this.mapping.getBlockById(blockId); if (StaticConfiguration.DEBUG_MODE) { if (block == null) { if (blockId == ProtocolDefinition.NULL_BLOCK_ID) { return null; } String blockName; - if (versionId <= ProtocolDefinition.PRE_FLATTENING_VERSION_ID) { + if (this.versionId <= ProtocolDefinition.PRE_FLATTENING_VERSION_ID) { blockName = String.format("%d:%d", blockId >> 4, blockId & 0xF); } else { blockName = String.valueOf(blockId); @@ -56,7 +56,7 @@ public class IndirectPalette implements Palette { @Override public byte getBitsPerBlock() { - return bitsPerBlock; + return this.bitsPerBlock; } @Override @@ -65,7 +65,7 @@ public class IndirectPalette implements Palette { this.mapping = buffer.getConnection().getMapping(); int paletteLength = buffer.readVarInt(); for (int i = 0; i < paletteLength; i++) { - map.put(i, buffer.readVarInt()); + this.map.put(i, buffer.readVarInt()); } } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/AccountListCell.java b/src/main/java/de/bixilon/minosoft/gui/main/AccountListCell.java index 9df1aca87..947b67df0 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/AccountListCell.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/AccountListCell.java @@ -29,7 +29,7 @@ import java.net.URL; import java.util.ResourceBundle; public class AccountListCell extends ListCell implements Initializable { - public static final ListView listView = new ListView<>(); + public static final ListView MOJANG_ACCOUNT_LIST_VIEW = new ListView<>(); public MenuButton optionsMenu; public Label playerName; @@ -54,23 +54,23 @@ public class AccountListCell extends ListCell implements Initiali @Override public void initialize(URL url, ResourceBundle rb) { updateSelected(false); - setGraphic(root); + setGraphic(this.root); // change locale - optionsSelect.setText(LocaleManager.translate(Strings.ACCOUNTS_ACTION_SELECT)); - optionsDelete.setText(LocaleManager.translate(Strings.ACCOUNTS_ACTION_DELETE)); + this.optionsSelect.setText(LocaleManager.translate(Strings.ACCOUNTS_ACTION_SELECT)); + this.optionsDelete.setText(LocaleManager.translate(Strings.ACCOUNTS_ACTION_DELETE)); } public AnchorPane getRoot() { - return root; + return this.root; } @Override protected void updateItem(MojangAccount account, boolean empty) { super.updateItem(account, empty); - root.setVisible(!empty); + this.root.setVisible(!empty); if (empty) { return; } @@ -85,32 +85,32 @@ public class AccountListCell extends ListCell implements Initiali resetCell(); this.account = account; - playerName.setText(account.getPlayerName()); - email.setText(account.getMojangUserName()); + this.playerName.setText(account.getPlayerName()); + this.email.setText(account.getMojangUserName()); if (Minosoft.getSelectedAccount() == account) { setStyle("-fx-background-color: darkseagreen;"); - optionsSelect.setDisable(true); + this.optionsSelect.setDisable(true); } } private void resetCell() { // clear all cells setStyle(null); - optionsSelect.setDisable(false); + this.optionsSelect.setDisable(false); } public void delete() { - account.delete(); - if (Minosoft.getSelectedAccount() == account) { + this.account.delete(); + if (Minosoft.getSelectedAccount() == this.account) { if (Minosoft.getConfig().getAccountList().isEmpty()) { Minosoft.selectAccount(null); } else { Minosoft.selectAccount(Minosoft.getConfig().getAccountList().values().iterator().next()); } - listView.refresh(); + MOJANG_ACCOUNT_LIST_VIEW.refresh(); } - Log.info(String.format("Deleted account (email=\"%s\", playerName=\"%s\")", account.getMojangUserName(), account.getPlayerName())); - listView.getItems().remove(account); + Log.info(String.format("Deleted account (email=\"%s\", playerName=\"%s\")", this.account.getMojangUserName(), this.account.getPlayerName())); + MOJANG_ACCOUNT_LIST_VIEW.getItems().remove(this.account); } public void clicked(MouseEvent e) { @@ -120,13 +120,13 @@ public class AccountListCell extends ListCell implements Initiali select(); } } - case SECONDARY -> optionsMenu.fire(); + case SECONDARY -> this.optionsMenu.fire(); } } public void select() { - Minosoft.selectAccount(account); - listView.refresh(); - ServerListCell.listView.refresh(); + Minosoft.selectAccount(this.account); + MOJANG_ACCOUNT_LIST_VIEW.refresh(); + ServerListCell.SERVER_LIST_VIEW.refresh(); } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/AccountWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/AccountWindow.java index 0f9909eb5..aeb823d7f 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/AccountWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/AccountWindow.java @@ -44,13 +44,13 @@ public class AccountWindow implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - AccountListCell.listView.setCellFactory((lv) -> AccountListCell.newInstance()); + AccountListCell.MOJANG_ACCOUNT_LIST_VIEW.setCellFactory((lv) -> AccountListCell.newInstance()); ObservableList accounts = FXCollections.observableArrayList(Minosoft.getConfig().getAccountList().values()); - AccountListCell.listView.setItems(accounts); - accountPane.setCenter(AccountListCell.listView); + AccountListCell.MOJANG_ACCOUNT_LIST_VIEW.setItems(accounts); + this.accountPane.setCenter(AccountListCell.MOJANG_ACCOUNT_LIST_VIEW); - menuAddAccount.setText(LocaleManager.translate(Strings.ACCOUNT_MODAL_MENU_ADD_ACCOUNT)); + this.menuAddAccount.setText(LocaleManager.translate(Strings.ACCOUNT_MODAL_MENU_ADD_ACCOUNT)); } @FXML @@ -93,7 +93,7 @@ public class AccountWindow implements Initializable { MojangAccount account = attempt.getAccount(); Minosoft.getConfig().putMojangAccount(account); account.saveToConfig(); - AccountListCell.listView.getItems().add(account); + AccountListCell.MOJANG_ACCOUNT_LIST_VIEW.getItems().add(account); Log.info(String.format("Added and saved account (playerName=%s, email=%s, uuid=%s)", account.getPlayerName(), account.getMojangUserName(), account.getUUID())); dialog.close(); return; @@ -111,7 +111,6 @@ public class AccountWindow implements Initializable { Window window = dialog.getDialogPane().getScene().getWindow(); window.setOnCloseRequest(windowEvent -> window.hide()); - dialog.getDialogPane().setOnKeyReleased(keyEvent -> { if (keyEvent.getCode() != KeyCode.ENTER) { return; diff --git a/src/main/java/de/bixilon/minosoft/gui/main/GUITools.java b/src/main/java/de/bixilon/minosoft/gui/main/GUITools.java index e9b7f7c0a..fa670facc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/GUITools.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/GUITools.java @@ -29,16 +29,16 @@ import java.util.Arrays; import java.util.Base64; public class GUITools { - public final static Image MINOSOFT_LOGO = new Image(GUITools.class.getResourceAsStream("/icons/windowIcon.png")); - public final static ObservableList VERSIONS = FXCollections.observableArrayList(); - public final static JFXComboBox VERSION_COMBO_BOX = new JFXComboBox<>(GUITools.VERSIONS); - public final static ObservableList LOG_LEVELS = FXCollections.observableList(Arrays.asList(LogLevels.values().clone())); + public static final Image MINOSOFT_LOGO = new Image(GUITools.class.getResourceAsStream("/icons/windowIcon.png")); + public static final ObservableList VERSIONS = FXCollections.observableArrayList(); + public static final JFXComboBox VERSION_COMBO_BOX = new JFXComboBox<>(VERSIONS); + public static final ObservableList LOG_LEVELS = FXCollections.observableList(Arrays.asList(LogLevels.values().clone())); static { - GUITools.VERSIONS.add(Versions.LOWEST_VERSION_SUPPORTED); - Versions.getVersionIdMap().forEach((key, value) -> GUITools.VERSIONS.add(value)); + VERSIONS.add(Versions.LOWEST_VERSION_SUPPORTED); + Versions.getVersionIdMap().forEach((key, value) -> VERSIONS.add(value)); - GUITools.VERSIONS.sort((a, b) -> { + VERSIONS.sort((a, b) -> { if (a.getVersionId() == -1) { return -Integer.MAX_VALUE; } @@ -73,7 +73,7 @@ public class GUITools { public static Scene initializeScene(Scene scene) { scene.getStylesheets().add("/layout/style.css"); if (scene.getWindow() instanceof Stage stage) { - stage.getIcons().add(GUITools.MINOSOFT_LOGO); + stage.getIcons().add(MINOSOFT_LOGO); } return scene; } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/Launcher.java b/src/main/java/de/bixilon/minosoft/gui/main/Launcher.java index f6d664142..87f3d0d11 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/Launcher.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/Launcher.java @@ -35,7 +35,7 @@ import java.util.concurrent.CountDownLatch; public class Launcher { private static Stage stage; - private static boolean exit = false; + private static boolean exit; public static void start() { Log.info("Starting launcher..."); @@ -59,11 +59,11 @@ public class Launcher { }; } }); - ServerListCell.listView.setCellFactory((lv) -> ServerListCell.newInstance()); + ServerListCell.SERVER_LIST_VIEW.setCellFactory((lv) -> ServerListCell.newInstance()); ObservableList servers = FXCollections.observableArrayList(); servers.addAll(Minosoft.getConfig().getServerList().values()); - ServerListCell.listView.setItems(servers); + ServerListCell.SERVER_LIST_VIEW.setItems(servers); LANServerListener.removeAll(); // remove all LAN Servers VBox root; diff --git a/src/main/java/de/bixilon/minosoft/gui/main/MainWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/MainWindow.java index 9247b31d5..2350897da 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/MainWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/MainWindow.java @@ -124,7 +124,6 @@ public class MainWindow implements Initializable { JFXAlert dialog = new JFXAlert<>(); GUITools.initializePane(dialog.getDialogPane()); - JFXDialogLayout layout = new JFXDialogLayout(); GridPane gridPane = new GridPane(); @@ -133,7 +132,6 @@ public class MainWindow implements Initializable { JFXButton submitButton; - JFXTextField serverNameField = new JFXTextField(); serverNameField.setPromptText(LocaleManager.translate(Strings.SERVER_NAME)); @@ -150,7 +148,6 @@ public class MainWindow implements Initializable { GUITools.VERSION_COMBO_BOX.getSelectionModel().select(Versions.LOWEST_VERSION_SUPPORTED); - if (server == null) { // add dialog.setTitle(LocaleManager.translate(Strings.ADD_SERVER_DIALOG_TITLE)); @@ -181,14 +178,12 @@ public class MainWindow implements Initializable { gridPane.add(new Label(LocaleManager.translate(Strings.VERSION) + ":"), 0, 2); gridPane.add(GUITools.VERSION_COMBO_BOX, 1, 2); - layout.setBody(gridPane); JFXButton closeButton = new JFXButton(ButtonType.CLOSE.getText()); closeButton.setOnAction((actionEvent -> dialog.hide())); closeButton.setButtonType(JFXButton.ButtonType.RAISED); layout.setActions(closeButton, submitButton); - serverAddressField.textProperty().addListener((observable, oldValue, newValue) -> submitButton.setDisable(newValue.trim().isEmpty())); submitButton.setDisable(serverAddressField.getText().isBlank()); dialog.setContent(layout); @@ -204,7 +199,7 @@ public class MainWindow implements Initializable { if (server1 == null) { server1 = new Server(Server.getNextServerId(), serverName, serverAddress, desiredVersionId); Minosoft.getConfig().putServer(server1); - ServerListCell.listView.getItems().add(server1); + ServerListCell.SERVER_LIST_VIEW.getItems().add(server1); } else { server1.setName(serverName); server1.setAddress(serverAddress); @@ -232,18 +227,18 @@ public class MainWindow implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - serversPane.setCenter(ServerListCell.listView); + this.serversPane.setCenter(ServerListCell.SERVER_LIST_VIEW); - menuAccount2 = menuAccount; - menuFile.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE)); - menuFilePreferences.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE_PREFERENCES)); - menuFileQuit.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE_QUIT)); - menuServers.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS)); - menuServersAdd.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ADD)); - menuServerRefresh.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_REFRESH)); - menuHelp.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_HELP)); - menuHelpAbout.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_HELP_ABOUT)); - menuAccountManage.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ACCOUNTS_MANAGE)); + menuAccount2 = this.menuAccount; + this.menuFile.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE)); + this.menuFilePreferences.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE_PREFERENCES)); + this.menuFileQuit.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_FILE_QUIT)); + this.menuServers.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS)); + this.menuServersAdd.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ADD)); + this.menuServerRefresh.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_REFRESH)); + this.menuHelp.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_HELP)); + this.menuHelpAbout.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_HELP_ABOUT)); + this.menuAccountManage.setText(LocaleManager.translate(Strings.MAIN_WINDOW_MENU_SERVERS_ACCOUNTS_MANAGE)); selectAccount(); } @@ -260,16 +255,16 @@ public class MainWindow implements Initializable { public void refreshServers() { Log.info("Refreshing server list"); // remove all lan servers - ServerListCell.listView.getItems().removeAll(LANServerListener.getServers().values()); + ServerListCell.SERVER_LIST_VIEW.getItems().removeAll(LANServerListener.getServerMap().values()); LANServerListener.removeAll(); - for (Server server : ServerListCell.listView.getItems()) { + for (Server server : ServerListCell.SERVER_LIST_VIEW.getItems()) { if (server.getLastPing() == null) { // server was not pinged, don't even try, only costs memory and cpu continue; } server.ping(); - ServerListCell.listView.refresh(); + ServerListCell.SERVER_LIST_VIEW.refresh(); } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/Server.java b/src/main/java/de/bixilon/minosoft/gui/main/Server.java index 78c00a0e6..eec94b5e3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/Server.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/Server.java @@ -35,7 +35,7 @@ public class Server { private int desiredVersion; private byte[] favicon; private Connection lastPing; - private boolean readOnly = false; + private boolean readOnly; private ServerListCell cell; public Server(int id, BaseComponent name, String address, int desiredVersion, byte[] favicon) { @@ -56,7 +56,7 @@ public class Server { public Server(ServerAddress address) { this.id = getNextServerId(); - this.name = new BaseComponent(String.format("LAN Server #%d", LANServerListener.getServers().size())); + this.name = new BaseComponent(String.format("LAN Server #%d", LANServerListener.getServerMap().size())); this.address = address.toString(); this.desiredVersion = -1; // Automatic this.readOnly = true; @@ -76,7 +76,7 @@ public class Server { @Nullable public byte[] getFavicon() { - return favicon; + return this.favicon; } public void setFavicon(byte[] favicon) { @@ -84,7 +84,7 @@ public class Server { } public int getId() { - return id; + return this.id; } public void saveToConfig() { @@ -104,12 +104,12 @@ public class Server { } public Connection getLastPing() { - return lastPing; + return this.lastPing; } @Override public int hashCode() { - return id; + return this.id; } @Override @@ -118,19 +118,18 @@ public class Server { } public BaseComponent getName() { - if (name.isEmpty()) { - return addressName; + if (this.name.isEmpty()) { + return this.addressName; } - return name; + return this.name; } - public void setName(BaseComponent name) { this.name = name; } public String getAddress() { - return address; + return this.address; } public void setAddress(String address) { @@ -139,14 +138,14 @@ public class Server { } public void ping() { - if (lastPing == null) { - lastPing = new Connection(Connection.lastConnectionId++, getAddress(), null); + if (this.lastPing == null) { + this.lastPing = new Connection(Connection.lastConnectionId++, getAddress(), null); } - lastPing.resolve(ConnectionReasons.PING, getDesiredVersionId()); // resolve dns address and ping + this.lastPing.resolve(ConnectionReasons.PING, getDesiredVersionId()); // resolve dns address and ping } public int getDesiredVersionId() { - return desiredVersion; + return this.desiredVersion; } public void setDesiredVersionId(int versionId) { @@ -154,15 +153,15 @@ public class Server { } public ArrayList getConnections() { - return connections; + return this.connections; } public void addConnection(Connection connection) { - connections.add(connection); + this.connections.add(connection); } public boolean isConnected() { - for (Connection connection : connections) { + for (Connection connection : this.connections) { if (connection.isConnected()) { return true; } @@ -172,11 +171,11 @@ public class Server { public JsonObject serialize() { JsonObject json = new JsonObject(); - json.addProperty("id", id); - json.addProperty("name", name.getLegacyText()); - json.addProperty("address", address); - json.addProperty("version", desiredVersion); - if (favicon != null) { + json.addProperty("id", this.id); + json.addProperty("name", this.name.getLegacyText()); + json.addProperty("address", this.address); + json.addProperty("version", this.desiredVersion); + if (this.favicon != null) { json.addProperty("favicon", getBase64Favicon()); } return json; @@ -184,18 +183,18 @@ public class Server { @Nullable public String getBase64Favicon() { - if (favicon == null) { + if (this.favicon == null) { return null; } - return Base64.getEncoder().encodeToString(favicon); + return Base64.getEncoder().encodeToString(this.favicon); } public boolean isReadOnly() { - return readOnly; + return this.readOnly; } public ServerListCell getCell() { - return cell; + return this.cell; } public void setCell(ServerListCell cell) { diff --git a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java index 37128fc3a..48b2777fa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java @@ -53,7 +53,7 @@ import java.util.Arrays; import java.util.ResourceBundle; public class ServerListCell extends ListCell implements Initializable { - public static final ListView listView = new ListView<>(); + public static final ListView SERVER_LIST_VIEW = new ListView<>(); public ImageView faviconField; public TextFlow nameField; @@ -71,7 +71,7 @@ public class ServerListCell extends ListCell implements Initializable { public MenuItem optionsDelete; public MenuButton optionsMenu; - boolean canConnect = false; + boolean canConnect; private Server server; public static ServerListCell newInstance() { @@ -88,22 +88,22 @@ public class ServerListCell extends ListCell implements Initializable { @Override public void initialize(URL url, ResourceBundle rb) { updateSelected(false); - setGraphic(root); + setGraphic(this.root); // change locale - optionsConnect.setText(LocaleManager.translate(Strings.SERVER_ACTION_CONNECT)); - optionsShowInfo.setText(LocaleManager.translate(Strings.SERVER_ACTION_SHOW_INFO)); - optionsEdit.setText(LocaleManager.translate(Strings.SERVER_ACTION_EDIT)); - optionsRefresh.setText(LocaleManager.translate(Strings.SERVER_ACTION_REFRESH)); - optionsSessions.setText(LocaleManager.translate(Strings.SERVER_ACTION_SESSIONS)); - optionsDelete.setText(LocaleManager.translate(Strings.SERVER_ACTION_DELETE)); + this.optionsConnect.setText(LocaleManager.translate(Strings.SERVER_ACTION_CONNECT)); + this.optionsShowInfo.setText(LocaleManager.translate(Strings.SERVER_ACTION_SHOW_INFO)); + this.optionsEdit.setText(LocaleManager.translate(Strings.SERVER_ACTION_EDIT)); + this.optionsRefresh.setText(LocaleManager.translate(Strings.SERVER_ACTION_REFRESH)); + this.optionsSessions.setText(LocaleManager.translate(Strings.SERVER_ACTION_SESSIONS)); + this.optionsDelete.setText(LocaleManager.translate(Strings.SERVER_ACTION_DELETE)); } @Override protected void updateItem(Server server, boolean empty) { super.updateItem(server, empty); - root.setVisible(!empty); + this.root.setVisible(!empty); if (empty) { return; } @@ -125,12 +125,12 @@ public class ServerListCell extends ListCell implements Initializable { if (favicon == null) { favicon = GUITools.MINOSOFT_LOGO; } - faviconField.setImage(favicon); + this.faviconField.setImage(favicon); if (server.isConnected()) { getStyleClass().add("list-cell-connected"); - optionsSessions.setDisable(false); + this.optionsSessions.setDisable(false); } else { - optionsSessions.setDisable(true); + this.optionsSessions.setDisable(true); } if (server.getLastPing() == null) { server.ping(); @@ -148,59 +148,59 @@ public class ServerListCell extends ListCell implements Initializable { } if (ping == null) { // Offline - playersField.setText(""); - versionField.setText(LocaleManager.translate(Strings.OFFLINE)); - versionField.getStyleClass().add("version-error"); + this.playersField.setText(""); + this.versionField.setText(LocaleManager.translate(Strings.OFFLINE)); + this.versionField.getStyleClass().add("version-error"); setErrorMotd(String.format("%s", server.getLastPing().getLastConnectionException())); - optionsConnect.setDisable(true); - canConnect = false; + this.optionsConnect.setDisable(true); + this.canConnect = false; return; } - playersField.setText(LocaleManager.translate(Strings.SERVER_INFO_SLOTS_PLAYERS_ONLINE, ping.getPlayerOnline(), ping.getMaxPlayers())); + this.playersField.setText(LocaleManager.translate(Strings.SERVER_INFO_SLOTS_PLAYERS_ONLINE, ping.getPlayerOnline(), ping.getMaxPlayers())); Version serverVersion; if (server.getDesiredVersionId() == -1) { serverVersion = Versions.getVersionByProtocolId(ping.getProtocolId()); } else { serverVersion = Versions.getVersionById(server.getDesiredVersionId()); - versionField.setStyle("-fx-text-fill: -secondary-light-light-color;"); + this.versionField.setStyle("-fx-text-fill: -secondary-light-light-color;"); } if (serverVersion == null) { - versionField.setText(ping.getServerBrand()); - versionField.setStyle("-fx-text-fill: red;"); - optionsConnect.setDisable(true); - canConnect = false; + this.versionField.setText(ping.getServerBrand()); + this.versionField.setStyle("-fx-text-fill: red;"); + this.optionsConnect.setDisable(true); + this.canConnect = false; } else { - versionField.setText(serverVersion.getVersionName()); - optionsConnect.setDisable(false); - canConnect = true; + this.versionField.setText(serverVersion.getVersionName()); + this.optionsConnect.setDisable(false); + this.canConnect = true; } - brandField.setText(ping.getServerModInfo().getBrand()); - brandField.setTooltip(new Tooltip(ping.getServerModInfo().getInfo())); - motdField.getChildren().setAll(ping.getMotd().getJavaFXText()); + this.brandField.setText(ping.getServerModInfo().getBrand()); + this.brandField.setTooltip(new Tooltip(ping.getServerModInfo().getInfo())); + this.motdField.getChildren().setAll(ping.getMotd().getJavaFXText()); if (ping.getFavicon() != null) { - faviconField.setImage(GUITools.getImage(ping.getFavicon())); + this.faviconField.setImage(GUITools.getImage(ping.getFavicon())); if (!Arrays.equals(ping.getFavicon(), server.getFavicon())) { server.setFavicon(ping.getFavicon()); server.saveToConfig(); } } if (server.isReadOnly()) { - optionsEdit.setDisable(true); - optionsDelete.setDisable(true); + this.optionsEdit.setDisable(true); + this.optionsDelete.setDisable(true); } if (server.getLastPing().getLastConnectionException() != null) { // connection failed because of an error in minosoft, but ping was okay - versionField.setStyle("-fx-text-fill: red;"); - optionsConnect.setDisable(true); - canConnect = false; + this.versionField.setStyle("-fx-text-fill: red;"); + this.optionsConnect.setDisable(true); + this.canConnect = false; setErrorMotd(String.format("%s: %s", server.getLastPing().getLastConnectionException().getClass().getCanonicalName(), server.getLastPing().getLastConnectionException().getMessage())); } }))); } public void setName(BaseComponent name) { - nameField.getChildren().setAll(name.getJavaFXText()); - for (Node node : nameField.getChildren()) { + this.nameField.getChildren().setAll(name.getJavaFXText()); + for (Node node : this.nameField.getChildren()) { node.setStyle("-fx-font-size: 15pt ;"); } } @@ -209,42 +209,42 @@ public class ServerListCell extends ListCell implements Initializable { // clear all cells setStyle(null); getStyleClass().remove("list-cell-connected"); - motdField.getChildren().clear(); - brandField.setText(""); - brandField.setTooltip(null); - motdField.setStyle(null); - versionField.setText(LocaleManager.translate(Strings.CONNECTING)); - versionField.getStyleClass().remove("version-error"); - versionField.setStyle(null); - playersField.setText(""); - optionsConnect.setDisable(true); - optionsEdit.setDisable(false); - optionsDelete.setDisable(false); + this.motdField.getChildren().clear(); + this.brandField.setText(""); + this.brandField.setTooltip(null); + this.motdField.setStyle(null); + this.versionField.setText(LocaleManager.translate(Strings.CONNECTING)); + this.versionField.getStyleClass().remove("version-error"); + this.versionField.setStyle(null); + this.playersField.setText(""); + this.optionsConnect.setDisable(true); + this.optionsEdit.setDisable(false); + this.optionsDelete.setDisable(false); } private void setErrorMotd(String message) { Text text = new Text(message); text.setFill(Color.RED); - motdField.getChildren().setAll(text); + this.motdField.getChildren().setAll(text); } public void delete() { - if (server.isReadOnly()) { + if (this.server.isReadOnly()) { return; } - server.getConnections().forEach(Connection::disconnect); - server.delete(); - Log.info(String.format("Deleted server (name=\"%s\", address=\"%s\")", server.getName().getLegacyText(), server.getAddress())); - listView.getItems().remove(server); + this.server.getConnections().forEach(Connection::disconnect); + this.server.delete(); + Log.info(String.format("Deleted server (name=\"%s\", address=\"%s\")", this.server.getName().getLegacyText(), this.server.getAddress())); + SERVER_LIST_VIEW.getItems().remove(this.server); } public void refresh() { - Log.info(String.format("Refreshing server status (serverName=\"%s\", address=\"%s\")", server.getName().getLegacyText(), server.getAddress())); - if (server.getLastPing() == null) { + Log.info(String.format("Refreshing server status (serverName=\"%s\", address=\"%s\")", this.server.getName().getLegacyText(), this.server.getAddress())); + if (this.server.getLastPing() == null) { // server was not pinged, don't even try, only costs memory and cpu return; } - server.ping(); + this.server.ping(); } public void clicked(MouseEvent e) { @@ -254,68 +254,67 @@ public class ServerListCell extends ListCell implements Initializable { connect(); } } - case SECONDARY -> optionsMenu.fire(); + case SECONDARY -> this.optionsMenu.fire(); case MIDDLE -> { - listView.getSelectionModel().select(server); + SERVER_LIST_VIEW.getSelectionModel().select(this.server); editServer(); } } } public void connect() { - if (!canConnect || server.getLastPing() == null) { + if (!this.canConnect || this.server.getLastPing() == null) { return; } - Connection connection = new Connection(Connection.lastConnectionId++, server.getAddress(), new Player(Minosoft.getSelectedAccount())); + Connection connection = new Connection(Connection.lastConnectionId++, this.server.getAddress(), new Player(Minosoft.getSelectedAccount())); Version version; - if (server.getDesiredVersionId() == -1) { - version = server.getLastPing().getVersion(); + if (this.server.getDesiredVersionId() == -1) { + version = this.server.getLastPing().getVersion(); } else { - version = Versions.getVersionById(server.getDesiredVersionId()); + version = Versions.getVersionById(this.server.getDesiredVersionId()); } - optionsConnect.setDisable(true); - connection.connect(server.getLastPing().getAddress(), version); + this.optionsConnect.setDisable(true); + connection.connect(this.server.getLastPing().getAddress(), version); connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback)); - server.addConnection(connection); + this.server.addConnection(connection); } public void editServer() { - MainWindow.addOrEditServer(server); + MainWindow.addOrEditServer(this.server); } private void handleConnectionCallback(ConnectionStateChangeEvent event) { Connection connection = event.getConnection(); - if (!server.getConnections().contains(connection)) { + if (!this.server.getConnections().contains(connection)) { // the card got recycled return; } Platform.runLater(() -> { if (!connection.isConnected()) { // maybe we got disconnected - if (!server.isConnected()) { + if (!this.server.isConnected()) { setStyle(null); getStyleClass().remove("list-cell-connected"); - optionsSessions.setDisable(true); - optionsConnect.setDisable(false); + this.optionsSessions.setDisable(true); + this.optionsConnect.setDisable(false); return; } } - optionsConnect.setDisable(Minosoft.getSelectedAccount() == connection.getPlayer().getAccount()); + this.optionsConnect.setDisable(Minosoft.getSelectedAccount() == connection.getPlayer().getAccount()); getStyleClass().add("list-cell-connected"); - optionsSessions.setDisable(false); + this.optionsSessions.setDisable(false); }); } public void showInfo() { JFXAlert dialog = new JFXAlert<>(); - dialog.setTitle("View server info: " + server.getName().getMessage()); + dialog.setTitle("View server info: " + this.server.getName().getMessage()); GUITools.initializePane(dialog.getDialogPane()); JFXDialogLayout layout = new JFXDialogLayout(); - JFXButton closeButton = new JFXButton(ButtonType.CLOSE.getText()); closeButton.setOnAction((actionEvent -> dialog.hide())); closeButton.setButtonType(JFXButton.ButtonType.RAISED); @@ -326,14 +325,14 @@ public class ServerListCell extends ListCell implements Initializable { grid.setVgap(10); TextFlow serverNameLabel = new TextFlow(); - serverNameLabel.getChildren().setAll(server.getName().getJavaFXText()); - Label serverAddressLabel = new Label(server.getAddress()); + serverNameLabel.getChildren().setAll(this.server.getName().getJavaFXText()); + Label serverAddressLabel = new Label(this.server.getAddress()); Label forcedVersionLabel = new Label(); - if (server.getDesiredVersionId() == -1) { + if (this.server.getDesiredVersionId() == -1) { forcedVersionLabel.setText(Versions.LOWEST_VERSION_SUPPORTED.getVersionName()); } else { - forcedVersionLabel.setText(Versions.getVersionById(server.getDesiredVersionId()).getVersionName()); + forcedVersionLabel.setText(Versions.getVersionById(this.server.getDesiredVersionId()).getVersionName()); } int column = -1; @@ -346,16 +345,16 @@ public class ServerListCell extends ListCell implements Initializable { grid.add(new Label(LocaleManager.translate(Strings.FORCED_VERSION) + ":"), 0, ++column); grid.add(forcedVersionLabel, 1, column); - if (server.getLastPing() != null) { - if (server.getLastPing().getLastConnectionException() != null) { - Label lastConnectionExceptionLabel = new Label(server.getLastPing().getLastConnectionException().toString()); + if (this.server.getLastPing() != null) { + if (this.server.getLastPing().getLastConnectionException() != null) { + Label lastConnectionExceptionLabel = new Label(this.server.getLastPing().getLastConnectionException().toString()); lastConnectionExceptionLabel.setStyle("-fx-text-fill: red"); grid.add(new Label(LocaleManager.translate(Strings.SERVER_INFO_LAST_CONNECTION_EXCEPTION) + ":"), 0, ++column); grid.add(lastConnectionExceptionLabel, 1, column); } - if (server.getLastPing().getLastPing() != null) { - ServerListPing lastPing = server.getLastPing().getLastPing(); + if (this.server.getLastPing().getLastPing() != null) { + ServerListPing lastPing = this.server.getLastPing().getLastPing(); Version serverVersion = Versions.getVersionByProtocolId(lastPing.getProtocolId()); String serverVersionString; if (serverVersion == null) { @@ -363,7 +362,7 @@ public class ServerListCell extends ListCell implements Initializable { } else { serverVersionString = serverVersion.getVersionName(); } - Label realServerAddressLabel = new Label(server.getLastPing().getAddress().toString()); + Label realServerAddressLabel = new Label(this.server.getLastPing().getAddress().toString()); Label serverVersionLabel = new Label(serverVersionString); Label serverBrandLabel = new Label(lastPing.getServerBrand()); Label playersOnlineMaxLabel = new Label(LocaleManager.translate(Strings.SERVER_INFO_SLOTS_PLAYERS_ONLINE, lastPing.getPlayerOnline(), lastPing.getMaxPlayers())); @@ -403,10 +402,10 @@ public class ServerListCell extends ListCell implements Initializable { try { FXMLLoader loader = new FXMLLoader(getClass().getResource("/layout/sessions.fxml")); Parent parent = loader.load(); - ((SessionsWindow) loader.getController()).setServer(server); + ((SessionsWindow) loader.getController()).setServer(this.server); Stage stage = new Stage(); stage.initModality(Modality.APPLICATION_MODAL); - stage.setTitle(LocaleManager.translate(Strings.SESSIONS_DIALOG_TITLE, server.getName())); + stage.setTitle(LocaleManager.translate(Strings.SESSIONS_DIALOG_TITLE, this.server.getName())); stage.setScene(new Scene(parent)); GUITools.initializeScene(stage.getScene()); stage.show(); diff --git a/src/main/java/de/bixilon/minosoft/gui/main/SessionListCell.java b/src/main/java/de/bixilon/minosoft/gui/main/SessionListCell.java index ba6afc84f..8a5d4003b 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/SessionListCell.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/SessionListCell.java @@ -33,7 +33,7 @@ import java.net.URL; import java.util.ResourceBundle; public class SessionListCell extends ListCell implements Initializable { - public static final ListView listView = new ListView<>(); + public static final ListView CONNECTION_LIST_VIEW = new ListView<>(); public Label account; public Label connectionId; @@ -56,20 +56,20 @@ public class SessionListCell extends ListCell implements Initializab @Override public void initialize(URL url, ResourceBundle rb) { updateSelected(false); - setGraphic(root); + setGraphic(this.root); - optionsDisconnect.setText(LocaleManager.translate(Strings.SESSIONS_ACTION_DISCONNECT)); + this.optionsDisconnect.setText(LocaleManager.translate(Strings.SESSIONS_ACTION_DISCONNECT)); } public AnchorPane getRoot() { - return root; + return this.root; } @Override protected void updateItem(Connection connection, boolean empty) { super.updateItem(connection, empty); - root.setVisible(!empty); + this.root.setVisible(!empty); if (empty) { return; } @@ -84,8 +84,8 @@ public class SessionListCell extends ListCell implements Initializab setStyle(null); this.connection = connection; connection.registerEvent(new EventInvokerCallback<>(ConnectionStateChangeEvent.class, this::handleConnectionCallback)); - connectionId.setText(String.format("#%d", connection.getConnectionId())); - account.setText(connection.getPlayer().getAccount().getPlayerName()); + this.connectionId.setText(String.format("#%d", connection.getConnectionId())); + this.account.setText(connection.getPlayer().getAccount().getPlayerName()); } private void handleConnectionCallback(ConnectionStateChangeEvent event) { @@ -97,9 +97,9 @@ public class SessionListCell extends ListCell implements Initializab if (!connection.isConnected()) { Platform.runLater(() -> { - listView.getItems().remove(connection); - if (listView.getItems().size() == 0) { - ((Stage) root.getScene().getWindow()).close(); + CONNECTION_LIST_VIEW.getItems().remove(connection); + if (CONNECTION_LIST_VIEW.getItems().isEmpty()) { + ((Stage) this.root.getScene().getWindow()).close(); } }); } @@ -107,6 +107,6 @@ public class SessionListCell extends ListCell implements Initializab public void disconnect() { setStyle("-fx-background-color: indianred"); - connection.disconnect(); + this.connection.disconnect(); } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/SessionsWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/SessionsWindow.java index 9cc80df38..1f345d743 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/SessionsWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/SessionsWindow.java @@ -35,10 +35,10 @@ public class SessionsWindow implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - SessionListCell.listView.setCellFactory((lv) -> SessionListCell.newInstance()); + SessionListCell.CONNECTION_LIST_VIEW.setCellFactory((lv) -> SessionListCell.newInstance()); - menuDisconnect.setText(LocaleManager.translate(Strings.SESSIONS_MENU_DISCONNECT)); - menuDisconnectFromAll.setText(LocaleManager.translate(Strings.SESSIONS_MENU_DISCONNECT_FROM_ALL)); + this.menuDisconnect.setText(LocaleManager.translate(Strings.SESSIONS_MENU_DISCONNECT)); + this.menuDisconnectFromAll.setText(LocaleManager.translate(Strings.SESSIONS_MENU_DISCONNECT_FROM_ALL)); } public void setServer(Server server) { @@ -50,11 +50,11 @@ public class SessionsWindow implements Initializable { } connections.add(connection); } - SessionListCell.listView.setItems(connections); - accountPane.setCenter(SessionListCell.listView); + SessionListCell.CONNECTION_LIST_VIEW.setItems(connections); + this.accountPane.setCenter(SessionListCell.CONNECTION_LIST_VIEW); } public void disconnectAll() { - server.getConnections().forEach(Connection::disconnect); + this.server.getConnections().forEach(Connection::disconnect); } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java index a17a62663..1d88ab855 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java @@ -37,10 +37,10 @@ public class SettingsWindow implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { - generalLogLevel.setItems(GUITools.LOG_LEVELS); - generalLogLevel.getSelectionModel().select(Log.getLevel()); - generalLogLevel.setOnAction((actionEvent -> { - LogLevels newLevel = generalLogLevel.getValue(); + this.generalLogLevel.setItems(GUITools.LOG_LEVELS); + this.generalLogLevel.getSelectionModel().select(Log.getLevel()); + this.generalLogLevel.setOnAction((actionEvent -> { + LogLevels newLevel = this.generalLogLevel.getValue(); if (Log.getLevel() == newLevel) { return; } @@ -49,8 +49,8 @@ public class SettingsWindow implements Initializable { Minosoft.getConfig().saveToFile(); })); - general.setText(LocaleManager.translate(Strings.SETTINGS_GENERAL)); - generalLogLevelLabel.setText(LocaleManager.translate(Strings.SETTINGS_GENERAL_LOG_LEVEL)); - download.setText(LocaleManager.translate(Strings.SETTINGS_DOWNLOAD)); + this.general.setText(LocaleManager.translate(Strings.SETTINGS_GENERAL)); + this.generalLogLevelLabel.setText(LocaleManager.translate(Strings.SETTINGS_GENERAL_LOG_LEVEL)); + this.download.setText(LocaleManager.translate(Strings.SETTINGS_DOWNLOAD)); } } diff --git a/src/main/java/de/bixilon/minosoft/gui/main/StartProgressWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/StartProgressWindow.java index fac7b19db..bf3bf095c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/StartProgressWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/StartProgressWindow.java @@ -30,11 +30,11 @@ import javafx.stage.Stage; import java.util.concurrent.CountDownLatch; public class StartProgressWindow extends Application { - public final static CountDownLatch toolkitLatch = new CountDownLatch(2); // 2 if not started, 1 if started, 2 if loaded + public static final CountDownLatch TOOLKIT_LATCH = new CountDownLatch(2); // 2 if not started, 1 if started, 2 if loaded public static JFXAlert progressDialog; private static JFXProgressBar progressBar; private static Label progressLabel; - private static boolean exit = false; + private static boolean exit; public static void show(CountUpAndDownLatch progress) { if (exit) { @@ -52,7 +52,6 @@ public class StartProgressWindow extends Application { JFXDialogLayout layout = new JFXDialogLayout(); layout.setHeading(new Label(LocaleManager.translate(Strings.MINOSOFT_STILL_STARTING_HEADER))); - progressBar = new JFXProgressBar(); progressBar.setPrefHeight(50); @@ -63,7 +62,6 @@ public class StartProgressWindow extends Application { gridPane.add(progressBar, 0, 0); gridPane.add(progressLabel, 1, 0); - layout.setBody(gridPane); progressDialog.setContent(layout); @@ -93,9 +91,9 @@ public class StartProgressWindow extends Application { public static void start() throws InterruptedException { Log.debug("Initializing JavaFX Toolkit..."); - toolkitLatch.countDown(); + TOOLKIT_LATCH.countDown(); new Thread(Application::launch).start(); - toolkitLatch.await(); + TOOLKIT_LATCH.await(); Log.debug("Initialized JavaFX Toolkit!"); } @@ -113,6 +111,6 @@ public class StartProgressWindow extends Application { @Override public void start(Stage stage) { Platform.setImplicitExit(false); - toolkitLatch.countDown(); + TOOLKIT_LATCH.countDown(); } } diff --git a/src/main/java/de/bixilon/minosoft/logging/Log.java b/src/main/java/de/bixilon/minosoft/logging/Log.java index a8e0bda71..ef11c0f25 100644 --- a/src/main/java/de/bixilon/minosoft/logging/Log.java +++ b/src/main/java/de/bixilon/minosoft/logging/Log.java @@ -22,9 +22,9 @@ import java.text.SimpleDateFormat; import java.util.concurrent.LinkedBlockingQueue; public class Log { - public final static long MINOSOFT_START_TIME = System.currentTimeMillis(); - private final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - private final static LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); + public static final long MINOSOFT_START_TIME = System.currentTimeMillis(); + private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + private static final LinkedBlockingQueue LOG_QUEUE = new LinkedBlockingQueue<>(); private static LogLevels level = LogLevels.PROTOCOL; static { @@ -33,7 +33,7 @@ public class Log { // something to print String message; try { - message = queue.take(); + message = LOG_QUEUE.take(); } catch (InterruptedException e) { e.printStackTrace(); continue; @@ -71,7 +71,7 @@ public class Log { if (StaticConfiguration.LOG_RELATIVE_TIME) { builder.append(System.currentTimeMillis() - MINOSOFT_START_TIME); } else { - builder.append(timeFormat.format(System.currentTimeMillis())); + builder.append(TIME_FORMAT.format(System.currentTimeMillis())); } builder.append("] ["); builder.append(Thread.currentThread().getName()); @@ -87,7 +87,7 @@ public class Log { builder.append(message); } builder.append(PostChatFormattingCodes.RESET.getANSI()); - queue.add(builder.toString()); + LOG_QUEUE.add(builder.toString()); } /** @@ -162,7 +162,6 @@ public class Log { log(LogLevels.INFO, ChatColors.WHITE, message, format); } - public static LogLevels getLevel() { return level; } @@ -171,13 +170,13 @@ public class Log { if (Log.level == level) { return; } - Log.info(String.format("Log level changed from %s to %s", Log.level, level)); + info(String.format("Log level changed from %s to %s", Log.level, level)); Log.level = level; } public static boolean printException(Throwable exception, LogLevels minimumLogLevel) { // ToDo: log to file, print also exceptions that are not printed with this method - if (Log.getLevel().ordinal() >= minimumLogLevel.ordinal()) { + if (getLevel().ordinal() >= minimumLogLevel.ordinal()) { exception.printStackTrace(); return true; } diff --git a/src/main/java/de/bixilon/minosoft/modding/Logger.java b/src/main/java/de/bixilon/minosoft/modding/Logger.java index 3288a2f2f..26e7cd7c5 100644 --- a/src/main/java/de/bixilon/minosoft/modding/Logger.java +++ b/src/main/java/de/bixilon/minosoft/modding/Logger.java @@ -26,7 +26,7 @@ public class Logger { } public void log(LogLevels level, RGBColor color, Object message, Object... format) { - Log.log(level, String.format("[%s] ", modName), color, message, format); + Log.log(level, String.format("[%s] ", this.modName), color, message, format); } public void game(Object message, Object... format) { diff --git a/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java b/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java index 5bc5563e4..d6f30dffc 100644 --- a/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java +++ b/src/main/java/de/bixilon/minosoft/modding/MinosoftMod.java @@ -24,7 +24,7 @@ public abstract class MinosoftMod { private Logger logger; public boolean isEnabled() { - return enabled; + return this.enabled; } public void setEnabled(boolean enabled) { @@ -32,7 +32,7 @@ public abstract class MinosoftMod { } public ModInfo getInfo() { - return info; + return this.info; } public void setInfo(ModInfo info) { @@ -44,11 +44,11 @@ public abstract class MinosoftMod { } public EventManager getEventManager() { - return eventManager; + return this.eventManager; } public Logger getLogger() { - return logger; + return this.logger; } /** diff --git a/src/main/java/de/bixilon/minosoft/modding/channels/DefaultPluginChannels.java b/src/main/java/de/bixilon/minosoft/modding/channels/DefaultPluginChannels.java index 4d43167b6..9d56ef8cf 100644 --- a/src/main/java/de/bixilon/minosoft/modding/channels/DefaultPluginChannels.java +++ b/src/main/java/de/bixilon/minosoft/modding/channels/DefaultPluginChannels.java @@ -38,6 +38,6 @@ public enum DefaultPluginChannels { } public ChangeableIdentifier getChangeableIdentifier() { - return changeableIdentifier; + return this.changeableIdentifier; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/EventInvoker.java b/src/main/java/de/bixilon/minosoft/modding/event/EventInvoker.java index 0c8de01c0..3ad7ddb49 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/EventInvoker.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/EventInvoker.java @@ -28,11 +28,11 @@ public abstract class EventInvoker { } public boolean isIgnoreCancelled() { - return ignoreCancelled; + return this.ignoreCancelled; } public Priorities getPriority() { - return priority; + return this.priority; } public abstract void invoke(ConnectionEvent event); diff --git a/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerCallback.java b/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerCallback.java index ccdf635ff..833bf743e 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerCallback.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerCallback.java @@ -26,7 +26,6 @@ public class EventInvokerCallback extends EventInvoke this.callback = callback; } - // if you need instant fireing support public EventInvokerCallback(Class eventType, InvokerCallback callback) { this(false, callback); @@ -35,14 +34,14 @@ public class EventInvokerCallback extends EventInvoke @SuppressWarnings("unchecked") public void invoke(ConnectionEvent event) { - if (eventType != event.getClass()) { + if (this.eventType != event.getClass()) { return; } - callback.handle((V) event); + this.callback.handle((V) event); } public Class getEventType() { - return eventType; + return this.eventType; } public interface InvokerCallback { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerMethod.java b/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerMethod.java index eab103551..86ad7eebb 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerMethod.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/EventInvokerMethod.java @@ -29,7 +29,7 @@ public class EventInvokerMethod extends EventInvoker { public EventInvokerMethod(boolean ignoreCancelled, Priorities priority, EventListener listener, Method method) { super(ignoreCancelled, priority, listener); this.method = method; - eventType = (Class) method.getParameters()[0].getType(); + this.eventType = (Class) method.getParameters()[0].getType(); } public EventInvokerMethod(EventHandler annotation, EventListener listener, Method method) { @@ -37,24 +37,24 @@ public class EventInvokerMethod extends EventInvoker { } public Method getMethod() { - return method; + return this.method; } public void invoke(ConnectionEvent event) { - if (!method.getParameters()[0].getType().isAssignableFrom(event.getClass())) { + if (!this.method.getParameters()[0].getType().isAssignableFrom(event.getClass())) { return; } - if (!ignoreCancelled && event instanceof CancelableEvent cancelableEvent && cancelableEvent.isCancelled()) { + if (!this.ignoreCancelled && event instanceof CancelableEvent cancelableEvent && cancelableEvent.isCancelled()) { return; } try { - method.invoke(listener, event); + this.method.invoke(this.listener, event); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } } public Class getEventType() { - return eventType; + return this.eventType; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java b/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java index 9fbfebebf..fc8d5a55c 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/EventManager.java @@ -27,7 +27,7 @@ public class EventManager { private final HashMap, HashSet> specificEventListeners = new HashMap<>(); public void registerGlobalListener(EventListener listener) { - globalEventListeners.addAll(getEventMethods(listener)); + this.globalEventListeners.addAll(getEventMethods(listener)); } private HashSet getEventMethods(EventListener listener) { @@ -50,7 +50,7 @@ public class EventManager { } public HashSet getGlobalEventListeners() { - return globalEventListeners; + return this.globalEventListeners; } public void registerConnectionListener(EventListener listener, ServerAddressValidator... addresses) { @@ -58,10 +58,10 @@ public class EventManager { throw new RuntimeException("You must provide at least one address validator or use global events!"); } HashSet serverAddresses = new HashSet<>(Arrays.asList(addresses)); - specificEventListeners.put(serverAddresses, getEventMethods(listener)); + this.specificEventListeners.put(serverAddresses, getEventMethods(listener)); } public HashMap, HashSet> getSpecificEventListeners() { - return specificEventListeners; + return this.specificEventListeners; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java b/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java index 8a202432d..ea8e3c34e 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/address/HostnameValidator.java @@ -36,16 +36,16 @@ public class HostnameValidator implements ServerAddressValidator { } public HashSet getHostnames() { - return hostnames; + return this.hostnames; } @Override public int hashCode() { - return hostnames.hashCode(); + return this.hostnames.hashCode(); } @Override public boolean equals(Object obj) { - return hostnames.equals(obj); + return this.hostnames.equals(obj); } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/address/PortValidator.java b/src/main/java/de/bixilon/minosoft/modding/event/address/PortValidator.java index adf4f2553..0f6355c66 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/address/PortValidator.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/address/PortValidator.java @@ -22,7 +22,7 @@ public class PortValidator implements ServerAddressValidator { public PortValidator(int port) { this.ports = new HashSet<>(); - ports.add(port); + this.ports.add(port); } public PortValidator(HashSet ports) { @@ -31,12 +31,12 @@ public class PortValidator implements ServerAddressValidator { @Override public boolean check(ServerAddress address) { - return ports.contains(address.getPort()); + return this.ports.contains(address.getPort()); } @Override public int hashCode() { - return ports.hashCode(); + return this.ports.hashCode(); } @Override @@ -48,10 +48,10 @@ public class PortValidator implements ServerAddressValidator { return false; } PortValidator their = (PortValidator) obj; - return ports.equals(their.getPorts()); + return this.ports.equals(their.getPorts()); } public HashSet getPorts() { - return ports; + return this.ports; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/address/RegexValidator.java b/src/main/java/de/bixilon/minosoft/modding/event/address/RegexValidator.java index 713898b5b..1e17e39ca 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/address/RegexValidator.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/address/RegexValidator.java @@ -26,20 +26,20 @@ public class RegexValidator implements ServerAddressValidator { @Override public boolean check(ServerAddress address) { - return pattern.matcher(address.getHostname()).find(); + return this.pattern.matcher(address.getHostname()).find(); } @Override public int hashCode() { - return pattern.hashCode(); + return this.pattern.hashCode(); } @Override public boolean equals(Object obj) { - return pattern.equals(obj); + return this.pattern.equals(obj); } public Pattern getPattern() { - return pattern; + return this.pattern; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/address/SimpleAddressValidator.java b/src/main/java/de/bixilon/minosoft/modding/event/address/SimpleAddressValidator.java index 04f4391d7..89ea95bb0 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/address/SimpleAddressValidator.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/address/SimpleAddressValidator.java @@ -28,17 +28,17 @@ public class SimpleAddressValidator implements ServerAddressValidator { } public ServerAddress getAddress() { - return address; + return this.address; } @Override public int hashCode() { - return address.hashCode(); + return this.address.hashCode(); } @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(Object obj) { - return address.equals(obj); + return this.address.equals(obj); } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockActionEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockActionEvent.java index bf5e92472..1e7de3f78 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockActionEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockActionEvent.java @@ -38,10 +38,10 @@ public class BlockActionEvent extends CancelableEvent { } public BlockPosition getPosition() { - return position; + return this.position; } public BlockAction getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockBreakAnimationEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockBreakAnimationEvent.java index 2ff808658..0cb66f019 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockBreakAnimationEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockBreakAnimationEvent.java @@ -39,14 +39,14 @@ public class BlockBreakAnimationEvent extends CancelableEvent { } public int getEntityId() { - return entityId; + return this.entityId; } public BlockPosition getPosition() { - return position; + return this.position; } public byte getStage() { - return stage; + return this.stage; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockChangeEvent.java index acf6fedb8..25c9cb3c3 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockChangeEvent.java @@ -38,10 +38,10 @@ public class BlockChangeEvent extends ConnectionEvent { } public BlockPosition getPosition() { - return position; + return this.position; } public Block getBlock() { - return block; + return this.block; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockEntityMetaDataChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockEntityMetaDataChangeEvent.java index 0f1968638..2bcae139a 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/BlockEntityMetaDataChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/BlockEntityMetaDataChangeEvent.java @@ -40,15 +40,15 @@ public class BlockEntityMetaDataChangeEvent extends ConnectionEvent { } public BlockPosition getPosition() { - return position; + return this.position; } @Nullable public PacketBlockEntityMetadata.BlockEntityActions getAction() { - return action; + return this.action; } public BlockEntityMetaData getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/BossBarChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/BossBarChangeEvent.java index 38b5ff04a..71501f143 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/BossBarChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/BossBarChangeEvent.java @@ -60,7 +60,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public UUID getUUID() { - return uuid; + return this.uuid; } public void setUUID(UUID uuid) { @@ -68,7 +68,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public PacketBossBar.BossBarActions getAction() { - return action; + return this.action; } public void setAction(PacketBossBar.BossBarActions action) { @@ -76,7 +76,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public ChatComponent getTitle() { - return title; + return this.title; } public void setTitle(ChatComponent title) { @@ -84,7 +84,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public float getHealth() { - return health; + return this.health; } public void setHealth(float health) { @@ -92,7 +92,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public PacketBossBar.BossBarColors getColor() { - return color; + return this.color; } public void setColor(PacketBossBar.BossBarColors color) { @@ -100,7 +100,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public PacketBossBar.BossBarDivisions getDivisions() { - return divisions; + return this.divisions; } public void setDivisions(PacketBossBar.BossBarDivisions divisions) { @@ -108,15 +108,15 @@ public class BossBarChangeEvent extends CancelableEvent { } public boolean isDragonBar() { - return isDragonBar; + return this.isDragonBar; } public void setDragonBar(boolean dragonBar) { - isDragonBar = dragonBar; + this.isDragonBar = dragonBar; } public boolean isShouldDarkenSky() { - return shouldDarkenSky; + return this.shouldDarkenSky; } public void setShouldDarkenSky(boolean shouldDarkenSky) { @@ -124,7 +124,7 @@ public class BossBarChangeEvent extends CancelableEvent { } public boolean isCreateFog() { - return createFog; + return this.createFog; } public void setCreateFog(boolean createFog) { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/CancelableEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/CancelableEvent.java index 7f954c181..28d261bc4 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/CancelableEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/CancelableEvent.java @@ -16,14 +16,14 @@ package de.bixilon.minosoft.modding.event.events; import de.bixilon.minosoft.protocol.network.Connection; public abstract class CancelableEvent extends ConnectionEvent { - private boolean cancelled = false; + private boolean cancelled; protected CancelableEvent(Connection connection) { super(connection); } public boolean isCancelled() { - return cancelled; + return this.cancelled; } public void setCancelled(boolean cancelled) { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ChangeGameStateEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ChangeGameStateEvent.java index 23fc5a553..ccff1557d 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ChangeGameStateEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ChangeGameStateEvent.java @@ -36,10 +36,10 @@ public class ChangeGameStateEvent extends CancelableEvent { } public PacketChangeGameState.Reason getReason() { - return reason; + return this.reason; } public float getValue() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageReceivingEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageReceivingEvent.java index da55a407f..8b0f13014 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageReceivingEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageReceivingEvent.java @@ -41,11 +41,11 @@ public class ChatMessageReceivingEvent extends CancelableEvent { } public ChatComponent getMessage() { - return message; + return this.message; } public ChatTextPositions getPosition() { - return position; + return this.position; } /** diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageSendingEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageSendingEvent.java index 5c7133aed..8ae08806e 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageSendingEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ChatMessageSendingEvent.java @@ -24,7 +24,7 @@ public class ChatMessageSendingEvent extends CancelableEvent { } public String getMessage() { - return message; + return this.message; } public void setMessage(String message) { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ChunkDataChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ChunkDataChangeEvent.java index 23dde8dde..2e6d627c8 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ChunkDataChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ChunkDataChangeEvent.java @@ -49,14 +49,14 @@ public class ChunkDataChangeEvent extends ConnectionEvent { } public ChunkLocation getLocation() { - return location; + return this.location; } public Chunk getChunk() { - return chunk; + return this.chunk; } public CompoundTag getHeightMap() { - return heightMap; + return this.heightMap; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/CloseWindowEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/CloseWindowEvent.java index c6925727d..7fd0b1a6e 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/CloseWindowEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/CloseWindowEvent.java @@ -43,11 +43,11 @@ public class CloseWindowEvent extends CancelableEvent { } public byte getWindowId() { - return windowId; + return this.windowId; } public Initiators getInitiator() { - return initiator; + return this.initiator; } public enum Initiators { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/CollectItemAnimationEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/CollectItemAnimationEvent.java index b7350d126..7c2cea7ab 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/CollectItemAnimationEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/CollectItemAnimationEvent.java @@ -39,15 +39,15 @@ public class CollectItemAnimationEvent extends CancelableEvent { } public ItemEntity getItem() { - return item; + return this.item; } public Entity getCollector() { - return collector; + return this.collector; } @MinimumProtocolVersion(versionId = 301) public int getCount() { - return count; + return this.count; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionEvent.java index 34cc76b5d..f2d6a3279 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionEvent.java @@ -23,6 +23,6 @@ public abstract class ConnectionEvent { } public Connection getConnection() { - return connection; + return this.connection; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionStateChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionStateChangeEvent.java index 6bb8ef047..b865c7a15 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionStateChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ConnectionStateChangeEvent.java @@ -32,10 +32,10 @@ public class ConnectionStateChangeEvent extends ConnectionEvent { } public ConnectionStates getPreviousState() { - return previousState; + return this.previousState; } public ConnectionStates getCurrentState() { - return currentState; + return this.currentState; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/DisconnectEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/DisconnectEvent.java index 222178441..d50f74f35 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/DisconnectEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/DisconnectEvent.java @@ -31,6 +31,6 @@ public class DisconnectEvent extends ConnectionEvent { } public ChatComponent getReason() { - return reason; + return this.reason; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/EffectEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/EffectEvent.java index 15bccf984..a0917c51d 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/EffectEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/EffectEvent.java @@ -40,18 +40,18 @@ public class EffectEvent extends CancelableEvent { } public PacketEffect.EffectEffects getEffect() { - return effect; + return this.effect; } public BlockPosition getPosition() { - return position; + return this.position; } public int getData() { - return data; + return this.data; } public boolean isDisableRelativeVolume() { - return disableRelativeVolume; + return this.disableRelativeVolume; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/EntityDespawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/EntityDespawnEvent.java index 8d562b8ed..60f9e96a6 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/EntityDespawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/EntityDespawnEvent.java @@ -31,14 +31,14 @@ public class EntityDespawnEvent extends ConnectionEvent { } public Entity[] getEntities() { - Entity[] ret = new Entity[entityIds.length]; - for (int i = 0; i < entityIds.length; i++) { - ret[i] = getConnection().getPlayer().getWorld().getEntity(entityIds[i]); + Entity[] ret = new Entity[this.entityIds.length]; + for (int i = 0; i < this.entityIds.length; i++) { + ret[i] = getConnection().getPlayer().getWorld().getEntity(this.entityIds[i]); } return ret; } public int[] getEntityIds() { - return entityIds; + return this.entityIds; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/EntityEquipmentChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/EntityEquipmentChangeEvent.java index 57307a971..5e4539600 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/EntityEquipmentChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/EntityEquipmentChangeEvent.java @@ -38,14 +38,14 @@ public class EntityEquipmentChangeEvent extends ConnectionEvent { } public Entity getEntity() { - return getConnection().getPlayer().getWorld().getEntity(entityId); + return getConnection().getPlayer().getWorld().getEntity(this.entityId); } public int getEntityId() { - return entityId; + return this.entityId; } public HashMap getSlots() { - return slots; + return this.slots; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpawnEvent.java index 1d059e328..f56630624 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpawnEvent.java @@ -56,6 +56,6 @@ public class EntitySpawnEvent extends ConnectionEvent { } public Entity getEntity() { - return entity; + return this.entity; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpectateEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpectateEvent.java index 61cd858b0..dec9704f4 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpectateEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/EntitySpectateEvent.java @@ -33,6 +33,6 @@ public class EntitySpectateEvent extends ConnectionEvent { } public int getEntityId() { - return entityId; + return this.entityId; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ExperienceChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ExperienceChangeEvent.java index 78a0a3297..68cc82621 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ExperienceChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ExperienceChangeEvent.java @@ -36,14 +36,14 @@ public class ExperienceChangeEvent extends CancelableEvent { } public float getBar() { - return bar; + return this.bar; } public int getLevel() { - return level; + return this.level; } public int getTotal() { - return total; + return this.total; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java index 3df200836..7a6977398 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/JoinGameEvent.java @@ -70,50 +70,50 @@ public class JoinGameEvent extends CancelableEvent { } public int getEntityId() { - return entityId; + return this.entityId; } public boolean isHardcore() { - return hardcore; + return this.hardcore; } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public Dimension getDimension() { - return dimension; + return this.dimension; } public Difficulties getDifficulty() { - return difficulty; + return this.difficulty; } public int getViewDistance() { - return viewDistance; + return this.viewDistance; } public int getMaxPlayers() { - return maxPlayers; + return this.maxPlayers; } public LevelTypes getLevelType() { - return levelType; + return this.levelType; } public boolean isReducedDebugScreen() { - return reducedDebugScreen; + return this.reducedDebugScreen; } public boolean isEnableRespawnScreen() { - return enableRespawnScreen; + return this.enableRespawnScreen; } public long getHashedSeed() { - return hashedSeed; + return this.hashedSeed; } public HashMap> getDimensions() { - return dimensions; + return this.dimensions; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/LightningBoltSpawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/LightningBoltSpawnEvent.java index e1edaa85d..a1a156877 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/LightningBoltSpawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/LightningBoltSpawnEvent.java @@ -31,6 +31,6 @@ public class LightningBoltSpawnEvent extends ConnectionEvent { } public LightningBolt getEntity() { - return entity; + return this.entity; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/LoginDisconnectEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/LoginDisconnectEvent.java index 9f030ae92..86d868617 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/LoginDisconnectEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/LoginDisconnectEvent.java @@ -31,6 +31,6 @@ public class LoginDisconnectEvent extends ConnectionEvent { } public ChatComponent getReason() { - return reason; + return this.reason; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/LoginPluginMessageRequestEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/LoginPluginMessageRequestEvent.java index 354f69f7b..b9b92d8b6 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/LoginPluginMessageRequestEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/LoginPluginMessageRequestEvent.java @@ -37,14 +37,14 @@ public class LoginPluginMessageRequestEvent extends CancelableEvent { } public int getMessageId() { - return messageId; + return this.messageId; } public String getChannel() { - return channel; + return this.channel; } public InByteBuffer getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/MultiBlockChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/MultiBlockChangeEvent.java index e74541498..42adc014e 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/MultiBlockChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/MultiBlockChangeEvent.java @@ -41,10 +41,10 @@ public class MultiBlockChangeEvent extends ConnectionEvent { } public HashMap getBlocks() { - return blocks; + return this.blocks; } public ChunkLocation getLocation() { - return location; + return this.location; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/MultiSlotChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/MultiSlotChangeEvent.java index 7b9e42677..f9ed3f5e1 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/MultiSlotChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/MultiSlotChangeEvent.java @@ -34,13 +34,13 @@ public class MultiSlotChangeEvent extends ConnectionEvent { } public byte getWindowId() { - return windowId; + return this.windowId; } /** * @return Data array. Array position equals the slot id */ public Slot[] getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/OpenSignEditorEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/OpenSignEditorEvent.java index 2f30254cd..4dc8d40d1 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/OpenSignEditorEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/OpenSignEditorEvent.java @@ -31,6 +31,6 @@ public class OpenSignEditorEvent extends CancelableEvent { } public BlockPosition getPosition() { - return position; + return this.position; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/PacketReceiveEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/PacketReceiveEvent.java index 81f862804..cfe59c1d0 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/PacketReceiveEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/PacketReceiveEvent.java @@ -27,6 +27,6 @@ public class PacketReceiveEvent extends ConnectionEvent { } public ClientboundPacket getPacket() { - return packet; + return this.packet; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/PacketSendEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/PacketSendEvent.java index cf39fcdba..70d21353a 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/PacketSendEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/PacketSendEvent.java @@ -27,6 +27,6 @@ public class PacketSendEvent extends ConnectionEvent { } public ServerboundPacket getPacket() { - return packet; + return this.packet; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ParticleSpawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ParticleSpawnEvent.java index 706df8ac4..211168a58 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ParticleSpawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ParticleSpawnEvent.java @@ -61,15 +61,15 @@ public class ParticleSpawnEvent extends CancelableEvent { } public Particle getParticleType() { - return particleType; + return this.particleType; } public ParticleData getParticleData() { - return particleData; + return this.particleData; } public boolean isLongDistance() { - return longDistance; + return this.longDistance; } public void setLongDistance(boolean longDistance) { @@ -77,11 +77,11 @@ public class ParticleSpawnEvent extends CancelableEvent { } public Location getLocation() { - return location; + return this.location; } public float getOffsetX() { - return offsetX; + return this.offsetX; } public void setOffsetX(float offsetX) { @@ -89,7 +89,7 @@ public class ParticleSpawnEvent extends CancelableEvent { } public float getOffsetY() { - return offsetY; + return this.offsetY; } public void setOffsetY(float offsetY) { @@ -97,7 +97,7 @@ public class ParticleSpawnEvent extends CancelableEvent { } public float getOffsetZ() { - return offsetZ; + return this.offsetZ; } public void setOffsetZ(float offsetZ) { @@ -105,7 +105,7 @@ public class ParticleSpawnEvent extends CancelableEvent { } public int getCount() { - return count; + return this.count; } public void setCount(int count) { diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListInfoChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListInfoChangeEvent.java index 3bcf77bfb..ce910ddf5 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListInfoChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListInfoChangeEvent.java @@ -34,10 +34,10 @@ public class PlayerListInfoChangeEvent extends CancelableEvent { } public ChatComponent getHeader() { - return header; + return this.header; } public ChatComponent getFooter() { - return footer; + return this.footer; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListItemChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListItemChangeEvent.java index 2e37b9fd4..d39e37fd9 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListItemChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/PlayerListItemChangeEvent.java @@ -33,6 +33,6 @@ public class PlayerListItemChangeEvent extends CancelableEvent { } public ArrayList getPlayerList() { - return playerList; + return this.playerList; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/PluginMessageReceiveEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/PluginMessageReceiveEvent.java index 7e9a6f6bc..e88195c4a 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/PluginMessageReceiveEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/PluginMessageReceiveEvent.java @@ -34,10 +34,10 @@ public class PluginMessageReceiveEvent extends CancelableEvent { } public String getChannel() { - return channel; + return this.channel; } public InByteBuffer getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ResourcePackChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ResourcePackChangeEvent.java index 6ae871f6b..f53095814 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ResourcePackChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ResourcePackChangeEvent.java @@ -36,7 +36,7 @@ public class ResourcePackChangeEvent extends CancelableEvent { } public String getUrl() { - return url; + return this.url; } public void setUrl(String url) { @@ -45,7 +45,7 @@ public class ResourcePackChangeEvent extends CancelableEvent { @MaximumProtocolVersion(versionId = 204) public String getHash() { - return hash; + return this.hash; } @MaximumProtocolVersion(versionId = 204) diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java index 799e0813d..ae4b5e090 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/RespawnEvent.java @@ -43,18 +43,18 @@ public class RespawnEvent extends CancelableEvent { } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public Dimension getDimension() { - return dimension; + return this.dimension; } public Difficulties getDifficulty() { - return difficulty; + return this.difficulty; } public LevelTypes getLevelType() { - return levelType; + return this.levelType; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/ServerListPingArriveEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/ServerListPingArriveEvent.java index be8095f6e..9963fd1c8 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/ServerListPingArriveEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/ServerListPingArriveEvent.java @@ -31,6 +31,6 @@ public class ServerListPingArriveEvent extends ConnectionEvent { @Nullable public ServerListPing getServerListPing() { - return serverListPing; + return this.serverListPing; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/SingleSlotChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/SingleSlotChangeEvent.java index b85d15308..bc4064d8a 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/SingleSlotChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/SingleSlotChangeEvent.java @@ -37,14 +37,14 @@ public class SingleSlotChangeEvent extends ConnectionEvent { } public byte getWindowId() { - return windowId; + return this.windowId; } public short getSlotId() { - return slotId; + return this.slotId; } public Slot getSlot() { - return slot; + return this.slot; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/SpawnLocationChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/SpawnLocationChangeEvent.java index c953b7acd..a09241c50 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/SpawnLocationChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/SpawnLocationChangeEvent.java @@ -31,6 +31,6 @@ public class SpawnLocationChangeEvent extends ConnectionEvent { } public BlockPosition getSpawnLocation() { - return location; + return this.location; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/StatusPongEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/StatusPongEvent.java index f9d86066c..4ccf5d427 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/StatusPongEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/StatusPongEvent.java @@ -33,6 +33,6 @@ public class StatusPongEvent extends ConnectionEvent { } public long getPongId() { - return pongId; + return this.pongId; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/StatusResponseEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/StatusResponseEvent.java index b460bf10b..f5d7337b1 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/StatusResponseEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/StatusResponseEvent.java @@ -34,6 +34,6 @@ public class StatusResponseEvent extends ConnectionEvent { } public ServerListPing getResponse() { - return response; + return this.response; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java index 30ff0d14c..e863b12c0 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/TimeChangeEvent.java @@ -33,10 +33,10 @@ public class TimeChangeEvent extends CancelableEvent { } public long getWorldAge() { - return worldAge; + return this.worldAge; } public long getTimeOfDay() { - return timeOfDay; + return this.timeOfDay; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java index 56d6aa580..82f38d9e4 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java @@ -48,26 +48,26 @@ public class TitleChangeEvent extends CancelableEvent { } public PacketTitle.TitleActions getAction() { - return action; + return this.action; } public ChatComponent getText() { - return text; + return this.text; } public ChatComponent getSubText() { - return subText; + return this.subText; } public int getFadeInTime() { - return fadeInTime; + return this.fadeInTime; } public int getStayTime() { - return stayTime; + return this.stayTime; } public int getFadeOutTime() { - return fadeOutTime; + return this.fadeOutTime; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/UpdateHealthEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/UpdateHealthEvent.java index c938bed1d..0ca1c24b7 100644 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/UpdateHealthEvent.java +++ b/src/main/java/de/bixilon/minosoft/modding/event/events/UpdateHealthEvent.java @@ -36,14 +36,14 @@ public class UpdateHealthEvent extends ConnectionEvent { } public float getHealth() { - return health; + return this.health; } public int getFood() { - return food; + return this.food; } public float getSaturation() { - return saturation; + return this.saturation; } } diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java index 8cdc60000..0347d96e5 100644 --- a/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/LoadingInfo.java @@ -24,7 +24,7 @@ public class LoadingInfo { } public Priorities getLoadingPriority() { - return loadingPriority; + return this.loadingPriority; } public void setLoadingPriority(Priorities loadingPriority) { diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/ModDependency.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModDependency.java index 8f0a93f2e..efb0b3b98 100644 --- a/src/main/java/de/bixilon/minosoft/modding/loading/ModDependency.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModDependency.java @@ -60,26 +60,26 @@ public class ModDependency { } public UUID getUUID() { - return uuid; + return this.uuid; } public Integer getVersionMinimum() { - return versionMinimum; + return this.versionMinimum; } public Integer getVersionMaximum() { - return versionMaximum; + return this.versionMaximum; } @Override public int hashCode() { - int result = uuid.hashCode(); - if (versionMinimum != null && versionMinimum > 0) { - result *= versionMinimum; + int result = this.uuid.hashCode(); + if (this.versionMinimum != null && this.versionMinimum > 0) { + result *= this.versionMinimum; } - if (versionMaximum != null && versionMaximum > 0) { - result *= versionMaximum; + if (this.versionMaximum != null && this.versionMaximum > 0) { + result *= this.versionMaximum; } return result; } @@ -98,12 +98,12 @@ public class ModDependency { @Override public String toString() { - String result = uuid.toString(); - if (versionMinimum != null) { - result += " >" + versionMinimum; + String result = this.uuid.toString(); + if (this.versionMinimum != null) { + result += " >" + this.versionMinimum; } - if (versionMaximum != null) { - result += " <" + versionMaximum; + if (this.versionMaximum != null) { + result += " <" + this.versionMaximum; } return result; } diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java index d42d9520a..24ccba3dd 100644 --- a/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModInfo.java @@ -40,9 +40,9 @@ public class ModInfo { this.authors = new String[authors.size()]; AtomicInteger i = new AtomicInteger(); authors.forEach((authorElement) -> this.authors[i.getAndIncrement()] = authorElement.getAsString()); - moddingAPIVersion = json.get("moddingAPIVersion").getAsInt(); - if (moddingAPIVersion > ModLoader.CURRENT_MODDING_API_VERSION) { - throw new ModLoadingException(String.format("Mod was written with for a newer version of minosoft (moddingAPIVersion=%d, expected=%d)", moddingAPIVersion, ModLoader.CURRENT_MODDING_API_VERSION)); + this.moddingAPIVersion = json.get("moddingAPIVersion").getAsInt(); + if (this.moddingAPIVersion > ModLoader.CURRENT_MODDING_API_VERSION) { + throw new ModLoadingException(String.format("Mod was written with for a newer version of minosoft (moddingAPIVersion=%d, expected=%d)", this.moddingAPIVersion, ModLoader.CURRENT_MODDING_API_VERSION)); } this.identifier = json.get("identifier").getAsString(); this.mainClass = json.get("mainClass").getAsString(); @@ -56,58 +56,58 @@ public class ModInfo { if (json.has("dependencies")) { JsonObject dependencies = json.getAsJsonObject("dependencies"); if (dependencies.has("hard")) { - hardDependencies.addAll(ModDependency.serializeDependencyArray(dependencies.getAsJsonArray("hard"))); + this.hardDependencies.addAll(ModDependency.serializeDependencyArray(dependencies.getAsJsonArray("hard"))); } if (dependencies.has("soft")) { - softDependencies.addAll(ModDependency.serializeDependencyArray(dependencies.getAsJsonArray("soft"))); + this.softDependencies.addAll(ModDependency.serializeDependencyArray(dependencies.getAsJsonArray("soft"))); } } } public String[] getAuthors() { - return authors; + return this.authors; } public String getIdentifier() { - return identifier; + return this.identifier; } public String getMainClass() { - return mainClass; + return this.mainClass; } public LoadingInfo getLoadingInfo() { - return loadingInfo; + return this.loadingInfo; } @Deprecated public UUID getUUID() { - return modVersionIdentifier.getUUID(); + return this.modVersionIdentifier.getUUID(); } @Deprecated public int getVersionId() { - return modVersionIdentifier.getVersionId(); + return this.modVersionIdentifier.getVersionId(); } public ModVersionIdentifier getModIdentifier() { - return modVersionIdentifier; + return this.modVersionIdentifier; } public String getVersionName() { - return versionName; + return this.versionName; } public String getName() { - return name; + return this.name; } public HashSet getHardDependencies() { - return hardDependencies; + return this.hardDependencies; } public HashSet getSoftDependencies() { - return softDependencies; + return this.softDependencies; } @Override diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java index cd4ecf327..58c881675 100644 --- a/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java @@ -35,8 +35,7 @@ import java.util.zip.ZipFile; public class ModLoader { public static final int CURRENT_MODDING_API_VERSION = 1; - public static final ConcurrentHashMap mods = new ConcurrentHashMap<>(); - + public static final ConcurrentHashMap MOD_MAP = new ConcurrentHashMap<>(); public static void loadMods(CountUpAndDownLatch progress) throws Exception { final long startTime = System.currentTimeMillis(); @@ -59,41 +58,40 @@ public class ModLoader { executor.execute(() -> { MinosoftMod mod = loadMod(progress, modFile); if (mod != null) { - mods.put(mod.getInfo().getModIdentifier().getUUID(), mod); + MOD_MAP.put(mod.getInfo().getModIdentifier().getUUID(), mod); } latch.countDown(); }); } latch.await(); - if (mods.size() == 0) { + if (MOD_MAP.isEmpty()) { Log.info("No mods to load."); return; } - progress.addCount(mods.size() * ModPhases.values().length); // count * mod phases - + progress.addCount(MOD_MAP.size() * ModPhases.values().length); // count * mod phases // check if all dependencies are available modLoop: - for (Map.Entry modEntry : mods.entrySet()) { + for (Map.Entry modEntry : MOD_MAP.entrySet()) { ModInfo currentModInfo = modEntry.getValue().getInfo(); for (ModDependency dependency : currentModInfo.getHardDependencies()) { ModInfo info = getModInfoByUUID(dependency.getUUID()); if (info == null) { Log.warn("Could not satisfy mod dependency for mod %s (Requires %s)", modEntry.getValue().getInfo(), dependency.getUUID()); - mods.remove(modEntry.getKey()); + MOD_MAP.remove(modEntry.getKey()); continue modLoop; } if (dependency.getVersionMinimum() < info.getModIdentifier().getVersionId()) { Log.warn("Could not satisfy mod dependency for mod %s (Requires %s version > %d)", modEntry.getValue().getInfo(), dependency.getUUID(), dependency.getVersionMinimum()); - mods.remove(modEntry.getKey()); + MOD_MAP.remove(modEntry.getKey()); continue modLoop; } if (dependency.getVersionMaximum() > info.getModIdentifier().getVersionId()) { Log.warn("Could not satisfy mod dependency for mod %s (Requires %s version < %d)", modEntry.getValue().getInfo(), dependency.getUUID(), dependency.getVersionMaximum()); - mods.remove(modEntry.getKey()); + MOD_MAP.remove(modEntry.getKey()); continue modLoop; } } @@ -114,16 +112,15 @@ public class ModLoader { } - final TreeMap sortedModMap = new TreeMap<>((mod1UUID, mod2UUID) -> { // ToDo: Load dependencies first if (mod1UUID == null || mod2UUID == null) { return 0; } - return -(getLoadingPriorityOrDefault(mods.get(mod2UUID).getInfo()).ordinal() - getLoadingPriorityOrDefault(mods.get(mod1UUID).getInfo()).ordinal()); + return -(getLoadingPriorityOrDefault(MOD_MAP.get(mod2UUID).getInfo()).ordinal() - getLoadingPriorityOrDefault(MOD_MAP.get(mod1UUID).getInfo()).ordinal()); }); - sortedModMap.putAll(mods); + sortedModMap.putAll(MOD_MAP); for (ModPhases phase : ModPhases.values()) { Log.verbose(String.format("Mod loading phase changed: %s", phase)); @@ -153,9 +150,9 @@ public class ModLoader { for (Map.Entry entry : sortedModMap.entrySet()) { if (entry.getValue().isEnabled()) { - Minosoft.eventManagers.add(entry.getValue().getEventManager()); + Minosoft.EVENT_MANAGERS.add(entry.getValue().getEventManager()); } else { - mods.remove(entry.getKey()); + MOD_MAP.remove(entry.getKey()); } } Log.info("Loading of %d mods finished in %dms!", sortedModMap.size(), (System.currentTimeMillis() - startTime)); @@ -197,12 +194,12 @@ public class ModLoader { } public static boolean isModLoaded(ModInfo info) { - return mods.containsKey(info.getModIdentifier().getUUID()); + return MOD_MAP.containsKey(info.getModIdentifier().getUUID()); } @Nullable public static MinosoftMod getModByUUID(UUID uuid) { - return mods.get(uuid); + return MOD_MAP.get(uuid); } @Nullable diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/Priorities.java b/src/main/java/de/bixilon/minosoft/modding/loading/Priorities.java index a32b9af2a..adc1f8042 100644 --- a/src/main/java/de/bixilon/minosoft/modding/loading/Priorities.java +++ b/src/main/java/de/bixilon/minosoft/modding/loading/Priorities.java @@ -21,7 +21,13 @@ public enum Priorities { HIGHEST, ULTRA_HIGH; // this priority is even higher. Do not use in normal case! + private static final Priorities[] PRIORITIES = values(); + + public static Priorities byId(int id) { + return PRIORITIES[id]; + } + public static Priorities getHigherPriority(Priorities priority) { - return Priorities.values()[priority.ordinal() + 1]; + return byId(priority.ordinal() + 1); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java index d1c347ff3..ae2c59d13 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java @@ -44,28 +44,29 @@ import java.util.concurrent.atomic.AtomicBoolean; public class Connection { public static int lastConnectionId; - final Network network = Network.getNetworkInstance(this); - final PacketHandler handler = new PacketHandler(this); - final PacketSender sender = new PacketSender(this); - final LinkedBlockingQueue handlingQueue = new LinkedBlockingQueue<>(); - final VelocityHandler velocityHandler = new VelocityHandler(this); - final LinkedList eventListeners = new LinkedList<>(); - final int connectionId; - final Player player; - final String hostname; - LinkedList addresses; - int desiredVersionNumber = -1; - ServerAddress address; - Thread handleThread; - Version version = Versions.LOWEST_VERSION_SUPPORTED; // default - final VersionMapping customMapping = new VersionMapping(version); - ConnectionStates state = ConnectionStates.DISCONNECTED; - ConnectionReasons reason; - ConnectionReasons nextReason; - public ConnectionPing connectionStatusPing; - ServerListPing lastPing; - Exception lastException; + private final Network network = Network.getNetworkInstance(this); + private final PacketHandler handler = new PacketHandler(this); + private final PacketSender sender = new PacketSender(this); + private final LinkedBlockingQueue handlingQueue = new LinkedBlockingQueue<>(); + private final VelocityHandler velocityHandler = new VelocityHandler(this); + private final LinkedList eventListeners = new LinkedList<>(); + private final int connectionId; + private final Player player; + private final String hostname; + private final Recipes recipes = new Recipes(); + private LinkedList addresses; + private int desiredVersionNumber = -1; + private ServerAddress address; + private Thread handleThread; + private Version version = Versions.LOWEST_VERSION_SUPPORTED; // default + private final VersionMapping customMapping = new VersionMapping(this.version); + private ConnectionStates state = ConnectionStates.DISCONNECTED; + private ConnectionReasons reason; + private ConnectionReasons nextReason; + private ServerListPing lastPing; + private Exception lastException; private CommandRootNode commandRootNode; + private ConnectionPing connectionStatusPing; public Connection(int connectionId, String hostname, Player player) { this.connectionId = connectionId; @@ -74,31 +75,31 @@ public class Connection { } public void resolve(ConnectionReasons reason, int versionId) { - lastException = null; + this.lastException = null; this.desiredVersionNumber = versionId; Thread resolveThread = new Thread(() -> { - if (desiredVersionNumber != -1) { - setVersion(Versions.getVersionById(desiredVersionNumber)); + if (this.desiredVersionNumber != -1) { + setVersion(Versions.getVersionById(this.desiredVersionNumber)); } - if (addresses == null) { + if (this.addresses == null) { try { - addresses = DNSUtil.getServerAddresses(hostname); + this.addresses = DNSUtil.getServerAddresses(this.hostname); } catch (TextParseException e) { setConnectionState(ConnectionStates.FAILED_NO_RETRY); - lastException = e; + this.lastException = e; e.printStackTrace(); return; } } - address = addresses.getFirst(); + this.address = this.addresses.getFirst(); this.nextReason = reason; - Log.info(String.format("Trying to connect to %s", address)); + Log.info(String.format("Trying to connect to %s", this.address)); if (versionId != -1) { setVersion(Versions.getVersionById(versionId)); } - resolve(address); - }, String.format("%d/Resolving", connectionId)); + resolve(this.address); + }, String.format("%d/Resolving", this.connectionId)); resolveThread.start(); } @@ -107,17 +108,17 @@ public class Connection { } public void resolve(ServerAddress address) { - reason = ConnectionReasons.DNS; - network.connect(address); + this.reason = ConnectionReasons.DNS; + this.network.connect(address); } private void connect() { - Log.info(String.format("Connecting to server: %s", address)); - if (reason == null || reason == ConnectionReasons.DNS) { + Log.info(String.format("Connecting to server: %s", this.address)); + if (this.reason == null || this.reason == ConnectionReasons.DNS) { // first get version, then login - reason = ConnectionReasons.GET_VERSION; + this.reason = ConnectionReasons.GET_VERSION; } - network.connect(address); + this.network.connect(this.address); } public void connect(ServerAddress address, Version version) { @@ -125,19 +126,19 @@ public class Connection { this.reason = ConnectionReasons.CONNECT; setVersion(version); Log.info(String.format("Connecting to server: %s", address)); - network.connect(address); + this.network.connect(address); } public ServerAddress getAddress() { - return address; + return this.address; } public LinkedList getAvailableAddresses() { - return addresses; + return this.addresses; } public Version getVersion() { - return version; + return this.version; } public void setVersion(Version version) { @@ -148,12 +149,12 @@ public class Connection { this.version = version; try { Versions.loadVersionMappings(version); - customMapping.setVersion(version); + this.customMapping.setVersion(version); this.customMapping.setParentMapping(version.getMapping()); } catch (Exception e) { Log.printException(e, LogLevels.DEBUG); Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version)); - lastException = new MappingsLoadingException("Mappings could not be loaded", e); + this.lastException = new MappingsLoadingException("Mappings could not be loaded", e); setConnectionState(ConnectionStates.FAILED_NO_RETRY); } } @@ -163,17 +164,17 @@ public class Connection { } public void handle(ClientboundPacket p) { - handlingQueue.add(p); + this.handlingQueue.add(p); } public void disconnect() { setConnectionState(ConnectionStates.DISCONNECTING); - network.disconnect(); - handleThread.interrupt(); + this.network.disconnect(); + this.handleThread.interrupt(); } public Player getPlayer() { - return player; + return this.player; } public void sendPacket(ServerboundPacket packet) { @@ -181,7 +182,7 @@ public class Connection { if (fireEvent(event)) { return; } - network.sendPacket(packet); + this.network.sendPacket(packet); } /** @@ -189,8 +190,8 @@ public class Connection { * @return if the event has been cancelled or not */ public boolean fireEvent(ConnectionEvent connectionEvent) { - Minosoft.eventManagers.forEach((eventManager -> eventManager.getGlobalEventListeners().forEach((method) -> method.invoke(connectionEvent)))); - eventListeners.forEach((method -> method.invoke(connectionEvent))); + Minosoft.EVENT_MANAGERS.forEach((eventManager -> eventManager.getGlobalEventListeners().forEach((method) -> method.invoke(connectionEvent)))); + this.eventListeners.forEach((method -> method.invoke(connectionEvent))); if (connectionEvent instanceof CancelableEvent cancelableEvent) { return cancelableEvent.isCancelled(); } @@ -198,11 +199,11 @@ public class Connection { } private void startHandlingThread() { - handleThread = new Thread(() -> { + this.handleThread = new Thread(() -> { while (isConnected()) { ClientboundPacket packet; try { - packet = handlingQueue.take(); + packet = this.handlingQueue.take(); } catch (InterruptedException e) { continue; } @@ -217,30 +218,34 @@ public class Connection { Log.printException(e, LogLevels.PROTOCOL); } } - }, String.format("%d/Handling", connectionId)); - handleThread.start(); + }, String.format("%d/Handling", this.connectionId)); + this.handleThread.start(); } public boolean isConnected() { - return state != ConnectionStates.FAILED && state != ConnectionStates.FAILED_NO_RETRY && state != ConnectionStates.DISCONNECTING && state != ConnectionStates.DISCONNECTED && state != ConnectionStates.CONNECTING; + return this.state != ConnectionStates.FAILED && this.state != ConnectionStates.FAILED_NO_RETRY && this.state != ConnectionStates.DISCONNECTING && this.state != ConnectionStates.DISCONNECTED && this.state != ConnectionStates.CONNECTING; } public PacketSender getSender() { - return sender; + return this.sender; } public ConnectionPing getConnectionStatusPing() { - return connectionStatusPing; + return this.connectionStatusPing; + } + + public void setConnectionStatusPing(ConnectionPing connectionStatusPing) { + this.connectionStatusPing = connectionStatusPing; } public VersionMapping getMapping() { - return customMapping; + return this.customMapping; } public int getPacketCommand(Packets.Serverbound packet) { Integer command = null; if (getReason() == ConnectionReasons.CONNECT) { - command = version.getCommandByPacket(packet); + command = this.version.getCommandByPacket(packet); } if (command == null) { return Protocol.getPacketCommand(packet); @@ -248,18 +253,18 @@ public class Connection { return command; } - public ConnectionReasons getReason() { - return reason; - } - public void setReason(ConnectionReasons reason) { this.reason = reason; } + public ConnectionReasons getReason() { + return this.reason; + } + public Packets.Clientbound getPacketByCommand(ConnectionStates state, int command) { Packets.Clientbound packet = null; if (getReason() == ConnectionReasons.CONNECT) { - packet = version.getPacketByCommand(state, command); + packet = this.version.getPacketByCommand(state, command); } if (packet == null) { return Protocol.getPacketByCommand(state, command); @@ -268,15 +273,15 @@ public class Connection { } public VelocityHandler getVelocityHandler() { - return velocityHandler; + return this.velocityHandler; } public int getConnectionId() { - return connectionId; + return this.connectionId; } public ConnectionStates getConnectionState() { - return state; + return this.state; } public void setConnectionState(ConnectionStates state) { @@ -289,18 +294,18 @@ public class Connection { switch (state) { case HANDSHAKING -> { // get and add all events, that are connection specific - Minosoft.eventManagers.forEach((eventManagers -> eventManagers.getSpecificEventListeners().forEach((serverAddresses, listener) -> { + Minosoft.EVENT_MANAGERS.forEach((eventManagers -> eventManagers.getSpecificEventListeners().forEach((serverAddresses, listener) -> { AtomicBoolean isValid = new AtomicBoolean(false); serverAddresses.forEach((validator) -> { - if (validator.check(address)) { + if (validator.check(this.address)) { isValid.set(true); } }); if (isValid.get()) { - eventListeners.addAll(listener); + this.eventListeners.addAll(listener); } }))); - eventListeners.sort((a, b) -> { + this.eventListeners.sort((a, b) -> { if (a == null || b == null) { return 0; } @@ -308,28 +313,28 @@ public class Connection { }); // connection established, starting threads and logging in startHandlingThread(); - ConnectionStates next = ((reason == ConnectionReasons.CONNECT) ? ConnectionStates.LOGIN : ConnectionStates.STATUS); - if (reason == ConnectionReasons.DNS) { + ConnectionStates next = ((this.reason == ConnectionReasons.CONNECT) ? ConnectionStates.LOGIN : ConnectionStates.STATUS); + if (this.reason == ConnectionReasons.DNS) { // valid hostname found - reason = nextReason; - Log.info(String.format("Connection to %s seems to be okay, connecting...", address)); + this.reason = this.nextReason; + Log.info(String.format("Connection to %s seems to be okay, connecting...", this.address)); } - network.sendPacket(new PacketHandshake(address, next, (next == ConnectionStates.STATUS) ? -1 : getVersion().getProtocolId())); + this.network.sendPacket(new PacketHandshake(this.address, next, (next == ConnectionStates.STATUS) ? -1 : getVersion().getProtocolId())); // after sending it, switch to next state setConnectionState(next); } case STATUS -> { // send status request - network.sendPacket(new PacketStatusRequest()); + this.network.sendPacket(new PacketStatusRequest()); } - case LOGIN -> network.sendPacket(new PacketLoginStart(player)); + case LOGIN -> this.network.sendPacket(new PacketLoginStart(this.player)); case DISCONNECTED -> { - if (reason == ConnectionReasons.GET_VERSION) { + if (this.reason == ConnectionReasons.GET_VERSION) { setReason(ConnectionReasons.CONNECT); connect(); } else { // unregister all custom recipes - Recipes.removeCustomRecipes(); + this.recipes.removeCustomRecipes(); } } case FAILED -> { @@ -338,12 +343,12 @@ public class Connection { // connection was good, do not reconnect break; } - int nextIndex = addresses.indexOf(address) + 1; - if (addresses.size() > nextIndex) { - ServerAddress nextAddress = addresses.get(nextIndex); - Log.warn(String.format("Could not connect to %s, trying next hostname: %s", address, nextAddress)); + int nextIndex = this.addresses.indexOf(this.address) + 1; + if (this.addresses.size() > nextIndex) { + ServerAddress nextAddress = this.addresses.get(nextIndex); + Log.warn(String.format("Could not connect to %s, trying next hostname: %s", this.address, nextAddress)); this.address = nextAddress; - resolve(address); + resolve(this.address); } else { // no connection and no servers available anymore... sorry, but you can not play today :( handlePingCallbacks(null); @@ -355,10 +360,6 @@ public class Connection { fireEvent(new ConnectionStateChangeEvent(this, previousState, state)); } - public int getDesiredVersionNumber() { - return desiredVersionNumber; - } - public void setDesiredVersionNumber(int desiredVersionNumber) { this.desiredVersionNumber = desiredVersionNumber; } @@ -368,25 +369,37 @@ public class Connection { fireEvent(new ServerListPingArriveEvent(this, ping)); } + public int getDesiredVersionNumber() { + return this.desiredVersionNumber; + } + public void registerEvent(EventInvoker method) { - eventListeners.add(method); + this.eventListeners.add(method); if (method.getEventType() == ServerListPingArriveEvent.class) { - if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || lastPing != null) { + if (getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY || this.lastPing != null) { // ping done - method.invoke(new ServerListPingArriveEvent(this, lastPing)); + method.invoke(new ServerListPingArriveEvent(this, this.lastPing)); } } } public Throwable getLastConnectionException() { - return (lastException != null) ? lastException : network.getLastException(); + return (this.lastException != null) ? this.lastException : this.network.getLastException(); } public ServerListPing getLastPing() { - return lastPing; + return this.lastPing; + } + + public Recipes getRecipes() { + return this.recipes; } public void setCommandRootNode(CommandRootNode commandRootNode) { this.commandRootNode = commandRootNode; } + + public CommandRootNode getCommandRootNode() { + return this.commandRootNode; + } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java index 8d1196e7e..7dcc9901a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java @@ -57,9 +57,9 @@ public class SocketNetwork implements Network { @Override public void connect(ServerAddress address) { - lastException = null; + this.lastException = null; // check if we are already connected or try to connect - if (connection.isConnected() || connection.getConnectionState() == ConnectionStates.CONNECTING) { + if (this.connection.isConnected() || this.connection.getConnectionState() == ConnectionStates.CONNECTING) { return; } // wait for data or send until it should disconnect @@ -69,41 +69,41 @@ public class SocketNetwork implements Network { // everything sent for now, waiting for data // add to queue // Could not connect - socketRThread = new Thread(() -> { + this.socketRThread = new Thread(() -> { try { - socket = new Socket(); - socket.setSoTimeout(ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); - socket.connect(new InetSocketAddress(address.getHostname(), address.getPort()), ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); + this.socket = new Socket(); + this.socket.setSoTimeout(ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); + this.socket.connect(new InetSocketAddress(address.getHostname(), address.getPort()), ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); // connected, use minecraft timeout - socket.setSoTimeout(ProtocolDefinition.SOCKET_TIMEOUT); - connection.setConnectionState(ConnectionStates.HANDSHAKING); - socket.setKeepAlive(true); - outputStream = socket.getOutputStream(); - inputStream = socket.getInputStream(); + this.socket.setSoTimeout(ProtocolDefinition.SOCKET_TIMEOUT); + this.connection.setConnectionState(ConnectionStates.HANDSHAKING); + this.socket.setKeepAlive(true); + this.outputStream = this.socket.getOutputStream(); + this.inputStream = this.socket.getInputStream(); - socketRThread.setName(String.format("%d/SocketR", connection.getConnectionId())); + this.socketRThread.setName(String.format("%d/SocketR", this.connection.getConnectionId())); - socketSThread = new Thread(() -> { + this.socketSThread = new Thread(() -> { try { - while (connection.getConnectionState() != ConnectionStates.DISCONNECTING) { + while (this.connection.getConnectionState() != ConnectionStates.DISCONNECTING) { // wait for data or send until it should disconnect // check if still connected - if (!socket.isConnected() || socket.isClosed()) { + if (!this.socket.isConnected() || this.socket.isClosed()) { break; } - ServerboundPacket packet = queue.take(); + ServerboundPacket packet = this.queue.take(); packet.log(); - queue.remove(packet); - byte[] data = packet.write(connection).toByteArray(); - if (compressionThreshold >= 0) { + this.queue.remove(packet); + byte[] data = packet.write(this.connection).toByteArray(); + if (this.compressionThreshold >= 0) { // compression is enabled // check if there is a need to compress it and if so, do it! - OutByteBuffer outRawBuffer = new OutByteBuffer(connection); - if (data.length >= compressionThreshold) { + OutByteBuffer outRawBuffer = new OutByteBuffer(this.connection); + if (data.length >= this.compressionThreshold) { // compress it - OutByteBuffer lengthPrefixedBuffer = new OutByteBuffer(connection); + OutByteBuffer lengthPrefixedBuffer = new OutByteBuffer(this.connection); byte[] compressed = Util.compress(data); lengthPrefixedBuffer.writeVarInt(data.length); // uncompressed length lengthPrefixedBuffer.writeBytes(compressed); @@ -117,32 +117,32 @@ public class SocketNetwork implements Network { data = outRawBuffer.toByteArray(); } else { // append packet length - OutByteBuffer bufferWithLengthPrefix = new OutByteBuffer(connection); + OutByteBuffer bufferWithLengthPrefix = new OutByteBuffer(this.connection); bufferWithLengthPrefix.writeVarInt(data.length); bufferWithLengthPrefix.writeBytes(data); data = bufferWithLengthPrefix.toByteArray(); } - outputStream.write(data); - outputStream.flush(); + this.outputStream.write(data); + this.outputStream.flush(); if (packet instanceof PacketEncryptionResponse packetEncryptionResponse) { // enable encryption enableEncryption(packetEncryptionResponse.getSecretKey()); // wake up other thread - socketRThread.interrupt(); + this.socketRThread.interrupt(); } } } catch (IOException | InterruptedException ignored) { } - }, String.format("%d/SocketS", connection.getConnectionId())); - socketSThread.start(); + }, String.format("%d/SocketS", this.connection.getConnectionId())); + this.socketSThread.start(); - while (connection.getConnectionState() != ConnectionStates.DISCONNECTING) { + while (this.connection.getConnectionState() != ConnectionStates.DISCONNECTING) { // wait for data or send until it should disconnect // first send, then receive // check if still connected - if (!socket.isConnected() || socket.isClosed()) { + if (!this.socket.isConnected() || this.socket.isClosed()) { break; } @@ -151,7 +151,7 @@ public class SocketNetwork implements Network { int length = 0; int read; do { - read = inputStream.read(); + read = this.inputStream.read(); if (read == -1) { disconnect(); return; @@ -166,15 +166,15 @@ public class SocketNetwork implements Network { } while ((read & 0x80) != 0); if (length > ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE) { Log.protocol(String.format("Server sent us a to big packet (%d bytes > %d bytes)", length, ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE)); - inputStream.skip(length); + this.inputStream.skip(length); continue; } - byte[] data = inputStream.readNBytes(length); + byte[] data = this.inputStream.readNBytes(length); - if (compressionThreshold >= 0) { + if (this.compressionThreshold >= 0) { // compression is enabled // check if there is a need to decompress it and if so, do it! - InByteBuffer rawBuffer = new InByteBuffer(data, connection); + InByteBuffer rawBuffer = new InByteBuffer(data, this.connection); int packetSize = rawBuffer.readVarInt(); byte[] left = rawBuffer.readBytesLeft(); if (packetSize == 0) { @@ -182,23 +182,23 @@ public class SocketNetwork implements Network { data = left; } else { // need to decompress data - data = Util.decompress(left, connection).readBytesLeft(); + data = Util.decompress(left, this.connection).readBytesLeft(); } } - InPacketBuffer inPacketBuffer = new InPacketBuffer(data, connection); + InPacketBuffer inPacketBuffer = new InPacketBuffer(data, this.connection); Packets.Clientbound packet = null; try { - packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand()); + packet = this.connection.getPacketByCommand(this.connection.getConnectionState(), inPacketBuffer.getCommand()); if (packet == null) { disconnect(); - lastException = new UnknownPacketException(String.format("Server sent us an unknown packet (id=0x%x, length=%d, data=%s)", inPacketBuffer.getCommand(), length, inPacketBuffer.getBase64())); - throw lastException; + this.lastException = new UnknownPacketException(String.format("Server sent us an unknown packet (id=0x%x, length=%d, data=%s)", inPacketBuffer.getCommand(), length, inPacketBuffer.getBase64())); + throw this.lastException; } Class clazz = packet.getClazz(); if (clazz == null) { - throw new UnknownPacketException(String.format("Packet not implemented yet (id=0x%x, name=%s, length=%d, dataLength=%d, version=%s, state=%s)", inPacketBuffer.getCommand(), packet, inPacketBuffer.getLength(), inPacketBuffer.getBytesLeft(), connection.getVersion(), connection.getConnectionState())); + throw new UnknownPacketException(String.format("Packet not implemented yet (id=0x%x, name=%s, length=%d, dataLength=%d, version=%s, state=%s)", inPacketBuffer.getCommand(), packet, inPacketBuffer.getLength(), inPacketBuffer.getBytesLeft(), this.connection.getVersion(), this.connection.getConnectionState())); } try { ClientboundPacket packetInstance = clazz.getConstructor().newInstance(); @@ -209,32 +209,32 @@ public class SocketNetwork implements Network { // set special settings to avoid miss timing issues if (packetInstance instanceof PacketLoginSuccess) { - connection.setConnectionState(ConnectionStates.PLAY); + this.connection.setConnectionState(ConnectionStates.PLAY); } else if (packetInstance instanceof PacketCompressionInterface compressionPacket) { - compressionThreshold = compressionPacket.getThreshold(); + this.compressionThreshold = compressionPacket.getThreshold(); } else if (packetInstance instanceof PacketEncryptionRequest) { // wait until response is ready - connection.handle(packetInstance); + this.connection.handle(packetInstance); try { Thread.sleep(Integer.MAX_VALUE); } catch (InterruptedException ignored) { } continue; } - connection.handle(packetInstance); + this.connection.handle(packetInstance); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { // safety first, but will not occur e.printStackTrace(); } } catch (Throwable e) { Log.protocol(String.format("An error occurred while parsing a packet (%s): %s", packet, e)); - if (connection.getConnectionState() == ConnectionStates.PLAY) { + if (this.connection.getConnectionState() == ConnectionStates.PLAY) { Log.printException(e, LogLevels.PROTOCOL); continue; } - lastException = e; + this.lastException = e; disconnect(); - connection.setConnectionState(ConnectionStates.FAILED); + this.connection.setConnectionState(ConnectionStates.FAILED); throw new RuntimeException(e); } } @@ -242,47 +242,47 @@ public class SocketNetwork implements Network { } catch (IOException e) { // Could not connect Log.printException(e, LogLevels.PROTOCOL); - if (socketSThread != null) { - socketSThread.interrupt(); + if (this.socketSThread != null) { + this.socketSThread.interrupt(); } if (e instanceof SocketException && e.getMessage().equals("Socket closed")) { return; } - lastException = e; - connection.setConnectionState(ConnectionStates.FAILED); + this.lastException = e; + this.connection.setConnectionState(ConnectionStates.FAILED); } - }, String.format("%d/Socket", connection.getConnectionId())); - socketRThread.start(); + }, String.format("%d/Socket", this.connection.getConnectionId())); + this.socketRThread.start(); } @Override public void sendPacket(ServerboundPacket packet) { - queue.add(packet); + this.queue.add(packet); } @Override public void disconnect() { - connection.setConnectionState(ConnectionStates.DISCONNECTING); + this.connection.setConnectionState(ConnectionStates.DISCONNECTING); try { - socket.close(); + this.socket.close(); } catch (IOException e) { e.printStackTrace(); } - socketRThread.interrupt(); - socketSThread.interrupt(); - connection.setConnectionState(ConnectionStates.DISCONNECTED); + this.socketRThread.interrupt(); + this.socketSThread.interrupt(); + this.connection.setConnectionState(ConnectionStates.DISCONNECTED); } @Override public Throwable getLastException() { - return lastException; + return this.lastException; } private void enableEncryption(SecretKey secretKey) { Cipher cipherEncrypt = CryptManager.createNetCipherInstance(Cipher.ENCRYPT_MODE, secretKey); Cipher cipherDecrypt = CryptManager.createNetCipherInstance(Cipher.DECRYPT_MODE, secretKey); - inputStream = new CipherInputStream(inputStream, cipherDecrypt); - outputStream = new CipherOutputStream(outputStream, cipherEncrypt); + this.inputStream = new CipherInputStream(this.inputStream, cipherDecrypt); + this.outputStream = new CipherOutputStream(this.outputStream, cipherEncrypt); Log.debug("Encryption enabled!"); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java index 3594ee76f..504d6cf1e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketEncryptionRequest.java @@ -26,9 +26,9 @@ public class PacketEncryptionRequest implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - serverId = buffer.readString(); - publicKey = buffer.readByteArray(); - verifyToken = buffer.readByteArray(); + this.serverId = buffer.readString(); + this.publicKey = buffer.readByteArray(); + this.verifyToken = buffer.readByteArray(); return true; } @@ -43,14 +43,14 @@ public class PacketEncryptionRequest implements ClientboundPacket { } public byte[] getPublicKey() { - return publicKey; + return this.publicKey; } public byte[] getVerifyToken() { - return verifyToken; + return this.verifyToken; } public String getServerId() { - return serverId; + return this.serverId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginDisconnect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginDisconnect.java index 37ddf5e34..66d4b7455 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginDisconnect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginDisconnect.java @@ -24,7 +24,7 @@ public class PacketLoginDisconnect implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - reason = buffer.readChatComponent(); + this.reason = buffer.readChatComponent(); return true; } @@ -35,10 +35,10 @@ public class PacketLoginDisconnect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving login disconnect packet (%s)", reason.getANSIColoredMessage())); + Log.protocol(String.format("[IN] Receiving login disconnect packet (%s)", this.reason.getANSIColoredMessage())); } public ChatComponent getReason() { - return reason; + return this.reason; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginPluginRequest.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginPluginRequest.java index 17ddf36a9..cd0ddfe91 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginPluginRequest.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginPluginRequest.java @@ -28,9 +28,9 @@ public class PacketLoginPluginRequest implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { this.connection = buffer.getConnection(); - messageId = buffer.readVarInt(); - channel = buffer.readString(); - data = buffer.readBytesLeft(); + this.messageId = buffer.readVarInt(); + this.channel = buffer.readString(); + this.data = buffer.readBytesLeft(); return true; } @@ -41,22 +41,22 @@ public class PacketLoginPluginRequest implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received login plugin request in channel \"%s\" with %s bytes of data (messageId=%d)", channel, data.length, messageId)); + Log.protocol(String.format("[IN] Received login plugin request in channel \"%s\" with %s bytes of data (messageId=%d)", this.channel, this.data.length, this.messageId)); } public int getMessageId() { - return messageId; + return this.messageId; } public String getChannel() { - return channel; + return this.channel; } public byte[] getData() { - return data; + return this.data; } public InByteBuffer getDataAsBuffer() { - return new InByteBuffer(data, connection); + return new InByteBuffer(this.data, this.connection); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSetCompression.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSetCompression.java index a4bec7e36..50638ea83 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSetCompression.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSetCompression.java @@ -23,7 +23,7 @@ public class PacketLoginSetCompression implements PacketCompressionInterface { @Override public boolean read(InByteBuffer buffer) { - threshold = buffer.readVarInt(); + this.threshold = buffer.readVarInt(); return true; } @@ -34,11 +34,11 @@ public class PacketLoginSetCompression implements PacketCompressionInterface { @Override public void log() { - Log.protocol(String.format("[IN] Received set compression packet (threshold=%d)", threshold)); + Log.protocol(String.format("[IN] Received set compression packet (threshold=%d)", this.threshold)); } @Override public int getThreshold() { - return threshold; + return this.threshold; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSuccess.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSuccess.java index 8bfa8d6f4..482feea2b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSuccess.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/login/PacketLoginSuccess.java @@ -28,12 +28,12 @@ public class PacketLoginSuccess implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 707) { - uuid = Util.getUUIDFromString(buffer.readString()); - username = buffer.readString(); + this.uuid = Util.getUUIDFromString(buffer.readString()); + this.username = buffer.readString(); return true; } - uuid = buffer.readUUID(); - username = buffer.readString(); + this.uuid = buffer.readUUID(); + this.username = buffer.readString(); return true; } @@ -44,14 +44,14 @@ public class PacketLoginSuccess implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving login success packet (username=%s, UUID=%s)", username, uuid)); + Log.protocol(String.format("[IN] Receiving login success packet (username=%s, UUID=%s)", this.username, this.uuid)); } public UUID getUUID() { - return uuid; + return this.uuid; } public String getUsername() { - return username; + return this.username; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java index e69b373fb..2ba055a09 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAcknowledgePlayerDigging.java @@ -29,10 +29,10 @@ public class PacketAcknowledgePlayerDigging implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - position = buffer.readPosition(); - block = buffer.getConnection().getMapping().getBlockById(buffer.readVarInt()); - status = PacketPlayerDigging.DiggingStatus.byId(buffer.readVarInt()); - successful = buffer.readBoolean(); + this.position = buffer.readPosition(); + this.block = buffer.getConnection().getMapping().getBlockById(buffer.readVarInt()); + this.status = PacketPlayerDigging.DiggingStatus.byId(buffer.readVarInt()); + this.successful = buffer.readBoolean(); return true; } @@ -43,22 +43,22 @@ public class PacketAcknowledgePlayerDigging implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received acknowledge digging packet (position=%s, block=%s, status=%s, successful=%s)", position, block, status, successful)); + Log.protocol(String.format("[IN] Received acknowledge digging packet (position=%s, block=%s, status=%s, successful=%s)", this.position, this.block, this.status, this.successful)); } public BlockPosition getPosition() { - return position; + return this.position; } public Block getBlock() { - return block; + return this.block; } public PacketPlayerDigging.DiggingStatus getStatus() { - return status; + return this.status; } public boolean isSuccessful() { - return successful; + return this.successful; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAdvancements.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAdvancements.java index a441249e5..613b6653e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAdvancements.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAdvancements.java @@ -36,7 +36,7 @@ public class PacketAdvancements implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - reset = buffer.readBoolean(); + this.reset = buffer.readBoolean(); int length = buffer.readVarInt(); for (int i = 0; i < length; i++) { String advancementKey = buffer.readString(); @@ -74,11 +74,11 @@ public class PacketAdvancements implements ClientboundPacket { } requirements.add(requirement); } - advancements.put(advancementKey, new Advancement(parentName, display, criteria, requirements)); + this.advancements.put(advancementKey, new Advancement(parentName, display, criteria, requirements)); } - toRemove = new String[buffer.readVarInt()]; - for (int i = 0; i < toRemove.length; i++) { - toRemove[i] = buffer.readString(); + this.toRemove = new String[buffer.readVarInt()]; + for (int i = 0; i < this.toRemove.length; i++) { + this.toRemove[i] = buffer.readString(); } int progressesLength = buffer.readVarInt(); for (int i = 0; i < progressesLength; i++) { @@ -95,7 +95,7 @@ public class PacketAdvancements implements ClientboundPacket { CriterionProgress criterionProgress = new CriterionProgress(archived, archiveTime); progress.put(criterionName, criterionProgress); } - progresses.put(progressName, new AdvancementProgress(progress)); + this.progresses.put(progressName, new AdvancementProgress(progress)); } return true; @@ -108,18 +108,18 @@ public class PacketAdvancements implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving advancements (reset=%s, advancements=%s, progresses=%s)", reset, advancements.size(), progresses.size())); + Log.protocol(String.format("[IN] Receiving advancements (reset=%s, advancements=%s, progresses=%s)", this.reset, this.advancements.size(), this.progresses.size())); } public boolean isReset() { - return reset; + return this.reset; } public HashMap getAdvancements() { - return advancements; + return this.advancements; } public HashMap getProgresses() { - return progresses; + return this.progresses; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAttachEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAttachEntity.java index 0d5ff2f6b..c2c3713cf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAttachEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketAttachEntity.java @@ -42,18 +42,18 @@ public class PacketAttachEntity implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Attaching entity %d to entity %d (leash=%s)", entityId, vehicleId, leash)); + Log.protocol(String.format("[IN] Attaching entity %d to entity %d (leash=%s)", this.entityId, this.vehicleId, this.leash)); } public int getEntityId() { - return entityId; + return this.entityId; } public int getVehicleId() { - return vehicleId; + return this.vehicleId; } public boolean isLeash() { - return leash; + return this.leash; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockAction.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockAction.java index 19a841c94..1fe557ae7 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockAction.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockAction.java @@ -29,15 +29,15 @@ public class PacketBlockAction implements ClientboundPacket { public boolean read(InByteBuffer buffer) { // that's the only difference here if (buffer.getVersionId() < 6) { - position = buffer.readBlockPositionShort(); + this.position = buffer.readBlockPositionShort(); } else { - position = buffer.readPosition(); + this.position = buffer.readPosition(); } short byte1 = buffer.readUnsignedByte(); short byte2 = buffer.readUnsignedByte(); BlockId blockId = buffer.getConnection().getMapping().getBlockIdById(buffer.readVarInt()); - data = switch (blockId.getIdentifier()) { + this.data = switch (blockId.getIdentifier()) { case "noteblock" -> new NoteBlockAction(byte1, byte2); // ToDo: was replaced in 17w47a (346) with the block id case "sticky_piston", "piston" -> new PistonAction(byte1, byte2); case "chest", "ender_chest", "trapped_chest", "white_shulker_box", "shulker_box", "orange_shulker_box", "magenta_shulker_box", "light_blue_shulker_box", "yellow_shulker_box", "lime_shulker_box", "pink_shulker_box", "gray_shulker_box", "silver_shulker_box", "cyan_shulker_box", "purple_shulker_box", "blue_shulker_box", "brown_shulker_box", "green_shulker_box", "red_shulker_box", "black_shulker_box" -> new ChestAction(byte1, byte2); @@ -50,11 +50,11 @@ public class PacketBlockAction implements ClientboundPacket { } public BlockPosition getPosition() { - return position; + return this.position; } public BlockAction getData() { - return data; + return this.data; } @Override @@ -64,6 +64,6 @@ public class PacketBlockAction implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Block action received %s at %s", data, position)); + Log.protocol(String.format("[IN] Block action received %s at %s", this.data, this.position)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockBreakAnimation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockBreakAnimation.java index b808bb267..89a73eb8b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockBreakAnimation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockBreakAnimation.java @@ -26,13 +26,13 @@ public class PacketBlockBreakAnimation implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readVarInt(); + this.entityId = buffer.readVarInt(); if (buffer.getVersionId() < 6) { - position = buffer.readBlockPositionInteger(); + this.position = buffer.readBlockPositionInteger(); } else { - position = buffer.readPosition(); + this.position = buffer.readPosition(); } - stage = buffer.readByte(); + this.stage = buffer.readByte(); return true; } @@ -44,19 +44,19 @@ public class PacketBlockBreakAnimation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving block break packet (entityId=%d, stage=%d) at %s", entityId, stage, position)); + Log.protocol(String.format("[IN] Receiving block break packet (entityId=%d, stage=%d) at %s", this.entityId, this.stage, this.position)); } public BlockPosition getPosition() { - return position; + return this.position; } public int getEntityId() { - return entityId; + return this.entityId; } public byte getStage() { - return stage; + return this.stage; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockChange.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockChange.java index cdbcde288..e889c0d41 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockChange.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockChange.java @@ -27,12 +27,12 @@ public class PacketBlockChange implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 6) { - position = buffer.readBlockPosition(); - block = buffer.getConnection().getMapping().getBlockById((buffer.readVarInt() << 4) | buffer.readByte()); // ToDo: When was the meta data "compacted"? (between 1.7.10 - 1.8) + this.position = buffer.readBlockPosition(); + this.block = buffer.getConnection().getMapping().getBlockById((buffer.readVarInt() << 4) | buffer.readByte()); // ToDo: When was the meta data "compacted"? (between 1.7.10 - 1.8) return true; } - position = buffer.readPosition(); - block = buffer.getConnection().getMapping().getBlockById(buffer.readVarInt()); + this.position = buffer.readPosition(); + this.block = buffer.getConnection().getMapping().getBlockById(buffer.readVarInt()); return true; } @@ -44,14 +44,14 @@ public class PacketBlockChange implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Block change received at %s (block=%s)", position, block)); + Log.protocol(String.format("[IN] Block change received at %s (block=%s)", this.position, this.block)); } public BlockPosition getPosition() { - return position; + return this.position; } public Block getBlock() { - return block; + return this.block; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java index 6fac4e694..fceb36ec6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBlockEntityMetadata.java @@ -31,14 +31,14 @@ public class PacketBlockEntityMetadata implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 6) { - position = buffer.readBlockPositionShort(); - action = BlockEntityActions.byId(buffer.readUnsignedByte(), buffer.getVersionId()); - data = BlockEntityMetaData.getData(action, (CompoundTag) buffer.readNBT(true)); + this.position = buffer.readBlockPositionShort(); + this.action = BlockEntityActions.byId(buffer.readUnsignedByte(), buffer.getVersionId()); + this.data = BlockEntityMetaData.getData(this.action, (CompoundTag) buffer.readNBT(true)); return true; } - position = buffer.readPosition(); - action = BlockEntityActions.byId(buffer.readUnsignedByte(), buffer.getVersionId()); - data = BlockEntityMetaData.getData(action, (CompoundTag) buffer.readNBT()); + this.position = buffer.readPosition(); + this.action = BlockEntityActions.byId(buffer.readUnsignedByte(), buffer.getVersionId()); + this.data = BlockEntityMetaData.getData(this.action, (CompoundTag) buffer.readNBT()); return true; } @@ -49,19 +49,19 @@ public class PacketBlockEntityMetadata implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving blockEntityMeta (position=%s, action=%s)", position, action)); + Log.protocol(String.format("[IN] Receiving blockEntityMeta (position=%s, action=%s)", this.position, this.action)); } public BlockPosition getPosition() { - return position; + return this.position; } public BlockEntityActions getAction() { - return action; + return this.action; } public BlockEntityMetaData getData() { - return data; + return this.data; } public enum BlockEntityActions { @@ -84,7 +84,7 @@ public class PacketBlockEntityMetadata implements ClientboundPacket { final VersionValueMap valueMap; BlockEntityActions(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } public static BlockEntityActions byId(int id, int versionId) { @@ -97,7 +97,7 @@ public class PacketBlockEntityMetadata implements ClientboundPacket { } public int getId(int versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBossBar.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBossBar.java index 16e3ef5d4..314d16537 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBossBar.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketBossBar.java @@ -35,23 +35,23 @@ public class PacketBossBar implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - uuid = buffer.readUUID(); - action = BossBarActions.byId(buffer.readVarInt()); - switch (action) { + this.uuid = buffer.readUUID(); + this.action = BossBarActions.byId(buffer.readVarInt()); + switch (this.action) { case ADD -> { - title = buffer.readChatComponent(); - health = buffer.readFloat(); - color = BossBarColors.byId(buffer.readVarInt()); - divisions = BossBarDivisions.byId(buffer.readVarInt()); - flags = buffer.readByte(); + this.title = buffer.readChatComponent(); + this.health = buffer.readFloat(); + this.color = BossBarColors.byId(buffer.readVarInt()); + this.divisions = BossBarDivisions.byId(buffer.readVarInt()); + this.flags = buffer.readByte(); } - case UPDATE_HEALTH -> health = buffer.readFloat(); - case UPDATE_TITLE -> title = buffer.readChatComponent(); + case UPDATE_HEALTH -> this.health = buffer.readFloat(); + case UPDATE_TITLE -> this.title = buffer.readChatComponent(); case UPDATE_STYLE -> { - color = BossBarColors.byId(buffer.readVarInt()); - divisions = BossBarDivisions.byId(buffer.readVarInt()); + this.color = BossBarColors.byId(buffer.readVarInt()); + this.divisions = BossBarDivisions.byId(buffer.readVarInt()); } - case UPDATE_FLAGS -> flags = buffer.readByte(); + case UPDATE_FLAGS -> this.flags = buffer.readByte(); } return true; } @@ -63,54 +63,54 @@ public class PacketBossBar implements ClientboundPacket { @Override public void log() { - switch (action) { - case ADD -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, title=\"%s\", health=%s, color=%s, divisions=%s, dragonBar=%s, darkenSky=%s)", action, uuid.toString(), title.getANSIColoredMessage(), health, color, divisions, isDragonBar(), shouldDarkenSky())); - case REMOVE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s)", action, uuid.toString())); - case UPDATE_HEALTH -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, health=%s)", action, uuid.toString(), health)); - case UPDATE_TITLE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, title=\"%s\")", action, uuid.toString(), title.getANSIColoredMessage())); - case UPDATE_STYLE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, color=%s, divisions=%s)", action, uuid.toString(), color, divisions)); - case UPDATE_FLAGS -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, dragonBar=%s, darkenSky=%s)", action, uuid.toString(), isDragonBar(), shouldDarkenSky())); + switch (this.action) { + case ADD -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, title=\"%s\", health=%s, color=%s, divisions=%s, dragonBar=%s, darkenSky=%s)", this.action, this.uuid.toString(), this.title.getANSIColoredMessage(), this.health, this.color, this.divisions, isDragonBar(), shouldDarkenSky())); + case REMOVE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s)", this.action, this.uuid.toString())); + case UPDATE_HEALTH -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, health=%s)", this.action, this.uuid.toString(), this.health)); + case UPDATE_TITLE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, title=\"%s\")", this.action, this.uuid.toString(), this.title.getANSIColoredMessage())); + case UPDATE_STYLE -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, color=%s, divisions=%s)", this.action, this.uuid.toString(), this.color, this.divisions)); + case UPDATE_FLAGS -> Log.protocol(String.format("[IN] Received boss bar (action=%s, uuid=%s, dragonBar=%s, darkenSky=%s)", this.action, this.uuid.toString(), isDragonBar(), shouldDarkenSky())); } } public boolean isDragonBar() { - return BitByte.isBitMask(flags, 0x02); + return BitByte.isBitMask(this.flags, 0x02); } public boolean shouldDarkenSky() { - return BitByte.isBitMask(flags, 0x01); + return BitByte.isBitMask(this.flags, 0x01); } public UUID getUUID() { - return uuid; + return this.uuid; } public BossBarActions getAction() { - return action; + return this.action; } public BossBarDivisions getDivisions() { - return divisions; + return this.divisions; } public BossBarColors getColor() { - return color; + return this.color; } public float getHealth() { - return health; + return this.health; } public ChatComponent getTitle() { - return title; + return this.title; } public byte getFlags() { - return flags; + return this.flags; } public boolean createFog() { - return BitByte.isBitMask(flags, 0x04); + return BitByte.isBitMask(this.flags, 0x04); } public enum BossBarActions { @@ -121,8 +121,10 @@ public class PacketBossBar implements ClientboundPacket { UPDATE_STYLE, UPDATE_FLAGS; + private static final BossBarActions[] BOSS_BAR_ACTIONS = values(); + public static BossBarActions byId(int id) { - return values()[id]; + return BOSS_BAR_ACTIONS[id]; } } @@ -135,8 +137,10 @@ public class PacketBossBar implements ClientboundPacket { PURPLE, WHITE; + private static final BossBarColors[] BOSS_BAR_COLORS = values(); + public static BossBarColors byId(int id) { - return values()[id]; + return BOSS_BAR_COLORS[id]; } } @@ -147,8 +151,10 @@ public class PacketBossBar implements ClientboundPacket { NOTCHES_12, NOTCHES_20; + private static final BossBarDivisions[] BOSS_BAR_DIVISIONS = values(); + public static BossBarDivisions byId(int id) { - return values()[id]; + return BOSS_BAR_DIVISIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCamera.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCamera.java index d8b20da79..68465ca0b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCamera.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCamera.java @@ -23,7 +23,7 @@ public class PacketCamera implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readVarInt(); + this.entityId = buffer.readVarInt(); return true; } @@ -34,10 +34,10 @@ public class PacketCamera implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving camera packet (entityId=%d)", entityId)); + Log.protocol(String.format("[IN] Receiving camera packet (entityId=%d)", this.entityId)); } public int getEntityId() { - return entityId; + return this.entityId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChangeGameState.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChangeGameState.java index 559239c06..b8662f22c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChangeGameState.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChangeGameState.java @@ -26,8 +26,8 @@ public class PacketChangeGameState implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - reason = Reason.byId(buffer.readByte(), buffer.getVersionId()); - value = buffer.readFloat(); + this.reason = Reason.byId(buffer.readByte(), buffer.getVersionId()); + this.value = buffer.readFloat(); return true; } @@ -42,15 +42,15 @@ public class PacketChangeGameState implements ClientboundPacket { } public Reason getReason() { - return reason; + return this.reason; } public float getFloatValue() { - return value; + return this.value; } public int getIntValue() { - return (int) value; + return (int) this.value; } public enum Reason { @@ -70,7 +70,7 @@ public class PacketChangeGameState implements ClientboundPacket { final VersionValueMap valueMap; Reason(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } public static Reason byId(int id, int versionId) { @@ -83,7 +83,7 @@ public class PacketChangeGameState implements ClientboundPacket { } public int getId(Integer versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChatMessageReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChatMessageReceiving.java index f68967d35..053867602 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChatMessageReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChatMessageReceiving.java @@ -29,14 +29,14 @@ public class PacketChatMessageReceiving implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - message = buffer.readChatComponent(); + this.message = buffer.readChatComponent(); if (buffer.getVersionId() < 7) { - position = ChatTextPositions.CHAT_BOX; + this.position = ChatTextPositions.CHAT_BOX; return true; } - position = ChatTextPositions.byId(buffer.readUnsignedByte()); + this.position = ChatTextPositions.byId(buffer.readUnsignedByte()); if (buffer.getVersionId() >= 718) { - sender = buffer.readUUID(); + this.sender = buffer.readUUID(); } return true; } @@ -48,18 +48,18 @@ public class PacketChatMessageReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received chat message (message=\"%s\")", message.getMessage())); + Log.protocol(String.format("[IN] Received chat message (message=\"%s\")", this.message.getMessage())); } public ChatComponent getMessage() { - return message; + return this.message; } public ChatTextPositions getPosition() { - return position; + return this.position; } public UUID getSender() { - return sender; + return this.sender; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkBulk.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkBulk.java index 58de885a9..b601bd77b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkBulk.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkBulk.java @@ -49,7 +49,7 @@ public class PacketChunkBulk implements ClientboundPacket { int sectionBitMask = buffer.readUnsignedShort(); int addBitMask = buffer.readUnsignedShort(); - chunks.put(new ChunkLocation(x, z), ChunkUtil.readChunkPacket(decompressed, sectionBitMask, addBitMask, true, containsSkyLight)); + this.chunks.put(new ChunkLocation(x, z), ChunkUtil.readChunkPacket(decompressed, sectionBitMask, addBitMask, true, containsSkyLight)); } return true; } @@ -67,7 +67,7 @@ public class PacketChunkBulk implements ClientboundPacket { sectionBitMask[i] = buffer.readUnsignedShort(); } for (int i = 0; i < chunkCount; i++) { - chunks.put(new ChunkLocation(x[i], z[i]), ChunkUtil.readChunkPacket(buffer, sectionBitMask[i], (short) 0, true, containsSkyLight)); + this.chunks.put(new ChunkLocation(x[i], z[i]), ChunkUtil.readChunkPacket(buffer, sectionBitMask[i], (short) 0, true, containsSkyLight)); } return true; } @@ -79,10 +79,10 @@ public class PacketChunkBulk implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Chunk bulk packet received (chunks=%s)", chunks.size())); + Log.protocol(String.format("[IN] Chunk bulk packet received (chunks=%s)", this.chunks.size())); } public HashMap getChunks() { - return chunks; + return this.chunks; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkData.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkData.java index d82ce26bc..311a85884 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkData.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketChunkData.java @@ -52,7 +52,7 @@ public class PacketChunkData implements ClientboundPacket { decompressed = buffer; } - chunk = ChunkUtil.readChunkPacket(decompressed, sectionBitMask, addBitMask, groundUpContinuous, containsSkyLight); + this.chunk = ChunkUtil.readChunkPacket(decompressed, sectionBitMask, addBitMask, groundUpContinuous, containsSkyLight); return true; } if (buffer.getVersionId() < 62) { // ToDo: was this really changed in 62? @@ -66,7 +66,7 @@ public class PacketChunkData implements ClientboundPacket { } int size = buffer.readVarInt(); int lastPos = buffer.getPosition(); - chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight); + this.chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight); buffer.setPosition(size + lastPos); return true; } @@ -85,20 +85,20 @@ public class PacketChunkData implements ClientboundPacket { sectionBitMask = buffer.readVarInt(); } if (buffer.getVersionId() >= 443) { - heightMap = (CompoundTag) buffer.readNBT(); + this.heightMap = (CompoundTag) buffer.readNBT(); } if (groundUpContinuous) { if (buffer.getVersionId() >= 740) { - biomes = buffer.readVarIntArray(); + this.biomes = buffer.readVarIntArray(); } else if (buffer.getVersionId() >= 552) { - biomes = buffer.readIntArray(1024); + this.biomes = buffer.readIntArray(1024); } } int size = buffer.readVarInt(); int lastPos = buffer.getPosition(); if (size > 0) { - chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight); + this.chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, 0, groundUpContinuous, containsSkyLight); // set position of the byte buffer, because of some reasons HyPixel makes some weird stuff and sends way to much 0 bytes. (~ 190k), thanks @pokechu22 buffer.setPosition(size + lastPos); } @@ -110,7 +110,7 @@ public class PacketChunkData implements ClientboundPacket { if (data == null) { continue; } - blockEntities.put(new BlockPosition(tag.getIntTag("x").getValue(), (short) tag.getIntTag("y").getValue(), tag.getIntTag("z").getValue()), data); + this.blockEntities.put(new BlockPosition(tag.getIntTag("x").getValue(), (short) tag.getIntTag("y").getValue(), tag.getIntTag("z").getValue()), data); } } return true; @@ -123,22 +123,22 @@ public class PacketChunkData implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Chunk packet received (chunk: %s)", location)); + Log.protocol(String.format("[IN] Chunk packet received (chunk: %s)", this.location)); } public ChunkLocation getLocation() { - return location; + return this.location; } public Chunk getChunk() { - return chunk; + return this.chunk; } public HashMap getBlockEntities() { - return blockEntities; + return this.blockEntities; } public CompoundTag getHeightMap() { - return heightMap; + return this.heightMap; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindowReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindowReceiving.java index f1aa9fef7..cecffbff1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindowReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCloseWindowReceiving.java @@ -34,10 +34,10 @@ public class PacketCloseWindowReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Closing inventory (windowId=%d)", windowId)); + Log.protocol(String.format("[IN] Closing inventory (windowId=%d)", this.windowId)); } public byte getWindowId() { - return windowId; + return this.windowId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCollectItem.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCollectItem.java index b0bf74bd0..a77343414 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCollectItem.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCollectItem.java @@ -25,14 +25,14 @@ public class PacketCollectItem implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - itemEntityId = buffer.readEntityId(); + this.itemEntityId = buffer.readEntityId(); if (buffer.getVersionId() < 7) { - collectorEntityId = buffer.readInt(); + this.collectorEntityId = buffer.readInt(); return true; } - collectorEntityId = buffer.readVarInt(); + this.collectorEntityId = buffer.readVarInt(); if (buffer.getVersionId() >= 301) { - count = buffer.readVarInt(); + this.count = buffer.readVarInt(); } return true; } @@ -44,18 +44,18 @@ public class PacketCollectItem implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Item %d was collected by %d (count=%s)", itemEntityId, collectorEntityId, ((count == 0) ? "?" : count))); + Log.protocol(String.format("[IN] Item %d was collected by %d (count=%s)", this.itemEntityId, this.collectorEntityId, ((this.count == 0) ? "?" : this.count))); } public int getItemEntityId() { - return itemEntityId; + return this.itemEntityId; } public int getCollectorEntityId() { - return collectorEntityId; + return this.collectorEntityId; } public int getCount() { - return count; + return this.count; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCombatEvent.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCombatEvent.java index 759a5ab45..0e7624905 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCombatEvent.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCombatEvent.java @@ -29,16 +29,16 @@ public class PacketCombatEvent implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - action = CombatEvents.byId(buffer.readVarInt()); - switch (action) { + this.action = CombatEvents.byId(buffer.readVarInt()); + switch (this.action) { case END_COMBAT -> { - duration = buffer.readVarInt(); - entityId = buffer.readInt(); + this.duration = buffer.readVarInt(); + this.entityId = buffer.readInt(); } case ENTITY_DEAD -> { - playerId = buffer.readVarInt(); - entityId = buffer.readInt(); - message = buffer.readChatComponent(); + this.playerId = buffer.readVarInt(); + this.entityId = buffer.readInt(); + this.message = buffer.readChatComponent(); } } return true; @@ -51,10 +51,10 @@ public class PacketCombatEvent implements ClientboundPacket { @Override public void log() { - switch (action) { - case ENTER_COMBAT -> Log.protocol(String.format("[IN] Received combat packet (action=%s)", action)); - case END_COMBAT -> Log.protocol(String.format("[IN] Received combat packet (action=%s, duration=%d, entityId=%d)", action, duration, entityId)); - case ENTITY_DEAD -> Log.protocol(String.format("[IN] Received combat packet (action=%s, playerId=%d, entityId=%d, message=\"%s\")", action, playerId, entityId, message)); + switch (this.action) { + case ENTER_COMBAT -> Log.protocol(String.format("[IN] Received combat packet (action=%s)", this.action)); + case END_COMBAT -> Log.protocol(String.format("[IN] Received combat packet (action=%s, duration=%d, entityId=%d)", this.action, this.duration, this.entityId)); + case ENTITY_DEAD -> Log.protocol(String.format("[IN] Received combat packet (action=%s, playerId=%d, entityId=%d, message=\"%s\")", this.action, this.playerId, this.entityId, this.message)); } } @@ -63,8 +63,10 @@ public class PacketCombatEvent implements ClientboundPacket { END_COMBAT, ENTITY_DEAD; + private static final CombatEvents[] COMBAT_EVENTS = values(); + public static CombatEvents byId(int id) { - return values()[id]; + return COMBAT_EVENTS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java index 062a1dcfb..bf3d5ebcf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketConfirmTransactionReceiving.java @@ -38,18 +38,18 @@ public class PacketConfirmTransactionReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Closing inventory (windowId=%d)", windowId)); + Log.protocol(String.format("[IN] Closing inventory (windowId=%d)", this.windowId)); } public byte getWindowId() { - return windowId; + return this.windowId; } public boolean wasAccepted() { - return accepted; + return this.accepted; } public short getActionNumber() { - return actionNumber; + return this.actionNumber; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCraftRecipeResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCraftRecipeResponse.java index 143654c66..8d4b59283 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCraftRecipeResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketCraftRecipeResponse.java @@ -26,12 +26,12 @@ public class PacketCraftRecipeResponse implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 346) { // ToDo: was this really in 346? - windowId = buffer.readByte(); - recipeId = buffer.readVarInt(); + this.windowId = buffer.readByte(); + this.recipeId = buffer.readVarInt(); return true; } - windowId = buffer.readByte(); - recipeName = buffer.readString(); + this.windowId = buffer.readByte(); + this.recipeName = buffer.readString(); return true; } @@ -42,14 +42,14 @@ public class PacketCraftRecipeResponse implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received Crafting recipe response (windowId=%d, recipeId=%d)", windowId, recipeId)); + Log.protocol(String.format("[IN] Received Crafting recipe response (windowId=%d, recipeId=%d)", this.windowId, this.recipeId)); } public byte getWindowId() { - return windowId; + return this.windowId; } public int getRecipeId() { - return recipeId; + return this.recipeId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java index 661dc7a9b..a1c9e4acb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareCommands.java @@ -26,12 +26,12 @@ public class PacketDeclareCommands implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) throws Exception { CommandNode[] nodes = buffer.readCommandNodesArray(); - rootNode = (CommandRootNode) nodes[buffer.readVarInt()]; + this.rootNode = (CommandRootNode) nodes[buffer.readVarInt()]; return true; } public CommandRootNode getRootNode() { - return rootNode; + return this.rootNode; } @Override diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java index 8ee28a372..584cc457c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDeclareRecipes.java @@ -79,7 +79,7 @@ public class PacketDeclareRecipes implements ClientboundPacket { } default -> recipe = new Recipe(type); } - recipes.put(identifier, recipe); + this.recipes.put(identifier, recipe); } return true; } @@ -91,10 +91,10 @@ public class PacketDeclareRecipes implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received declare recipe packet (recipeLength=%d)", recipes.size())); + Log.protocol(String.format("[IN] Received declare recipe packet (recipeLength=%d)", this.recipes.size())); } public HashBiMap getRecipes() { - return recipes; + return this.recipes; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java index 761f496c9..dbd10cfa5 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDestroyEntity.java @@ -31,8 +31,8 @@ public class PacketDestroyEntity implements ClientboundPacket { this.entityIds = new int[buffer.readVarInt()]; } - for (int i = 0; i < entityIds.length; i++) { - entityIds[i] = buffer.readEntityId(); + for (int i = 0; i < this.entityIds.length; i++) { + this.entityIds[i] = buffer.readEntityId(); } return true; } @@ -44,10 +44,10 @@ public class PacketDestroyEntity implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Despawning the following entities: %s", Arrays.toString(entityIds))); + Log.protocol(String.format("[IN] Despawning the following entities: %s", Arrays.toString(this.entityIds))); } public int[] getEntityIds() { - return entityIds; + return this.entityIds; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDisconnect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDisconnect.java index 82b1525da..89911658d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDisconnect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketDisconnect.java @@ -24,7 +24,7 @@ public class PacketDisconnect implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - reason = buffer.readChatComponent(); + this.reason = buffer.readChatComponent(); return true; } @@ -35,10 +35,10 @@ public class PacketDisconnect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received disconnect packet (reason=\"%s\")", reason.getANSIColoredMessage())); + Log.protocol(String.format("[IN] Received disconnect packet (reason=\"%s\")", this.reason.getANSIColoredMessage())); } public ChatComponent getReason() { - return reason; + return this.reason; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEffect.java index 45fcfd666..90e24480f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEffect.java @@ -31,12 +31,12 @@ public class PacketEffect implements ClientboundPacket { public boolean read(InByteBuffer buffer) { this.effect = EffectEffects.byId(buffer.readInt(), buffer.getVersionId()); if (buffer.getVersionId() < 6) { - position = buffer.readBlockPosition(); + this.position = buffer.readBlockPosition(); } else { - position = buffer.readPosition(); + this.position = buffer.readPosition(); } - data = buffer.readInt(); - disableRelativeVolume = buffer.readBoolean(); + this.data = buffer.readInt(); + this.disableRelativeVolume = buffer.readBoolean(); return true; } @@ -47,31 +47,31 @@ public class PacketEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received effect packet at %s (effect=%s, data=%d, disableRelativeVolume=%s)", position, effect, data, disableRelativeVolume)); + Log.protocol(String.format("[IN] Received effect packet at %s (effect=%s, data=%d, disableRelativeVolume=%s)", this.position, this.effect, this.data, this.disableRelativeVolume)); } public BlockPosition getPosition() { - return position; + return this.position; } public EffectEffects getEffect() { - return effect; + return this.effect; } public int getData() { - return data; + return this.data; } public SmokeDirections getSmokeDirection() { - if (effect == EffectEffects.PARTICLE_10_SMOKE) { - return SmokeDirections.byId(data); + if (this.effect == EffectEffects.PARTICLE_10_SMOKE) { + return SmokeDirections.byId(this.data); } return null; } // ToDo all other dataTypes public boolean isDisableRelativeVolume() { - return disableRelativeVolume; + return this.disableRelativeVolume; } public enum EffectEffects { @@ -150,7 +150,7 @@ public class PacketEffect implements ClientboundPacket { final VersionValueMap valueMap; EffectEffects(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } public static EffectEffects byId(int id, int versionId) { @@ -163,7 +163,7 @@ public class PacketEffect implements ClientboundPacket { } public int getId(Integer versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } @@ -182,8 +182,10 @@ public class PacketEffect implements ClientboundPacket { NORTH, NORTH_WEST; + private static final SmokeDirections[] SMOKE_DIRECTIONS = values(); + public static SmokeDirections byId(int id) { - return values()[id]; + return SMOKE_DIRECTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java index 4c575d383..5bb734400 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityAnimation.java @@ -26,8 +26,8 @@ public class PacketEntityAnimation implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readVarInt(); - animation = EntityAnimations.byId(buffer.readByte(), buffer.getVersionId()); + this.entityId = buffer.readVarInt(); + this.animation = EntityAnimations.byId(buffer.readByte(), buffer.getVersionId()); return true; } @@ -38,7 +38,7 @@ public class PacketEntityAnimation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Play entity animation (entityId=%d, animation=%s)", entityId, animation)); + Log.protocol(String.format("[IN] Play entity animation (entityId=%d, animation=%s)", this.entityId, this.animation)); } public enum EntityAnimations { @@ -57,7 +57,7 @@ public class PacketEntityAnimation implements ClientboundPacket { final VersionValueMap valueMap; EntityAnimations(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } public static EntityAnimations byId(int id, int versionId) { @@ -70,7 +70,7 @@ public class PacketEntityAnimation implements ClientboundPacket { } public int getId(Integer versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java index c81475f9c..ba75d16b9 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEffect.java @@ -24,28 +24,28 @@ public class PacketEntityEffect implements ClientboundPacket { int entityId; StatusEffect effect; boolean isAmbient; - boolean hideParticles = false; + boolean hideParticles; boolean showIcon = true; @Override public boolean read(InByteBuffer buffer) { this.entityId = buffer.readEntityId(); if (buffer.getVersionId() < 7) { - effect = new StatusEffect(buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()), buffer.readByte() + 1, buffer.readShort()); + this.effect = new StatusEffect(buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()), buffer.readByte() + 1, buffer.readShort()); return true; } - effect = new StatusEffect(buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()), buffer.readByte() + 1, buffer.readVarInt()); + this.effect = new StatusEffect(buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()), buffer.readByte() + 1, buffer.readVarInt()); if (buffer.getVersionId() < 110) { // ToDo if (buffer.getVersionId() >= 10) { - hideParticles = buffer.readBoolean(); + this.hideParticles = buffer.readBoolean(); return true; } } byte flags = buffer.readByte(); - isAmbient = BitByte.isBitMask(flags, 0x01); - hideParticles = !BitByte.isBitMask(flags, 0x02); + this.isAmbient = BitByte.isBitMask(flags, 0x01); + this.hideParticles = !BitByte.isBitMask(flags, 0x02); if (buffer.getVersionId() >= 498) { // ToDo - showIcon = BitByte.isBitMask(flags, 0x04); + this.showIcon = BitByte.isBitMask(flags, 0x04); } return true; } @@ -57,26 +57,26 @@ public class PacketEntityEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity effect added: %d %s", entityId, effect.toString())); + Log.protocol(String.format("[IN] Entity effect added: %d %s", this.entityId, this.effect.toString())); } public int getEntityId() { - return entityId; + return this.entityId; } public StatusEffect getEffect() { - return effect; + return this.effect; } public boolean hideParticles() { - return hideParticles; + return this.hideParticles; } public boolean showIcon() { - return showIcon; + return this.showIcon; } public boolean isAmbient() { - return isAmbient; + return this.isAmbient; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEquipment.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEquipment.java index a4702cee6..83f8683de 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEquipment.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEquipment.java @@ -29,13 +29,13 @@ public class PacketEntityEquipment implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readEntityId(); + this.entityId = buffer.readEntityId(); if (buffer.getVersionId() < 49) { - slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getVersionId()), buffer.readSlot()); + this.slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readShort(), buffer.getVersionId()), buffer.readSlot()); return true; } if (buffer.getVersionId() < 732) { - slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readVarInt(), buffer.getVersionId()), buffer.readSlot()); + this.slots.put(InventorySlots.EntityInventorySlots.byId(buffer.readVarInt(), buffer.getVersionId()), buffer.readSlot()); return true; } boolean slotAvailable = true; @@ -45,7 +45,7 @@ public class PacketEntityEquipment implements ClientboundPacket { slotAvailable = false; } slotId &= 0x7F; - slots.put(InventorySlots.EntityInventorySlots.byId(slotId, buffer.getVersionId()), buffer.readSlot()); + this.slots.put(InventorySlots.EntityInventorySlots.byId(slotId, buffer.getVersionId()), buffer.readSlot()); } return true; } @@ -57,23 +57,23 @@ public class PacketEntityEquipment implements ClientboundPacket { @Override public void log() { - if (slots.size() == 1) { - Map.Entry set = slots.entrySet().iterator().next(); + if (this.slots.size() == 1) { + Map.Entry set = this.slots.entrySet().iterator().next(); if (set.getValue() == null) { - Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slot=%s): AIR", entityId, set.getKey())); + Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slot=%s): AIR", this.entityId, set.getKey())); return; } - Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slot=%s, item=%s): %dx %s", entityId, set.getKey(), set.getValue().getItem(), set.getValue().getItemCount(), set.getValue().getDisplayName())); + Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slot=%s, item=%s): %dx %s", this.entityId, set.getKey(), set.getValue().getItem(), set.getValue().getItemCount(), set.getValue().getDisplayName())); } else { - Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slotCount=%d)", entityId, slots.size())); + Log.protocol(String.format("[IN] Entity equipment changed (entityId=%d, slotCount=%d)", this.entityId, this.slots.size())); } } public int getEntityId() { - return entityId; + return this.entityId; } public HashMap getSlots() { - return slots; + return this.slots; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEvent.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEvent.java index fb00d689b..eeec4f974 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEvent.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityEvent.java @@ -24,8 +24,8 @@ public class PacketEntityEvent implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readInt(); - eventId = buffer.readByte(); + this.entityId = buffer.readInt(); + this.eventId = buffer.readByte(); return true; } @@ -36,6 +36,6 @@ public class PacketEntityEvent implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity status: (entityId=%d, eventId=%s)", entityId, eventId)); + Log.protocol(String.format("[IN] Entity status: (entityId=%d, eventId=%s)", this.entityId, this.eventId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityHeadRotation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityHeadRotation.java index 3715cc7f9..20c3c918f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityHeadRotation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityHeadRotation.java @@ -37,14 +37,14 @@ public class PacketEntityHeadRotation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity %d moved head (yaw=%s)", entityId, headYaw)); + Log.protocol(String.format("[IN] Entity %d moved head (yaw=%s)", this.entityId, this.headYaw)); } public int getEntityId() { - return entityId; + return this.entityId; } public short getHeadYaw() { - return headYaw; + return this.headYaw; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityInitialisation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityInitialisation.java index 440d199de..c8fbb9ab9 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityInitialisation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityInitialisation.java @@ -23,7 +23,7 @@ public class PacketEntityInitialisation implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readEntityId(); + this.entityId = buffer.readEntityId(); return true; } @@ -34,10 +34,10 @@ public class PacketEntityInitialisation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Initialising entity (entityId=%d)", entityId)); + Log.protocol(String.format("[IN] Initialising entity (entityId=%d)", this.entityId)); } public int getEntityId() { - return entityId; + return this.entityId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java index 549637e8d..a25322b4c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMetadata.java @@ -26,7 +26,7 @@ public class PacketEntityMetadata implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { this.entityId = buffer.readEntityId(); - entityMetaData = buffer.readMetaData(); + this.entityMetaData = buffer.readMetaData(); return true; } @@ -37,14 +37,14 @@ public class PacketEntityMetadata implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received entity metadata (entityId=%d)", entityId)); + Log.protocol(String.format("[IN] Received entity metadata (entityId=%d)", this.entityId)); } public int getEntityId() { - return entityId; + return this.entityId; } public EntityMetaData getEntityData() { - return entityMetaData; + return this.entityMetaData; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovement.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovement.java index d3b024f77..16eb6f5a8 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovement.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovement.java @@ -45,14 +45,14 @@ public class PacketEntityMovement implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity %d moved relative %s", entityId, location)); + Log.protocol(String.format("[IN] Entity %d moved relative %s", this.entityId, this.location)); } public int getEntityId() { - return entityId; + return this.entityId; } public RelativeLocation getRelativeLocation() { - return location; + return this.location; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovementAndRotation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovementAndRotation.java index a534abed3..74220262e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovementAndRotation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityMovementAndRotation.java @@ -38,7 +38,7 @@ public class PacketEntityMovementAndRotation implements ClientboundPacket { this.yaw = buffer.readAngle(); this.pitch = buffer.readAngle(); if (buffer.getVersionId() >= 22) { - onGround = buffer.readBoolean(); + this.onGround = buffer.readBoolean(); } return true; } @@ -50,22 +50,22 @@ public class PacketEntityMovementAndRotation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity %d moved relative %s (yaw=%s, pitch=%s)", entityId, location, yaw, pitch)); + Log.protocol(String.format("[IN] Entity %d moved relative %s (yaw=%s, pitch=%s)", this.entityId, this.location, this.yaw, this.pitch)); } public int getEntityId() { - return entityId; + return this.entityId; } public RelativeLocation getRelativeLocation() { - return location; + return this.location; } public short getYaw() { - return yaw; + return this.yaw; } public short getPitch() { - return pitch; + return this.pitch; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java index 0121e6569..a89d48301 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityProperties.java @@ -42,7 +42,7 @@ public class PacketEntityProperties implements ClientboundPacket { ModifierActions operation = ModifierActions.byId(buffer.readUnsignedByte()); // ToDo: modifiers } - properties.put(key, new EntityProperty(value)); + this.properties.put(key, new EntityProperty(value)); } return true; } @@ -57,7 +57,7 @@ public class PacketEntityProperties implements ClientboundPacket { ModifierActions operation = ModifierActions.byId(buffer.readUnsignedByte()); // ToDo: modifiers } - properties.put(key, new EntityProperty(value)); + this.properties.put(key, new EntityProperty(value)); } return true; } @@ -69,11 +69,11 @@ public class PacketEntityProperties implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received entity properties (entityId=%d)", entityId)); + Log.protocol(String.format("[IN] Received entity properties (entityId=%d)", this.entityId)); } public int getEntityId() { - return entityId; + return this.entityId; } public enum ModifierActions { @@ -81,8 +81,10 @@ public class PacketEntityProperties implements ClientboundPacket { ADD_PERCENT, MULTIPLY; + private static final ModifierActions[] MODIFIER_ACTIONS = values(); + public static ModifierActions byId(int id) { - return values()[id]; + return MODIFIER_ACTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityRotation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityRotation.java index 39bc71354..8689f6ffa 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityRotation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityRotation.java @@ -32,7 +32,7 @@ public class PacketEntityRotation implements ClientboundPacket { this.pitch = buffer.readAngle(); if (buffer.getVersionId() >= 22) { - onGround = buffer.readBoolean(); + this.onGround = buffer.readBoolean(); } return true; } @@ -44,18 +44,18 @@ public class PacketEntityRotation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity %d moved relative (yaw=%s, pitch=%s)", entityId, yaw, pitch)); + Log.protocol(String.format("[IN] Entity %d moved relative (yaw=%s, pitch=%s)", this.entityId, this.yaw, this.pitch)); } public int getEntityId() { - return entityId; + return this.entityId; } public short getYaw() { - return yaw; + return this.yaw; } public short getPitch() { - return pitch; + return this.pitch; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntitySoundEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntitySoundEffect.java index 60130b1ad..671ce71b4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntitySoundEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntitySoundEffect.java @@ -28,11 +28,11 @@ public class PacketEntitySoundEffect implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - soundId = buffer.readVarInt(); - category = SoundCategories.byId(buffer.readVarInt()); - entityId = buffer.readVarInt(); - volume = buffer.readFloat(); - pitch = buffer.readFloat(); + this.soundId = buffer.readVarInt(); + this.category = SoundCategories.byId(buffer.readVarInt()); + this.entityId = buffer.readVarInt(); + this.volume = buffer.readFloat(); + this.pitch = buffer.readFloat(); return true; } @@ -43,26 +43,26 @@ public class PacketEntitySoundEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Play sound entity effect (soundId=%d, category=%s, entityId=%d, volume=%s, pitch=%s)", soundId, category, entityId, volume, pitch)); + Log.protocol(String.format("[IN] Play sound entity effect (soundId=%d, category=%s, entityId=%d, volume=%s, pitch=%s)", this.soundId, this.category, this.entityId, this.volume, this.pitch)); } public int getSoundId() { - return soundId; + return this.soundId; } public SoundCategories getCategory() { - return category; + return this.category; } public int getEntityId() { - return entityId; + return this.entityId; } public float getVolume() { - return volume; + return this.volume; } public float getPitch() { - return pitch; + return this.pitch; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityTeleport.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityTeleport.java index c4dd81ff5..3f3c23009 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityTeleport.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityTeleport.java @@ -51,22 +51,22 @@ public class PacketEntityTeleport implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity %d moved to %s (yaw=%s, pitch=%s)", entityId, location, yaw, pitch)); + Log.protocol(String.format("[IN] Entity %d moved to %s (yaw=%s, pitch=%s)", this.entityId, this.location, this.yaw, this.pitch)); } public int getEntityId() { - return entityId; + return this.entityId; } public Location getRelativeLocation() { - return location; + return this.location; } public short getYaw() { - return yaw; + return this.yaw; } public short getPitch() { - return pitch; + return this.pitch; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityVelocity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityVelocity.java index 50db055b1..619cfdcd1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityVelocity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketEntityVelocity.java @@ -38,14 +38,14 @@ public class PacketEntityVelocity implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity velocity changed %d: %s", entityId, velocity.toString())); + Log.protocol(String.format("[IN] Entity velocity changed %d: %s", this.entityId, this.velocity.toString())); } public int getEntityId() { - return entityId; + return this.entityId; } public Velocity getVelocity() { - return velocity; + return this.velocity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketExplosion.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketExplosion.java index 0b292db6e..13003524e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketExplosion.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketExplosion.java @@ -29,22 +29,22 @@ public class PacketExplosion implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = new Location(buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); - radius = buffer.readFloat(); - if (radius > 100.0F) { + this.location = new Location(buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); + this.radius = buffer.readFloat(); + if (this.radius > 100.0F) { // maybe somebody tries to make bullshit? // Sorry, Maximilian Rosenmüller - throw new IllegalArgumentException(String.format("Explosion to big %s > 100.0F", radius)); + throw new IllegalArgumentException(String.format("Explosion to big %s > 100.0F", this.radius)); } int recordCount = buffer.readInt(); - records = new byte[recordCount][3]; + this.records = new byte[recordCount][3]; for (int i = 0; i < recordCount; i++) { - records[i] = buffer.readBytes(3); + this.records[i] = buffer.readBytes(3); } - motionX = buffer.readFloat(); - motionY = buffer.readFloat(); - motionZ = buffer.readFloat(); + this.motionX = buffer.readFloat(); + this.motionY = buffer.readFloat(); + this.motionZ = buffer.readFloat(); return true; } @@ -55,30 +55,30 @@ public class PacketExplosion implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Explosion packet received at %s (recordCount=%d, radius=%s)", location, records.length, radius)); + Log.protocol(String.format("[IN] Explosion packet received at %s (recordCount=%d, radius=%s)", this.location, this.records.length, this.radius)); } public Location getLocation() { - return location; + return this.location; } public float getMotionX() { - return motionX; + return this.motionX; } public float getMotionY() { - return motionY; + return this.motionY; } public float getMotionZ() { - return motionZ; + return this.motionZ; } public byte[][] getRecords() { - return records; + return this.records; } public float getRadius() { - return radius; + return this.radius; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketFacePlayer.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketFacePlayer.java index 2e66b322c..7a1bfa15e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketFacePlayer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketFacePlayer.java @@ -27,12 +27,12 @@ public class PacketFacePlayer implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - face = PlayerFaces.byId(buffer.readVarInt()); - location = buffer.readLocation(); + this.face = PlayerFaces.byId(buffer.readVarInt()); + this.location = buffer.readLocation(); if (buffer.readBoolean()) { // entity present - entityId = buffer.readVarInt(); - entityFace = PlayerFaces.byId(buffer.readVarInt()); + this.entityId = buffer.readVarInt(); + this.entityFace = PlayerFaces.byId(buffer.readVarInt()); } return true; } @@ -44,31 +44,33 @@ public class PacketFacePlayer implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received face player packet (face=%s, location=%s, entityId=%d, entityFace=%s)", face, location, entityId, entityFace)); + Log.protocol(String.format("[IN] Received face player packet (face=%s, location=%s, entityId=%d, entityFace=%s)", this.face, this.location, this.entityId, this.entityFace)); } public PlayerFaces getFace() { - return face; + return this.face; } public Location getLocation() { - return location; + return this.location; } public int getEntityId() { - return entityId; + return this.entityId; } public PlayerFaces getEntityFace() { - return entityFace; + return this.entityFace; } public enum PlayerFaces { FEET, EYES; + private static final PlayerFaces[] PLAYER_FACES = values(); + public static PlayerFaces byId(int id) { - return values()[id]; + return PLAYER_FACES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketHeldItemChangeReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketHeldItemChangeReceiving.java index 90dc3c424..18defdb27 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketHeldItemChangeReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketHeldItemChangeReceiving.java @@ -23,7 +23,7 @@ public class PacketHeldItemChangeReceiving implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - slot = buffer.readByte(); + this.slot = buffer.readByte(); return true; } @@ -34,10 +34,10 @@ public class PacketHeldItemChangeReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Slot change received. Now on slot %s", slot)); + Log.protocol(String.format("[IN] Slot change received. Now on slot %s", this.slot)); } public byte getSlot() { - return slot; + return this.slot; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketJoinGame.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketJoinGame.java index 3f208d875..47a2ec244 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketJoinGame.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketJoinGame.java @@ -49,38 +49,38 @@ public class PacketJoinGame implements ClientboundPacket { if (buffer.getVersionId() < 108) { this.entityId = buffer.readInt(); byte gameModeRaw = buffer.readByte(); - hardcore = BitByte.isBitSet(gameModeRaw, 3); + this.hardcore = BitByte.isBitSet(gameModeRaw, 3); // remove hardcore bit and get gamemode gameModeRaw &= ~0x8; - gameMode = GameModes.byId(gameModeRaw); + this.gameMode = GameModes.byId(gameModeRaw); if (buffer.getVersionId() < 108) { - dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readByte()); + this.dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readByte()); } else { - dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); + this.dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); } - difficulty = Difficulties.byId(buffer.readUnsignedByte()); - maxPlayers = buffer.readByte(); + this.difficulty = Difficulties.byId(buffer.readUnsignedByte()); + this.maxPlayers = buffer.readByte(); if (buffer.getVersionId() >= 1) { - levelType = LevelTypes.byType(buffer.readString()); + this.levelType = LevelTypes.byType(buffer.readString()); } if (buffer.getVersionId() < 29) { return true; } - reducedDebugScreen = buffer.readBoolean(); + this.reducedDebugScreen = buffer.readBoolean(); return true; } this.entityId = buffer.readInt(); if (buffer.getVersionId() < 738) { byte gameModeRaw = buffer.readByte(); - hardcore = BitByte.isBitSet(gameModeRaw, 3); + this.hardcore = BitByte.isBitSet(gameModeRaw, 3); // remove hardcore bit and get gamemode gameModeRaw &= ~0x8; - gameMode = GameModes.byId(gameModeRaw); + this.gameMode = GameModes.byId(gameModeRaw); } else { - hardcore = buffer.readBoolean(); - gameMode = GameModes.byId(buffer.readUnsignedByte()); + this.hardcore = buffer.readBoolean(); + this.gameMode = GameModes.byId(buffer.readUnsignedByte()); } if (buffer.getVersionId() >= 730) { buffer.readByte(); // previous game mode @@ -89,19 +89,19 @@ public class PacketJoinGame implements ClientboundPacket { String[] worlds = buffer.readStringArray(buffer.readVarInt()); } if (buffer.getVersionId() < 718) { - dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); + this.dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); } else { NBTTag dimensionCodec = buffer.readNBT(); - dimensions = parseDimensionCodec(dimensionCodec, buffer.getVersionId()); + this.dimensions = parseDimensionCodec(dimensionCodec, buffer.getVersionId()); if (buffer.getVersionId() < 748) { String[] currentDimensionSplit = buffer.readString().split(":", 2); - dimension = dimensions.get(currentDimensionSplit[0]).get(currentDimensionSplit[1]); + this.dimension = this.dimensions.get(currentDimensionSplit[0]).get(currentDimensionSplit[1]); } else { CompoundTag tag = (CompoundTag) buffer.readNBT(); if (tag.getByteTag("has_skylight").getValue() == 0x01) { // ToDo: this is just for not messing up the skylight - dimension = dimensions.get(ProtocolDefinition.DEFAULT_MOD).get("overworld"); + this.dimension = this.dimensions.get(ProtocolDefinition.DEFAULT_MOD).get("overworld"); } else { - dimension = dimensions.get(ProtocolDefinition.DEFAULT_MOD).get("the_nether"); + this.dimension = this.dimensions.get(ProtocolDefinition.DEFAULT_MOD).get("the_nether"); } } } @@ -110,31 +110,31 @@ public class PacketJoinGame implements ClientboundPacket { buffer.readString(); // world } if (buffer.getVersionId() >= 552) { - hashedSeed = buffer.readLong(); + this.hashedSeed = buffer.readLong(); } if (buffer.getVersionId() < 464) { - difficulty = Difficulties.byId(buffer.readUnsignedByte()); + this.difficulty = Difficulties.byId(buffer.readUnsignedByte()); } if (buffer.getVersionId() < 749) { - maxPlayers = buffer.readByte(); + this.maxPlayers = buffer.readByte(); } else { - maxPlayers = buffer.readVarInt(); + this.maxPlayers = buffer.readVarInt(); } if (buffer.getVersionId() < 716) { - levelType = LevelTypes.byType(buffer.readString()); + this.levelType = LevelTypes.byType(buffer.readString()); } if (buffer.getVersionId() >= 468) { - viewDistance = buffer.readVarInt(); + this.viewDistance = buffer.readVarInt(); } if (buffer.getVersionId() >= 716) { boolean isDebug = buffer.readBoolean(); if (buffer.readBoolean()) { - levelType = LevelTypes.FLAT; + this.levelType = LevelTypes.FLAT; } } - reducedDebugScreen = buffer.readBoolean(); + this.reducedDebugScreen = buffer.readBoolean(); if (buffer.getVersionId() >= 552) { - enableRespawnScreen = buffer.readBoolean(); + this.enableRespawnScreen = buffer.readBoolean(); } return true; } @@ -177,54 +177,54 @@ public class PacketJoinGame implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving join game packet (entityId=%s, gameMode=%s, dimension=%s, difficulty=%s, hardcore=%s, viewDistance=%d)", entityId, gameMode, dimension, difficulty, hardcore, viewDistance)); + Log.protocol(String.format("[IN] Receiving join game packet (entityId=%s, gameMode=%s, dimension=%s, difficulty=%s, hardcore=%s, viewDistance=%d)", this.entityId, this.gameMode, this.dimension, this.difficulty, this.hardcore, this.viewDistance)); } public boolean isHardcore() { - return hardcore; + return this.hardcore; } public int getEntityId() { - return entityId; + return this.entityId; } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public int getMaxPlayers() { - return maxPlayers; + return this.maxPlayers; } public LevelTypes getLevelType() { - return levelType; + return this.levelType; } public Difficulties getDifficulty() { - return difficulty; + return this.difficulty; } public Dimension getDimension() { - return dimension; + return this.dimension; } public int getViewDistance() { - return viewDistance; + return this.viewDistance; } public HashMap> getDimensions() { - return dimensions; + return this.dimensions; } public boolean isReducedDebugScreen() { - return reducedDebugScreen; + return this.reducedDebugScreen; } public boolean isEnableRespawnScreen() { - return enableRespawnScreen; + return this.enableRespawnScreen; } public long getHashedSeed() { - return hashedSeed; + return this.hashedSeed; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketKeepAlive.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketKeepAlive.java index a0482e3e6..6a28261dc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketKeepAlive.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketKeepAlive.java @@ -24,14 +24,14 @@ public class PacketKeepAlive implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 32) { - id = buffer.readInt(); + this.id = buffer.readInt(); return true; } if (buffer.getVersionId() < 339) { - id = buffer.readVarInt(); + this.id = buffer.readVarInt(); return true; } - id = buffer.readLong(); + this.id = buffer.readLong(); return true; } @@ -42,10 +42,10 @@ public class PacketKeepAlive implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Keep alive packet received (%d)", id)); + Log.protocol(String.format("[IN] Keep alive packet received (%d)", this.id)); } public long getId() { - return id; + return this.id; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java index ebcd64111..52a005bab 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java @@ -34,7 +34,7 @@ public class PacketMapData implements ClientboundPacket { // players ArrayList pins; - boolean locked = false; + boolean locked; // scale byte scale; @@ -42,37 +42,37 @@ public class PacketMapData implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - mapId = buffer.readVarInt(); // mapId + this.mapId = buffer.readVarInt(); // mapId if (buffer.getVersionId() < 27) { int length = buffer.readUnsignedShort(); // read action - dataData = PacketMapDataDataActions.byId(buffer.readUnsignedByte()); - switch (dataData) { + this.dataData = PacketMapDataDataActions.byId(buffer.readUnsignedByte()); + switch (this.dataData) { case START -> { - xStart = buffer.readByte(); - yStart = buffer.readByte(); - colors = buffer.readBytes(length - 3); // 3: dataData(1) + xStart (1) + yStart (1) + this.xStart = buffer.readByte(); + this.yStart = buffer.readByte(); + this.colors = buffer.readBytes(length - 3); // 3: dataData(1) + xStart (1) + yStart (1) } case PLAYERS -> { - pins = new ArrayList<>(); + this.pins = new ArrayList<>(); length--; // minus the dataData for (int i = 0; i < length / 3; i++) { // loop over all sets ( 1 set: 3 bytes) byte directionAndType = buffer.readByte(); byte x = buffer.readByte(); byte z = buffer.readByte(); - pins.add(new MapPinSet(MapPinTypes.byId(directionAndType & 0xF), directionAndType >>> 4, x, z)); + this.pins.add(new MapPinSet(MapPinTypes.byId(directionAndType & 0xF), directionAndType >>> 4, x, z)); } } - case SCALE -> scale = buffer.readByte(); + case SCALE -> this.scale = buffer.readByte(); } return true; } - scale = buffer.readByte(); + this.scale = buffer.readByte(); if (buffer.getVersionId() >= 58 && buffer.getVersionId() < 759) { boolean trackPosition = buffer.readBoolean(); } if (buffer.getVersionId() >= 452) { - locked = buffer.readBoolean(); + this.locked = buffer.readBoolean(); } int pinCount = 0; if (buffer.getVersionId() < 759) { @@ -82,7 +82,7 @@ public class PacketMapData implements ClientboundPacket { pinCount = buffer.readVarInt(); } } - pins = new ArrayList<>(); + this.pins = new ArrayList<>(); for (int i = 0; i < pinCount; i++) { if (buffer.getVersionId() < 373) { @@ -90,9 +90,9 @@ public class PacketMapData implements ClientboundPacket { byte x = buffer.readByte(); byte z = buffer.readByte(); if (buffer.getVersionId() >= 340) { // ToDo - pins.add(new MapPinSet(MapPinTypes.byId(directionAndType >>> 4), directionAndType & 0xF, x, z)); + this.pins.add(new MapPinSet(MapPinTypes.byId(directionAndType >>> 4), directionAndType & 0xF, x, z)); } else { - pins.add(new MapPinSet(MapPinTypes.byId(directionAndType & 0xF), directionAndType >>> 4, x, z)); + this.pins.add(new MapPinSet(MapPinTypes.byId(directionAndType & 0xF), directionAndType >>> 4, x, z)); } continue; } @@ -104,7 +104,7 @@ public class PacketMapData implements ClientboundPacket { if (buffer.readBoolean()) { displayName = buffer.readChatComponent(); } - pins.add(new MapPinSet(type, direction, x, z, displayName)); + this.pins.add(new MapPinSet(type, direction, x, z, displayName)); } short columns = buffer.readUnsignedByte(); @@ -114,7 +114,7 @@ public class PacketMapData implements ClientboundPacket { short zOffset = buffer.readUnsignedByte(); int dataLength = buffer.readVarInt(); - data = buffer.readBytes(dataLength); + this.data = buffer.readBytes(dataLength); } return true; } @@ -126,31 +126,31 @@ public class PacketMapData implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received map meta data (mapId=%d)", mapId)); + Log.protocol(String.format("[IN] Received map meta data (mapId=%d)", this.mapId)); } public PacketMapDataDataActions getDataData() { - return dataData; + return this.dataData; } public byte getXStart() { - return xStart; + return this.xStart; } public byte getYStart() { - return yStart; + return this.yStart; } public byte[] getColors() { - return colors; + return this.colors; } public ArrayList getPins() { - return pins; + return this.pins; } public byte getScale() { - return scale; + return this.scale; } public enum PacketMapDataDataActions { @@ -158,8 +158,10 @@ public class PacketMapData implements ClientboundPacket { PLAYERS, SCALE; + private static final PacketMapDataDataActions[] MAP_DATA_DATA_ACTIONS = values(); + public static PacketMapDataDataActions byId(int id) { - return values()[id]; + return MAP_DATA_DATA_ACTIONS[id]; } } @@ -193,8 +195,10 @@ public class PacketMapData implements ClientboundPacket { BLACK_BANNER, TREASURE_MARKER; + private static final MapPinTypes[] MAP_PIN_TYPES = values(); + public static MapPinTypes byId(int id) { - return values()[id]; + return MAP_PIN_TYPES[id]; } } @@ -210,7 +214,7 @@ public class PacketMapData implements ClientboundPacket { this.direction = (byte) direction; this.x = x; this.z = z; - displayName = null; + this.displayName = null; } public MapPinSet(MapPinTypes type, int direction, byte x, byte z, ChatComponent displayName) { @@ -222,19 +226,19 @@ public class PacketMapData implements ClientboundPacket { } public MapPinTypes getType() { - return type; + return this.type; } public byte getDirection() { - return direction; + return this.direction; } public byte getX() { - return x; + return this.x; } public byte getZ() { - return z; + return this.z; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMultiBlockChange.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMultiBlockChange.java index 65b3f60ec..5315acb79 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMultiBlockChange.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMultiBlockChange.java @@ -31,9 +31,9 @@ public class PacketMultiBlockChange implements ClientboundPacket { public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 25) { if (buffer.getVersionId() < 4) { - location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); + this.location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); } else { - location = new ChunkLocation(buffer.readInt(), buffer.readInt()); + this.location = new ChunkLocation(buffer.readInt(), buffer.readInt()); } short count = buffer.readShort(); int dataSize = buffer.readInt(); // should be count * 4 @@ -44,23 +44,23 @@ public class PacketMultiBlockChange implements ClientboundPacket { byte y = (byte) ((raw & 0xFF_00_00) >>> 16); byte z = (byte) ((raw & 0x0F_00_00_00) >>> 24); byte x = (byte) ((raw & 0xF0_00_00_00) >>> 28); - blocks.put(new InChunkLocation(x, y, z), buffer.getConnection().getMapping().getBlockById((blockId << 4) | meta)); + this.blocks.put(new InChunkLocation(x, y, z), buffer.getConnection().getMapping().getBlockById((blockId << 4) | meta)); } return true; } if (buffer.getVersionId() < 740) { - location = new ChunkLocation(buffer.readInt(), buffer.readInt()); + this.location = new ChunkLocation(buffer.readInt(), buffer.readInt()); int count = buffer.readVarInt(); for (int i = 0; i < count; i++) { byte pos = buffer.readByte(); byte y = buffer.readByte(); int blockId = buffer.readVarInt(); - blocks.put(new InChunkLocation((pos & 0xF0 >>> 4) & 0xF, y, pos & 0xF), buffer.getConnection().getMapping().getBlockById(blockId)); + this.blocks.put(new InChunkLocation((pos & 0xF0 >>> 4) & 0xF, y, pos & 0xF), buffer.getConnection().getMapping().getBlockById(blockId)); } return true; } long rawPos = buffer.readLong(); - location = new ChunkLocation((int) (rawPos >> 42), (int) (rawPos << 22 >> 42)); + this.location = new ChunkLocation((int) (rawPos >> 42), (int) (rawPos << 22 >> 42)); int yOffset = ((int) rawPos & 0xFFFFF) * 16; if (buffer.getVersionId() > 748) { buffer.readBoolean(); // ToDo @@ -68,7 +68,7 @@ public class PacketMultiBlockChange implements ClientboundPacket { int count = buffer.readVarInt(); for (int i = 0; i < count; i++) { long data = buffer.readVarLong(); - blocks.put(new InChunkLocation((int) ((data >> 8) & 0xF), yOffset + (int) ((data >> 4) & 0xF), (int) (data & 0xF)), buffer.getConnection().getMapping().getBlockById(((int) (data >>> 12)))); + this.blocks.put(new InChunkLocation((int) ((data >> 8) & 0xF), yOffset + (int) ((data >> 4) & 0xF), (int) (data & 0xF)), buffer.getConnection().getMapping().getBlockById(((int) (data >>> 12)))); } return true; } @@ -80,14 +80,14 @@ public class PacketMultiBlockChange implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Multi block change received at %s (size=%d)", location, blocks.size())); + Log.protocol(String.format("[IN] Multi block change received at %s (size=%d)", this.location, this.blocks.size())); } public ChunkLocation getLocation() { - return location; + return this.location; } public HashMap getBlocks() { - return blocks; + return this.blocks; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNBTQueryResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNBTQueryResponse.java index a58b42ba6..fe647de25 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNBTQueryResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNBTQueryResponse.java @@ -25,8 +25,8 @@ public class PacketNBTQueryResponse implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - transactionId = buffer.readVarInt(); - tag = (CompoundTag) buffer.readNBT(); + this.transactionId = buffer.readVarInt(); + this.tag = (CompoundTag) buffer.readNBT(); return true; } @@ -37,14 +37,14 @@ public class PacketNBTQueryResponse implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received nbt response (transactionId=%d, nbt=%s)", transactionId, tag.toString())); + Log.protocol(String.format("[IN] Received nbt response (transactionId=%d, nbt=%s)", this.transactionId, this.tag.toString())); } public int getTransactionId() { - return transactionId; + return this.transactionId; } public CompoundTag getTag() { - return tag; + return this.tag; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java index cf3738256..b54a394cc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketNamedSoundEffect.java @@ -19,9 +19,9 @@ import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; public class PacketNamedSoundEffect implements ClientboundPacket { - static final float pitchCalc = 100.0F / 63.0F; Location location; String sound; float volume; @@ -32,28 +32,28 @@ public class PacketNamedSoundEffect implements ClientboundPacket { public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() >= 321 && buffer.getVersionId() < 326) { // category was moved to the top - category = SoundCategories.byId(buffer.readVarInt()); + this.category = SoundCategories.byId(buffer.readVarInt()); } - sound = buffer.readString(); + this.sound = buffer.readString(); if (buffer.getVersionId() >= 321 && buffer.getVersionId() < 326) { buffer.readString(); // parrot entity type } if (buffer.getVersionId() < 95) { - location = new Location(buffer.readInt() * 8, buffer.readInt() * 8, buffer.readInt() * 8); // ToDo: check if it is not * 4 + this.location = new Location(buffer.readInt() * 8, buffer.readInt() * 8, buffer.readInt() * 8); // ToDo: check if it is not * 4 } if (buffer.getVersionId() >= 95 && (buffer.getVersionId() < 321 || buffer.getVersionId() >= 326)) { - category = SoundCategories.byId(buffer.readVarInt()); + this.category = SoundCategories.byId(buffer.readVarInt()); } if (buffer.getVersionId() >= 95) { - location = new Location(buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4); + this.location = new Location(buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4); } - volume = buffer.readFloat(); + this.volume = buffer.readFloat(); if (buffer.getVersionId() < 201) { - pitch = (buffer.readByte() * pitchCalc) / 100F; + this.pitch = (buffer.readByte() * ProtocolDefinition.PITCH_CALCULATION_CONSTANT) / 100F; } else { - pitch = buffer.readFloat(); + this.pitch = buffer.readFloat(); } return true; } @@ -65,29 +65,29 @@ public class PacketNamedSoundEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Play sound effect (sound=%s, category=%s, volume=%s, pitch=%s, location=%s)", sound, category, volume, pitch, location)); + Log.protocol(String.format("[IN] Play sound effect (sound=%s, category=%s, volume=%s, pitch=%s, location=%s)", this.sound, this.category, this.volume, this.pitch, this.location)); } public Location getLocation() { - return location; + return this.location; } /** * @return Pitch in Percent */ public float getPitch() { - return pitch; + return this.pitch; } public String getSound() { - return sound; + return this.sound; } public float getVolume() { - return volume; + return this.volume; } public SoundCategories getCategory() { - return category; + return this.category; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java index 93e23d57a..4b2d6aff4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenBook.java @@ -25,10 +25,10 @@ public class PacketOpenBook implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.readVarInt() == 0) { - hand = Hands.MAIN_HAND; + this.hand = Hands.MAIN_HAND; return true; } - hand = Hands.OFF_HAND; + this.hand = Hands.OFF_HAND; return true; } @@ -39,10 +39,10 @@ public class PacketOpenBook implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received open book packet (hand=%s)", hand)); + Log.protocol(String.format("[IN] Received open book packet (hand=%s)", this.hand)); } public Hands getHand() { - return hand; + return this.hand; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenHorseWindow.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenHorseWindow.java index e938d1dcf..41859c084 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenHorseWindow.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenHorseWindow.java @@ -38,18 +38,18 @@ public class PacketOpenHorseWindow implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received open horse window packet (windowId=%d, slotCount=%d, entityId=%s)", windowId, slotCount, entityId)); + Log.protocol(String.format("[IN] Received open horse window packet (windowId=%d, slotCount=%d, entityId=%s)", this.windowId, this.slotCount, this.entityId)); } public byte getWindowId() { - return windowId; + return this.windowId; } public int getSlotCount() { - return slotCount; + return this.slotCount; } public int getEntityId() { - return entityId; + return this.entityId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenSignEditor.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenSignEditor.java index 306f88d6e..d7aab53e0 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenSignEditor.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenSignEditor.java @@ -25,10 +25,10 @@ public class PacketOpenSignEditor implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 6) { - position = buffer.readBlockPositionInteger(); + this.position = buffer.readBlockPositionInteger(); return true; } - position = buffer.readPosition(); + this.position = buffer.readPosition(); return true; } @@ -39,10 +39,10 @@ public class PacketOpenSignEditor implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Opening sign editor: %s", position)); + Log.protocol(String.format("[IN] Opening sign editor: %s", this.position)); } public BlockPosition getPosition() { - return position; + return this.position; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java index cf73173a6..d47589ac4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketOpenWindow.java @@ -34,21 +34,21 @@ public class PacketOpenWindow implements ClientboundPacket { this.windowId = buffer.readByte(); this.type = InventoryTypes.byId(buffer.readUnsignedByte()); this.title = buffer.readChatComponent(); - slotCount = buffer.readByte(); + this.slotCount = buffer.readByte(); if (!buffer.readBoolean()) { // no custom name - title = null; + this.title = null; } this.entityId = buffer.readInt(); return true; } this.windowId = buffer.readByte(); - this.type = InventoryTypes.byName(buffer.readString()); + this.type = InventoryTypes.byIdentifier(buffer.readIdentifier()); this.title = buffer.readChatComponent(); if (buffer.getVersionId() < 452 || buffer.getVersionId() >= 464) { - slotCount = buffer.readByte(); + this.slotCount = buffer.readByte(); } - if (type == InventoryTypes.HORSE) { + if (this.type == InventoryTypes.HORSE) { this.entityId = buffer.readInt(); } return true; @@ -61,30 +61,30 @@ public class PacketOpenWindow implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received inventory open packet (windowId=%d, type=%s, title=%s, entityId=%d, slotCount=%d)", windowId, type, title, entityId, slotCount)); + Log.protocol(String.format("[IN] Received inventory open packet (windowId=%d, type=%s, title=%s, entityId=%d, slotCount=%d)", this.windowId, this.type, this.title, this.entityId, this.slotCount)); } public byte getSlotCount() { - return slotCount; + return this.slotCount; } public int getEntityId() { - return entityId; + return this.entityId; } public ChatComponent getTitle() { - return title; + return this.title; } public InventoryProperties getInventoryProperties() { - return new InventoryProperties(getWindowId(), getType(), title, slotCount); + return new InventoryProperties(getWindowId(), getType(), this.title, this.slotCount); } public byte getWindowId() { - return windowId; + return this.windowId; } public InventoryTypes getType() { - return type; + return this.type; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketParticle.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketParticle.java index 210c3c208..3622a62cb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketParticle.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketParticle.java @@ -24,7 +24,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketParticle implements ClientboundPacket { Particle particleType; ParticleData particleData; - boolean longDistance = false; + boolean longDistance; Location location; float offsetX; float offsetY; @@ -36,37 +36,37 @@ public class PacketParticle implements ClientboundPacket { public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 569) { if (buffer.getVersionId() < 17) { - particleType = buffer.getConnection().getMapping().getParticleByIdentifier(buffer.readString()); + this.particleType = buffer.getConnection().getMapping().getParticleByIdentifier(buffer.readString()); } else { - particleType = buffer.getConnection().getMapping().getParticleById(buffer.readInt()); + this.particleType = buffer.getConnection().getMapping().getParticleById(buffer.readInt()); } if (buffer.getVersionId() >= 29) { - longDistance = buffer.readBoolean(); + this.longDistance = buffer.readBoolean(); } - location = buffer.readSmallLocation(); + this.location = buffer.readSmallLocation(); // offset - offsetX = buffer.readFloat(); - offsetY = buffer.readFloat(); - offsetZ = buffer.readFloat(); + this.offsetX = buffer.readFloat(); + this.offsetY = buffer.readFloat(); + this.offsetZ = buffer.readFloat(); - particleDataFloat = buffer.readFloat(); - count = buffer.readInt(); - particleData = buffer.readParticleData(particleType); + this.particleDataFloat = buffer.readFloat(); + this.count = buffer.readInt(); + this.particleData = buffer.readParticleData(this.particleType); return true; } - particleType = buffer.getConnection().getMapping().getParticleById(buffer.readInt()); - longDistance = buffer.readBoolean(); - location = buffer.readLocation(); + this.particleType = buffer.getConnection().getMapping().getParticleById(buffer.readInt()); + this.longDistance = buffer.readBoolean(); + this.location = buffer.readLocation(); // offset - offsetX = buffer.readFloat(); - offsetY = buffer.readFloat(); - offsetZ = buffer.readFloat(); + this.offsetX = buffer.readFloat(); + this.offsetY = buffer.readFloat(); + this.offsetZ = buffer.readFloat(); - particleDataFloat = buffer.readFloat(); - count = buffer.readInt(); - particleData = buffer.readParticleData(particleType); + this.particleDataFloat = buffer.readFloat(); + this.count = buffer.readInt(); + this.particleData = buffer.readParticleData(this.particleType); return true; } @@ -77,42 +77,42 @@ public class PacketParticle implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received particle spawn packet (location=%s, offsetX=%s, offsetY=%s, offsetZ=%s, particleType=%s, dataFloat=%s, count=%d, particleData=%s)", location, offsetX, offsetY, offsetZ, particleType, particleDataFloat, count, particleData)); + Log.protocol(String.format("[IN] Received particle spawn packet (location=%s, offsetX=%s, offsetY=%s, offsetZ=%s, particleType=%s, dataFloat=%s, count=%d, particleData=%s)", this.location, this.offsetX, this.offsetY, this.offsetZ, this.particleType, this.particleDataFloat, this.count, this.particleData)); } public Location getLocation() { - return location; + return this.location; } public float getOffsetX() { - return offsetX; + return this.offsetX; } public float getOffsetY() { - return offsetY; + return this.offsetY; } public float getOffsetZ() { - return offsetZ; + return this.offsetZ; } public int getCount() { - return count; + return this.count; } public Particle getParticleType() { - return particleType; + return this.particleType; } public ParticleData getParticleData() { - return particleData; + return this.particleData; } public float getParticleDataFloat() { - return particleDataFloat; + return this.particleDataFloat; } public boolean isLongDistance() { - return longDistance; + return this.longDistance; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java index 566f96ba3..613ccbc0a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerAbilitiesReceiving.java @@ -31,21 +31,21 @@ public class PacketPlayerAbilitiesReceiving implements ClientboundPacket { public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 6) { // ToDo byte flags = buffer.readByte(); - creative = BitByte.isBitSet(flags, 0); - flying = BitByte.isBitSet(flags, 1); - canFly = BitByte.isBitSet(flags, 2); - godMode = BitByte.isBitSet(flags, 3); - flyingSpeed = buffer.readFloat(); - walkingSpeed = buffer.readFloat(); + this.creative = BitByte.isBitSet(flags, 0); + this.flying = BitByte.isBitSet(flags, 1); + this.canFly = BitByte.isBitSet(flags, 2); + this.godMode = BitByte.isBitSet(flags, 3); + this.flyingSpeed = buffer.readFloat(); + this.walkingSpeed = buffer.readFloat(); return true; } byte flags = buffer.readByte(); - godMode = BitByte.isBitSet(flags, 0); - flying = BitByte.isBitSet(flags, 1); - canFly = BitByte.isBitSet(flags, 2); - creative = BitByte.isBitSet(flags, 3); - flyingSpeed = buffer.readFloat(); - walkingSpeed = buffer.readFloat(); + this.godMode = BitByte.isBitSet(flags, 0); + this.flying = BitByte.isBitSet(flags, 1); + this.canFly = BitByte.isBitSet(flags, 2); + this.creative = BitByte.isBitSet(flags, 3); + this.flyingSpeed = buffer.readFloat(); + this.walkingSpeed = buffer.readFloat(); return true; } @@ -56,22 +56,22 @@ public class PacketPlayerAbilitiesReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", creative, flying, canFly, godMode, flyingSpeed, walkingSpeed)); + Log.protocol(String.format("[IN] Received player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", this.creative, this.flying, this.canFly, this.godMode, this.flyingSpeed, this.walkingSpeed)); } public boolean canFly() { - return canFly; + return this.canFly; } public boolean isCreative() { - return creative; + return this.creative; } public boolean isGodMode() { - return godMode; + return this.godMode; } public boolean isFlying() { - return flying; + return this.flying; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerListItem.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerListItem.java index bf1446062..e7cc1c2c8 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerListItem.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerListItem.java @@ -41,7 +41,7 @@ public class PacketPlayerListItem implements ClientboundPacket { ping = buffer.readVarInt(); } PlayerListItemActions action = (buffer.readBoolean() ? PlayerListItemActions.UPDATE_LATENCY : PlayerListItemActions.REMOVE_PLAYER); - playerList.add(new PlayerListItemBulk(name, ping, action)); + this.playerList.add(new PlayerListItemBulk(name, ping, action)); return true; } PlayerListItemActions action = PlayerListItemActions.byId(buffer.readVarInt()); @@ -70,7 +70,7 @@ public class PacketPlayerListItem implements ClientboundPacket { case REMOVE_PLAYER -> listItemBulk = new PlayerListItemBulk(uuid, null, 0, null, null, null, action); default -> listItemBulk = null; } - playerList.add(listItemBulk); + this.playerList.add(listItemBulk); } return true; } @@ -82,13 +82,13 @@ public class PacketPlayerListItem implements ClientboundPacket { @Override public void log() { - for (PlayerListItemBulk property : playerList) { + for (PlayerListItemBulk property : this.playerList) { Log.protocol(String.format("[IN] Received player list item bulk (%s)", property)); } } public ArrayList getPlayerList() { - return playerList; + return this.playerList; } public enum PlayerListItemActions { @@ -98,8 +98,10 @@ public class PacketPlayerListItem implements ClientboundPacket { UPDATE_DISPLAY_NAME, REMOVE_PLAYER; + private static final PlayerListItemActions[] PLAYER_LIST_ITEM_ACTIONS = values(); + public static PlayerListItemActions byId(int id) { - return values()[id]; + return PLAYER_LIST_ITEM_ACTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java index b592a0eee..1227f06bf 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java @@ -30,16 +30,16 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = buffer.readLocation(); - rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0); + this.location = buffer.readLocation(); + this.rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0); if (buffer.getVersionId() < 6) { - onGround = buffer.readBoolean(); + this.onGround = buffer.readBoolean(); return true; } else { - flags = buffer.readByte(); + this.flags = buffer.readByte(); } if (buffer.getVersionId() >= 79) { - teleportId = buffer.readVarInt(); + this.teleportId = buffer.readVarInt(); } return true; } @@ -51,23 +51,23 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received player location: (location=%s, rotation=%s, onGround=%b)", location, rotation, onGround)); + Log.protocol(String.format("[IN] Received player location: (location=%s, rotation=%s, onGround=%b)", this.location, this.rotation, this.onGround)); } public Location getLocation() { - return location; + return this.location; } public EntityRotation getRotation() { - return rotation; + return this.rotation; } public boolean isOnGround() { - return onGround; + return this.onGround; } public int getTeleportId() { - return teleportId; + return this.teleportId; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPluginMessageReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPluginMessageReceiving.java index 944bb38cb..7c055ca0e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPluginMessageReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPluginMessageReceiving.java @@ -27,14 +27,14 @@ public class PacketPluginMessageReceiving implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { this.connection = buffer.getConnection(); - channel = buffer.readString(); + this.channel = buffer.readString(); // "read" length prefix if (buffer.getVersionId() < 29) { buffer.readShort(); } else if (buffer.getVersionId() < 32) { buffer.readVarInt(); } - data = buffer.readBytesLeft(); + this.data = buffer.readBytesLeft(); return true; } @@ -45,18 +45,18 @@ public class PacketPluginMessageReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Plugin message received in channel \"%s\" with %s bytes of data", channel, data.length)); + Log.protocol(String.format("[IN] Plugin message received in channel \"%s\" with %s bytes of data", this.channel, this.data.length)); } public String getChannel() { - return channel; + return this.channel; } public byte[] getData() { - return data; + return this.data; } public InByteBuffer getDataAsBuffer() { - return new InByteBuffer(getData(), connection); + return new InByteBuffer(getData(), this.connection); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRemoveEntityEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRemoveEntityEffect.java index 633a37d19..f6130fb05 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRemoveEntityEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRemoveEntityEffect.java @@ -27,7 +27,7 @@ public class PacketRemoveEntityEffect implements ClientboundPacket { public boolean read(InByteBuffer buffer) { this.entityId = buffer.readEntityId(); - effect = buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()); + this.effect = buffer.getConnection().getMapping().getMobEffectById(buffer.readByte()); return true; } @@ -38,14 +38,14 @@ public class PacketRemoveEntityEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity effect removed (entityId=%d, effect=%s)", entityId, effect)); + Log.protocol(String.format("[IN] Entity effect removed (entityId=%d, effect=%s)", this.entityId, this.effect)); } public int getEntityId() { - return entityId; + return this.entityId; } public MobEffect getEffect() { - return effect; + return this.effect; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketResourcePackSend.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketResourcePackSend.java index adf790180..14b8b3bd2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketResourcePackSend.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketResourcePackSend.java @@ -21,14 +21,14 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketResourcePackSend implements ClientboundPacket { String url; String hash; - boolean forced = false; + boolean forced; @Override public boolean read(InByteBuffer buffer) { - url = buffer.readString(); - hash = buffer.readString(); + this.url = buffer.readString(); + this.hash = buffer.readString(); if (buffer.getVersionId() >= 758) { - forced = buffer.readBoolean(); + this.forced = buffer.readBoolean(); } return true; } @@ -40,18 +40,18 @@ public class PacketResourcePackSend implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received resource pack send (url=\"%s\", hash=%s", url, hash)); + Log.protocol(String.format("[IN] Received resource pack send (url=\"%s\", hash=%s", this.url, this.hash)); } public String getUrl() { - return url; + return this.url; } public String getHash() { - return hash; + return this.hash; } public boolean isForced() { - return forced; + return this.forced; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRespawn.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRespawn.java index fae106496..2ed8a8abb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRespawn.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketRespawn.java @@ -29,48 +29,48 @@ public class PacketRespawn implements ClientboundPacket { GameModes gameMode; LevelTypes levelType; long hashedSeed; - boolean isDebug = false; - boolean isFlat = false; - boolean copyMetaData = false; + boolean isDebug; + boolean isFlat; + boolean copyMetaData; @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 718) { if (buffer.getVersionId() < 47) { // ToDo: this should be 108 but wiki.vg is wrong. In 1.8 it is an int. - dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readByte()); + this.dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readByte()); } else { - dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); + this.dimension = buffer.getConnection().getMapping().getDimensionById(buffer.readInt()); } } else if (buffer.getVersionId() < 748) { - dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(buffer.readString()); + this.dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(buffer.readString()); } else { CompoundTag tag = (CompoundTag) buffer.readNBT(); - dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(tag.getStringTag("effects").getValue()); // ToDo + this.dimension = buffer.getConnection().getMapping().getDimensionByIdentifier(tag.getStringTag("effects").getValue()); // ToDo } if (buffer.getVersionId() < 464) { - difficulty = Difficulties.byId(buffer.readUnsignedByte()); + this.difficulty = Difficulties.byId(buffer.readUnsignedByte()); } if (buffer.getVersionId() >= 719) { buffer.readString(); // world } if (buffer.getVersionId() >= 552) { - hashedSeed = buffer.readLong(); + this.hashedSeed = buffer.readLong(); } - gameMode = GameModes.byId(buffer.readUnsignedByte()); + this.gameMode = GameModes.byId(buffer.readUnsignedByte()); if (buffer.getVersionId() >= 730) { buffer.readByte(); // previous game mode } if (buffer.getVersionId() >= 1 && buffer.getVersionId() < 716) { - levelType = LevelTypes.byType(buffer.readString()); + this.levelType = LevelTypes.byType(buffer.readString()); } if (buffer.getVersionId() >= 716) { - isDebug = buffer.readBoolean(); - isFlat = buffer.readBoolean(); + this.isDebug = buffer.readBoolean(); + this.isFlat = buffer.readBoolean(); } if (buffer.getVersionId() >= 714) { - copyMetaData = buffer.readBoolean(); + this.copyMetaData = buffer.readBoolean(); } return true; } @@ -82,22 +82,22 @@ public class PacketRespawn implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Respawn packet received (dimension=%s, difficulty=%s, gamemode=%s, levelType=%s)", dimension, difficulty, gameMode, levelType)); + Log.protocol(String.format("[IN] Respawn packet received (dimension=%s, difficulty=%s, gamemode=%s, levelType=%s)", this.dimension, this.difficulty, this.gameMode, this.levelType)); } public Dimension getDimension() { - return dimension; + return this.dimension; } public Difficulties getDifficulty() { - return difficulty; + return this.difficulty; } public GameModes getGameMode() { - return gameMode; + return this.gameMode; } public LevelTypes getLevelType() { - return levelType; + return this.levelType; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardDisplayScoreboard.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardDisplayScoreboard.java index a3e29e307..a9d8a7646 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardDisplayScoreboard.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardDisplayScoreboard.java @@ -24,8 +24,8 @@ public class PacketScoreboardDisplayScoreboard implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - action = ScoreboardAnimations.byId(buffer.readUnsignedByte()); - scoreName = buffer.readString(); + this.action = ScoreboardAnimations.byId(buffer.readUnsignedByte()); + this.scoreName = buffer.readString(); return true; } @@ -36,7 +36,7 @@ public class PacketScoreboardDisplayScoreboard implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received display scoreboard packet (position=%s, scoreName=\"%s\"", action, scoreName)); + Log.protocol(String.format("[IN] Received display scoreboard packet (position=%s, scoreName=\"%s\"", this.action, this.scoreName)); } public enum ScoreboardAnimations { @@ -60,8 +60,10 @@ public class PacketScoreboardDisplayScoreboard implements ClientboundPacket { TEAM_YELLOW, TEAM_WHITE; + private static final ScoreboardAnimations[] SCOREBOARD_ANIMATIONS = values(); + public static ScoreboardAnimations byId(int id) { - return values()[id]; + return SCOREBOARD_ANIMATIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardObjective.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardObjective.java index 4447fabc3..e6f05788a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardObjective.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardObjective.java @@ -27,14 +27,14 @@ public class PacketScoreboardObjective implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - name = buffer.readString(); + this.name = buffer.readString(); if (buffer.getVersionId() < 7) { // ToDo - value = buffer.readChatComponent(); + this.value = buffer.readChatComponent(); } - action = ScoreboardObjectiveActions.byId(buffer.readUnsignedByte()); - if (action == ScoreboardObjectiveActions.CREATE || action == ScoreboardObjectiveActions.UPDATE) { + this.action = ScoreboardObjectiveActions.byId(buffer.readUnsignedByte()); + if (this.action == ScoreboardObjectiveActions.CREATE || this.action == ScoreboardObjectiveActions.UPDATE) { if (buffer.getVersionId() >= 7) { // ToDo - value = buffer.readChatComponent(); + this.value = buffer.readChatComponent(); } if (buffer.getVersionId() >= 12) { if (buffer.getVersionId() >= 346 && buffer.getVersionId() < 349) { @@ -42,9 +42,9 @@ public class PacketScoreboardObjective implements ClientboundPacket { return true; } if (buffer.getVersionId() < 349) { - type = ScoreboardObjectiveTypes.byName(buffer.readString()); + this.type = ScoreboardObjectiveTypes.byName(buffer.readString()); } else { - type = ScoreboardObjectiveTypes.byId(buffer.readVarInt()); + this.type = ScoreboardObjectiveTypes.byId(buffer.readVarInt()); } } } @@ -58,23 +58,23 @@ public class PacketScoreboardObjective implements ClientboundPacket { @Override public void log() { - if (action == ScoreboardObjectiveActions.CREATE || action == ScoreboardObjectiveActions.UPDATE) { - Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\", value=\"%s\", type=%s)", action, name, value.getANSIColoredMessage(), type)); + if (this.action == ScoreboardObjectiveActions.CREATE || this.action == ScoreboardObjectiveActions.UPDATE) { + Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\", value=\"%s\", type=%s)", this.action, this.name, this.value.getANSIColoredMessage(), this.type)); } else { - Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\")", action, name)); + Log.protocol(String.format("[IN] Received scoreboard objective action (action=%s, name=\"%s\")", this.action, this.name)); } } public String getName() { - return name; + return this.name; } public ChatComponent getValue() { - return value; + return this.value; } public ScoreboardObjectiveActions getAction() { - return action; + return this.action; } public enum ScoreboardObjectiveActions { @@ -82,8 +82,10 @@ public class PacketScoreboardObjective implements ClientboundPacket { REMOVE, UPDATE; + private static final ScoreboardObjectiveActions[] SCOREBOARD_OBJECTIVE_ACTIONS = values(); + public static ScoreboardObjectiveActions byId(int id) { - return values()[id]; + return SCOREBOARD_OBJECTIVE_ACTIONS[id]; } } @@ -91,6 +93,7 @@ public class PacketScoreboardObjective implements ClientboundPacket { INTEGER("integer"), HEARTS("hearts"); + private static final ScoreboardObjectiveTypes[] SCOREBOARD_OBJECTIVE_TYPES = values(); final String name; ScoreboardObjectiveTypes(String name) { @@ -107,11 +110,11 @@ public class PacketScoreboardObjective implements ClientboundPacket { } public static ScoreboardObjectiveTypes byId(int id) { - return values()[id]; + return SCOREBOARD_OBJECTIVE_TYPES[id]; } public String getName() { - return name; + return this.name; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardUpdateScore.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardUpdateScore.java index 7417414bd..bf5e72511 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardUpdateScore.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketScoreboardUpdateScore.java @@ -26,24 +26,24 @@ public class PacketScoreboardUpdateScore implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - itemName = buffer.readString(); - action = ScoreboardUpdateScoreActions.byId(buffer.readUnsignedByte()); + this.itemName = buffer.readString(); + this.action = ScoreboardUpdateScoreActions.byId(buffer.readUnsignedByte()); if (buffer.getVersionId() < 7) { // ToDo - if (action == ScoreboardUpdateScoreActions.REMOVE) { + if (this.action == ScoreboardUpdateScoreActions.REMOVE) { return true; } // not present id action == REMOVE - scoreName = buffer.readString(); - scoreValue = buffer.readInt(); + this.scoreName = buffer.readString(); + this.scoreValue = buffer.readInt(); return true; } - scoreName = buffer.readString(); + this.scoreName = buffer.readString(); - if (action == ScoreboardUpdateScoreActions.REMOVE) { + if (this.action == ScoreboardUpdateScoreActions.REMOVE) { return true; } // not present id action == REMOVE - scoreValue = buffer.readVarInt(); + this.scoreValue = buffer.readVarInt(); return true; } @@ -54,31 +54,33 @@ public class PacketScoreboardUpdateScore implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received scoreboard score update (itemName=\"%s\", action=%s, scoreName=\"%s\", scoreValue=%d", itemName, action, scoreName, scoreValue)); + Log.protocol(String.format("[IN] Received scoreboard score update (itemName=\"%s\", action=%s, scoreName=\"%s\", scoreValue=%d", this.itemName, this.action, this.scoreName, this.scoreValue)); } public String getItemName() { - return itemName; + return this.itemName; } public ScoreboardUpdateScoreActions getAction() { - return action; + return this.action; } public String getScoreName() { - return scoreName; + return this.scoreName; } public int getScoreValue() { - return scoreValue; + return this.scoreValue; } public enum ScoreboardUpdateScoreActions { CREATE_UPDATE, REMOVE; + private static final ScoreboardUpdateScoreActions[] SCOREBOARD_UPDATE_SCORE_ACTIONS = values(); + public static ScoreboardUpdateScoreActions byId(int id) { - return values()[id]; + return SCOREBOARD_UPDATE_SCORE_ACTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSelectAdvancementTab.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSelectAdvancementTab.java index 6b57e189b..e5a568f70 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSelectAdvancementTab.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSelectAdvancementTab.java @@ -25,7 +25,7 @@ public class PacketSelectAdvancementTab implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.readBoolean()) { - tab = AdvancementTabs.byName(buffer.readString(), buffer.getVersionId()); + this.tab = AdvancementTabs.byName(buffer.readString(), buffer.getVersionId()); } return true; } @@ -37,11 +37,11 @@ public class PacketSelectAdvancementTab implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received select advancement tab (tab=%s)", tab)); + Log.protocol(String.format("[IN] Received select advancement tab (tab=%s)", this.tab)); } public AdvancementTabs getTab() { - return tab; + return this.tab; } public enum AdvancementTabs { @@ -67,7 +67,7 @@ public class PacketSelectAdvancementTab implements ClientboundPacket { } public ChangeableIdentifier getChangeableIdentifier() { - return changeableIdentifier; + return this.changeableIdentifier; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketServerDifficulty.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketServerDifficulty.java index 5ccb354c0..18a6c36f3 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketServerDifficulty.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketServerDifficulty.java @@ -25,9 +25,9 @@ public class PacketServerDifficulty implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - difficulty = Difficulties.byId(buffer.readUnsignedByte()); + this.difficulty = Difficulties.byId(buffer.readUnsignedByte()); if (buffer.getVersionId() > 464) { - locked = buffer.readBoolean(); + this.locked = buffer.readBoolean(); } return true; } @@ -39,10 +39,10 @@ public class PacketServerDifficulty implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received server difficulty (difficulty=%s)", difficulty)); + Log.protocol(String.format("[IN] Received server difficulty (difficulty=%s)", this.difficulty)); } public Difficulties getDifficulty() { - return difficulty; + return this.difficulty; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCompression.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCompression.java index 7edb4c7e0..1b213df49 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCompression.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCompression.java @@ -23,7 +23,7 @@ public class PacketSetCompression implements PacketCompressionInterface { @Override public boolean read(InByteBuffer buffer) { - threshold = buffer.readVarInt(); + this.threshold = buffer.readVarInt(); return true; } @@ -34,11 +34,11 @@ public class PacketSetCompression implements PacketCompressionInterface { @Override public void log() { - Log.protocol(String.format("[IN] Received set compression packet (threshold=%d)", threshold)); + Log.protocol(String.format("[IN] Received set compression packet (threshold=%d)", this.threshold)); } @Override public int getThreshold() { - return threshold; + return this.threshold; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCooldown.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCooldown.java index 91e3ee773..d99a6fa8e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCooldown.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetCooldown.java @@ -25,8 +25,8 @@ public class PacketSetCooldown implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - item = buffer.readVarInt(); - cooldownTicks = buffer.readVarInt(); + this.item = buffer.readVarInt(); + this.cooldownTicks = buffer.readVarInt(); return true; } @@ -37,14 +37,14 @@ public class PacketSetCooldown implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving item cooldown (item=%s, coolDown=%dt)", item, cooldownTicks)); + Log.protocol(String.format("[IN] Receiving item cooldown (item=%s, coolDown=%dt)", this.item, this.cooldownTicks)); } public int getItem() { - return item; + return this.item; } public int getCooldownTicks() { - return cooldownTicks; + return this.cooldownTicks; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetExperience.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetExperience.java index 8864fcbcb..620f561da 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetExperience.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetExperience.java @@ -25,14 +25,14 @@ public class PacketSetExperience implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - bar = buffer.readFloat(); + this.bar = buffer.readFloat(); if (buffer.getVersionId() < 7) { - level = buffer.readUnsignedShort(); - total = buffer.readUnsignedShort(); + this.level = buffer.readUnsignedShort(); + this.total = buffer.readUnsignedShort(); return true; } - level = buffer.readVarInt(); - total = buffer.readVarInt(); + this.level = buffer.readVarInt(); + this.total = buffer.readVarInt(); return true; } @@ -43,18 +43,18 @@ public class PacketSetExperience implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Level update received. Now at %d levels, totally %d exp", level, total)); + Log.protocol(String.format("[IN] Level update received. Now at %d levels, totally %d exp", this.level, this.total)); } public float getBar() { - return bar; + return this.bar; } public int getLevel() { - return level; + return this.level; } public int getTotal() { - return total; + return this.total; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetPassenger.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetPassenger.java index 56563a5b2..a5f9de92c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetPassenger.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetPassenger.java @@ -25,9 +25,9 @@ public class PacketSetPassenger implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { this.vehicleId = buffer.readVarInt(); - entityIds = new int[buffer.readVarInt()]; - for (int i = 0; i < entityIds.length; i++) { - entityIds[i] = buffer.readVarInt(); + this.entityIds = new int[buffer.readVarInt()]; + for (int i = 0; i < this.entityIds.length; i++) { + this.entityIds[i] = buffer.readVarInt(); } return true; } @@ -39,14 +39,14 @@ public class PacketSetPassenger implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Attaching %d entities (vehicleId=%d)", entityIds.length, vehicleId)); + Log.protocol(String.format("[IN] Attaching %d entities (vehicleId=%d)", this.entityIds.length, this.vehicleId)); } public int getVehicleId() { - return vehicleId; + return this.vehicleId; } public int[] getEntityIds() { - return entityIds; + return this.entityIds; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java index 50dea4566..2b4e5b157 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSetSlot.java @@ -39,18 +39,18 @@ public class PacketSetSlot implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received slot data (windowId=%d, slotId=%d, item=%s)", windowId, slotId, ((slot == null) ? "AIR" : slot.getDisplayName()))); + Log.protocol(String.format("[IN] Received slot data (windowId=%d, slotId=%d, item=%s)", this.windowId, this.slotId, ((this.slot == null) ? "AIR" : this.slot.getDisplayName()))); } public byte getWindowId() { - return windowId; + return this.windowId; } public short getSlotId() { - return slotId; + return this.slotId; } public Slot getSlot() { - return slot; + return this.slot; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java index 6759e4314..43f12a681 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSoundEffect.java @@ -19,9 +19,9 @@ import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; +import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition; public class PacketSoundEffect implements ClientboundPacket { - static final float pitchCalc = 100.0F / 63.0F; Location location; SoundCategories category; int soundId; @@ -32,22 +32,22 @@ public class PacketSoundEffect implements ClientboundPacket { public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() >= 321 && buffer.getVersionId() < 326) { // category was moved to the top - category = SoundCategories.byId(buffer.readVarInt()); + this.category = SoundCategories.byId(buffer.readVarInt()); } - soundId = buffer.readVarInt(); + this.soundId = buffer.readVarInt(); if (buffer.getVersionId() >= 321 && buffer.getVersionId() < 326) { buffer.readString(); // parrot entity type } if (buffer.getVersionId() >= 95 && (buffer.getVersionId() < 321 || buffer.getVersionId() >= 326)) { - category = SoundCategories.byId(buffer.readVarInt()); + this.category = SoundCategories.byId(buffer.readVarInt()); } - location = new Location(buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4); - volume = buffer.readFloat(); + this.location = new Location(buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4, buffer.readFixedPointNumberInt() * 4); + this.volume = buffer.readFloat(); if (buffer.getVersionId() < 201) { - pitch = (buffer.readByte() * pitchCalc) / 100F; + this.pitch = (buffer.readByte() * ProtocolDefinition.PITCH_CALCULATION_CONSTANT) / 100F; } else { - pitch = buffer.readFloat(); + this.pitch = buffer.readFloat(); } return true; } @@ -59,29 +59,29 @@ public class PacketSoundEffect implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Play sound effect (soundId=%d, category=%s, volume=%s, pitch=%s, location=%s)", soundId, category, volume, pitch, location)); + Log.protocol(String.format("[IN] Play sound effect (soundId=%d, category=%s, volume=%s, pitch=%s, location=%s)", this.soundId, this.category, this.volume, this.pitch, this.location)); } public Location getLocation() { - return location; + return this.location; } /** * @return Pitch in Percent */ public float getPitch() { - return pitch; + return this.pitch; } public int getSoundId() { - return soundId; + return this.soundId; } public float getVolume() { - return volume; + return this.volume; } public SoundCategories getCategory() { - return category; + return this.category; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnExperienceOrb.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnExperienceOrb.java index 6eecbcf12..2d50bbd86 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnExperienceOrb.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnExperienceOrb.java @@ -33,7 +33,7 @@ public class PacketSpawnExperienceOrb implements ClientboundPacket { location = buffer.readLocation(); } int count = buffer.readUnsignedShort(); - entity = new ExperienceOrb(buffer.getConnection(), entityId, location, count); + this.entity = new ExperienceOrb(buffer.getConnection(), entityId, location, count); return true; } @@ -44,10 +44,10 @@ public class PacketSpawnExperienceOrb implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Experience orb spawned at %s(entityId=%d, count=%d)", entity.getLocation().toString(), entity.getEntityId(), entity.getCount())); + Log.protocol(String.format("[IN] Experience orb spawned at %s(entityId=%d, count=%d)", this.entity.getLocation().toString(), this.entity.getEntityId(), this.entity.getCount())); } public ExperienceOrb getEntity() { - return entity; + return this.entity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnLocation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnLocation.java index ebaf0efca..e14fccd47 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnLocation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnLocation.java @@ -25,10 +25,10 @@ public class PacketSpawnLocation implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 6) { - location = buffer.readBlockPositionInteger(); + this.location = buffer.readBlockPositionInteger(); return true; } - location = buffer.readPosition(); + this.location = buffer.readPosition(); return true; } @@ -39,10 +39,10 @@ public class PacketSpawnLocation implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received spawn location %s", location)); + Log.protocol(String.format("[IN] Received spawn location %s", this.location)); } public BlockPosition getSpawnLocation() { - return location; + return this.location; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java index aa62fe062..97f1ea379 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnMob.java @@ -54,7 +54,7 @@ public class PacketSpawnMob implements ClientboundPacket { location = buffer.readLocation(); } EntityRotation rotation = new EntityRotation(buffer.readAngle(), buffer.readAngle(), buffer.readAngle()); - velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); + this.velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); EntityMetaData metaData = null; if (buffer.getVersionId() < 550) { @@ -67,9 +67,9 @@ public class PacketSpawnMob implements ClientboundPacket { } try { - entity = typeClass.getConstructor(Connection.class, int.class, UUID.class, Location.class, EntityRotation.class).newInstance(buffer.getConnection(), entityId, uuid, location, rotation); + this.entity = typeClass.getConstructor(Connection.class, int.class, UUID.class, Location.class, EntityRotation.class).newInstance(buffer.getConnection(), entityId, uuid, location, rotation); if (metaData != null) { - entity.setMetaData(metaData); + this.entity.setMetaData(metaData); } return true; } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NullPointerException e) { @@ -85,15 +85,15 @@ public class PacketSpawnMob implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Mob spawned at %s (entityId=%d, type=%s)", entity.getLocation().toString(), entity.getEntityId(), entity)); + Log.protocol(String.format("[IN] Mob spawned at %s (entityId=%d, type=%s)", this.entity.getLocation().toString(), this.entity.getEntityId(), this.entity)); } public Entity getEntity() { - return entity; + return this.entity; } public Velocity getVelocity() { - return velocity; + return this.velocity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java index d895be9b4..5fb25958b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnObject.java @@ -65,10 +65,10 @@ public class PacketSpawnObject implements ClientboundPacket { if (buffer.getVersionId() < 49) { if (data != 0) { - velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); + this.velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); } } else { - velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); + this.velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); } if (buffer.getVersionId() <= 47) { // ToDo @@ -80,7 +80,7 @@ public class PacketSpawnObject implements ClientboundPacket { } try { - entity = typeClass.getConstructor(Connection.class, int.class, UUID.class, Location.class, EntityRotation.class).newInstance(buffer.getConnection(), entityId, uuid, location, rotation); + this.entity = typeClass.getConstructor(Connection.class, int.class, UUID.class, Location.class, EntityRotation.class).newInstance(buffer.getConnection(), entityId, uuid, location, rotation); return true; } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | NullPointerException e) { e.printStackTrace(); @@ -95,15 +95,15 @@ public class PacketSpawnObject implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Object spawned at %s (entityId=%d, type=%s)", entity.getLocation().toString(), entity.getEntityId(), entity)); + Log.protocol(String.format("[IN] Object spawned at %s (entityId=%d, type=%s)", this.entity.getLocation().toString(), this.entity.getEntityId(), this.entity)); } public Entity getEntity() { - return entity; + return this.entity; } public Velocity getVelocity() { - return velocity; + return this.velocity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPainting.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPainting.java index ee3fc9f2e..a687a4de0 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPainting.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPainting.java @@ -49,7 +49,7 @@ public class PacketSpawnPainting implements ClientboundPacket { position = buffer.readPosition(); direction = Directions.byId(buffer.readUnsignedByte()); } - entity = new Painting(buffer.getConnection(), entityId, uuid, position, direction, motive); + this.entity = new Painting(buffer.getConnection(), entityId, uuid, position, direction, motive); return true; } @@ -60,11 +60,11 @@ public class PacketSpawnPainting implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Spawning painting at %s (entityId=%d, motive=%s, direction=%s)", entity.getLocation(), entity.getEntityId(), entity.getMotive(), entity.getDirection())); + Log.protocol(String.format("[IN] Spawning painting at %s (entityId=%d, motive=%s, direction=%s)", this.entity.getLocation(), this.entity.getEntityId(), this.entity.getMotive(), this.entity.getDirection())); } public Painting getEntity() { - return entity; + return this.entity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java index a734ff0f0..ed68f4e32 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnPlayer.java @@ -68,7 +68,7 @@ public class PacketSpawnPlayer implements ClientboundPacket { } this.entity = new PlayerEntity(buffer.getConnection(), entityId, uuid, location, new EntityRotation(yaw, pitch, 0), name, properties, currentItem); if (metaData != null) { - entity.setMetaData(metaData); + this.entity.setMetaData(metaData); } return true; } @@ -80,15 +80,15 @@ public class PacketSpawnPlayer implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Player spawned at %s (entityId=%d, name=%s, uuid=%s)", entity.getLocation(), entity.getEntityId(), entity.getName(), entity.getUUID())); + Log.protocol(String.format("[IN] Player spawned at %s (entityId=%d, name=%s, uuid=%s)", this.entity.getLocation(), this.entity.getEntityId(), this.entity.getName(), this.entity.getUUID())); } public PlayerEntity getEntity() { - return entity; + return this.entity; } public Velocity getVelocity() { - return velocity; + return this.velocity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnWeatherEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnWeatherEntity.java index 0b5a7a86c..115a05a24 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnWeatherEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketSpawnWeatherEntity.java @@ -33,7 +33,7 @@ public class PacketSpawnWeatherEntity implements ClientboundPacket { } else { location = buffer.readLocation(); } - entity = new LightningBolt(buffer.getConnection(), entityId, location); + this.entity = new LightningBolt(buffer.getConnection(), entityId, location); return true; } @@ -44,10 +44,10 @@ public class PacketSpawnWeatherEntity implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Thunderbolt spawned at %s (entityId=%d)", entity.getLocation(), entity.getEntityId())); + Log.protocol(String.format("[IN] Thunderbolt spawned at %s (entityId=%d)", this.entity.getLocation(), this.entity.getEntityId())); } public LightningBolt getEntity() { - return entity; + return this.entity; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java index 5569fe522..5dff4f309 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStatistics.java @@ -30,10 +30,10 @@ public class PacketStatistics implements ClientboundPacket { int length = buffer.readVarInt(); for (int i = 0; i < length; i++) { if (buffer.getVersionId() < 346) { // ToDo - statistics.put(buffer.getConnection().getMapping().getStatisticByIdentifier(buffer.readString()), buffer.readVarInt()); + this.statistics.put(buffer.getConnection().getMapping().getStatisticByIdentifier(buffer.readString()), buffer.readVarInt()); } else { StatisticCategories category = StatisticCategories.byId(buffer.readVarInt()); - statistics.put(buffer.getConnection().getMapping().getStatisticById(buffer.readVarInt()), buffer.readVarInt()); + this.statistics.put(buffer.getConnection().getMapping().getStatisticById(buffer.readVarInt()), buffer.readVarInt()); } } return true; @@ -46,10 +46,10 @@ public class PacketStatistics implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received player statistics (count=%d)", statistics.size())); + Log.protocol(String.format("[IN] Received player statistics (count=%d)", this.statistics.size())); } public HashMap getStatistics() { - return statistics; + return this.statistics; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java index f66852787..73b658584 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketStopSound.java @@ -28,16 +28,16 @@ public class PacketStopSound implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 343) { // ToDo: these 2 values need to be switched in before 1.12.2 - category = SoundCategories.valueOf(buffer.readString().toUpperCase()); - soundIdentifier = buffer.readIdentifier(); + this.category = SoundCategories.valueOf(buffer.readString().toUpperCase()); + this.soundIdentifier = buffer.readIdentifier(); return true; } byte flags = buffer.readByte(); if (BitByte.isBitMask(flags, 0x01)) { - category = SoundCategories.byId(buffer.readVarInt()); + this.category = SoundCategories.byId(buffer.readVarInt()); } if (BitByte.isBitMask(flags, 0x02)) { - soundIdentifier = buffer.readIdentifier(); + this.soundIdentifier = buffer.readIdentifier(); } return true; } @@ -49,14 +49,14 @@ public class PacketStopSound implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received stop sound (category=%s, soundIdentifier=%s)", category, soundIdentifier)); + Log.protocol(String.format("[IN] Received stop sound (category=%s, soundIdentifier=%s)", this.category, this.soundIdentifier)); } public SoundCategories getSoundId() { - return category; + return this.category; } public ModIdentifier getSoundIdentifier() { - return soundIdentifier; + return this.soundIdentifier; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabCompleteReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabCompleteReceiving.java index b77dd407b..9103b1e94 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabCompleteReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabCompleteReceiving.java @@ -25,15 +25,15 @@ public class PacketTabCompleteReceiving implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 37) { - count = buffer.readVarInt(); - match = new String[]{buffer.readString()}; + this.count = buffer.readVarInt(); + this.match = new String[]{buffer.readString()}; return true; } if (buffer.getVersionId() < 343) { - count = buffer.readVarInt(); - match = new String[count]; - for (int i = 0; i < count; i++) { - match[i] = buffer.readString(); + this.count = buffer.readVarInt(); + this.match = new String[this.count]; + for (int i = 0; i < this.count; i++) { + this.match[i] = buffer.readString(); } return true; } @@ -48,14 +48,14 @@ public class PacketTabCompleteReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received tab complete for message(count=%d)", count)); + Log.protocol(String.format("[IN] Received tab complete for message(count=%d)", this.count)); } public int getCount() { - return count; + return this.count; } public String[] getMatch() { - return match; + return this.match; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabHeaderAndFooter.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabHeaderAndFooter.java index 1f0d72846..6ca4fb1b7 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabHeaderAndFooter.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTabHeaderAndFooter.java @@ -25,8 +25,8 @@ public class PacketTabHeaderAndFooter implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - header = buffer.readChatComponent(); - footer = buffer.readChatComponent(); + this.header = buffer.readChatComponent(); + this.footer = buffer.readChatComponent(); return true; } @@ -37,15 +37,15 @@ public class PacketTabHeaderAndFooter implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received tab list header: %s", header.getANSIColoredMessage())); - Log.protocol(String.format("[IN] Received tab list footer: %s", footer.getANSIColoredMessage())); + Log.protocol(String.format("[IN] Received tab list header: %s", this.header.getANSIColoredMessage())); + Log.protocol(String.format("[IN] Received tab list footer: %s", this.footer.getANSIColoredMessage())); } public ChatComponent getHeader() { - return header; + return this.header; } public ChatComponent getFooter() { - return footer; + return this.footer; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java index 549941432..a52731450 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTags.java @@ -27,11 +27,11 @@ public class PacketTags implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - blockTags = readTags(buffer); - itemTags = readTags(buffer); - fluidTags = readTags(buffer); // ToDo: when was this added? Was not available in 18w01 + this.blockTags = readTags(buffer); + this.itemTags = readTags(buffer); + this.fluidTags = readTags(buffer); // ToDo: when was this added? Was not available in 18w01 if (buffer.getVersionId() >= 440) { - entityTags = readTags(buffer); + this.entityTags = readTags(buffer); } return true; } @@ -51,6 +51,6 @@ public class PacketTags implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received tags (blockLength=%d, itemLength=%d, fluidLength=%d, entityLength=%d)", blockTags.length, itemTags.length, fluidTags.length, ((entityTags == null) ? 0 : entityTags.length))); + Log.protocol(String.format("[IN] Received tags (blockLength=%d, itemLength=%d, fluidLength=%d, entityLength=%d)", this.blockTags.length, this.itemTags.length, this.fluidTags.length, ((this.entityTags == null) ? 0 : this.entityTags.length))); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTeams.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTeams.java index 465c888d0..216efd3c4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTeams.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTeams.java @@ -37,47 +37,47 @@ public class PacketTeams implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - name = buffer.readString(); - action = TeamActions.byId(buffer.readUnsignedByte()); - if (action == TeamActions.CREATE || action == TeamActions.INFORMATION_UPDATE) { - displayName = buffer.readChatComponent(); + this.name = buffer.readString(); + this.action = TeamActions.byId(buffer.readUnsignedByte()); + if (this.action == TeamActions.CREATE || this.action == TeamActions.INFORMATION_UPDATE) { + this.displayName = buffer.readChatComponent(); if (buffer.getVersionId() < 352) { - prefix = buffer.readChatComponent(); - suffix = buffer.readChatComponent(); + this.prefix = buffer.readChatComponent(); + this.suffix = buffer.readChatComponent(); } if (buffer.getVersionId() < 100) { // ToDo setFriendlyFireByLegacy(buffer.readByte()); } else { byte friendlyFireRaw = buffer.readByte(); - friendlyFire = BitByte.isBitMask(friendlyFireRaw, 0x01); - seeFriendlyInvisibles = BitByte.isBitMask(friendlyFireRaw, 0x02); + this.friendlyFire = BitByte.isBitMask(friendlyFireRaw, 0x01); + this.seeFriendlyInvisibles = BitByte.isBitMask(friendlyFireRaw, 0x02); } if (buffer.getVersionId() >= 11) { - nameTagVisibility = TeamNameTagVisibilities.byName(buffer.readString()); + this.nameTagVisibility = TeamNameTagVisibilities.byName(buffer.readString()); if (buffer.getVersionId() >= 100) { // ToDo - collisionRule = TeamCollisionRules.byName(buffer.readString()); + this.collisionRule = TeamCollisionRules.byName(buffer.readString()); } if (buffer.getVersionId() < 352) { - formattingCode = ChatColors.getFormattingById(buffer.readByte()); + this.formattingCode = ChatColors.getFormattingById(buffer.readByte()); } else { - formattingCode = ChatColors.getFormattingById(buffer.readVarInt()); + this.formattingCode = ChatColors.getFormattingById(buffer.readVarInt()); } } if (buffer.getVersionId() >= 375) { - prefix = buffer.readChatComponent(); - suffix = buffer.readChatComponent(); + this.prefix = buffer.readChatComponent(); + this.suffix = buffer.readChatComponent(); } } - if (action == TeamActions.CREATE || action == TeamActions.PLAYER_ADD || action == TeamActions.PLAYER_REMOVE) { + if (this.action == TeamActions.CREATE || this.action == TeamActions.PLAYER_ADD || this.action == TeamActions.PLAYER_REMOVE) { int playerCount; if (buffer.getVersionId() < 7) { playerCount = buffer.readUnsignedShort(); } else { playerCount = buffer.readVarInt(); } - playerNames = new String[playerCount]; + this.playerNames = new String[playerCount]; for (int i = 0; i < playerCount; i++) { - playerNames[i] = buffer.readString(); + this.playerNames[i] = buffer.readString(); } } return true; @@ -90,11 +90,11 @@ public class PacketTeams implements ClientboundPacket { private void setFriendlyFireByLegacy(byte raw) { switch (raw) { - case 0 -> friendlyFire = false; - case 1 -> friendlyFire = true; + case 0 -> this.friendlyFire = false; + case 1 -> this.friendlyFire = true; case 2 -> { - friendlyFire = false; - seeFriendlyInvisibles = true; + this.friendlyFire = false; + this.seeFriendlyInvisibles = true; } } // ToDo: seeFriendlyInvisibles for case 0 and 1 @@ -102,51 +102,51 @@ public class PacketTeams implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received scoreboard Team update (name=\"%s\", action=%s, displayName=\"%s\", prefix=\"%s\", suffix=\"%s\", friendlyFire=%s, seeFriendlyInvisibiles=%s, playerCount=%s)", name, action, displayName, prefix, suffix, friendlyFire, seeFriendlyInvisibles, ((playerNames == null) ? null : playerNames.length))); + Log.protocol(String.format("[IN] Received scoreboard Team update (name=\"%s\", action=%s, displayName=\"%s\", prefix=\"%s\", suffix=\"%s\", friendlyFire=%s, seeFriendlyInvisibiles=%s, playerCount=%s)", this.name, this.action, this.displayName, this.prefix, this.suffix, this.friendlyFire, this.seeFriendlyInvisibles, ((this.playerNames == null) ? null : this.playerNames.length))); } public String getName() { - return name; + return this.name; } public TeamActions getAction() { - return action; + return this.action; } public ChatComponent getDisplayName() { - return displayName; + return this.displayName; } public ChatComponent getPrefix() { - return prefix; + return this.prefix; } public ChatComponent getSuffix() { - return suffix; + return this.suffix; } public boolean isFriendlyFireEnabled() { - return friendlyFire; + return this.friendlyFire; } public boolean isSeeingFriendlyInvisibles() { - return seeFriendlyInvisibles; + return this.seeFriendlyInvisibles; } public ChatCode getFormattingCode() { - return formattingCode; + return this.formattingCode; } public TeamCollisionRules getCollisionRule() { - return collisionRule; + return this.collisionRule; } public TeamNameTagVisibilities getNameTagVisibility() { - return nameTagVisibility; + return this.nameTagVisibility; } public String[] getPlayerNames() { - return playerNames; + return this.playerNames; } public enum TeamActions { @@ -156,8 +156,10 @@ public class PacketTeams implements ClientboundPacket { PLAYER_ADD, PLAYER_REMOVE; + private static final TeamActions[] TEAM_ACTIONS = values(); + public static TeamActions byId(int id) { - return values()[id]; + return TEAM_ACTIONS[id]; } } @@ -183,7 +185,7 @@ public class PacketTeams implements ClientboundPacket { } public String getName() { - return name; + return this.name; } } @@ -209,7 +211,7 @@ public class PacketTeams implements ClientboundPacket { } public String getName() { - return name; + return this.name; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTimeUpdate.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTimeUpdate.java index d49b2a840..8fe07aa80 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTimeUpdate.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTimeUpdate.java @@ -24,8 +24,8 @@ public class PacketTimeUpdate implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - worldAge = buffer.readLong(); - timeOfDay = buffer.readLong(); + this.worldAge = buffer.readLong(); + this.timeOfDay = buffer.readLong(); return true; } @@ -36,14 +36,14 @@ public class PacketTimeUpdate implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Time Update packet received. Time is now %st (total %st, moving=%s)", Math.abs(timeOfDay), worldAge, timeOfDay > 0)); + Log.protocol(String.format("[IN] Time Update packet received. Time is now %st (total %st, moving=%s)", Math.abs(this.timeOfDay), this.worldAge, this.timeOfDay > 0)); } public long getWorldAge() { - return worldAge; + return this.worldAge; } public long getTimeOfDay() { - return timeOfDay; + return this.timeOfDay; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTitle.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTitle.java index 81cc04fdd..41d44f9df 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTitle.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTitle.java @@ -33,14 +33,14 @@ public class PacketTitle implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - action = TitleActions.byId(buffer.readVarInt(), buffer.getVersionId()); - switch (action) { - case SET_TITLE -> text = buffer.readChatComponent(); - case SET_SUBTITLE -> subText = buffer.readChatComponent(); + this.action = TitleActions.byId(buffer.readVarInt(), buffer.getVersionId()); + switch (this.action) { + case SET_TITLE -> this.text = buffer.readChatComponent(); + case SET_SUBTITLE -> this.subText = buffer.readChatComponent(); case SET_TIMES_AND_DISPLAY -> { - fadeInTime = buffer.readInt(); - stayTime = buffer.readInt(); - fadeOutTime = buffer.readInt(); + this.fadeInTime = buffer.readInt(); + this.stayTime = buffer.readInt(); + this.fadeOutTime = buffer.readInt(); } } return true; @@ -53,36 +53,36 @@ public class PacketTitle implements ClientboundPacket { @Override public void log() { - switch (action) { - case SET_TITLE -> Log.protocol(String.format("[IN] Received title (action=%s, text=%s)", action, text.getANSIColoredMessage())); - case SET_SUBTITLE -> Log.protocol(String.format("[IN] Received title (action=%s, subText=%s)", action, subText.getANSIColoredMessage())); - case SET_TIMES_AND_DISPLAY -> Log.protocol(String.format("[IN] Received title (action=%s, fadeInTime=%d, stayTime=%d, fadeOutTime=%d)", action, fadeInTime, stayTime, fadeOutTime)); - case HIDE, RESET -> Log.protocol(String.format("[IN] Received title (action=%s)", action)); + switch (this.action) { + case SET_TITLE -> Log.protocol(String.format("[IN] Received title (action=%s, text=%s)", this.action, this.text.getANSIColoredMessage())); + case SET_SUBTITLE -> Log.protocol(String.format("[IN] Received title (action=%s, subText=%s)", this.action, this.subText.getANSIColoredMessage())); + case SET_TIMES_AND_DISPLAY -> Log.protocol(String.format("[IN] Received title (action=%s, fadeInTime=%d, stayTime=%d, fadeOutTime=%d)", this.action, this.fadeInTime, this.stayTime, this.fadeOutTime)); + case HIDE, RESET -> Log.protocol(String.format("[IN] Received title (action=%s)", this.action)); } } public int getFadeInTime() { - return fadeInTime; + return this.fadeInTime; } public int getFadeOutTime() { - return fadeOutTime; + return this.fadeOutTime; } public int getStayTime() { - return stayTime; + return this.stayTime; } public ChatComponent getSubText() { - return subText; + return this.subText; } public ChatComponent getText() { - return text; + return this.text; } public TitleActions getAction() { - return action; + return this.action; } public enum TitleActions { @@ -96,11 +96,11 @@ public class PacketTitle implements ClientboundPacket { final VersionValueMap valueMap; TitleActions(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } TitleActions(int id) { - valueMap = new VersionValueMap<>(id); + this.valueMap = new VersionValueMap<>(id); } public static TitleActions byId(int id, int versionId) { @@ -113,7 +113,7 @@ public class PacketTitle implements ClientboundPacket { } public int getId(int versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTradeList.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTradeList.java index 93aa07b9e..b1aea7e3f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTradeList.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketTradeList.java @@ -31,9 +31,9 @@ public class PacketTradeList implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - windowId = buffer.readVarInt(); - trades = new Trade[buffer.readByte()]; - for (int i = 0; i < trades.length; i++) { + this.windowId = buffer.readVarInt(); + this.trades = new Trade[buffer.readByte()]; + for (int i = 0; i < this.trades.length; i++) { Slot input1 = buffer.readSlot(); Slot input2 = null; if (buffer.readBoolean()) { @@ -50,13 +50,13 @@ public class PacketTradeList implements ClientboundPacket { if (buffer.getVersionId() >= 495) { demand = buffer.readInt(); } - trades[i] = new Trade(input1, input2, enabled, usages, maxUsages, xp, specialPrice, priceMultiplier, demand); + this.trades[i] = new Trade(input1, input2, enabled, usages, maxUsages, xp, specialPrice, priceMultiplier, demand); } - level = VillagerData.VillagerLevels.values()[buffer.readVarInt()]; - experience = buffer.readVarInt(); - isRegularVillager = buffer.readBoolean(); + this.level = VillagerData.VillagerLevels.byId(buffer.readVarInt()); + this.experience = buffer.readVarInt(); + this.isRegularVillager = buffer.readBoolean(); if (buffer.getVersionId() >= 486) { - canRestock = buffer.readBoolean(); + this.canRestock = buffer.readBoolean(); } return true; } @@ -68,30 +68,30 @@ public class PacketTradeList implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received select trade packet (windowId=%d, tradeLength=%d, level=%s, experience=%d, regularVillager=%s, canRestock=%s)", windowId, trades.length, level, experience, isRegularVillager, canRestock)); + Log.protocol(String.format("[IN] Received select trade packet (windowId=%d, tradeLength=%d, level=%s, experience=%d, regularVillager=%s, canRestock=%s)", this.windowId, this.trades.length, this.level, this.experience, this.isRegularVillager, this.canRestock)); } public int getWindowId() { - return windowId; + return this.windowId; } public Trade[] getTrades() { - return trades; + return this.trades; } public VillagerData.VillagerLevels getLevel() { - return level; + return this.level; } public int getExperience() { - return experience; + return this.experience; } public boolean isRegularVillager() { - return isRegularVillager; + return this.isRegularVillager; } public boolean canRestock() { - return canRestock; + return this.canRestock; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnloadChunk.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnloadChunk.java index f65349086..e2e4ea32c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnloadChunk.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnloadChunk.java @@ -24,7 +24,7 @@ public class PacketUnloadChunk implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = new ChunkLocation(buffer.readInt(), buffer.readInt()); + this.location = new ChunkLocation(buffer.readInt(), buffer.readInt()); return true; } @@ -35,10 +35,10 @@ public class PacketUnloadChunk implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received unload chunk packet (location=%s)", location)); + Log.protocol(String.format("[IN] Received unload chunk packet (location=%s)", this.location)); } public ChunkLocation getLocation() { - return location; + return this.location; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java index 028de4cec..11ed16003 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUnlockRecipes.java @@ -14,59 +14,58 @@ package de.bixilon.minosoft.protocol.packets.clientbound.play; import de.bixilon.minosoft.data.mappings.recipes.Recipe; -import de.bixilon.minosoft.data.mappings.recipes.Recipes; import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.protocol.InByteBuffer; import de.bixilon.minosoft.protocol.protocol.PacketHandler; public class PacketUnlockRecipes implements ClientboundPacket { - UnlockRecipeActions action; - boolean isCraftingBookOpen; - boolean isSmeltingBookOpen = false; - boolean isBlastFurnaceBookOpen = false; - boolean isSmokerBookOpen = false; - boolean isCraftingFilteringActive; - boolean isSmeltingFilteringActive = false; - boolean isBlastFurnaceFilteringActive = false; - boolean isSmokerFilteringActive = false; - Recipe[] listed; - Recipe[] tagged; + private UnlockRecipeActions action; + private boolean isCraftingBookOpen; + private boolean isSmeltingBookOpen; + private boolean isBlastFurnaceBookOpen; + private boolean isSmokerBookOpen; + private boolean isCraftingFilteringActive; + private boolean isSmeltingFilteringActive; + private boolean isBlastFurnaceFilteringActive; + private boolean isSmokerFilteringActive; + private Recipe[] listed; + private Recipe[] tagged; @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 333) { - action = UnlockRecipeActions.byId(buffer.readInt()); + this.action = UnlockRecipeActions.byId(buffer.readInt()); } else { - action = UnlockRecipeActions.byId(buffer.readVarInt()); + this.action = UnlockRecipeActions.byId(buffer.readVarInt()); } - isCraftingBookOpen = buffer.readBoolean(); - isCraftingFilteringActive = buffer.readBoolean(); + this.isCraftingBookOpen = buffer.readBoolean(); + this.isCraftingFilteringActive = buffer.readBoolean(); if (buffer.getVersionId() >= 348) { // ToDo - isSmeltingBookOpen = buffer.readBoolean(); - isSmeltingFilteringActive = buffer.readBoolean(); + this.isSmeltingBookOpen = buffer.readBoolean(); + this.isSmeltingFilteringActive = buffer.readBoolean(); } if (buffer.getVersionId() >= 738) { - isBlastFurnaceBookOpen = buffer.readBoolean(); - isBlastFurnaceFilteringActive = buffer.readBoolean(); - isSmokerBookOpen = buffer.readBoolean(); - isSmokerFilteringActive = buffer.readBoolean(); + this.isBlastFurnaceBookOpen = buffer.readBoolean(); + this.isBlastFurnaceFilteringActive = buffer.readBoolean(); + this.isSmokerBookOpen = buffer.readBoolean(); + this.isSmokerFilteringActive = buffer.readBoolean(); } - listed = new Recipe[buffer.readVarInt()]; - for (int i = 0; i < listed.length; i++) { + this.listed = new Recipe[buffer.readVarInt()]; + for (int i = 0; i < this.listed.length; i++) { if (buffer.getVersionId() < 348) { - listed[i] = Recipes.getRecipeById(buffer.readVarInt()); + this.listed[i] = buffer.getConnection().getRecipes().getRecipeById(buffer.readVarInt()); } else { - listed[i] = Recipes.getRecipe(buffer.readIdentifier()); + this.listed[i] = buffer.getConnection().getRecipes().getRecipe(buffer.readIdentifier()); } } - if (action == UnlockRecipeActions.INITIALIZE) { - tagged = new Recipe[buffer.readVarInt()]; - for (int i = 0; i < tagged.length; i++) { + if (this.action == UnlockRecipeActions.INITIALIZE) { + this.tagged = new Recipe[buffer.readVarInt()]; + for (int i = 0; i < this.tagged.length; i++) { if (buffer.getVersionId() < 348) { - tagged[i] = Recipes.getRecipeById(buffer.readVarInt()); + this.tagged[i] = buffer.getConnection().getRecipes().getRecipeById(buffer.readVarInt()); } else { - tagged[i] = Recipes.getRecipe(buffer.readIdentifier()); + this.tagged[i] = buffer.getConnection().getRecipes().getRecipe(buffer.readIdentifier()); } } } @@ -80,51 +79,51 @@ public class PacketUnlockRecipes implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received unlock crafting recipe packet (action=%s, isCraftingBookOpen=%s, isFilteringActive=%s, isSmeltingBookOpen=%s, isSmeltingFilteringActive=%s listedLength=%d, taggedLength=%s)", action, isCraftingBookOpen, isCraftingFilteringActive, isSmeltingBookOpen, isSmeltingFilteringActive, listed.length, ((tagged == null) ? 0 : tagged.length))); + Log.protocol(String.format("[IN] Received unlock crafting recipe packet (action=%s, isCraftingBookOpen=%s, isFilteringActive=%s, isSmeltingBookOpen=%s, isSmeltingFilteringActive=%s listedLength=%d, taggedLength=%s)", this.action, this.isCraftingBookOpen, this.isCraftingFilteringActive, this.isSmeltingBookOpen, this.isSmeltingFilteringActive, this.listed.length, ((this.tagged == null) ? 0 : this.tagged.length))); } public boolean isCraftingBookOpen() { - return isCraftingBookOpen; + return this.isCraftingBookOpen; } public boolean isCraftingFilteringActive() { - return isCraftingFilteringActive; + return this.isCraftingFilteringActive; } public boolean isBlastFurnaceBookOpen() { - return isBlastFurnaceBookOpen; + return this.isBlastFurnaceBookOpen; } public boolean isBlastFurnaceFilteringActive() { - return isBlastFurnaceFilteringActive; + return this.isBlastFurnaceFilteringActive; } public boolean isSmeltingBookOpen() { - return isSmeltingBookOpen; + return this.isSmeltingBookOpen; } public boolean isSmeltingFilteringActive() { - return isSmeltingFilteringActive; + return this.isSmeltingFilteringActive; } public boolean isSmokerBookOpen() { - return isSmokerBookOpen; + return this.isSmokerBookOpen; } public boolean isSmokerFilteringActive() { - return isSmokerFilteringActive; + return this.isSmokerFilteringActive; } public Recipe[] getListed() { - return listed; + return this.listed; } public Recipe[] getTagged() { - return tagged; + return this.tagged; } public UnlockRecipeActions getAction() { - return action; + return this.action; } public enum UnlockRecipeActions { @@ -132,8 +131,10 @@ public class PacketUnlockRecipes implements ClientboundPacket { ADD, REMOVE; + private static final UnlockRecipeActions[] UNLOCK_RECIPE_ACTIONS = values(); + public static UnlockRecipeActions byId(int id) { - return values()[id]; + return UNLOCK_RECIPE_ACTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateHealth.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateHealth.java index 31d0bfc51..d79f5b013 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateHealth.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateHealth.java @@ -25,13 +25,13 @@ public class PacketUpdateHealth implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - health = buffer.readFloat(); + this.health = buffer.readFloat(); if (buffer.getVersionId() < 7) { - food = buffer.readUnsignedShort(); + this.food = buffer.readUnsignedShort(); } else { - food = buffer.readVarInt(); + this.food = buffer.readVarInt(); } - saturation = buffer.readFloat(); + this.saturation = buffer.readFloat(); return true; } @@ -42,18 +42,18 @@ public class PacketUpdateHealth implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Health update. Now at %s hearts and %s food level and %s saturation", health, food, saturation)); + Log.protocol(String.format("[IN] Health update. Now at %s hearts and %s food level and %s saturation", this.health, this.food, this.saturation)); } public int getFood() { - return food; + return this.food; } public float getHealth() { - return health; + return this.health; } public float getSaturation() { - return saturation; + return this.saturation; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java index 4205355b8..90a4e2e62 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateLight.java @@ -25,7 +25,7 @@ public class PacketUpdateLight implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); + this.location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); if (buffer.getVersionId() >= 725) { boolean trustEdges = buffer.readBoolean(); } @@ -45,6 +45,6 @@ public class PacketUpdateLight implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received light update (location=%s)", location)); + Log.protocol(String.format("[IN] Received light update (location=%s)", this.location)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateSignReceiving.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateSignReceiving.java index 244a33561..464b3b13d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateSignReceiving.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateSignReceiving.java @@ -27,12 +27,12 @@ public class PacketUpdateSignReceiving implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { if (buffer.getVersionId() < 7) { - position = buffer.readBlockPositionShort(); + this.position = buffer.readBlockPositionShort(); } else { - position = buffer.readPosition(); + this.position = buffer.readPosition(); } for (byte i = 0; i < 4; i++) { - lines[i] = buffer.readChatComponent(); + this.lines[i] = buffer.readChatComponent(); } return true; } @@ -44,14 +44,14 @@ public class PacketUpdateSignReceiving implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Sign data received at: %s", position)); + Log.protocol(String.format("[IN] Sign data received at: %s", this.position)); } public BlockPosition getPosition() { - return position; + return this.position; } public ChatComponent[] getLines() { - return lines; + return this.lines; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewDistance.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewDistance.java index 09c744862..fd6576071 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewDistance.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewDistance.java @@ -23,7 +23,7 @@ public class PacketUpdateViewDistance implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - viewDistance = buffer.readVarInt(); + this.viewDistance = buffer.readVarInt(); return true; } @@ -34,6 +34,6 @@ public class PacketUpdateViewDistance implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received view distance update (viewDistance=%s)", viewDistance)); + Log.protocol(String.format("[IN] Received view distance update (viewDistance=%s)", this.viewDistance)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewPosition.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewPosition.java index a15f88669..899cb3c63 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewPosition.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUpdateViewPosition.java @@ -24,7 +24,7 @@ public class PacketUpdateViewPosition implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); + this.location = new ChunkLocation(buffer.readVarInt(), buffer.readVarInt()); return true; } @@ -35,6 +35,6 @@ public class PacketUpdateViewPosition implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received view position update (location=%s)", location)); + Log.protocol(String.format("[IN] Received view position update (location=%s)", this.location)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUseBed.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUseBed.java index 4638f6f45..7b4c8c7cb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUseBed.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketUseBed.java @@ -25,11 +25,11 @@ public class PacketUseBed implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - entityId = buffer.readInt(); + this.entityId = buffer.readInt(); if (buffer.getVersionId() < 7) { - position = buffer.readBlockPosition(); + this.position = buffer.readBlockPosition(); } else { - position = buffer.readPosition(); + this.position = buffer.readPosition(); } return true; } @@ -41,14 +41,14 @@ public class PacketUseBed implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Entity used bed at %s (entityId=%d)", position, entityId)); + Log.protocol(String.format("[IN] Entity used bed at %s (entityId=%d)", this.position, this.entityId)); } public int getEntityId() { - return entityId; + return this.entityId; } public BlockPosition getPosition() { - return position; + return this.position; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketVehicleMovement.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketVehicleMovement.java index 97fa9ef8f..ccb699a2f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketVehicleMovement.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketVehicleMovement.java @@ -26,9 +26,9 @@ public class PacketVehicleMovement implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - location = buffer.readLocation(); - yaw = buffer.readFloat(); - pitch = buffer.readFloat(); + this.location = buffer.readLocation(); + this.yaw = buffer.readFloat(); + this.pitch = buffer.readFloat(); return true; } @@ -39,18 +39,18 @@ public class PacketVehicleMovement implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received vehicle movement (location=%s, yaw=%s, pitch=%s)", location, yaw, pitch)); + Log.protocol(String.format("[IN] Received vehicle movement (location=%s, yaw=%s, pitch=%s)", this.location, this.yaw, this.pitch)); } public Location getLocation() { - return location; + return this.location; } public float getYaw() { - return yaw; + return this.yaw; } public float getPitch() { - return pitch; + return this.pitch; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java index 02940fd65..2a6fd5d17 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowItems.java @@ -25,10 +25,10 @@ public class PacketWindowItems implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - windowId = buffer.readByte(); - data = new Slot[buffer.readUnsignedShort()]; - for (int i = 0; i < data.length; i++) { - data[i] = buffer.readSlot(); + this.windowId = buffer.readByte(); + this.data = new Slot[buffer.readUnsignedShort()]; + for (int i = 0; i < this.data.length; i++) { + this.data[i] = buffer.readSlot(); } return true; } @@ -40,14 +40,14 @@ public class PacketWindowItems implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Inventory slot change: %d", data.length)); + Log.protocol(String.format("[IN] Inventory slot change: %d", this.data.length)); } public byte getWindowId() { - return windowId; + return this.windowId; } public Slot[] getData() { - return data; + return this.data; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java index c15351605..60ab670d6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWindowProperty.java @@ -38,18 +38,18 @@ public class PacketWindowProperty implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Received window property (windowId=%d, property=%d, value=%d)", windowId, property, value)); + Log.protocol(String.format("[IN] Received window property (windowId=%d, property=%d, value=%d)", this.windowId, this.property, this.value)); } public byte getWindowId() { - return windowId; + return this.windowId; } public short getProperty() { - return property; + return this.property; } public short getValue() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWorldBorder.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWorldBorder.java index 01f89962e..9fc647f30 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWorldBorder.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketWorldBorder.java @@ -37,30 +37,30 @@ public class PacketWorldBorder implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - action = WorldBorderActions.byId(buffer.readVarInt()); - switch (action) { - case SET_SIZE -> radius = buffer.readDouble(); + this.action = WorldBorderActions.byId(buffer.readVarInt()); + switch (this.action) { + case SET_SIZE -> this.radius = buffer.readDouble(); case LERP_SIZE -> { - oldRadius = buffer.readDouble(); - newRadius = buffer.readDouble(); - speed = buffer.readVarLong(); + this.oldRadius = buffer.readDouble(); + this.newRadius = buffer.readDouble(); + this.speed = buffer.readVarLong(); } case SET_CENTER -> { - x = buffer.readDouble(); - z = buffer.readDouble(); + this.x = buffer.readDouble(); + this.z = buffer.readDouble(); } case INITIALIZE -> { - x = buffer.readDouble(); - z = buffer.readDouble(); - oldRadius = buffer.readDouble(); - newRadius = buffer.readDouble(); - speed = buffer.readVarLong(); - portalBound = buffer.readVarInt(); - warningTime = buffer.readVarInt(); - warningBlocks = buffer.readVarInt(); + this.x = buffer.readDouble(); + this.z = buffer.readDouble(); + this.oldRadius = buffer.readDouble(); + this.newRadius = buffer.readDouble(); + this.speed = buffer.readVarLong(); + this.portalBound = buffer.readVarInt(); + this.warningTime = buffer.readVarInt(); + this.warningBlocks = buffer.readVarInt(); } - case SET_WARNING_TIME -> warningTime = buffer.readVarInt(); - case SET_WARNING_BLOCKS -> warningBlocks = buffer.readVarInt(); + case SET_WARNING_TIME -> this.warningTime = buffer.readVarInt(); + case SET_WARNING_BLOCKS -> this.warningBlocks = buffer.readVarInt(); } return true; } @@ -72,46 +72,46 @@ public class PacketWorldBorder implements ClientboundPacket { @Override public void log() { - switch (action) { - case SET_SIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, radius=%s)", action, radius)); - case LERP_SIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, oldRadius=%s, newRadius=%s, speed=%s", action, oldRadius, newRadius, speed)); - case SET_CENTER -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, x=%s, z=%s)", action, x, z)); - case INITIALIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, x=%s, z=%s, oldRadius=%s, newRadius=%s, speed=%s, portalBound=%s, warningTime=%s, warningBlocks=%s)", action, x, z, oldRadius, newRadius, speed, portalBound, warningTime, warningBlocks)); - case SET_WARNING_TIME -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, warningTime=%s)", action, warningTime)); - case SET_WARNING_BLOCKS -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, warningBlocks=%s)", action, warningBlocks)); + switch (this.action) { + case SET_SIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, radius=%s)", this.action, this.radius)); + case LERP_SIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, oldRadius=%s, newRadius=%s, speed=%s", this.action, this.oldRadius, this.newRadius, this.speed)); + case SET_CENTER -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, x=%s, z=%s)", this.action, this.x, this.z)); + case INITIALIZE -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, x=%s, z=%s, oldRadius=%s, newRadius=%s, speed=%s, portalBound=%s, warningTime=%s, warningBlocks=%s)", this.action, this.x, this.z, this.oldRadius, this.newRadius, this.speed, this.portalBound, this.warningTime, this.warningBlocks)); + case SET_WARNING_TIME -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, warningTime=%s)", this.action, this.warningTime)); + case SET_WARNING_BLOCKS -> Log.protocol(String.format("[IN] Receiving world border packet (action=%s, warningBlocks=%s)", this.action, this.warningBlocks)); } } public double getRadius() { - return radius; + return this.radius; } public double getOldRadius() { - return oldRadius; + return this.oldRadius; } public double getNewRadius() { - return newRadius; + return this.newRadius; } public double getX() { - return x; + return this.x; } public double getZ() { - return z; + return this.z; } public int getPortalBound() { - return portalBound; + return this.portalBound; } public int getWarningTime() { - return warningTime; + return this.warningTime; } public int getWarningBlocks() { - return warningBlocks; + return this.warningBlocks; } public enum WorldBorderActions { @@ -122,8 +122,10 @@ public class PacketWorldBorder implements ClientboundPacket { SET_WARNING_TIME, SET_WARNING_BLOCKS; + private static final WorldBorderActions[] WORLD_BORDER_ACTIONS = values(); + public static WorldBorderActions byId(int id) { - return values()[id]; + return WORLD_BORDER_ACTIONS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusPong.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusPong.java index 13542e281..d9477e83f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusPong.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusPong.java @@ -34,7 +34,7 @@ public class PacketStatusPong implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving pong packet (%s)", id)); + Log.protocol(String.format("[IN] Receiving pong packet (%s)", this.id)); } public long getID() { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusResponse.java index 43ccfe6e3..8bdeab56e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/status/PacketStatusResponse.java @@ -24,7 +24,7 @@ public class PacketStatusResponse implements ClientboundPacket { @Override public boolean read(InByteBuffer buffer) { - response = new ServerListPing(buffer.readJSON()); + this.response = new ServerListPing(buffer.readJSON()); return true; } @@ -35,7 +35,7 @@ public class PacketStatusResponse implements ClientboundPacket { @Override public void log() { - Log.protocol(String.format("[IN] Receiving status response packet (online=%d, maxPlayers=%d, protocolId=%d)", response.getPlayerOnline(), response.getMaxPlayers(), response.getProtocolId())); + Log.protocol(String.format("[IN] Receiving status response packet (online=%d, maxPlayers=%d, protocolId=%d)", this.response.getPlayerOnline(), this.response.getMaxPlayers(), this.response.getProtocolId())); } public ServerListPing getResponse() { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/handshaking/PacketHandshake.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/handshaking/PacketHandshake.java index 65374d80c..c109c5ac0 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/handshaking/PacketHandshake.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/handshaking/PacketHandshake.java @@ -42,15 +42,15 @@ public class PacketHandshake implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.HANDSHAKING_HANDSHAKE); - buffer.writeVarInt((nextState == ConnectionStates.STATUS ? -1 : connection.getVersion().getProtocolId())); // get best protocol version - buffer.writeString(address.getHostname()); - buffer.writeShort((short) address.getPort()); - buffer.writeVarInt(nextState.ordinal()); + buffer.writeVarInt((this.nextState == ConnectionStates.STATUS ? -1 : connection.getVersion().getProtocolId())); // get best protocol version + buffer.writeString(this.address.getHostname()); + buffer.writeShort((short) this.address.getPort()); + buffer.writeVarInt(this.nextState.ordinal()); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending handshake packet (address=%s)", address)); + Log.protocol(String.format("[OUT] Sending handshake packet (address=%s)", this.address)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketEncryptionResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketEncryptionResponse.java index 385aefd75..a8dfdcabb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketEncryptionResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketEncryptionResponse.java @@ -36,14 +36,14 @@ public class PacketEncryptionResponse implements ServerboundPacket { } public SecretKey getSecretKey() { - return secretKey; + return this.secretKey; } @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.LOGIN_ENCRYPTION_RESPONSE); - buffer.writeByteArray(secret); - buffer.writeByteArray(token); + buffer.writeByteArray(this.secret); + buffer.writeByteArray(this.token); return buffer; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginPluginResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginPluginResponse.java index 02f8fadf9..ce1276be0 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginPluginResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginPluginResponse.java @@ -38,16 +38,16 @@ public class PacketLoginPluginResponse implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.LOGIN_PLUGIN_RESPONSE); - buffer.writeVarInt(messageId); - buffer.writeBoolean(successful); - if (successful) { - buffer.writeBytes(data); + buffer.writeVarInt(this.messageId); + buffer.writeBoolean(this.successful); + if (this.successful) { + buffer.writeBytes(this.data); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending login plugin response (messageId=%d, successful=%s)", messageId, successful)); + Log.protocol(String.format("[OUT] Sending login plugin response (messageId=%d, successful=%s)", this.messageId, this.successful)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginStart.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginStart.java index ede9336ad..541da6443 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginStart.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/login/PacketLoginStart.java @@ -25,7 +25,7 @@ public class PacketLoginStart implements ServerboundPacket { final String username; public PacketLoginStart(Player p) { - username = p.getPlayerName(); + this.username = p.getPlayerName(); } public PacketLoginStart(String username) { @@ -35,12 +35,12 @@ public class PacketLoginStart implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.LOGIN_LOGIN_START); - buffer.writeString(username); + buffer.writeString(this.username); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending login start (username=%s)", username)); + Log.protocol(String.format("[OUT] Sending login start (username=%s)", this.username)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java index 4fbb7cbc7..cc6cd4c97 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAdvancementTab.java @@ -25,7 +25,7 @@ public class PacketAdvancementTab implements ServerboundPacket { public PacketAdvancementTab(AdvancementTabStatus action) { this.action = action; - tabToOpen = null; + this.tabToOpen = null; } public PacketAdvancementTab(AdvancementTabStatus action, String tabToOpen) { @@ -36,24 +36,26 @@ public class PacketAdvancementTab implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ADVANCEMENT_TAB); - buffer.writeVarInt(action.ordinal()); - if (action == AdvancementTabStatus.OPEN_TAB) { - buffer.writeString(tabToOpen); + buffer.writeVarInt(this.action.ordinal()); + if (this.action == AdvancementTabStatus.OPEN_TAB) { + buffer.writeString(this.tabToOpen); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending advancement tab packet (action=%s, tabToOpen=%s)", action, tabToOpen)); + Log.protocol(String.format("[OUT] Sending advancement tab packet (action=%s, tabToOpen=%s)", this.action, this.tabToOpen)); } public enum AdvancementTabStatus { OPEN_TAB, CLOSE_TAB; + private static final AdvancementTabStatus[] ADVANCEMENT_TAB_STATUSES = values(); + public static AdvancementTabStatus byId(int id) { - return values()[id]; + return ADVANCEMENT_TAB_STATUSES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAnimation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAnimation.java index 050ce627e..8a0d5e4fb 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAnimation.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketAnimation.java @@ -31,13 +31,13 @@ public class PacketAnimation implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ANIMATION); if (buffer.getVersionId() >= 49) { - buffer.writeVarInt(hand.ordinal()); + buffer.writeVarInt(this.hand.ordinal()); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending hand animation (hand=%s)", hand)); + Log.protocol(String.format("[OUT] Sending hand animation (hand=%s)", this.hand)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketChatMessageSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketChatMessageSending.java index be3ac4a56..3f3e5e4f4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketChatMessageSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketChatMessageSending.java @@ -30,12 +30,12 @@ public class PacketChatMessageSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CHAT_MESSAGE); - buffer.writeString(message); + buffer.writeString(this.message); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending Chat message: %s", message)); + Log.protocol(String.format("[OUT] Sending Chat message: %s", this.message)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClickWindow.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClickWindow.java index eb5b93b6a..affd8db74 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClickWindow.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClickWindow.java @@ -40,17 +40,17 @@ public class PacketClickWindow implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLICK_WINDOW); - buffer.writeByte(windowId); - buffer.writeShort(slot); - buffer.writeByte(action.getButton()); - buffer.writeShort(actionNumber); - buffer.writeByte(action.getMode()); - buffer.writeSlot(clickedItem); + buffer.writeByte(this.windowId); + buffer.writeShort(this.slot); + buffer.writeByte(this.action.getButton()); + buffer.writeShort(this.actionNumber); + buffer.writeByte(this.action.getMode()); + buffer.writeSlot(this.clickedItem); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Clicking in window (windowId=%d, slot=%d, action=%s)", windowId, slot, action)); + Log.protocol(String.format("[OUT] Clicking in window (windowId=%d, slot=%d, action=%s)", this.windowId, this.slot, this.action)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientSettings.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientSettings.java index 742c4252a..8cd263857 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientSettings.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientSettings.java @@ -42,8 +42,8 @@ public class PacketClientSettings implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLIENT_SETTINGS); - buffer.writeString(locale); // locale - buffer.writeByte(renderDistance); // render Distance + buffer.writeString(this.locale); // locale + buffer.writeByte(this.renderDistance); // render Distance buffer.writeByte((byte) 0x00); // chat settings (nobody uses them) buffer.writeBoolean(true); // chat colors if (buffer.getVersionId() < 6) { @@ -53,13 +53,13 @@ public class PacketClientSettings implements ServerboundPacket { buffer.writeByte((byte) 0b01111111); // ToDo: skin parts } if (buffer.getVersionId() >= 49) { - buffer.writeVarInt(mainHand.ordinal()); + buffer.writeVarInt(this.mainHand.ordinal()); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending settings (locale=%s, renderDistance=%d)", locale, renderDistance)); + Log.protocol(String.format("[OUT] Sending settings (locale=%s, renderDistance=%d)", this.locale, this.renderDistance)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java index a3ae896af..bb542ecef 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketClientStatus.java @@ -31,16 +31,16 @@ public class PacketClientStatus implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLIENT_STATUS); if (buffer.getVersionId() < 7) { - buffer.writeByte((byte) status.ordinal()); + buffer.writeByte((byte) this.status.ordinal()); } else { - buffer.writeVarInt(status.ordinal()); + buffer.writeVarInt(this.status.ordinal()); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending client status packet (status=%s)", status)); + Log.protocol(String.format("[OUT] Sending client status packet (status=%s)", this.status)); } public enum ClientStates { @@ -48,8 +48,10 @@ public class PacketClientStatus implements ServerboundPacket { REQUEST_STATISTICS, OPEN_INVENTORY; + private static final ClientStates[] CLIENT_STATES = values(); + public static ClientStates byId(int id) { - return values()[id]; + return CLIENT_STATES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java index 2807b991e..de40ce03b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCloseWindowSending.java @@ -30,16 +30,16 @@ public class PacketCloseWindowSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLOSE_WINDOW); - buffer.writeByte(windowId); + buffer.writeByte(this.windowId); return buffer; } public byte getWindowId() { - return windowId; + return this.windowId; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending Close window packet (windowId=%d)", windowId)); + Log.protocol(String.format("[OUT] Sending Close window packet (windowId=%d)", this.windowId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTeleport.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTeleport.java index cb8a68756..60c977569 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTeleport.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTeleport.java @@ -30,12 +30,12 @@ public class PacketConfirmTeleport implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_TELEPORT_CONFIRM); - buffer.writeVarInt(teleportId); + buffer.writeVarInt(this.teleportId); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Confirming teleport (teleportId=%d)", teleportId)); + Log.protocol(String.format("[OUT] Confirming teleport (teleportId=%d)", this.teleportId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransactionSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransactionSending.java index 99b71dd24..f1b582084 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransactionSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketConfirmTransactionSending.java @@ -34,14 +34,14 @@ public class PacketConfirmTransactionSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_WINDOW_CONFIRMATION); - buffer.writeByte(windowId); - buffer.writeShort(actionNumber); - buffer.writeBoolean(accepted); + buffer.writeByte(this.windowId); + buffer.writeShort(this.actionNumber); + buffer.writeBoolean(this.accepted); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending confirm transaction packet (windowId=%d, actionNumber=%d, accepted=%s)", windowId, actionNumber, accepted)); + Log.protocol(String.format("[OUT] Sending confirm transaction packet (windowId=%d, actionNumber=%d, accepted=%s)", this.windowId, this.actionNumber, this.accepted)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingBookData.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingBookData.java index bd3e413f0..9263bb67d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingBookData.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingBookData.java @@ -34,8 +34,8 @@ public class PacketCraftingBookData implements ServerboundPacket { public PacketCraftingBookData(BookDataStatus action, int recipeId) { this.action = action; this.recipeId = recipeId; - craftingBookOpen = false; - craftingFilter = false; + this.craftingBookOpen = false; + this.craftingFilter = false; } public PacketCraftingBookData(BookDataStatus action, boolean craftingBookOpen, boolean craftingFilter) { @@ -58,21 +58,21 @@ public class PacketCraftingBookData implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_RECIPE_BOOK_DATA); if (buffer.getVersionId() < 333) { - buffer.writeInt(action.ordinal()); + buffer.writeInt(this.action.ordinal()); } else { - buffer.writeVarInt(action.ordinal()); + buffer.writeVarInt(this.action.ordinal()); } - switch (action) { - case DISPLAY_RECIPE -> buffer.writeVarInt(recipeId); + switch (this.action) { + case DISPLAY_RECIPE -> buffer.writeVarInt(this.recipeId); case CRAFTING_BOOK_STATUS -> { - buffer.writeBoolean(craftingBookOpen); - buffer.writeBoolean(craftingFilter); + buffer.writeBoolean(this.craftingBookOpen); + buffer.writeBoolean(this.craftingFilter); if (buffer.getVersionId() >= 451) { - buffer.writeBoolean(blastingBookOpen); - buffer.writeBoolean(blastingFilter); - buffer.writeBoolean(smokingBookOpen); - buffer.writeBoolean(smokingFilter); + buffer.writeBoolean(this.blastingBookOpen); + buffer.writeBoolean(this.blastingFilter); + buffer.writeBoolean(this.smokingBookOpen); + buffer.writeBoolean(this.smokingFilter); } } } @@ -81,9 +81,9 @@ public class PacketCraftingBookData implements ServerboundPacket { @Override public void log() { - switch (action) { - case DISPLAY_RECIPE -> Log.protocol(String.format("[OUT] Sending crafting book status (action=%s, recipeId=%d)", action, recipeId)); - case CRAFTING_BOOK_STATUS -> Log.protocol(String.format("[OUT] Sending crafting book status (action=%s, craftingBookOpen=%s, craftingFilter=%s)", action, craftingBookOpen, craftingFilter)); + switch (this.action) { + case DISPLAY_RECIPE -> Log.protocol(String.format("[OUT] Sending crafting book status (action=%s, recipeId=%d)", this.action, this.recipeId)); + case CRAFTING_BOOK_STATUS -> Log.protocol(String.format("[OUT] Sending crafting book status (action=%s, craftingBookOpen=%s, craftingFilter=%s)", this.action, this.craftingBookOpen, this.craftingFilter)); } } @@ -91,8 +91,10 @@ public class PacketCraftingBookData implements ServerboundPacket { DISPLAY_RECIPE, CRAFTING_BOOK_STATUS; + private static final BookDataStatus[] BOOK_DATA_STATUSES = values(); + public static BookDataStatus byId(int id) { - return values()[id]; + return BOOK_DATA_STATUSES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingRecipeRequest.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingRecipeRequest.java index f441d2b1e..ae1d9a193 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingRecipeRequest.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCraftingRecipeRequest.java @@ -31,13 +31,13 @@ public class PacketCraftingRecipeRequest implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CRAFT_RECIPE_REQUEST); - buffer.writeByte(windowId); - buffer.writeVarInt(recipeId); + buffer.writeByte(this.windowId); + buffer.writeVarInt(this.recipeId); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending entity action packet (windowId=%d, recipeId=%d)", windowId, recipeId)); + Log.protocol(String.format("[OUT] Sending entity action packet (windowId=%d, recipeId=%d)", this.windowId, this.recipeId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java index 6cabd090f..87acc992b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketCreativeInventoryAction.java @@ -33,13 +33,13 @@ public class PacketCreativeInventoryAction implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CREATIVE_INVENTORY_ACTION); - buffer.writeShort(slot); - buffer.writeSlot(clickedItem); + buffer.writeShort(this.slot); + buffer.writeSlot(this.clickedItem); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending creative inventory action (slot=%d, item=%s)", slot, clickedItem.getDisplayName())); + Log.protocol(String.format("[OUT] Sending creative inventory action (slot=%d, item=%s)", this.slot, this.clickedItem.getDisplayName())); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEntityAction.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEntityAction.java index b2927cf8b..0e35ce7ed 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEntityAction.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketEntityAction.java @@ -41,20 +41,20 @@ public class PacketEntityAction implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ENTITY_ACTION); - buffer.writeEntityId(entityId); + buffer.writeEntityId(this.entityId); if (buffer.getVersionId() < 7) { - buffer.writeByte((byte) action.getId(buffer.getVersionId())); - buffer.writeInt(parameter); + buffer.writeByte((byte) this.action.getId(buffer.getVersionId())); + buffer.writeInt(this.parameter); } else { - buffer.writeVarInt(action.getId(buffer.getVersionId())); - buffer.writeVarInt(parameter); + buffer.writeVarInt(this.action.getId(buffer.getVersionId())); + buffer.writeVarInt(this.parameter); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending entity action packet (entityId=%d, action=%s, parameter=%d)", entityId, action, parameter)); + Log.protocol(String.format("[OUT] Sending entity action packet (entityId=%d, action=%s, parameter=%d)", this.entityId, this.action, this.parameter)); } public enum EntityActions { @@ -71,7 +71,7 @@ public class PacketEntityAction implements ServerboundPacket { final VersionValueMap valueMap; EntityActions(MapSet[] values) { - valueMap = new VersionValueMap<>(values, true); + this.valueMap = new VersionValueMap<>(values, true); } public static EntityActions byId(int id, int versionId) { @@ -84,7 +84,7 @@ public class PacketEntityAction implements ServerboundPacket { } public int getId(int versionId) { - Integer ret = valueMap.get(versionId); + Integer ret = this.valueMap.get(versionId); if (ret == null) { return -2; } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketGenerateStructure.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketGenerateStructure.java index 197a645a9..6f2e9750d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketGenerateStructure.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketGenerateStructure.java @@ -34,16 +34,16 @@ public class PacketGenerateStructure implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_GENERATE_STRUCTURE); - buffer.writePosition(position); - buffer.writeVarInt(levels); + buffer.writePosition(this.position); + buffer.writeVarInt(this.levels); if (buffer.getVersionId() <= 719) { - buffer.writeBoolean(keepJigsaw); + buffer.writeBoolean(this.keepJigsaw); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending generate structure packet (position=%s, levels=%d, keepJigsaw=%s)", position, levels, keepJigsaw)); + Log.protocol(String.format("[OUT] Sending generate structure packet (position=%s, levels=%d, keepJigsaw=%s)", this.position, this.levels, this.keepJigsaw)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketHeldItemChangeSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketHeldItemChangeSending.java index 6763669a3..82a05c21a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketHeldItemChangeSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketHeldItemChangeSending.java @@ -34,12 +34,12 @@ public class PacketHeldItemChangeSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_HELD_ITEM_CHANGE); - buffer.writeShort(slot); + buffer.writeShort(this.slot); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending slot selection: (%s)", slot)); + Log.protocol(String.format("[OUT] Sending slot selection: (%s)", this.slot)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java index 541ffe438..87c334bb2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketInteractEntity.java @@ -63,32 +63,32 @@ public class PacketInteractEntity implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_INTERACT_ENTITY); - buffer.writeEntityId(entityId); + buffer.writeEntityId(this.entityId); if (buffer.getVersionId() < 33) { - if (click == EntityInteractionClicks.INTERACT_AT) { - click = EntityInteractionClicks.INTERACT; + if (this.click == EntityInteractionClicks.INTERACT_AT) { + this.click = EntityInteractionClicks.INTERACT; } } - buffer.writeByte((byte) click.ordinal()); + buffer.writeByte((byte) this.click.ordinal()); if (buffer.getVersionId() >= 33) { - if (click == EntityInteractionClicks.INTERACT_AT) { + if (this.click == EntityInteractionClicks.INTERACT_AT) { // position - buffer.writeFloat((float) location.getX()); - buffer.writeFloat((float) location.getY()); - buffer.writeFloat((float) location.getZ()); + buffer.writeFloat((float) this.location.getX()); + buffer.writeFloat((float) this.location.getY()); + buffer.writeFloat((float) this.location.getZ()); } - if (click == EntityInteractionClicks.INTERACT_AT || click == EntityInteractionClicks.INTERACT) { + if (this.click == EntityInteractionClicks.INTERACT_AT || this.click == EntityInteractionClicks.INTERACT) { if (buffer.getVersionId() >= 49) { - buffer.writeVarInt(hand.ordinal()); + buffer.writeVarInt(this.hand.ordinal()); } if (buffer.getVersionId() >= 725 && buffer.getVersionId() < 729) { - buffer.writeBoolean(sneaking); + buffer.writeBoolean(this.sneaking); } } if (buffer.getVersionId() <= 729) { - buffer.writeBoolean(sneaking); + buffer.writeBoolean(this.sneaking); } } return buffer; @@ -96,7 +96,7 @@ public class PacketInteractEntity implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Interacting with entity (entityId=%d, click=%s)", entityId, click)); + Log.protocol(String.format("[OUT] Interacting with entity (entityId=%d, click=%s)", this.entityId, this.click)); } public enum EntityInteractionClicks { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketKeepAliveResponse.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketKeepAliveResponse.java index 4c8ae4a67..c589022f7 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketKeepAliveResponse.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketKeepAliveResponse.java @@ -35,17 +35,17 @@ public class PacketKeepAliveResponse implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_KEEP_ALIVE); if (buffer.getVersionId() < 32) { - buffer.writeInt((int) id); + buffer.writeInt((int) this.id); } else if (buffer.getVersionId() < 339) { - buffer.writeVarInt((int) id); + buffer.writeVarInt((int) this.id); } else { - buffer.writeLong(id); + buffer.writeLong(this.id); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending keep alive back (%d)", id)); + Log.protocol(String.format("[OUT] Sending keep alive back (%d)", this.id)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketNameItem.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketNameItem.java index 86f3843cd..c304f6d54 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketNameItem.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketNameItem.java @@ -30,12 +30,12 @@ public class PacketNameItem implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_NAME_ITEM); - buffer.writeString(name); + buffer.writeString(this.name); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending name item packet (name=\"%s\")", name)); + Log.protocol(String.format("[OUT] Sending name item packet (name=\"%s\")", this.name)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java index 2b099ef6e..cdc66a5a9 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerAbilitiesSending.java @@ -30,7 +30,7 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_ABILITIES); byte flags = 0; - if (flying) { + if (this.flying) { flags |= 0b10; } buffer.writeByte(flags); @@ -44,6 +44,6 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Sending player abilities packet: (flying=%s)", flying)); + Log.protocol(String.format("[OUT] Sending player abilities packet: (flying=%s)", this.flying)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerBlockPlacement.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerBlockPlacement.java index 080b269df..650178ef1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerBlockPlacement.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerBlockPlacement.java @@ -65,41 +65,41 @@ public class PacketPlayerBlockPlacement implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_BLOCK_PLACEMENT); if (buffer.getVersionId() >= 453) { - buffer.writeVarInt(hand.ordinal()); + buffer.writeVarInt(this.hand.ordinal()); } if (buffer.getVersionId() < 7) { - buffer.writeBlockPositionByte(position); + buffer.writeBlockPositionByte(this.position); } else { - buffer.writePosition(position); + buffer.writePosition(this.position); } if (buffer.getVersionId() < 49) { - buffer.writeByte(direction); - buffer.writeSlot(item); + buffer.writeByte(this.direction); + buffer.writeSlot(this.item); } else { - buffer.writeVarInt(direction); + buffer.writeVarInt(this.direction); if (buffer.getVersionId() < 453) { - buffer.writeVarInt(hand.ordinal()); + buffer.writeVarInt(this.hand.ordinal()); } } if (buffer.getVersionId() >= 453) { - buffer.writeBoolean(insideBlock); + buffer.writeBoolean(this.insideBlock); } if (buffer.getVersionId() < 309) { - buffer.writeByte((byte) (cursorX * 15.0F)); - buffer.writeByte((byte) (cursorY * 15.0F)); - buffer.writeByte((byte) (cursorZ * 15.0F)); + buffer.writeByte((byte) (this.cursorX * 15.0F)); + buffer.writeByte((byte) (this.cursorY * 15.0F)); + buffer.writeByte((byte) (this.cursorZ * 15.0F)); } else { - buffer.writeFloat(cursorX); - buffer.writeFloat(cursorY); - buffer.writeFloat(cursorZ); + buffer.writeFloat(this.cursorX); + buffer.writeFloat(this.cursorY); + buffer.writeFloat(this.cursorZ); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Send player block placement (position=%s, direction=%d, item=%s, cursor=%s %s %s)", position, direction, item, cursorX, cursorY, cursorZ)); + Log.protocol(String.format("[OUT] Send player block placement (position=%s, direction=%d, item=%s, cursor=%s %s %s)", this.position, this.direction, this.item, this.cursorX, this.cursorY, this.cursorZ)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java index 3f0ad0267..9a3201d51 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerDigging.java @@ -35,30 +35,30 @@ public class PacketPlayerDigging implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_DIGGING); if (buffer.getVersionId() < 49) { // ToDo - buffer.writeByte((byte) status.ordinal()); + buffer.writeByte((byte) this.status.ordinal()); } else { - buffer.writeVarInt(status.ordinal()); + buffer.writeVarInt(this.status.ordinal()); } if (buffer.getVersionId() < 7) { - if (position == null) { + if (this.position == null) { buffer.writeInt(0); buffer.writeByte((byte) 0); buffer.writeInt(0); } else { - buffer.writeBlockPositionByte(position); + buffer.writeBlockPositionByte(this.position); } } else { - buffer.writePosition(position); + buffer.writePosition(this.position); } - buffer.writeByte(face.getId()); + buffer.writeByte(this.face.getId()); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Send player digging packet (status=%s, position=%s, face=%s)", status, position, face)); + Log.protocol(String.format("[OUT] Send player digging packet (status=%s, position=%s, face=%s)", this.status, this.position, this.face)); } public enum DiggingStatus { @@ -70,8 +70,10 @@ public class PacketPlayerDigging implements ServerboundPacket { SHOOT_ARROW__FINISH_EATING, SWAP_ITEMS_IN_HAND; + private static final DiggingStatus[] DIGGING_STATUSES = values(); + public static DiggingStatus byId(int id) { - return values()[id]; + return DIGGING_STATUSES[id]; } } @@ -91,7 +93,7 @@ public class PacketPlayerDigging implements ServerboundPacket { } public byte getId() { - return id; + return this.id; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java index fbe1a85fa..80ee73d4f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java @@ -35,20 +35,20 @@ public class PacketPlayerPositionAndRotationSending implements ServerboundPacket @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION_AND_ROTATION); - buffer.writeDouble(location.getX()); - buffer.writeDouble(location.getY()); + buffer.writeDouble(this.location.getX()); + buffer.writeDouble(this.location.getY()); if (buffer.getVersionId() < 10) { - buffer.writeDouble(location.getY() - 1.62); + buffer.writeDouble(this.location.getY() - 1.62); } - buffer.writeDouble(location.getZ()); - buffer.writeFloat(rotation.getYaw()); - buffer.writeFloat(rotation.getPitch()); - buffer.writeBoolean(onGround); + buffer.writeDouble(this.location.getZ()); + buffer.writeFloat(this.rotation.getYaw()); + buffer.writeFloat(this.rotation.getPitch()); + buffer.writeBoolean(this.onGround); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending player position and rotation: (location=%s, rotation=%s, onGround=%b)", location, rotation, onGround)); + Log.protocol(String.format("[OUT] Sending player position and rotation: (location=%s, rotation=%s, onGround=%b)", this.location, this.rotation, this.onGround)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java index aaa24b099..861d363a4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java @@ -45,18 +45,18 @@ public class PacketPlayerPositionSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION); - buffer.writeDouble(x); - buffer.writeDouble(feetY); + buffer.writeDouble(this.x); + buffer.writeDouble(this.feetY); if (buffer.getVersionId() < 10) { - buffer.writeDouble(headY); + buffer.writeDouble(this.headY); } - buffer.writeDouble(z); - buffer.writeBoolean(onGround); + buffer.writeDouble(this.z); + buffer.writeBoolean(this.onGround); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending player position: %s %s %s", x, headY, z)); + Log.protocol(String.format("[OUT] Sending player position: %s %s %s", this.x, this.headY, this.z)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java index 4ba3dd8d0..55d32526d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java @@ -33,14 +33,14 @@ public class PacketPlayerRotationSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_ROTATION); - buffer.writeFloat(yaw); - buffer.writeFloat(pitch); - buffer.writeBoolean(onGround); + buffer.writeFloat(this.yaw); + buffer.writeFloat(this.pitch); + buffer.writeBoolean(this.onGround); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending player rotation (yaw=%s, pitch=%s)", yaw, pitch)); + Log.protocol(String.format("[OUT] Sending player rotation (yaw=%s, pitch=%s)", this.yaw, this.pitch)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPluginMessageSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPluginMessageSending.java index 6e939d54a..bb15bf00e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPluginMessageSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPluginMessageSending.java @@ -32,20 +32,20 @@ public class PacketPluginMessageSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLUGIN_MESSAGE); - buffer.writeString(channel); + buffer.writeString(this.channel); if (buffer.getVersionId() < 29) { - buffer.writeShort((short) data.length); + buffer.writeShort((short) this.data.length); } else if (buffer.getVersionId() < 32) { - buffer.writeVarInt(data.length); + buffer.writeVarInt(this.data.length); } - buffer.writeBytes(data); + buffer.writeBytes(this.data); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending data in plugin channel \"%s\" with a length of %d bytes", channel, data.length)); + Log.protocol(String.format("[OUT] Sending data in plugin channel \"%s\" with a length of %d bytes", this.channel, this.data.length)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketQueryEntityNBT.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketQueryEntityNBT.java index 6876c1f6e..1aa38e061 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketQueryEntityNBT.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketQueryEntityNBT.java @@ -31,13 +31,13 @@ public class PacketQueryEntityNBT implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_ENTITY_NBT_REQUEST); - buffer.writeVarInt(transactionId); - buffer.writeVarInt(entityId); + buffer.writeVarInt(this.transactionId); + buffer.writeVarInt(this.entityId); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Querying entity nbt (transactionId=%d, entityId=%d)", transactionId, entityId)); + Log.protocol(String.format("[OUT] Querying entity nbt (transactionId=%d, entityId=%d)", this.transactionId, this.entityId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketRecipeBookState.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketRecipeBookState.java index 2e3e0475a..32468c4a6 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketRecipeBookState.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketRecipeBookState.java @@ -33,15 +33,15 @@ public class PacketRecipeBookState implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SET_RECIPE_BOOK_STATE); - buffer.writeVarInt(book.ordinal()); - buffer.writeBoolean(bookOpen); - buffer.writeBoolean(filterActive); + buffer.writeVarInt(this.book.ordinal()); + buffer.writeBoolean(this.bookOpen); + buffer.writeBoolean(this.filterActive); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending recipe book state (book=%s, bookOpen=%s, filterActive=%s)", book, bookOpen, filterActive)); + Log.protocol(String.format("[OUT] Sending recipe book state (book=%s, bookOpen=%s, filterActive=%s)", this.book, this.bookOpen, this.filterActive)); } public enum RecipeBooks { @@ -50,8 +50,10 @@ public class PacketRecipeBookState implements ServerboundPacket { BLAST_FURNACE, SMOKER; + private static final RecipeBooks[] RECIPE_BOOKS = values(); + public static RecipeBooks byId(int id) { - return values()[id]; + return RECIPE_BOOKS[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java index a1bc3f078..a0f0bde4f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketResourcePackStatus.java @@ -32,15 +32,15 @@ public class PacketResourcePackStatus implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_RESOURCE_PACK_STATUS); if (buffer.getVersionId() < 204) { - buffer.writeString(hash); + buffer.writeString(this.hash); } - buffer.writeVarInt(status.ordinal()); + buffer.writeVarInt(this.status.ordinal()); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending resource pack status (status=%s, hash=%s)", status, hash)); + Log.protocol(String.format("[OUT] Sending resource pack status (status=%s, hash=%s)", this.status, this.hash)); } public enum ResourcePackStates { diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSelectTrade.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSelectTrade.java index d7e5bb253..ec31d3e11 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSelectTrade.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSelectTrade.java @@ -30,12 +30,12 @@ public class PacketSelectTrade implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SELECT_TRADE); - buffer.writeVarInt(id); + buffer.writeVarInt(this.id); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending select trade packet (id=%d)", id)); + Log.protocol(String.format("[OUT] Sending select trade packet (id=%d)", this.id)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetBeaconEffect.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetBeaconEffect.java index b7d3c15c1..445a64f01 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetBeaconEffect.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetBeaconEffect.java @@ -32,13 +32,13 @@ public class PacketSetBeaconEffect implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SET_BEACON_EFFECT); - buffer.writeVarInt(primaryEffectId); - buffer.writeVarInt(secondaryEffectId); + buffer.writeVarInt(this.primaryEffectId); + buffer.writeVarInt(this.secondaryEffectId); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending beacon effect select packet (primaryEffectId=%d, secondaryEffectId=%d)", primaryEffectId, secondaryEffectId)); + Log.protocol(String.format("[OUT] Sending beacon effect select packet (primaryEffectId=%d, secondaryEffectId=%d)", this.primaryEffectId, this.secondaryEffectId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetDisplayedRecipe.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetDisplayedRecipe.java index 45d8839bd..699b7e914 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetDisplayedRecipe.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSetDisplayedRecipe.java @@ -30,12 +30,12 @@ public class PacketSetDisplayedRecipe implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SET_DISPLAYED_RECIPE); - buffer.writeString(recipe.getResult().getItem().getMod() + ":" + recipe.getResult().getItem().getIdentifier()); + buffer.writeString(this.recipe.getResult().getItem().getMod() + ":" + this.recipe.getResult().getItem().getIdentifier()); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending set displayed recipe packet (identifier=%s:%s)", recipe.getResult().getItem().getMod(), recipe.getResult().getItem().getIdentifier())); + Log.protocol(String.format("[OUT] Sending set displayed recipe packet (identifier=%s:%s)", this.recipe.getResult().getItem().getMod(), this.recipe.getResult().getItem().getIdentifier())); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSpectate.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSpectate.java index bec0fa36d..ede861a4e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSpectate.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSpectate.java @@ -31,12 +31,12 @@ public class PacketSpectate implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_SPECTATE); - buffer.writeUUID(entityUUID); + buffer.writeUUID(this.entityUUID); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Spectating entity (entityUUID=%s)", entityUUID)); + Log.protocol(String.format("[OUT] Spectating entity (entityUUID=%s)", this.entityUUID)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerBoat.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerBoat.java index b106bb1f2..6701ff9a0 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerBoat.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerBoat.java @@ -32,13 +32,13 @@ public class PacketSteerBoat implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_STEER_BOAT); - buffer.writeBoolean(leftPaddle); - buffer.writeBoolean(rightPaddle); + buffer.writeBoolean(this.leftPaddle); + buffer.writeBoolean(this.rightPaddle); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Steering boat: (leftPaddle=%s, rightPaddle=%s)", leftPaddle, rightPaddle)); + Log.protocol(String.format("[OUT] Steering boat: (leftPaddle=%s, rightPaddle=%s)", this.leftPaddle, this.rightPaddle)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerVehicle.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerVehicle.java index 405f28ff9..f2e550403 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerVehicle.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketSteerVehicle.java @@ -36,17 +36,17 @@ public class PacketSteerVehicle implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_STEER_VEHICLE); - buffer.writeFloat(sideways); - buffer.writeFloat(forward); + buffer.writeFloat(this.sideways); + buffer.writeFloat(this.forward); if (buffer.getVersionId() < 7) { - buffer.writeBoolean(jump); - buffer.writeBoolean(unmount); + buffer.writeBoolean(this.jump); + buffer.writeBoolean(this.unmount); } else { byte flags = 0; - if (jump) { + if (this.jump) { flags |= 0x1; } - if (unmount) { + if (this.unmount) { flags |= 0x2; } buffer.writeByte(flags); @@ -56,6 +56,6 @@ public class PacketSteerVehicle implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Steering vehicle: %s %s (jump=%s, unmount=%s)", sideways, forward, jump, unmount)); + Log.protocol(String.format("[OUT] Steering vehicle: %s %s (jump=%s, unmount=%s)", this.sideways, this.forward, this.jump, this.unmount)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketTabCompleteSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketTabCompleteSending.java index 618539107..88b176743 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketTabCompleteSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketTabCompleteSending.java @@ -27,14 +27,14 @@ public class PacketTabCompleteSending implements ServerboundPacket { public PacketTabCompleteSending(String text) { this.text = text; - position = null; - assumeCommand = false; + this.position = null; + this.assumeCommand = false; } public PacketTabCompleteSending(String text, BlockPosition position) { this.text = text; this.position = position; - assumeCommand = false; + this.assumeCommand = false; } public PacketTabCompleteSending(String text, boolean assumeCommand, BlockPosition position) { @@ -46,16 +46,16 @@ public class PacketTabCompleteSending implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_TAB_COMPLETE); - buffer.writeString(text); + buffer.writeString(this.text); if (buffer.getVersionId() >= 59) { - buffer.writeBoolean(assumeCommand); + buffer.writeBoolean(this.assumeCommand); } if (buffer.getVersionId() >= 37) { - if (position == null) { + if (this.position == null) { buffer.writeBoolean(false); } else { buffer.writeBoolean(true); - buffer.writePosition(position); + buffer.writePosition(this.position); } } return buffer; @@ -63,6 +63,6 @@ public class PacketTabCompleteSending implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Sending tab complete for message=\"%s\"", text.replace("\"", "\\\""))); + Log.protocol(String.format("[OUT] Sending tab complete for message=\"%s\"", this.text.replace("\"", "\\\""))); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlock.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlock.java index 6cf01e395..979355d02 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlock.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlock.java @@ -41,18 +41,18 @@ public class PacketUpdateCommandBlock implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_COMMAND_BLOCK); - buffer.writePosition(position); - buffer.writeString(command); - buffer.writeVarInt(type.ordinal()); + buffer.writePosition(this.position); + buffer.writeString(this.command); + buffer.writeVarInt(this.type.ordinal()); byte flags = 0x00; - if (trackOutput) { + if (this.trackOutput) { flags |= 0x01; } - if (isConditional) { + if (this.isConditional) { flags |= 0x02; } - if (isAutomatic) { + if (this.isAutomatic) { flags |= 0x04; } @@ -62,7 +62,7 @@ public class PacketUpdateCommandBlock implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Sending update command block packet at %s (command=\"%s\", type=%s, trackOutput=%s, isConditional=%s, isAutomatic=%s)", position, command, type, trackOutput, isConditional, isAutomatic)); + Log.protocol(String.format("[OUT] Sending update command block packet at %s (command=\"%s\", type=%s, trackOutput=%s, isConditional=%s, isAutomatic=%s)", this.position, this.command, this.type, this.trackOutput, this.isConditional, this.isAutomatic)); } public enum CommandBlockType { @@ -70,8 +70,10 @@ public class PacketUpdateCommandBlock implements ServerboundPacket { AUTO, REDSTONE; + private static final CommandBlockType[] COMMAND_BLOCK_TYPES = values(); + public static CommandBlockType byId(int id) { - return values()[id]; + return COMMAND_BLOCK_TYPES[id]; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlockMinecart.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlockMinecart.java index bf4318b11..9e83af782 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlockMinecart.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateCommandBlockMinecart.java @@ -34,14 +34,14 @@ public class PacketUpdateCommandBlockMinecart implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_COMMAND_BLOCK_MINECART); - buffer.writeVarInt(entityId); - buffer.writeString(command); - buffer.writeBoolean(trackOutput); + buffer.writeVarInt(this.entityId); + buffer.writeString(this.command); + buffer.writeBoolean(this.trackOutput); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending update minecart command block packet (entityId=%d, command=\"%s\", trackOutput=%s)", entityId, command, trackOutput)); + Log.protocol(String.format("[OUT] Sending update minecart command block packet (entityId=%d, command=\"%s\", trackOutput=%s)", this.entityId, this.command, this.trackOutput)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java index d67698827..79055a90c 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateJigsawBlock.java @@ -48,23 +48,23 @@ public class PacketUpdateJigsawBlock implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_JIGSAW_BLOCK); - buffer.writePosition(position); + buffer.writePosition(this.position); if (buffer.getVersionId() < 708) { - buffer.writeString(attachmentType); - buffer.writeString(targetPool); - buffer.writeString(finalState); + buffer.writeString(this.attachmentType); + buffer.writeString(this.targetPool); + buffer.writeString(this.finalState); } else { - buffer.writeString(name); - buffer.writeString(target); - buffer.writeString(targetPool); - buffer.writeString(finalState); - buffer.writeString(jointType); + buffer.writeString(this.name); + buffer.writeString(this.target); + buffer.writeString(this.targetPool); + buffer.writeString(this.finalState); + buffer.writeString(this.jointType); } return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Updating jigsaw block (position=%s, attachmentType=%s, targetPool=%s, finalState=%s)", position, attachmentType, targetPool, finalState)); + Log.protocol(String.format("[OUT] Updating jigsaw block (position=%s, attachmentType=%s, targetPool=%s, finalState=%s)", this.position, this.attachmentType, this.targetPool, this.finalState)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateSignSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateSignSending.java index 2a279a460..7bcc5ac47 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateSignSending.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateSignSending.java @@ -34,17 +34,17 @@ public class PacketUpdateSignSending implements ServerboundPacket { public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_SIGN); if (buffer.getVersionId() < 7) { - buffer.writeBlockPositionByte(position); + buffer.writeBlockPositionByte(this.position); } else { - buffer.writePosition(position); + buffer.writePosition(this.position); } if (buffer.getVersionId() < 21 || buffer.getVersionId() >= 62) { for (int i = 0; i < 4; i++) { - buffer.writeString(lines[i].getMessage()); + buffer.writeString(this.lines[i].getMessage()); } } else { for (int i = 0; i < 4; i++) { - buffer.writeChatComponent(lines[i]); + buffer.writeChatComponent(this.lines[i]); } } return buffer; @@ -52,6 +52,6 @@ public class PacketUpdateSignSending implements ServerboundPacket { @Override public void log() { - Log.protocol(String.format("[OUT] Sending Sign Update: %s", position)); + Log.protocol(String.format("[OUT] Sending Sign Update: %s", this.position)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateStructureBlock.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateStructureBlock.java index 17472feb4..eab80e708 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateStructureBlock.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUpdateStructureBlock.java @@ -63,28 +63,28 @@ public class PacketUpdateStructureBlock implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_UPDATE_STRUCTURE_BLOCK); - buffer.writePosition(position); - buffer.writeVarInt(action.ordinal()); - buffer.writeVarInt(mode.ordinal()); - buffer.writeString(name); - buffer.writeByte(offsetX); - buffer.writeByte(offsetY); - buffer.writeByte(offsetZ); - buffer.writeByte(sizeX); - buffer.writeByte(sizeY); - buffer.writeByte(sizeZ); - buffer.writeVarInt(mirror.ordinal()); - buffer.writeVarInt(rotation.ordinal()); - buffer.writeString(metaData); - buffer.writeFloat(integrity); - buffer.writeVarLong(seed); - buffer.writeByte(flags); + buffer.writePosition(this.position); + buffer.writeVarInt(this.action.ordinal()); + buffer.writeVarInt(this.mode.ordinal()); + buffer.writeString(this.name); + buffer.writeByte(this.offsetX); + buffer.writeByte(this.offsetY); + buffer.writeByte(this.offsetZ); + buffer.writeByte(this.sizeX); + buffer.writeByte(this.sizeY); + buffer.writeByte(this.sizeZ); + buffer.writeVarInt(this.mirror.ordinal()); + buffer.writeVarInt(this.rotation.ordinal()); + buffer.writeString(this.metaData); + buffer.writeFloat(this.integrity); + buffer.writeVarLong(this.seed); + buffer.writeByte(this.flags); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending update structure block packet (position=%s, action=%s, mode=%s, name=\"%s\", offsetX=%d, offsetY=%d, offsetZ=%d, sizeX=%d, sizeY=%d, sizeZ=%d, mirror=%s, rotation=%s, metaData=\"%s\", integrity=%s, seed=%s, flags=%s)", position, action, mode, name, offsetX, offsetY, offsetZ, sizeX, sizeY, sizeZ, mirror, rotation, metaData, integrity, seed, flags)); + Log.protocol(String.format("[OUT] Sending update structure block packet (position=%s, action=%s, mode=%s, name=\"%s\", offsetX=%d, offsetY=%d, offsetZ=%d, sizeX=%d, sizeY=%d, sizeZ=%d, mirror=%s, rotation=%s, metaData=\"%s\", integrity=%s, seed=%s, flags=%s)", this.position, this.action, this.mode, this.name, this.offsetX, this.offsetY, this.offsetZ, this.sizeX, this.sizeY, this.sizeZ, this.mirror, this.rotation, this.metaData, this.integrity, this.seed, this.flags)); } public enum StructureBlockActions { @@ -93,8 +93,10 @@ public class PacketUpdateStructureBlock implements ServerboundPacket { LOAD, DETECT_SIZE; + private static final StructureBlockActions[] STRUCTURE_BLOCK_ACTIONS = values(); + public static StructureBlockActions byId(int id) { - return values()[id]; + return STRUCTURE_BLOCK_ACTIONS[id]; } } @@ -104,8 +106,10 @@ public class PacketUpdateStructureBlock implements ServerboundPacket { CORNER, DATA; + private static final StructureBlockModes[] STRUCTURE_BLOCK_MODES = values(); + public static StructureBlockModes byId(int id) { - return values()[id]; + return STRUCTURE_BLOCK_MODES[id]; } } @@ -114,8 +118,10 @@ public class PacketUpdateStructureBlock implements ServerboundPacket { LEFT_RIGHT, FRONT_BACK; + private static final StructureBlockMirrors[] STRUCTURE_BLOCK_MIRRORS = values(); + public static StructureBlockMirrors byId(int id) { - return values()[id]; + return STRUCTURE_BLOCK_MIRRORS[id]; } } @@ -125,8 +131,10 @@ public class PacketUpdateStructureBlock implements ServerboundPacket { CLOCKWISE_180, COUNTERCLOCKWISE_90; + private static final StructureBlockRotations[] STRUCTURE_BLOCK_ROTATIONS = values(); + public static StructureBlockRotations byId(int id) { - return values()[id]; + return STRUCTURE_BLOCK_ROTATIONS[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseItem.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseItem.java index 98a246b9b..66d0684ad 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseItem.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketUseItem.java @@ -30,12 +30,12 @@ public class PacketUseItem implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_USE_ITEM); - buffer.writeVarInt(hand.ordinal()); + buffer.writeVarInt(this.hand.ordinal()); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Use hand (hand=%s)", hand)); + Log.protocol(String.format("[OUT] Use hand (hand=%s)", this.hand)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketVehicleMovement.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketVehicleMovement.java index 2d6d15def..f10ece56f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketVehicleMovement.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketVehicleMovement.java @@ -37,16 +37,16 @@ public class PacketVehicleMovement implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_VEHICLE_MOVE); - buffer.writeDouble(x); - buffer.writeDouble(y); - buffer.writeDouble(z); - buffer.writeFloat(yaw); - buffer.writeFloat(pitch); + buffer.writeDouble(this.x); + buffer.writeDouble(this.y); + buffer.writeDouble(this.z); + buffer.writeFloat(this.yaw); + buffer.writeFloat(this.pitch); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending vehicle movement: %s %s %s (yaw=%s, pitch=%s)", x, y, z, yaw, pitch)); + Log.protocol(String.format("[OUT] Sending vehicle movement: %s %s %s (yaw=%s, pitch=%s)", this.x, this.y, this.z, this.yaw, this.pitch)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketWindowClickButton.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketWindowClickButton.java index 2750f6de0..fc2d27c77 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketWindowClickButton.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketWindowClickButton.java @@ -32,13 +32,13 @@ public class PacketWindowClickButton implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_CLICK_WINDOW_BUTTON); - buffer.writeByte(windowId); - buffer.writeByte(buttonId); + buffer.writeByte(this.windowId); + buffer.writeByte(this.buttonId); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending Click Window Packet (windowId=%d, buttonId=%d)", windowId, buttonId)); + Log.protocol(String.format("[OUT] Sending Click Window Packet (windowId=%d, buttonId=%d)", this.windowId, this.buttonId)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/status/PacketStatusPing.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/status/PacketStatusPing.java index edaa13305..141493966 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/status/PacketStatusPing.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/status/PacketStatusPing.java @@ -38,12 +38,12 @@ public class PacketStatusPing implements ServerboundPacket { @Override public OutPacketBuffer write(Connection connection) { OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.STATUS_PING); - buffer.writeLong(id); + buffer.writeLong(this.id); return buffer; } @Override public void log() { - Log.protocol(String.format("[OUT] Sending ping packet (%s)", id)); + Log.protocol(String.format("[OUT] Sending ping packet (%s)", this.id)); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/ping/ForgeModInfo.java b/src/main/java/de/bixilon/minosoft/protocol/ping/ForgeModInfo.java index 22fdc1563..747ad29d2 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/ping/ForgeModInfo.java +++ b/src/main/java/de/bixilon/minosoft/protocol/ping/ForgeModInfo.java @@ -27,10 +27,10 @@ public class ForgeModInfo implements ServerModInfo { public ForgeModInfo(JsonObject modInfo) { this.modInfo = modInfo; JsonArray mods = modInfo.getAsJsonArray("modList"); - info = String.format("Modded server, %d mods present", mods.size()); + this.info = String.format("Modded server, %d mods present", mods.size()); for (JsonElement mod : mods) { JsonObject mod2 = (JsonObject) mod; - modList.add(new ServerModItem(mod2.get("modid").getAsString(), mod2.get("version").getAsString())); + this.modList.add(new ServerModItem(mod2.get("modid").getAsString(), mod2.get("version").getAsString())); } } @@ -41,7 +41,7 @@ public class ForgeModInfo implements ServerModInfo { @Override public String getInfo() { - return info; + return this.info; } @Override @@ -50,6 +50,6 @@ public class ForgeModInfo implements ServerModInfo { } public ArrayList getModList() { - return modList; + return this.modList; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/ping/ServerListPing.java b/src/main/java/de/bixilon/minosoft/protocol/ping/ServerListPing.java index 1dce47113..007377e2a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/ping/ServerListPing.java +++ b/src/main/java/de/bixilon/minosoft/protocol/ping/ServerListPing.java @@ -39,51 +39,51 @@ public class ServerListPing { } else { this.protocolId = protocolId; } - playersOnline = json.getAsJsonObject("players").get("online").getAsInt(); - maxPlayers = json.getAsJsonObject("players").get("max").getAsInt(); + this.playersOnline = json.getAsJsonObject("players").get("online").getAsInt(); + this.maxPlayers = json.getAsJsonObject("players").get("max").getAsInt(); if (json.has("favicon")) { - favicon = Base64.getDecoder().decode(json.get("favicon").getAsString().replace("data:image/png;base64,", "").replace("\n", "")); + this.favicon = Base64.getDecoder().decode(json.get("favicon").getAsString().replace("data:image/png;base64,", "").replace("\n", "")); } if (json.get("description").isJsonPrimitive()) { - motd = ChatComponent.valueOf(json.get("description").getAsString()); + this.motd = ChatComponent.valueOf(json.get("description").getAsString()); } else { - motd = new BaseComponent(json.getAsJsonObject("description")); + this.motd = new BaseComponent(json.getAsJsonObject("description")); } - serverBrand = json.getAsJsonObject("version").get("name").getAsString(); + this.serverBrand = json.getAsJsonObject("version").get("name").getAsString(); if (json.has("modinfo") && json.getAsJsonObject("modinfo").has("type") && json.getAsJsonObject("modinfo").get("type").getAsString().equals("FML")) { - serverModInfo = new ForgeModInfo(json.getAsJsonObject("modinfo")); + this.serverModInfo = new ForgeModInfo(json.getAsJsonObject("modinfo")); } else { - serverModInfo = new VanillaModInfo(); + this.serverModInfo = new VanillaModInfo(); } } public int getProtocolId() { - return protocolId; + return this.protocolId; } public int getPlayerOnline() { - return playersOnline; + return this.playersOnline; } public int getMaxPlayers() { - return maxPlayers; + return this.maxPlayers; } public byte[] getFavicon() { - return favicon; + return this.favicon; } public ChatComponent getMotd() { - return motd; + return this.motd; } public String getServerBrand() { - return serverBrand; + return this.serverBrand; } public ServerModInfo getServerModInfo() { - return serverModInfo; + return this.serverModInfo; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/ping/ServerModItem.java b/src/main/java/de/bixilon/minosoft/protocol/ping/ServerModItem.java index b35a30cc6..bb4504d3d 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/ping/ServerModItem.java +++ b/src/main/java/de/bixilon/minosoft/protocol/ping/ServerModItem.java @@ -23,15 +23,15 @@ public class ServerModItem { } public String getModId() { - return modId; + return this.modId; } public String getModVersion() { - return modVersion; + return this.modVersion; } @Override public String toString() { - return String.format("%s (%s)", modId, modVersion); + return String.format("%s (%s)", this.modId, this.modVersion); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionPing.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionPing.java index a054accfb..3b6b77915 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionPing.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionPing.java @@ -21,14 +21,14 @@ public class ConnectionPing { public ConnectionPing() { this.pingId = ThreadLocalRandom.current().nextLong(); - sendingTime = System.currentTimeMillis(); + this.sendingTime = System.currentTimeMillis(); } public long getPingId() { - return pingId; + return this.pingId; } public long getSendingTime() { - return sendingTime; + return this.sendingTime; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java index 61ded5e35..289b63237 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/ConnectionStates.java @@ -24,7 +24,9 @@ public enum ConnectionStates { FAILED, FAILED_NO_RETRY; + private static final ConnectionStates[] CONNECTION_STATES = values(); + public static ConnectionStates byId(int id) { - return values()[id]; + return CONNECTION_STATES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java index f6a63de34..52298644b 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java @@ -58,12 +58,12 @@ public class InByteBuffer { this.bytes = buffer.getBytes(); this.position = buffer.getPosition(); this.connection = buffer.getConnection(); - this.versionId = connection.getVersion().getVersionId(); + this.versionId = this.connection.getVersion().getVersionId(); } public byte[] readByteArray() { int count; - if (versionId < 19) { + if (this.versionId < 19) { count = readUnsignedShort(); } else { count = readVarInt(); @@ -85,8 +85,8 @@ public class InByteBuffer { public byte[] readBytes(int count) { byte[] ret = new byte[count]; - System.arraycopy(bytes, position, ret, 0, count); - position += count; + System.arraycopy(this.bytes, this.position, ret, 0, count); + this.position += count; return ret; } @@ -174,18 +174,18 @@ public class InByteBuffer { } public byte readByte() { - return bytes[position++]; + return this.bytes[this.position++]; } public short readUnsignedByte() { - return (short) (bytes[position++] & 0xFF); + return (short) (this.bytes[this.position++] & 0xFF); } public BlockPosition readPosition() { // ToDo: protocol id 7 long raw = readLong(); int x = (int) (raw >> 38); - if (versionId < 440) { + if (this.versionId < 440) { int y = (int) ((raw >> 26) & 0xFFF); int z = (int) (raw & 0x3FFFFFF); return new BlockPosition(x, y, z); @@ -200,7 +200,7 @@ public class InByteBuffer { } public int getLength() { - return bytes.length; + return this.bytes.length; } public Directions readDirection() { @@ -212,21 +212,21 @@ public class InByteBuffer { } public ParticleData readParticle() { - Particle type = connection.getMapping().getParticleById(readVarInt()); + Particle type = this.connection.getMapping().getParticleById(readVarInt()); return readParticleData(type); } public ParticleData readParticleData(Particle type) { - if (versionId < 343) { + if (this.versionId < 343) { // old particle format return switch (type.getIdentifier()) { - case "iconcrack" -> new ItemParticleData(new Slot(connection.getMapping().getItemByLegacy(readVarInt(), readVarInt())), type); - case "blockcrack", "blockdust", "falling_dust" -> new BlockParticleData(connection.getMapping().getBlockById(readVarInt() << 4), type); + case "iconcrack" -> new ItemParticleData(new Slot(this.connection.getMapping().getItemByLegacy(readVarInt(), readVarInt())), type); + case "blockcrack", "blockdust", "falling_dust" -> new BlockParticleData(this.connection.getMapping().getBlockById(readVarInt() << 4), type); default -> new ParticleData(type); }; } return switch (type.getIdentifier()) { - case "block", "falling_dust" -> new BlockParticleData(connection.getMapping().getBlockById(readVarInt()), type); + case "block", "falling_dust" -> new BlockParticleData(this.connection.getMapping().getBlockById(readVarInt()), type); case "dust" -> new DustParticleData(readFloat(), readFloat(), readFloat(), readFloat(), type); case "item" -> new ItemParticleData(readSlot(), type); default -> new ParticleData(type); @@ -241,14 +241,14 @@ public class InByteBuffer { return new CompoundTag(); } try { - return new InByteBuffer(Util.decompressGzip(readBytes(length)), connection).readNBT(); + return new InByteBuffer(Util.decompressGzip(readBytes(length)), this.connection).readNBT(); } catch (IOException e) { // oh no e.printStackTrace(); throw new IllegalArgumentException("Bad nbt"); } } - TagTypes type = TagTypes.getById(readByte()); + TagTypes type = TagTypes.byId(readByte()); if (type == TagTypes.COMPOUND) { // shouldn't be a subtag return new CompoundTag(false, this); @@ -279,7 +279,7 @@ public class InByteBuffer { } public Slot readSlot() { - if (versionId < 402) { + if (this.versionId < 402) { short id = readShort(); if (id == -1) { return null; @@ -287,14 +287,14 @@ public class InByteBuffer { byte count = readByte(); short metaData = 0; - if (versionId < ProtocolDefinition.FLATTING_VERSION_ID) { + if (this.versionId < ProtocolDefinition.FLATTING_VERSION_ID) { metaData = readShort(); } - CompoundTag nbt = (CompoundTag) readNBT(versionId < 28); - return new Slot(connection.getMapping(), connection.getMapping().getItemByLegacy(id, metaData), count, metaData, nbt); + CompoundTag nbt = (CompoundTag) readNBT(this.versionId < 28); + return new Slot(this.connection.getMapping(), this.connection.getMapping().getItemByLegacy(id, metaData), count, metaData, nbt); } if (readBoolean()) { - return new Slot(connection.getMapping(), connection.getMapping().getItemById(readVarInt()), readByte(), (CompoundTag) readNBT()); + return new Slot(this.connection.getMapping(), this.connection.getMapping().getItemById(readVarInt()), readByte(), (CompoundTag) readNBT()); } return null; } @@ -316,12 +316,12 @@ public class InByteBuffer { } public int getBytesLeft() { - return bytes.length - position; + return this.bytes.length - this.position; } byte[] readBytes(int pos, int count) { byte[] ret = new byte[count]; - System.arraycopy(bytes, pos, ret, 0, count); + System.arraycopy(this.bytes, pos, ret, 0, count); return ret; } @@ -378,18 +378,18 @@ public class InByteBuffer { } public int getVersionId() { - return versionId; + return this.versionId; } public EntityMetaData readMetaData() { - EntityMetaData metaData = new EntityMetaData(connection); + EntityMetaData metaData = new EntityMetaData(this.connection); EntityMetaData.MetaDataHashMap sets = metaData.getSets(); - if (versionId < 48) { + if (this.versionId < 48) { short item = readUnsignedByte(); while (item != 0x7F) { byte index = (byte) (item & 0x1F); - EntityMetaData.EntityMetaDataValueTypes type = EntityMetaData.EntityMetaDataValueTypes.byId((item & 0xFF) >> 5, versionId); + EntityMetaData.EntityMetaDataValueTypes type = EntityMetaData.EntityMetaDataValueTypes.byId((item & 0xFF) >> 5, this.versionId); sets.put((int) index, EntityMetaData.getData(type, this)); item = readByte(); } @@ -397,12 +397,12 @@ public class InByteBuffer { int index = readUnsignedByte(); while (index != 0xFF) { int id; - if (versionId < 107) { + if (this.versionId < 107) { id = readUnsignedByte(); } else { id = readVarInt(); } - EntityMetaData.EntityMetaDataValueTypes type = EntityMetaData.EntityMetaDataValueTypes.byId(id, versionId); + EntityMetaData.EntityMetaDataValueTypes type = EntityMetaData.EntityMetaDataValueTypes.byId(id, this.versionId); sets.put(index, EntityMetaData.getData(type, this)); index = readUnsignedByte(); } @@ -412,11 +412,11 @@ public class InByteBuffer { @Override public String toString() { - return "dataLen: " + bytes.length + "; position: " + position; + return "dataLen: " + this.bytes.length + "; position: " + this.position; } public byte[] getBytes() { - return bytes; + return this.bytes; } public int[] readVarIntArray(int length) { @@ -460,11 +460,11 @@ public class InByteBuffer { } public Connection getConnection() { - return connection; + return this.connection; } public int readEntityId() { - if (versionId < 7) { + if (this.versionId < 7) { return readInt(); } return readVarInt(); @@ -497,7 +497,7 @@ public class InByteBuffer { private CommandNode readCommandNode() { byte flags = readByte(); - return switch (CommandNode.NodeTypes.values()[flags & 0x03]) { + return switch (CommandNode.NodeTypes.byId(flags & 0x03)) { case ROOT -> new CommandRootNode(flags, this); case LITERAL -> new CommandLiteralNode(flags, this); case ARGUMENT -> new CommandArgumentNode(flags, this); diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InPacketBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InPacketBuffer.java index 297cbb2cd..b197137e3 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InPacketBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InPacketBuffer.java @@ -20,10 +20,10 @@ public class InPacketBuffer extends InByteBuffer { public InPacketBuffer(byte[] bytes, Connection connection) { super(bytes, connection); - command = readVarInt(); + this.command = readVarInt(); } public int getCommand() { - return command; + return this.command; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/LANServerListener.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/LANServerListener.java index 00f2a575a..35cf4e896 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/LANServerListener.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/LANServerListener.java @@ -29,12 +29,12 @@ import java.util.HashSet; import java.util.concurrent.CountDownLatch; public class LANServerListener { - public final static HashBiMap servers = HashBiMap.create(); - private final static String MOTD_BEGIN_STRING = "[MOTD]"; - private final static String MOTD_END_STRING = "[/MOTD]"; - private final static String PORT_START_STRING = "[AD]"; - private final static String PORT_END_STRING = "[/AD]"; - private final static String[] BROADCAST_MUST_CONTAIN = {MOTD_BEGIN_STRING, MOTD_END_STRING, PORT_START_STRING, PORT_END_STRING}; + public static final HashBiMap SERVER_MAP = HashBiMap.create(); + private static final String MOTD_BEGIN_STRING = "[MOTD]"; + private static final String MOTD_END_STRING = "[/MOTD]"; + private static final String PORT_START_STRING = "[AD]"; + private static final String PORT_END_STRING = "[/AD]"; + private static final String[] BROADCAST_MUST_CONTAIN = {MOTD_BEGIN_STRING, MOTD_END_STRING, PORT_START_STRING, PORT_END_STRING}; public static void listen() throws InterruptedException { CountDownLatch latch = new CountDownLatch(1); @@ -50,19 +50,19 @@ public class LANServerListener { socket.receive(packet); Log.protocol(String.format("LAN UDP Broadcast from %s:%s -> %s", packet.getAddress().getHostAddress(), packet.getPort(), new String(buf))); InetAddress sender = packet.getAddress(); - if (servers.containsKey(sender)) { + if (SERVER_MAP.containsKey(sender)) { // This guy sent us already a server, maybe just the regular 1.5 second interval, a duplicate or a DOS attack...We don't care continue; } Server server = getServerByBroadcast(sender, packet.getData()); - if (servers.containsValue(server)) { + if (SERVER_MAP.containsValue(server)) { continue; } - if (servers.size() > ProtocolDefinition.LAN_SERVER_MAXIMUM_SERVERS) { + if (SERVER_MAP.size() > ProtocolDefinition.LAN_SERVER_MAXIMUM_SERVERS) { continue; } - servers.put(sender, server); - Platform.runLater(() -> ServerListCell.listView.getItems().add(server)); + SERVER_MAP.put(sender, server); + Platform.runLater(() -> ServerListCell.SERVER_LIST_VIEW.getItems().add(server)); Log.debug(String.format("Discovered new LAN Server: %s", server)); } catch (Exception ignored) { } @@ -72,23 +72,23 @@ public class LANServerListener { e.printStackTrace(); latch.countDown(); } - servers.clear(); + SERVER_MAP.clear(); Log.warn("Stopping LAN Server Listener Thread"); }, "LAN Server Listener").start(); latch.await(); } - public static HashBiMap getServers() { - return servers; + public static HashBiMap getServerMap() { + return SERVER_MAP; } public static void removeAll() { - HashSet temp = new HashSet<>(servers.values()); + HashSet temp = new HashSet<>(SERVER_MAP.values()); for (Server server : temp) { if (server.isConnected()) { continue; } - servers.inverse().remove(server); + SERVER_MAP.inverse().remove(server); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java index d3f87afcf..57c672324 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutByteBuffer.java @@ -44,7 +44,7 @@ public class OutByteBuffer { } public void writeByteArray(byte[] data) { - if (versionId < 19) { + if (this.versionId < 19) { writeShort((short) data.length); } else { writeVarInt(data.length); @@ -66,7 +66,7 @@ public class OutByteBuffer { public void writeBytes(byte[] data) { for (byte singleByte : data) { - bytes.add(singleByte); + this.bytes.add(singleByte); } } @@ -109,15 +109,15 @@ public class OutByteBuffer { } public void writeByte(byte value) { - bytes.add(value); + this.bytes.add(value); } public void writeByte(int value) { - bytes.add((byte) (value & 0xFF)); + this.bytes.add((byte) (value & 0xFF)); } public void writeByte(long value) { - bytes.add((byte) (value & 0xFF)); + this.bytes.add((byte) (value & 0xFF)); } public void writeFloat(float value) { @@ -138,7 +138,7 @@ public class OutByteBuffer { } public ArrayList getBytes() { - return bytes; + return this.bytes; } public void writePosition(BlockPosition position) { @@ -146,7 +146,7 @@ public class OutByteBuffer { writeLong(0L); return; } - if (versionId < 440) { + if (this.versionId < 440) { writeLong((((long) position.getX() & 0x3FFFFFF) << 38) | (((long) position.getZ() & 0x3FFFFFF)) | ((long) position.getY() & 0xFFF) << 26); return; } @@ -174,28 +174,28 @@ public class OutByteBuffer { if (value != 0) { temp |= 0x80; } - bytes.add(count++, temp); + this.bytes.add(count++, temp); } while (value != 0); } public void writeSlot(Slot slot) { - if (versionId < 402) { + if (this.versionId < 402) { if (slot == null) { writeShort((short) -1); return; } - writeShort((short) (int) connection.getMapping().getItemId(slot.getItem())); + writeShort((short) (int) this.connection.getMapping().getItemId(slot.getItem())); writeByte((byte) slot.getItemCount()); writeShort(slot.getItemMetadata()); - writeNBT(slot.getNbt(connection.getMapping())); + writeNBT(slot.getNbt(this.connection.getMapping())); } if (slot == null) { writeBoolean(false); return; } - writeVarInt(connection.getMapping().getItemId(slot.getItem())); + writeVarInt(this.connection.getMapping().getItemId(slot.getItem())); writeByte((byte) slot.getItemCount()); - writeNBT(slot.getNbt(connection.getMapping())); + writeNBT(slot.getNbt(this.connection.getMapping())); } void writeNBT(CompoundTag nbt) { @@ -204,7 +204,7 @@ public class OutByteBuffer { } public void writeBoolean(boolean value) { - bytes.add((byte) ((value) ? 0x01 : 0x00)); + this.bytes.add((byte) ((value) ? 0x01 : 0x00)); } public void writeStringNoLength(String string) { @@ -218,9 +218,9 @@ public class OutByteBuffer { } public byte[] toByteArray() { - byte[] ret = new byte[bytes.size()]; - for (int i = 0; i < bytes.size(); i++) { - ret[i] = bytes.get(i); + byte[] ret = new byte[this.bytes.size()]; + for (int i = 0; i < this.bytes.size(); i++) { + ret[i] = this.bytes.get(i); } return ret; } @@ -238,11 +238,11 @@ public class OutByteBuffer { } public int getVersionId() { - return versionId; + return this.versionId; } public void writeEntityId(int entityId) { - if (versionId < 7) { + if (this.versionId < 7) { writeInt(entityId); } else { writeVarInt(entityId); @@ -250,6 +250,6 @@ public class OutByteBuffer { } public Connection getConnection() { - return connection; + return this.connection; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutPacketBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutPacketBuffer.java index 095d5f1b8..638da3ff1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/OutPacketBuffer.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/OutPacketBuffer.java @@ -31,6 +31,6 @@ public class OutPacketBuffer extends OutByteBuffer { } public int getCommand() { - return command; + return this.command; } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 6aeacc718..f52060b26 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -19,7 +19,6 @@ import de.bixilon.minosoft.data.GameModes; import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException; import de.bixilon.minosoft.data.entities.entities.Entity; import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity; -import de.bixilon.minosoft.data.mappings.recipes.Recipes; import de.bixilon.minosoft.data.mappings.versions.Version; import de.bixilon.minosoft.data.mappings.versions.Versions; import de.bixilon.minosoft.data.player.PingBars; @@ -53,20 +52,20 @@ import java.util.Arrays; import java.util.UUID; public class PacketHandler { - final Connection connection; + private final Connection connection; public PacketHandler(Connection connection) { this.connection = connection; } public void handle(PacketStatusResponse pkg) { - connection.fireEvent(new StatusResponseEvent(connection, pkg)); + this.connection.fireEvent(new StatusResponseEvent(this.connection, pkg)); // now we know the version, set it, if the config allows it Version version; int protocolId = -1; - if (connection.getDesiredVersionNumber() != -1) { - protocolId = Versions.getVersionById(connection.getDesiredVersionNumber()).getProtocolId(); + if (this.connection.getDesiredVersionNumber() != -1) { + protocolId = Versions.getVersionById(this.connection.getDesiredVersionNumber()).getProtocolId(); } if (protocolId == -1) { protocolId = pkg.getResponse().getProtocolId(); @@ -75,30 +74,30 @@ public class PacketHandler { if (version == null) { Log.fatal(String.format("Server is running on unknown version or a invalid version was forced (protocolId=%d, brand=\"%s\")", protocolId, pkg.getResponse().getServerBrand())); } else { - connection.setVersion(version); + this.connection.setVersion(version); } Log.info(String.format("Status response received: %s/%s online. MotD: '%s'", pkg.getResponse().getPlayerOnline(), pkg.getResponse().getMaxPlayers(), pkg.getResponse().getMotd().getANSIColoredMessage())); - connection.handlePingCallbacks(pkg.getResponse()); - connection.connectionStatusPing = new ConnectionPing(); - connection.sendPacket(new PacketStatusPing(connection.connectionStatusPing)); + this.connection.handlePingCallbacks(pkg.getResponse()); + this.connection.setConnectionStatusPing(new ConnectionPing()); + this.connection.sendPacket(new PacketStatusPing(this.connection.getConnectionStatusPing())); } public void handle(PacketStatusPong pkg) { - connection.fireEvent(new StatusPongEvent(connection, pkg)); + this.connection.fireEvent(new StatusPongEvent(this.connection, pkg)); - ConnectionPing ping = connection.getConnectionStatusPing(); + ConnectionPing ping = this.connection.getConnectionStatusPing(); if (ping.getPingId() != pkg.getID()) { Log.warn(String.format("Server sent unknown ping answer (pingId=%d, expected=%d)", pkg.getID(), ping.getPingId())); return; } long pingDifference = System.currentTimeMillis() - ping.getSendingTime(); Log.debug(String.format("Pong received (ping=%dms, pingBars=%s)", pingDifference, PingBars.byPing(pingDifference))); - switch (connection.getReason()) { - case PING -> connection.disconnect();// pong arrived, closing connection + switch (this.connection.getReason()) { + case PING -> this.connection.disconnect();// pong arrived, closing connection case GET_VERSION -> { // reconnect... - connection.disconnect(); - Log.info(String.format("Server is running on version %s (versionId=%d, protocolId=%d), reconnecting...", connection.getVersion().getVersionName(), connection.getVersion().getVersionId(), connection.getVersion().getProtocolId())); + this.connection.disconnect(); + Log.info(String.format("Server is running on version %s (versionId=%d, protocolId=%d), reconnecting...", this.connection.getVersion().getVersionName(), this.connection.getVersion().getVersionId(), this.connection.getVersion().getProtocolId())); } } } @@ -107,60 +106,60 @@ public class PacketHandler { SecretKey secretKey = CryptManager.createNewSharedKey(); PublicKey publicKey = CryptManager.decodePublicKey(pkg.getPublicKey()); String serverHash = new BigInteger(CryptManager.getServerHash(pkg.getServerId(), publicKey, secretKey)).toString(16); - connection.getPlayer().getAccount().join(serverHash); - connection.sendPacket(new PacketEncryptionResponse(secretKey, pkg.getVerifyToken(), publicKey)); + this.connection.getPlayer().getAccount().join(serverHash); + this.connection.sendPacket(new PacketEncryptionResponse(secretKey, pkg.getVerifyToken(), publicKey)); } public void handle(PacketLoginSuccess pkg) { } public void handle(PacketJoinGame pkg) { - if (connection.fireEvent(new JoinGameEvent(connection, pkg))) { + if (this.connection.fireEvent(new JoinGameEvent(this.connection, pkg))) { return; } - connection.getPlayer().setGameMode(pkg.getGameMode()); - connection.getPlayer().getWorld().setHardcore(pkg.isHardcore()); - connection.getMapping().setDimensions(pkg.getDimensions()); - connection.getPlayer().getWorld().setDimension(pkg.getDimension()); - PlayerEntity entity = new PlayerEntity(connection, pkg.getEntityId(), connection.getPlayer().getPlayerUUID(), null, null, connection.getPlayer().getPlayerName(), null, null); - connection.getPlayer().setEntity(entity); - connection.getPlayer().getWorld().addEntity(entity); - connection.getSender().sendChatMessage("I am alive! ~ Minosoft"); + this.connection.getPlayer().setGameMode(pkg.getGameMode()); + this.connection.getPlayer().getWorld().setHardcore(pkg.isHardcore()); + this.connection.getMapping().setDimensions(pkg.getDimensions()); + this.connection.getPlayer().getWorld().setDimension(pkg.getDimension()); + PlayerEntity entity = new PlayerEntity(this.connection, pkg.getEntityId(), this.connection.getPlayer().getPlayerUUID(), null, null, this.connection.getPlayer().getPlayerName(), null, null); + this.connection.getPlayer().setEntity(entity); + this.connection.getPlayer().getWorld().addEntity(entity); + this.connection.getSender().sendChatMessage("I am alive! ~ Minosoft"); } public void handle(PacketLoginDisconnect pkg) { - connection.fireEvent(new LoginDisconnectEvent(connection, pkg.getReason())); + this.connection.fireEvent(new LoginDisconnectEvent(this.connection, pkg.getReason())); Log.info(String.format("Disconnecting from server (reason=%s)", pkg.getReason().getANSIColoredMessage())); - connection.disconnect(); + this.connection.disconnect(); } public void handle(PacketPlayerListItem pkg) { - if (connection.fireEvent(new PlayerListItemChangeEvent(connection, pkg))) { + if (this.connection.fireEvent(new PlayerListItemChangeEvent(this.connection, pkg))) { return; } for (PlayerListItemBulk bulk : pkg.getPlayerList()) { - PlayerListItem item = connection.getPlayer().getPlayerList().get(bulk.getUUID()); + PlayerListItem item = this.connection.getPlayer().getPlayerList().get(bulk.getUUID()); if (item == null && !bulk.isLegacy()) { // Aaaaah. Fuck this shit. The server sends us bullshit! continue; } switch (bulk.getAction()) { - case ADD -> connection.getPlayer().getPlayerList().put(bulk.getUUID(), new PlayerListItem(bulk.getUUID(), bulk.getName(), bulk.getPing(), bulk.getGameMode(), bulk.getDisplayName(), bulk.getProperties())); + case ADD -> this.connection.getPlayer().getPlayerList().put(bulk.getUUID(), new PlayerListItem(bulk.getUUID(), bulk.getName(), bulk.getPing(), bulk.getGameMode(), bulk.getDisplayName(), bulk.getProperties())); case UPDATE_LATENCY -> { if (bulk.isLegacy()) { // add or update if (item == null) { // create UUID uuid = UUID.randomUUID(); - connection.getPlayer().getPlayerList().put(uuid, new PlayerListItem(uuid, bulk.getName(), bulk.getPing())); + this.connection.getPlayer().getPlayerList().put(uuid, new PlayerListItem(uuid, bulk.getName(), bulk.getPing())); } else { // update ping item.setPing(bulk.getPing()); } continue; } - connection.getPlayer().getPlayerList().get(bulk.getUUID()).setPing(bulk.getPing()); + this.connection.getPlayer().getPlayerList().get(bulk.getUUID()).setPing(bulk.getPing()); } case REMOVE_PLAYER -> { if (bulk.isLegacy()) { @@ -168,10 +167,10 @@ public class PacketHandler { // not initialized yet continue; } - connection.getPlayer().getPlayerList().remove(connection.getPlayer().getPlayerListItem(bulk.getName()).getUUID()); + this.connection.getPlayer().getPlayerList().remove(this.connection.getPlayer().getPlayerListItem(bulk.getName()).getUUID()); continue; } - connection.getPlayer().getPlayerList().remove(bulk.getUUID()); + this.connection.getPlayer().getPlayerList().remove(bulk.getUUID()); } case UPDATE_GAMEMODE -> item.setGameMode(bulk.getGameMode()); case UPDATE_DISPLAY_NAME -> item.setDisplayName(bulk.getDisplayName()); @@ -180,40 +179,40 @@ public class PacketHandler { } public void handle(PacketTimeUpdate pkg) { - if (connection.fireEvent(new TimeChangeEvent(connection, pkg))) { + if (this.connection.fireEvent(new TimeChangeEvent(this.connection, pkg))) { return; } } public void handle(PacketKeepAlive pkg) { - connection.sendPacket(new PacketKeepAliveResponse(pkg.getId())); + this.connection.sendPacket(new PacketKeepAliveResponse(pkg.getId())); } public void handle(PacketChunkBulk pkg) { - pkg.getChunks().forEach(((location, chunk) -> connection.fireEvent(new ChunkDataChangeEvent(connection, location, chunk)))); + pkg.getChunks().forEach(((location, chunk) -> this.connection.fireEvent(new ChunkDataChangeEvent(this.connection, location, chunk)))); - connection.getPlayer().getWorld().setChunks(pkg.getChunks()); + this.connection.getPlayer().getWorld().setChunks(pkg.getChunks()); } public void handle(PacketUpdateHealth pkg) { - connection.fireEvent(new UpdateHealthEvent(connection, pkg)); + this.connection.fireEvent(new UpdateHealthEvent(this.connection, pkg)); - connection.getPlayer().setFood(pkg.getFood()); - connection.getPlayer().setHealth(pkg.getHealth()); - connection.getPlayer().setSaturation(pkg.getSaturation()); + this.connection.getPlayer().setFood(pkg.getFood()); + this.connection.getPlayer().setHealth(pkg.getHealth()); + this.connection.getPlayer().setSaturation(pkg.getSaturation()); if (pkg.getHealth() <= 0.0F) { // do respawn - connection.getSender().respawn(); + this.connection.getSender().respawn(); } } public void handle(PacketPluginMessageReceiving pkg) { - if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()))) { + if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(this.connection.getVersion().getVersionId()))) { InByteBuffer data = pkg.getDataAsBuffer(); String serverVersion; String clientVersion = (Minosoft.getConfig().getBoolean(ConfigurationPaths.BooleanPaths.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft"); - OutByteBuffer toSend = new OutByteBuffer(connection); - if (connection.getVersion().getVersionId() < 29) { + OutByteBuffer toSend = new OutByteBuffer(this.connection); + if (this.connection.getVersion().getVersionId() < 29) { // no length prefix serverVersion = new String(data.getBytes()); toSend.writeBytes(clientVersion.getBytes()); @@ -222,14 +221,14 @@ public class PacketHandler { serverVersion = data.readString(); toSend.writeString(clientVersion); } - Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, connection.getVersion().getVersionName())); + Log.info(String.format("Server is running \"%s\", connected with %s", serverVersion, this.connection.getVersion().getVersionName())); - connection.getSender().sendPluginMessageData(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()), toSend); + this.connection.getSender().sendPluginMessageData(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(this.connection.getVersion().getVersionId()), toSend); return; } // MC|StopSound - if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()))) { + if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(this.connection.getVersion().getVersionId()))) { // it is basically a packet, handle it like a packet: PacketStopSound packet = new PacketStopSound(); packet.read(pkg.getDataAsBuffer()); @@ -237,17 +236,17 @@ public class PacketHandler { return; } - connection.fireEvent(new PluginMessageReceiveEvent(connection, pkg)); + this.connection.fireEvent(new PluginMessageReceiveEvent(this.connection, pkg)); } public void handle(PacketSpawnLocation pkg) { - connection.fireEvent(new SpawnLocationChangeEvent(connection, pkg)); - connection.getPlayer().setSpawnLocation(pkg.getSpawnLocation()); + this.connection.fireEvent(new SpawnLocationChangeEvent(this.connection, pkg)); + this.connection.getPlayer().setSpawnLocation(pkg.getSpawnLocation()); } public void handle(PacketChatMessageReceiving pkg) { - ChatMessageReceivingEvent event = new ChatMessageReceivingEvent(connection, pkg); - if (connection.fireEvent(event)) { + ChatMessageReceivingEvent event = new ChatMessageReceivingEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } Log.game(switch (pkg.getPosition()) { @@ -258,27 +257,27 @@ public class PacketHandler { } public void handle(PacketDisconnect pkg) { - connection.fireEvent(new LoginDisconnectEvent(connection, pkg)); + this.connection.fireEvent(new LoginDisconnectEvent(this.connection, pkg)); // got kicked - connection.disconnect(); + this.connection.disconnect(); } public void handle(PacketHeldItemChangeReceiving pkg) { - connection.getPlayer().setSelectedSlot(pkg.getSlot()); + this.connection.getPlayer().setSelectedSlot(pkg.getSlot()); } public void handle(PacketSetExperience pkg) { - if (connection.fireEvent(new ExperienceChangeEvent(connection, pkg))) { + if (this.connection.fireEvent(new ExperienceChangeEvent(this.connection, pkg))) { return; } - connection.getPlayer().setLevel(pkg.getLevel()); - connection.getPlayer().setTotalExperience(pkg.getTotal()); + this.connection.getPlayer().setLevel(pkg.getLevel()); + this.connection.getPlayer().setTotalExperience(pkg.getTotal()); } public void handle(PacketChangeGameState pkg) { - ChangeGameStateEvent event = new ChangeGameStateEvent(connection, pkg); - if (connection.fireEvent(event)) { + ChangeGameStateEvent event = new ChangeGameStateEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } @@ -290,21 +289,21 @@ public class PacketHandler { }); switch (pkg.getReason()) { - case STOP_RAINING -> connection.getPlayer().getWorld().setRaining(false); - case START_RAINING -> connection.getPlayer().getWorld().setRaining(true); - case CHANGE_GAMEMODE -> connection.getPlayer().setGameMode(GameModes.byId(pkg.getIntValue())); + case STOP_RAINING -> this.connection.getPlayer().getWorld().setRaining(false); + case START_RAINING -> this.connection.getPlayer().getWorld().setRaining(true); + case CHANGE_GAMEMODE -> this.connection.getPlayer().setGameMode(GameModes.byId(pkg.getIntValue())); } } public void handle(PacketSpawnMob pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); - connection.getPlayer().getWorld().addEntity(pkg.getEntity()); - connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); + this.connection.getPlayer().getWorld().addEntity(pkg.getEntity()); + this.connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); } public void handle(PacketEntityMovementAndRotation pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -314,7 +313,7 @@ public class PacketHandler { } public void handle(PacketEntityMovement pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -323,7 +322,7 @@ public class PacketHandler { } public void handle(PacketEntityRotation pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -332,32 +331,32 @@ public class PacketHandler { } public void handle(PacketDestroyEntity pkg) { - connection.fireEvent(new EntityDespawnEvent(connection, pkg)); + this.connection.fireEvent(new EntityDespawnEvent(this.connection, pkg)); for (int entityId : pkg.getEntityIds()) { - connection.getPlayer().getWorld().removeEntity(entityId); + this.connection.getPlayer().getWorld().removeEntity(entityId); } } public void handle(PacketEntityVelocity pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; } - connection.getVelocityHandler().handleVelocity(entity, pkg.getVelocity()); + this.connection.getVelocityHandler().handleVelocity(entity, pkg.getVelocity()); } public void handle(PacketSpawnPlayer pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); - connection.getPlayer().getWorld().addEntity(pkg.getEntity()); - connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); + this.connection.getPlayer().getWorld().addEntity(pkg.getEntity()); + this.connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); } public void handle(PacketEntityTeleport pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -367,7 +366,7 @@ public class PacketHandler { } public void handle(PacketEntityHeadRotation pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -376,13 +375,13 @@ public class PacketHandler { } public void handle(PacketWindowItems pkg) { - connection.fireEvent(new MultiSlotChangeEvent(connection, pkg)); + this.connection.fireEvent(new MultiSlotChangeEvent(this.connection, pkg)); - connection.getPlayer().setInventory(pkg.getWindowId(), pkg.getData()); + this.connection.getPlayer().setInventory(pkg.getWindowId(), pkg.getData()); } public void handle(PacketEntityMetadata pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -391,9 +390,9 @@ public class PacketHandler { } public void handle(PacketEntityEquipment pkg) { - connection.fireEvent(new EntityEquipmentChangeEvent(connection, pkg)); + this.connection.fireEvent(new EntityEquipmentChangeEvent(this.connection, pkg)); - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -402,73 +401,73 @@ public class PacketHandler { } public void handle(PacketBlockChange pkg) { - Chunk chunk = connection.getPlayer().getWorld().getChunk(pkg.getPosition().getChunkLocation()); + Chunk chunk = this.connection.getPlayer().getWorld().getChunk(pkg.getPosition().getChunkLocation()); if (chunk == null) { // thanks mojang return; } - connection.fireEvent(new BlockChangeEvent(connection, pkg)); + this.connection.fireEvent(new BlockChangeEvent(this.connection, pkg)); chunk.setBlock(pkg.getPosition().getInChunkLocation(), pkg.getBlock()); } public void handle(PacketMultiBlockChange pkg) { - Chunk chunk = connection.getPlayer().getWorld().getChunk(pkg.getLocation()); + Chunk chunk = this.connection.getPlayer().getWorld().getChunk(pkg.getLocation()); if (chunk == null) { // thanks mojang return; } - connection.fireEvent(new MultiBlockChangeEvent(connection, pkg)); + this.connection.fireEvent(new MultiBlockChangeEvent(this.connection, pkg)); chunk.setBlocks(pkg.getBlocks()); } public void handle(PacketRespawn pkg) { - if (connection.fireEvent(new RespawnEvent(connection, pkg))) { + if (this.connection.fireEvent(new RespawnEvent(this.connection, pkg))) { return; } // clear all chunks - connection.getPlayer().getWorld().getAllChunks().clear(); - connection.getPlayer().getWorld().setDimension(pkg.getDimension()); - connection.getPlayer().setSpawnConfirmed(false); - connection.getPlayer().setGameMode(pkg.getGameMode()); + this.connection.getPlayer().getWorld().getAllChunks().clear(); + this.connection.getPlayer().getWorld().setDimension(pkg.getDimension()); + this.connection.getPlayer().setSpawnConfirmed(false); + this.connection.getPlayer().setGameMode(pkg.getGameMode()); } public void handle(PacketOpenSignEditor pkg) { - OpenSignEditorEvent event = new OpenSignEditorEvent(connection, pkg); - if (connection.fireEvent(event)) { + OpenSignEditorEvent event = new OpenSignEditorEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } } public void handle(PacketSpawnObject pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); - connection.getPlayer().getWorld().addEntity(pkg.getEntity()); - connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); + this.connection.getPlayer().getWorld().addEntity(pkg.getEntity()); + this.connection.getVelocityHandler().handleVelocity(pkg.getEntity(), pkg.getVelocity()); } public void handle(PacketSpawnExperienceOrb pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); - connection.getPlayer().getWorld().addEntity(pkg.getEntity()); + this.connection.getPlayer().getWorld().addEntity(pkg.getEntity()); } public void handle(PacketSpawnWeatherEntity pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); - connection.fireEvent(new LightningBoltSpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); + this.connection.fireEvent(new LightningBoltSpawnEvent(this.connection, pkg)); } public void handle(PacketChunkData pkg) { - pkg.getBlockEntities().forEach(((position, compoundTag) -> connection.fireEvent(new BlockEntityMetaDataChangeEvent(connection, position, null, compoundTag)))); - connection.fireEvent(new ChunkDataChangeEvent(connection, pkg)); + pkg.getBlockEntities().forEach(((position, compoundTag) -> this.connection.fireEvent(new BlockEntityMetaDataChangeEvent(this.connection, position, null, compoundTag)))); + this.connection.fireEvent(new ChunkDataChangeEvent(this.connection, pkg)); - connection.getPlayer().getWorld().setChunk(pkg.getLocation(), pkg.getChunk()); - connection.getPlayer().getWorld().setBlockEntityData(pkg.getBlockEntities()); + this.connection.getPlayer().getWorld().setChunk(pkg.getLocation(), pkg.getChunk()); + this.connection.getPlayer().getWorld().setBlockEntityData(pkg.getBlockEntities()); } public void handle(PacketEntityEffect pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -477,7 +476,7 @@ public class PacketHandler { } public void handle(PacketRemoveEntityEffect pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -513,16 +512,16 @@ public class PacketHandler { public void handle(PacketPlayerPositionAndRotation pkg) { // ToDo: GUI should do this - connection.getPlayer().getEntity().setLocation(pkg.getLocation()); - if (connection.getVersion().getVersionId() >= 79) { - connection.sendPacket(new PacketConfirmTeleport(pkg.getTeleportId())); + this.connection.getPlayer().getEntity().setLocation(pkg.getLocation()); + if (this.connection.getVersion().getVersionId() >= 79) { + this.connection.sendPacket(new PacketConfirmTeleport(pkg.getTeleportId())); } else { - connection.sendPacket(new PacketPlayerPositionAndRotationSending(pkg.getLocation(), pkg.getRotation(), pkg.isOnGround())); + this.connection.sendPacket(new PacketPlayerPositionAndRotationSending(pkg.getLocation(), pkg.getRotation(), pkg.isOnGround())); } } public void handle(PacketAttachEntity pkg) { - Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); + Entity entity = this.connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if (entity == null) { // thanks mojang return; @@ -535,20 +534,20 @@ public class PacketHandler { } public void handle(PacketBlockEntityMetadata pkg) { - connection.fireEvent(new BlockEntityMetaDataChangeEvent(connection, pkg)); - connection.getPlayer().getWorld().setBlockEntityData(pkg.getPosition(), pkg.getData()); + this.connection.fireEvent(new BlockEntityMetaDataChangeEvent(this.connection, pkg)); + this.connection.getPlayer().getWorld().setBlockEntityData(pkg.getPosition(), pkg.getData()); } public void handle(PacketBlockBreakAnimation pkg) { - BlockBreakAnimationEvent event = new BlockBreakAnimationEvent(connection, pkg); - if (connection.fireEvent(event)) { + BlockBreakAnimationEvent event = new BlockBreakAnimationEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } } public void handle(PacketBlockAction pkg) { - BlockActionEvent event = new BlockActionEvent(connection, pkg); - if (connection.fireEvent(event)) { + BlockActionEvent event = new BlockActionEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } } @@ -560,40 +559,40 @@ public class PacketHandler { int y = ((int) pkg.getLocation().getY()) + record[1]; int z = ((int) pkg.getLocation().getZ()) + record[2]; BlockPosition blockPosition = new BlockPosition(x, (short) y, z); - connection.getPlayer().getWorld().setBlock(blockPosition, null); + this.connection.getPlayer().getWorld().setBlock(blockPosition, null); } // ToDo: motion support } public void handle(PacketCollectItem pkg) { - if (connection.fireEvent(new CollectItemAnimationEvent(connection, pkg))) { + if (this.connection.fireEvent(new CollectItemAnimationEvent(this.connection, pkg))) { return; } // ToDo } public void handle(PacketOpenWindow pkg) { - connection.getPlayer().createInventory(pkg.getInventoryProperties()); + this.connection.getPlayer().createInventory(pkg.getInventoryProperties()); } public void handle(PacketCloseWindowReceiving pkg) { - CloseWindowEvent event = new CloseWindowEvent(connection, pkg); - if (connection.fireEvent(event)) { + CloseWindowEvent event = new CloseWindowEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } - connection.getPlayer().deleteInventory(pkg.getWindowId()); + this.connection.getPlayer().deleteInventory(pkg.getWindowId()); } public void handle(PacketSetSlot pkg) { - connection.fireEvent(new SingleSlotChangeEvent(connection, pkg)); + this.connection.fireEvent(new SingleSlotChangeEvent(this.connection, pkg)); if (pkg.getWindowId() == -1) { // thanks mojang // ToDo: what is windowId -1 return; } - connection.getPlayer().setSlot(pkg.getWindowId(), pkg.getSlotId(), pkg.getSlot()); + this.connection.getPlayer().setSlot(pkg.getWindowId(), pkg.getSlotId(), pkg.getSlot()); } public void handle(PacketWindowProperty pkg) { @@ -613,36 +612,36 @@ public class PacketHandler { } public void handle(PacketSpawnPainting pkg) { - connection.fireEvent(new EntitySpawnEvent(connection, pkg)); + this.connection.fireEvent(new EntitySpawnEvent(this.connection, pkg)); - connection.getPlayer().getWorld().addEntity(pkg.getEntity()); + this.connection.getPlayer().getWorld().addEntity(pkg.getEntity()); } public void handle(PacketParticle pkg) { - if (connection.fireEvent(new ParticleSpawnEvent(connection, pkg))) { + if (this.connection.fireEvent(new ParticleSpawnEvent(this.connection, pkg))) { return; } } public void handle(PacketEffect pkg) { - if (connection.fireEvent(new EffectEvent(connection, pkg))) { + if (this.connection.fireEvent(new EffectEvent(this.connection, pkg))) { return; } } public void handle(PacketScoreboardObjective pkg) { switch (pkg.getAction()) { - case CREATE -> connection.getPlayer().getScoreboardManager().addObjective(new ScoreboardObjective(pkg.getName(), pkg.getValue())); - case UPDATE -> connection.getPlayer().getScoreboardManager().getObjective(pkg.getName()).setValue(pkg.getValue()); - case REMOVE -> connection.getPlayer().getScoreboardManager().removeObjective(pkg.getName()); + case CREATE -> this.connection.getPlayer().getScoreboardManager().addObjective(new ScoreboardObjective(pkg.getName(), pkg.getValue())); + case UPDATE -> this.connection.getPlayer().getScoreboardManager().getObjective(pkg.getName()).setValue(pkg.getValue()); + case REMOVE -> this.connection.getPlayer().getScoreboardManager().removeObjective(pkg.getName()); } } public void handle(PacketScoreboardUpdateScore pkg) { switch (pkg.getAction()) { - case CREATE_UPDATE -> connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).addScore(new ScoreboardScore(pkg.getItemName(), pkg.getScoreName(), pkg.getScoreValue())); + case CREATE_UPDATE -> this.connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()).addScore(new ScoreboardScore(pkg.getItemName(), pkg.getScoreName(), pkg.getScoreValue())); case REMOVE -> { - ScoreboardObjective objective = connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()); + ScoreboardObjective objective = this.connection.getPlayer().getScoreboardManager().getObjective(pkg.getScoreName()); if (objective != null) { // thanks mojang objective.removeScore(pkg.getItemName()); @@ -657,11 +656,11 @@ public class PacketHandler { public void handle(PacketTeams pkg) { switch (pkg.getAction()) { - case CREATE -> connection.getPlayer().getScoreboardManager().addTeam(new Team(pkg.getName(), pkg.getDisplayName(), pkg.getPrefix(), pkg.getSuffix(), pkg.isFriendlyFireEnabled(), pkg.isSeeingFriendlyInvisibles(), pkg.getPlayerNames())); - case INFORMATION_UPDATE -> connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).updateInformation(pkg.getDisplayName(), pkg.getPrefix(), pkg.getSuffix(), pkg.isFriendlyFireEnabled(), pkg.isSeeingFriendlyInvisibles()); - case REMOVE -> connection.getPlayer().getScoreboardManager().removeTeam(pkg.getName()); - case PLAYER_ADD -> connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).addPlayers(Arrays.asList(pkg.getPlayerNames())); - case PLAYER_REMOVE -> connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).removePlayers(Arrays.asList(pkg.getPlayerNames())); + case CREATE -> this.connection.getPlayer().getScoreboardManager().addTeam(new Team(pkg.getName(), pkg.getDisplayName(), pkg.getPrefix(), pkg.getSuffix(), pkg.isFriendlyFireEnabled(), pkg.isSeeingFriendlyInvisibles(), pkg.getPlayerNames())); + case INFORMATION_UPDATE -> this.connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).updateInformation(pkg.getDisplayName(), pkg.getPrefix(), pkg.getSuffix(), pkg.isFriendlyFireEnabled(), pkg.isSeeingFriendlyInvisibles()); + case REMOVE -> this.connection.getPlayer().getScoreboardManager().removeTeam(pkg.getName()); + case PLAYER_ADD -> this.connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).addPlayers(Arrays.asList(pkg.getPlayerNames())); + case PLAYER_REMOVE -> this.connection.getPlayer().getScoreboardManager().getTeam(pkg.getName()).removePlayers(Arrays.asList(pkg.getPlayerNames())); } } @@ -676,17 +675,17 @@ public class PacketHandler { } public void handle(PacketTabHeaderAndFooter pkg) { - if (connection.fireEvent(new PlayerListInfoChangeEvent(connection, pkg))) { + if (this.connection.fireEvent(new PlayerListInfoChangeEvent(this.connection, pkg))) { return; } - connection.getPlayer().setTabHeader(pkg.getHeader()); - connection.getPlayer().setTabFooter(pkg.getFooter()); + this.connection.getPlayer().setTabHeader(pkg.getHeader()); + this.connection.getPlayer().setTabFooter(pkg.getFooter()); } public void handle(PacketResourcePackSend pkg) { - ResourcePackChangeEvent event = new ResourcePackChangeEvent(connection, pkg); - if (connection.fireEvent(event)) { + ResourcePackChangeEvent event = new ResourcePackChangeEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } } @@ -700,7 +699,7 @@ public class PacketHandler { } public void handle(PacketTitle pkg) { - if (connection.fireEvent(new TitleChangeEvent(connection, pkg))) { + if (this.connection.fireEvent(new TitleChangeEvent(this.connection, pkg))) { return; } @@ -715,7 +714,7 @@ public class PacketHandler { } public void handle(PacketUnloadChunk pkg) { - connection.getPlayer().getWorld().unloadChunk(pkg.getLocation()); + this.connection.getPlayer().getWorld().unloadChunk(pkg.getLocation()); } public void handle(PacketSoundEffect pkg) { @@ -723,8 +722,8 @@ public class PacketHandler { } public void handle(PacketBossBar pkg) { - BossBarChangeEvent event = new BossBarChangeEvent(connection, pkg); - if (connection.fireEvent(event)) { + BossBarChangeEvent event = new BossBarChangeEvent(this.connection, pkg); + if (this.connection.fireEvent(event)) { return; } } @@ -759,7 +758,7 @@ public class PacketHandler { } public void handle(PacketDeclareRecipes pkg) { - Recipes.registerCustomRecipes(pkg.getRecipes()); + this.connection.getRecipes().registerCustomRecipes(pkg.getRecipes()); } public void handle(PacketStopSound pkg) { @@ -787,7 +786,7 @@ public class PacketHandler { } public void handle(PacketLoginPluginRequest pkg) { - connection.fireEvent(new LoginPluginMessageRequestEvent(connection, pkg)); + this.connection.fireEvent(new LoginPluginMessageRequestEvent(this.connection, pkg)); } public void handle(PacketEntitySoundEffect pkg) { @@ -803,7 +802,7 @@ public class PacketHandler { } public void handle(PacketDeclareCommands pkg) { - connection.setCommandRootNode(pkg.getRootNode()); + this.connection.setCommandRootNode(pkg.getRootNode()); // ToDo: Remove these dummy commands String[] commands = { "msg Bixilon TestReason 2Paramter 3 4 asd asd", @@ -820,7 +819,7 @@ public class PacketHandler { }; for (String command : commands) { try { - pkg.getRootNode().isSyntaxCorrect(connection, command); + pkg.getRootNode().isSyntaxCorrect(this.connection, command); Log.game("Command \"%s\" is valid", command); } catch (CommandParseException e) { Log.game("Command \"%s\" is invalid, %s: %s", command, e.getClass().getSimpleName(), e.getErrorMessage()); diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketSender.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketSender.java index f2feb9db7..94d08333a 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketSender.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketSender.java @@ -25,7 +25,7 @@ import de.bixilon.minosoft.protocol.packets.serverbound.play.*; import java.util.UUID; public class PacketSender { - public static final String[] ILLEGAL_CHAT_CHARS = new String[]{"§"}; + public static final String[] ILLEGAL_CHAT_CHARS = {"§"}; final Connection connection; public PacketSender(Connection connection) { @@ -33,7 +33,7 @@ public class PacketSender { } public void setFlyStatus(boolean flying) { - connection.sendPacket(new PacketPlayerAbilitiesSending(flying)); + this.connection.sendPacket(new PacketPlayerAbilitiesSending(flying)); } public void sendChatMessage(String message) { @@ -42,55 +42,55 @@ public class PacketSender { throw new IllegalArgumentException(String.format("%s is not allowed in chat", illegalChar)); } } - ChatMessageSendingEvent event = new ChatMessageSendingEvent(connection, message); - if (connection.fireEvent(event)) { + ChatMessageSendingEvent event = new ChatMessageSendingEvent(this.connection, message); + if (this.connection.fireEvent(event)) { return; } - connection.sendPacket(new PacketChatMessageSending(event.getMessage())); + this.connection.sendPacket(new PacketChatMessageSending(event.getMessage())); } public void spectateEntity(UUID entityUUID) { - connection.sendPacket(new PacketSpectate(entityUUID)); + this.connection.sendPacket(new PacketSpectate(entityUUID)); } public void setSlot(int slotId) { - connection.sendPacket(new PacketHeldItemChangeSending(slotId)); + this.connection.sendPacket(new PacketHeldItemChangeSending(slotId)); } public void swingArm(Hands hand) { - connection.sendPacket(new PacketAnimation(hand)); + this.connection.sendPacket(new PacketAnimation(hand)); } public void swingArm() { - connection.sendPacket(new PacketAnimation(Hands.MAIN_HAND)); + this.connection.sendPacket(new PacketAnimation(Hands.MAIN_HAND)); } public void sendAction(PacketEntityAction.EntityActions action) { - connection.sendPacket(new PacketEntityAction(connection.getPlayer().getEntity().getEntityId(), action)); + this.connection.sendPacket(new PacketEntityAction(this.connection.getPlayer().getEntity().getEntityId(), action)); } public void jumpWithHorse(int jumpBoost) { - connection.sendPacket(new PacketEntityAction(connection.getPlayer().getEntity().getEntityId(), PacketEntityAction.EntityActions.START_HORSE_JUMP, jumpBoost)); + this.connection.sendPacket(new PacketEntityAction(this.connection.getPlayer().getEntity().getEntityId(), PacketEntityAction.EntityActions.START_HORSE_JUMP, jumpBoost)); } public void dropItem() { - connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); + this.connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); } public void dropItemStack() { - connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM_STACK, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); + this.connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.DROP_ITEM_STACK, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); } public void swapItemInHand() { - connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.SWAP_ITEMS_IN_HAND, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); + this.connection.sendPacket(new PacketPlayerDigging(PacketPlayerDigging.DiggingStatus.SWAP_ITEMS_IN_HAND, null, PacketPlayerDigging.DiggingFaces.BOTTOM)); } public void closeWindow(byte windowId) { - CloseWindowEvent event = new CloseWindowEvent(connection, windowId, CloseWindowEvent.Initiators.CLIENT); - if (connection.fireEvent(event)) { + CloseWindowEvent event = new CloseWindowEvent(this.connection, windowId, CloseWindowEvent.Initiators.CLIENT); + if (this.connection.fireEvent(event)) { return; } - connection.sendPacket(new PacketCloseWindowSending(windowId)); + this.connection.sendPacket(new PacketCloseWindowSending(windowId)); } public void respawn() { @@ -98,20 +98,20 @@ public class PacketSender { } public void sendClientStatus(PacketClientStatus.ClientStates status) { - connection.sendPacket(new PacketClientStatus(status)); + this.connection.sendPacket(new PacketClientStatus(status)); } public void sendPluginMessageData(String channel, OutByteBuffer toSend) { - connection.sendPacket(new PacketPluginMessageSending(channel, toSend.toByteArray())); + this.connection.sendPacket(new PacketPluginMessageSending(channel, toSend.toByteArray())); } public void sendLoginPluginMessageResponse(int messageId, OutByteBuffer toSend) { - connection.sendPacket(new PacketLoginPluginResponse(messageId, toSend.toByteArray())); + this.connection.sendPacket(new PacketLoginPluginResponse(messageId, toSend.toByteArray())); } public void setLocation(Location location, EntityRotation rotation, boolean onGround) { - connection.sendPacket(new PacketPlayerPositionAndRotationSending(location, rotation, onGround)); - connection.getPlayer().getEntity().setLocation(location); - connection.getPlayer().getEntity().setRotation(rotation); + this.connection.sendPacket(new PacketPlayerPositionAndRotationSending(location, rotation, onGround)); + this.connection.getPlayer().getEntity().setLocation(location); + this.connection.getPlayer().getEntity().setRotation(rotation); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java index c65012261..e194dfedc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Packets.java @@ -88,7 +88,7 @@ public class Packets { } public ConnectionStates getState() { - return state; + return this.state; } } @@ -209,11 +209,11 @@ public class Packets { } public ConnectionStates getState() { - return state; + return this.state; } public Class getClazz() { - return clazz; + return this.clazz; } } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java index 124f74f1f..8ddc10af4 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/ProtocolDefinition.java @@ -23,6 +23,7 @@ public final class ProtocolDefinition { public static final int SOCKET_TIMEOUT = 30000; public static final int PROTOCOL_PACKET_MAX_SIZE = 2097152; public static final float ANGLE_CALCULATION_CONSTANT = 360.0F / 256.0F; + public static final float PITCH_CALCULATION_CONSTANT = 100.0F / 63.0F; public static final int PLAYER_INVENTORY_ID = 0; diff --git a/src/main/java/de/bixilon/minosoft/util/BitByte.java b/src/main/java/de/bixilon/minosoft/util/BitByte.java index 6123a4f56..58a634dc2 100644 --- a/src/main/java/de/bixilon/minosoft/util/BitByte.java +++ b/src/main/java/de/bixilon/minosoft/util/BitByte.java @@ -15,7 +15,7 @@ package de.bixilon.minosoft.util; public final class BitByte { public static boolean isBitSet(long in, int pos) { - long mask = 1 << pos; + long mask = 1L << pos; return ((in & mask) == mask); } diff --git a/src/main/java/de/bixilon/minosoft/util/CountUpAndDownLatch.java b/src/main/java/de/bixilon/minosoft/util/CountUpAndDownLatch.java index 28178fbcd..7d6b6cc8e 100644 --- a/src/main/java/de/bixilon/minosoft/util/CountUpAndDownLatch.java +++ b/src/main/java/de/bixilon/minosoft/util/CountUpAndDownLatch.java @@ -20,71 +20,71 @@ public class CountUpAndDownLatch { private long total; public CountUpAndDownLatch(int count) { - total = count; + this.total = count; this.count = count; } public void waitUntilZero() throws InterruptedException { - synchronized (lock) { - while (count > 0) { - lock.wait(); + synchronized (this.lock) { + while (this.count > 0) { + this.lock.wait(); } } } public void countUp() { - synchronized (lock) { - total++; - count++; - lock.notifyAll(); + synchronized (this.lock) { + this.total++; + this.count++; + this.lock.notifyAll(); } } public void countDown() { - synchronized (lock) { - count--; - lock.notifyAll(); + synchronized (this.lock) { + this.count--; + this.lock.notifyAll(); } } public long getCount() { - synchronized (lock) { - return count; + synchronized (this.lock) { + return this.count; } } public void setCount(int value) { - synchronized (lock) { - total += value; - count = value; - lock.notifyAll(); + synchronized (this.lock) { + this.total += value; + this.count = value; + this.lock.notifyAll(); } } public void addCount(int count) { - synchronized (lock) { - total += count; + synchronized (this.lock) { + this.total += count; this.count += count; - lock.notifyAll(); + this.lock.notifyAll(); } } public long getTotal() { - return total; + return this.total; } public void waitForChange() throws InterruptedException { - long latestCount = count; + long latestCount = this.count; long latestTotal = this.total; - synchronized (lock) { - while (latestCount == count && latestTotal == total) { - lock.wait(); + synchronized (this.lock) { + while (latestCount == this.count && latestTotal == this.total) { + this.lock.wait(); } } } @Override public String toString() { - return String.format("%d / %d", count, total); + return String.format("%d / %d", this.count, this.total); } } diff --git a/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java b/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java index 539d810dc..6da1f6042 100644 --- a/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java +++ b/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java @@ -20,40 +20,40 @@ import javax.annotation.Nullable; import java.util.HashMap; public class MinosoftCommandLineArguments { - private static final HashMap optionHashMap = new HashMap<>(); - private static final Options options = new Options(); - private static final HelpFormatter formatter = new HelpFormatter(); + private static final HashMap OPTION_HASH_MAP = new HashMap<>(); + private static final Options OPTIONS = new Options(); + private static final HelpFormatter HELP_FORMATTER = new HelpFormatter(); static { registerDefaultArguments(); } public static void parseCommandLineArguments(String[] args) { - MinosoftCommandLineArguments.optionHashMap.forEach((option, commandLineArgumentHandler) -> options.addOption(option)); + OPTION_HASH_MAP.forEach((option, commandLineArgumentHandler) -> OPTIONS.addOption(option)); try { - CommandLine commandLine = new DefaultParser().parse(options, args); + CommandLine commandLine = new DefaultParser().parse(OPTIONS, args); for (Option option : commandLine.getOptions()) { - if (!MinosoftCommandLineArguments.optionHashMap.containsKey(option)) { + if (!OPTION_HASH_MAP.containsKey(option)) { continue; } - MinosoftCommandLineArguments.optionHashMap.get(option).handle(option.getValue()); + OPTION_HASH_MAP.get(option).handle(option.getValue()); } } catch (ParseException e) { System.out.println(e.getMessage()); - formatter.printHelp("java -jar Minosoft.jar", options); + HELP_FORMATTER.printHelp("java -jar Minosoft.jar", OPTIONS); System.exit(1); } } public static void registerCommandLineOption(Option option, CommandLineArgumentHandler handler) { - optionHashMap.put(option, handler); + OPTION_HASH_MAP.put(option, handler); } private static void registerDefaultArguments() { registerCommandLineOption(new Option("?", "help", false, "Displays this help"), (value -> { - formatter.printHelp("java -jar Minosoft.jar", options); + HELP_FORMATTER.printHelp("java -jar Minosoft.jar", OPTIONS); System.exit(1); })); registerCommandLineOption(new Option("home_folder", true, "Home of Minosoft"), (value -> StaticConfiguration.HOME_DIRECTORY = value + "/")); diff --git a/src/main/java/de/bixilon/minosoft/util/ServerAddress.java b/src/main/java/de/bixilon/minosoft/util/ServerAddress.java index 3c1dfd1b6..9bb9c5eda 100644 --- a/src/main/java/de/bixilon/minosoft/util/ServerAddress.java +++ b/src/main/java/de/bixilon/minosoft/util/ServerAddress.java @@ -24,7 +24,7 @@ public class ServerAddress { @Override public int hashCode() { - return hostname.hashCode() * port; + return this.hostname.hashCode() * this.port; } @Override @@ -33,7 +33,7 @@ public class ServerAddress { return true; } ServerAddress their = (ServerAddress) obj; - return hostname.equals(their.getHostname()) && port == their.getPort(); + return this.hostname.equals(their.getHostname()) && this.port == their.getPort(); } @Override @@ -42,10 +42,10 @@ public class ServerAddress { } public String getHostname() { - return hostname; + return this.hostname; } public int getPort() { - return port; + return this.port; } } diff --git a/src/main/java/de/bixilon/minosoft/util/Util.java b/src/main/java/de/bixilon/minosoft/util/Util.java index dc885e689..96bb469ee 100644 --- a/src/main/java/de/bixilon/minosoft/util/Util.java +++ b/src/main/java/de/bixilon/minosoft/util/Util.java @@ -39,7 +39,7 @@ public final class Util { public static final Pattern UUID_FIX = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})"); // thanks https://www.spigotmc.org/threads/free-code-easily-convert-between-trimmed-and-full-uuids.165615 public static final String RANDOM_STRING_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; public static final String LINE_SEPARATOR = System.getProperty("line.separator"); - private static final Random random = ThreadLocalRandom.current(); + private static final Random THREAD_LOCAL_RANDOM = ThreadLocalRandom.current(); public static UUID getUUIDFromString(String uuid) { if (uuid.length() == 36) { @@ -264,7 +264,7 @@ public final class Util { public static String generateRandomString(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { - sb.append(RANDOM_STRING_CHARS.charAt(random.nextInt(RANDOM_STRING_CHARS.length()))); + sb.append(RANDOM_STRING_CHARS.charAt(THREAD_LOCAL_RANDOM.nextInt(RANDOM_STRING_CHARS.length()))); } return sb.toString(); } @@ -275,6 +275,6 @@ public final class Util { } public static String readAsset(String path) throws IOException { - return Util.readFile(new BufferedReader(Util.readAsset(path, Util.class)), true); + return readFile(new BufferedReader(readAsset(path, Util.class)), true); } } diff --git a/src/main/java/de/bixilon/minosoft/util/buffers/ImprovedStringReader.java b/src/main/java/de/bixilon/minosoft/util/buffers/ImprovedStringReader.java index 1e9d43667..c09ec7aa6 100644 --- a/src/main/java/de/bixilon/minosoft/util/buffers/ImprovedStringReader.java +++ b/src/main/java/de/bixilon/minosoft/util/buffers/ImprovedStringReader.java @@ -26,7 +26,7 @@ public class ImprovedStringReader { public Pair readUntil(String... search) { Pair ret = getUntil(search); - position += ret.getKey().length() + ret.getValue().length(); + this.position += ret.getKey().length() + ret.getValue().length(); return ret; } @@ -63,11 +63,11 @@ public class ImprovedStringReader { } public String getString() { - return string; + return this.string; } public int getPosition() { - return position; + return this.position; } public void setPosition(int position) { @@ -75,52 +75,52 @@ public class ImprovedStringReader { } public int getAvailableChars() { - return string.length() - position; + return this.string.length() - this.position; } public char readChar() { if (getRemainingChars() == 0) { return 0; } - return string.charAt(position++); + return this.string.charAt(this.position++); } public char getNextChar() { if (getRemainingChars() == 0) { return 0; } - return string.charAt(position); + return this.string.charAt(this.position); } public String getRest() { - if (position > string.length()) { + if (this.position > this.string.length()) { return ""; } - return string.substring(position); + return this.string.substring(this.position); } public String readRest() { String ret = getRest(); - position = string.length(); + this.position = this.string.length(); return ret; } public String read(int length) { String ret = get(length); - position += length; + this.position += length; return ret; } public String get(int length) { - return string.substring(position, position + length); + return this.string.substring(this.position, this.position + length); } public void skip(int length) { - position += length; + this.position += length; } public void skipChar() { - position++; + this.position++; } public int skipSpaces() { @@ -133,12 +133,12 @@ public class ImprovedStringReader { } public int getRemainingChars() { - int difference = string.length() - position; + int difference = this.string.length() - this.position; return Math.max(difference, 0); } @Override public String toString() { - return String.format("position=%d/%d: \"%s\"", position, string.length(), getRest()); + return String.format("position=%d/%d: \"%s\"", this.position, this.string.length(), getRest()); } } diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccount.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccount.java index a96bc77f0..166d0437c 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccount.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccount.java @@ -53,11 +53,11 @@ public class MojangAccount { public JsonObject serialize() { JsonObject json = new JsonObject(); - json.addProperty("accessToken", accessToken); - json.addProperty("userId", userId); - json.addProperty("uuid", uuid.toString()); - json.addProperty("playerName", playerName); - json.addProperty("userName", mojangUserName); + json.addProperty("accessToken", this.accessToken); + json.addProperty("userId", this.userId); + json.addProperty("uuid", this.uuid.toString()); + json.addProperty("playerName", this.playerName); + json.addProperty("userName", this.mojangUserName); return json; } @@ -66,21 +66,21 @@ public class MojangAccount { } public RefreshStates refreshToken() { - if (lastRefreshStatus != null) { - return lastRefreshStatus; + if (this.lastRefreshStatus != null) { + return this.lastRefreshStatus; } String accessToken = MojangAuthentication.refresh(this.accessToken); if (accessToken == null) { - lastRefreshStatus = RefreshStates.FAILED; - return lastRefreshStatus; + this.lastRefreshStatus = RefreshStates.FAILED; + return this.lastRefreshStatus; } if (accessToken.isBlank()) { - lastRefreshStatus = RefreshStates.ERROR; - return lastRefreshStatus; + this.lastRefreshStatus = RefreshStates.ERROR; + return this.lastRefreshStatus; } this.accessToken = accessToken; - lastRefreshStatus = RefreshStates.SUCCESSFUL; - return lastRefreshStatus; + this.lastRefreshStatus = RefreshStates.SUCCESSFUL; + return this.lastRefreshStatus; } public UUID getUUID() { @@ -92,11 +92,11 @@ public class MojangAccount { } public String getAccessToken() { - return accessToken; + return this.accessToken; } public String getMojangUserName() { - return mojangUserName; + return this.mojangUserName; } public void saveToConfig() { @@ -115,12 +115,12 @@ public class MojangAccount { } public String getUserId() { - return userId; + return this.userId; } @Override public int hashCode() { - return userId.hashCode(); + return this.userId.hashCode(); } @Override diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccountAuthenticationAttempt.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccountAuthenticationAttempt.java index 2f526ec97..e69e91d15 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccountAuthenticationAttempt.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAccountAuthenticationAttempt.java @@ -28,14 +28,14 @@ public class MojangAccountAuthenticationAttempt { } public String getError() { - return error; + return this.error; } public MojangAccount getAccount() { - return account; + return this.account; } public boolean succeeded() { - return account != null; + return this.account != null; } } diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java index 48fc01b84..da3ab0da4 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangURLs.java @@ -26,11 +26,11 @@ public enum MojangURLs { } public String getUrl() { - return url; + return this.url; } @Override public String toString() { - return url; + return this.url; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteArrayTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteArrayTag.java index 68fa01729..b353279e8 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteArrayTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteArrayTag.java @@ -34,22 +34,22 @@ public class ByteArrayTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - new IntTag(value.length).writeBytes(buffer); - buffer.writeBytes(value); + new IntTag(this.value.length).writeBytes(buffer); + buffer.writeBytes(this.value); } public byte[] getValue() { - return value; + return this.value; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append('['); - for (int i = 0; i < value.length; i++) { - builder.append(value[i]); + for (int i = 0; i < this.value.length; i++) { + builder.append(this.value[i]); builder.append("b"); - if (i == value.length - 1) { + if (i == this.value.length - 1) { break; } builder.append(", "); diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteTag.java index 6aee53701..db58ee49d 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ByteTag.java @@ -38,20 +38,20 @@ public class ByteTag extends NumberTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeByte(value); + buffer.writeByte(this.value); } public byte getValue() { - return value; + return this.value; } @Override public String toString() { - return value + "b"; + return this.value + "b"; } @Override public long getAsLong() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java index afe0e4b0f..b7c4c8bab 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/CompoundTag.java @@ -44,19 +44,19 @@ public class CompoundTag extends NBTTag { this.data = new HashMap<>(); while (true) { byte tag = buffer.readByte(); - TagTypes tagType = TagTypes.getById(tag); + TagTypes tagType = TagTypes.byId(tag); if (tagType == TagTypes.END) { // end tag break; } String tagName = buffer.readString(buffer.readUnsignedShort()); // length - data.put(tagName, buffer.readNBT(tagType)); + this.data.put(tagName, buffer.readNBT(tagType)); } } public CompoundTag() { - name = null; - data = new HashMap<>(); + this.name = null; + this.data = new HashMap<>(); } @Override @@ -67,14 +67,14 @@ public class CompoundTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { buffer.writeByte((byte) TagTypes.COMPOUND.ordinal()); - buffer.writeShort((short) name.length()); - buffer.writeStringNoLength(name); + buffer.writeShort((short) this.name.length()); + buffer.writeStringNoLength(this.name); // now with prefixed name, etc it is technically the same as a subtag writeBytesSubTag(buffer); } public void writeBytesSubTag(OutByteBuffer buffer) { - for (Map.Entry set : data.entrySet()) { + for (Map.Entry set : this.data.entrySet()) { buffer.writeByte((byte) set.getValue().getType().ordinal()); buffer.writeShort((short) set.getKey().length()); buffer.writeStringNoLength(set.getKey()); @@ -90,92 +90,92 @@ public class CompoundTag extends NBTTag { } public boolean containsKey(String key) { - return data.containsKey(key); + return this.data.containsKey(key); } public ByteTag getByteTag(String key) { - return (ByteTag) data.get(key); + return (ByteTag) this.data.get(key); } public ShortTag getShortTag(String key) { - return (ShortTag) data.get(key); + return (ShortTag) this.data.get(key); } public IntTag getIntTag(String key) { - return (IntTag) data.get(key); + return (IntTag) this.data.get(key); } public LongTag getLongTag(String key) { - return (LongTag) data.get(key); + return (LongTag) this.data.get(key); } public FloatTag getFloatTag(String key) { - return (FloatTag) data.get(key); + return (FloatTag) this.data.get(key); } public DoubleTag getDoubleTag(String key) { - return (DoubleTag) data.get(key); + return (DoubleTag) this.data.get(key); } public ByteArrayTag getByteArrayTag(String key) { - return (ByteArrayTag) data.get(key); + return (ByteArrayTag) this.data.get(key); } public StringTag getStringTag(String key) { - return (StringTag) data.get(key); + return (StringTag) this.data.get(key); } public ListTag getListTag(String key) { - return (ListTag) data.get(key); + return (ListTag) this.data.get(key); } public CompoundTag getCompoundTag(String key) { - return (CompoundTag) data.get(key); + return (CompoundTag) this.data.get(key); } public NumberTag getNumberTag(String key) { - return (NumberTag) data.get(key); + return (NumberTag) this.data.get(key); } public NBTTag getTag(String key) { - return data.get(key); + return this.data.get(key); } public void writeTag(String name, NBTTag tag) { - if (isFinal) { + if (this.isFinal) { throw new IllegalArgumentException("This tag is marked as final!"); } - data.put(name, tag); + this.data.put(name, tag); } public int size() { - return data.size(); + return this.data.size(); } // abstract functions public void writeBlockPosition(BlockPosition position) { - if (isFinal) { + if (this.isFinal) { throw new IllegalArgumentException("This tag is marked as final!"); } - data.put("x", new IntTag(position.getX())); - data.put("y", new IntTag(position.getY())); - data.put("z", new IntTag(position.getZ())); + this.data.put("x", new IntTag(position.getX())); + this.data.put("y", new IntTag(position.getY())); + this.data.put("z", new IntTag(position.getZ())); } @Override public String toString() { StringBuilder builder = new StringBuilder(); - if (name != null) { - builder.append(name); + if (this.name != null) { + builder.append(this.name); } builder.append('{'); AtomicInteger i = new AtomicInteger(); - data.forEach((key, value) -> { + this.data.forEach((key, value) -> { builder.append(key); builder.append(": "); builder.append(value); - if (i.get() == data.size() - 1) { + if (i.get() == this.data.size() - 1) { return; } builder.append(", "); diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/DoubleTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/DoubleTag.java index 627a3e659..47f6c7865 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/DoubleTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/DoubleTag.java @@ -34,15 +34,15 @@ public class DoubleTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeDouble(value); + buffer.writeDouble(this.value); } public double getValue() { - return value; + return this.value; } @Override public String toString() { - return value + "D"; + return this.value + "D"; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/FloatTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/FloatTag.java index 8f685e60b..4ee26d2bd 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/FloatTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/FloatTag.java @@ -34,15 +34,15 @@ public class FloatTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeFloat(value); + buffer.writeFloat(this.value); } public float getValue() { - return value; + return this.value; } @Override public String toString() { - return value + "F"; + return this.value + "F"; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntArrayTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntArrayTag.java index bf46fab9b..2dab6855a 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntArrayTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntArrayTag.java @@ -36,16 +36,16 @@ public class IntArrayTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - new IntTag(value.length).writeBytes(buffer); - buffer.writeInts(value); + new IntTag(this.value.length).writeBytes(buffer); + buffer.writeInts(this.value); } public int[] getValue() { - return value; + return this.value; } @Override public String toString() { - return Arrays.toString(value); + return Arrays.toString(this.value); } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntTag.java index 07e9d7f28..976aa640c 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/IntTag.java @@ -34,20 +34,20 @@ public class IntTag extends NumberTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeInt(value); + buffer.writeInt(this.value); } public int getValue() { - return value; + return this.value; } @Override public String toString() { - return String.valueOf(value); + return String.valueOf(this.value); } @Override public long getAsLong() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java index 9867b7831..d9b513e72 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ListTag.java @@ -34,21 +34,21 @@ public class ListTag extends NBTTag { } public ListTag(InByteBuffer buffer) { - this.type = TagTypes.getById(new ByteTag(buffer).getValue()); + this.type = TagTypes.byId(new ByteTag(buffer).getValue()); int length = new IntTag(buffer).getValue(); - list = new ArrayList<>(); + this.list = new ArrayList<>(); for (int i = 0; i < length; i++) { - switch (type) { - case BYTE -> list.add(new ByteTag(buffer)); - case SHORT -> list.add(new ShortTag(buffer)); - case INT -> list.add(new IntTag(buffer)); - case LONG -> list.add(new LongTag(buffer)); - case FLOAT -> list.add(new FloatTag(buffer)); - case DOUBLE -> list.add(new DoubleTag(buffer)); - case BYTE_ARRAY -> list.add(new ByteArrayTag(buffer)); - case STRING -> list.add(new StringTag(buffer)); - case LIST -> list.add(new ListTag(buffer)); - case COMPOUND -> list.add(new CompoundTag(true, buffer)); + switch (this.type) { + case BYTE -> this.list.add(new ByteTag(buffer)); + case SHORT -> this.list.add(new ShortTag(buffer)); + case INT -> this.list.add(new IntTag(buffer)); + case LONG -> this.list.add(new LongTag(buffer)); + case FLOAT -> this.list.add(new FloatTag(buffer)); + case DOUBLE -> this.list.add(new DoubleTag(buffer)); + case BYTE_ARRAY -> this.list.add(new ByteArrayTag(buffer)); + case STRING -> this.list.add(new StringTag(buffer)); + case LIST -> this.list.add(new ListTag(buffer)); + case COMPOUND -> this.list.add(new CompoundTag(true, buffer)); } } } @@ -60,22 +60,22 @@ public class ListTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - new ByteTag((byte) type.ordinal()).writeBytes(buffer); + new ByteTag((byte) this.type.ordinal()).writeBytes(buffer); - new IntTag(list.size()).writeBytes(buffer); + new IntTag(this.list.size()).writeBytes(buffer); - for (NBTTag NBTTag : list) { + for (NBTTag NBTTag : this.list) { NBTTag.writeBytes(buffer); } } @SuppressWarnings("unchecked") public ArrayList getValue() { - return (ArrayList) list; + return (ArrayList) this.list; } @Override public String toString() { - return list.toString(); + return this.list.toString(); } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongArrayTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongArrayTag.java index 9e36bc96d..4cf98adbe 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongArrayTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongArrayTag.java @@ -34,22 +34,22 @@ public class LongArrayTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - new IntTag(value.length).writeBytes(buffer); - buffer.writeLongs(value); + new IntTag(this.value.length).writeBytes(buffer); + buffer.writeLongs(this.value); } public long[] getValue() { - return value; + return this.value; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append('['); - for (int i = 0; i < value.length; i++) { - builder.append(value[i]); + for (int i = 0; i < this.value.length; i++) { + builder.append(this.value[i]); builder.append("l"); - if (i == value.length - 1) { + if (i == this.value.length - 1) { break; } builder.append(", "); diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongTag.java index a0350231f..457c2cd8b 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/LongTag.java @@ -34,20 +34,20 @@ public class LongTag extends NumberTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeLong(value); + buffer.writeLong(this.value); } public long getValue() { - return value; + return this.value; } @Override public String toString() { - return value + "l"; + return this.value + "l"; } @Override public long getAsLong() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/NBTTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/NBTTag.java index c999cb147..73d58b1f1 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/NBTTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/NBTTag.java @@ -16,14 +16,14 @@ package de.bixilon.minosoft.util.nbt.tag; import de.bixilon.minosoft.protocol.protocol.OutByteBuffer; public abstract class NBTTag { - boolean isFinal = false; + boolean isFinal; abstract TagTypes getType(); abstract void writeBytes(OutByteBuffer buffer); public boolean isFinal() { - return isFinal; + return this.isFinal; } public void setFinal() { diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ShortTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ShortTag.java index 42e6a2da7..6a49f93f8 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/ShortTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/ShortTag.java @@ -34,20 +34,20 @@ public class ShortTag extends NumberTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeShort(value); + buffer.writeShort(this.value); } public short getValue() { - return value; + return this.value; } @Override public String toString() { - return value + "s"; + return this.value + "s"; } @Override public long getAsLong() { - return value; + return this.value; } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/StringTag.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/StringTag.java index ac8d92951..f56219c46 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/StringTag.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/StringTag.java @@ -24,7 +24,7 @@ public class StringTag extends NBTTag { } public StringTag(InByteBuffer buffer) { - value = buffer.readString(new ShortTag(buffer).getValue()); + this.value = buffer.readString(new ShortTag(buffer).getValue()); } @Override @@ -34,16 +34,16 @@ public class StringTag extends NBTTag { @Override public void writeBytes(OutByteBuffer buffer) { - buffer.writeShort((short) value.length()); - buffer.writeStringNoLength(value); + buffer.writeShort((short) this.value.length()); + buffer.writeStringNoLength(this.value); } public String getValue() { - return value; + return this.value; } @Override public String toString() { - return String.format("\"%s\"", value); + return String.format("\"%s\"", this.value); } } diff --git a/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java b/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java index 1bf13b47a..24d619a0f 100644 --- a/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java +++ b/src/main/java/de/bixilon/minosoft/util/nbt/tag/TagTypes.java @@ -28,7 +28,9 @@ public enum TagTypes { INT_ARRAY, LONG_ARRAY; - public static TagTypes getById(int id) { - return values()[id]; + private static final TagTypes[] TAG_TYPES = values(); + + public static TagTypes byId(int id) { + return TAG_TYPES[id]; } } diff --git a/src/main/java/de/bixilon/minosoft/util/task/AsyncTaskWorker.java b/src/main/java/de/bixilon/minosoft/util/task/AsyncTaskWorker.java index 00d84d00a..bb7b9c450 100644 --- a/src/main/java/de/bixilon/minosoft/util/task/AsyncTaskWorker.java +++ b/src/main/java/de/bixilon/minosoft/util/task/AsyncTaskWorker.java @@ -49,30 +49,30 @@ public class AsyncTaskWorker { } public LinkedList getTasks() { - return tasks; + return this.tasks; } public void addTask(Task task) { - tasks.add(task); + this.tasks.add(task); } public void work(CountUpAndDownLatch progress) { - tasks.sort((a, b) -> { + this.tasks.sort((a, b) -> { if (a == null || b == null) { return 0; } return -(a.getPriority().ordinal() - b.getPriority().ordinal()); }); - ConcurrentLinkedQueue doing = new ConcurrentLinkedQueue<>(tasks); + ConcurrentLinkedQueue doing = new ConcurrentLinkedQueue<>(this.tasks); CountUpAndDownLatch latch = new CountUpAndDownLatch(doing.size()); - ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), Util.getThreadFactory(name)); - while (doing.size() > 0) { + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), Util.getThreadFactory(this.name)); + while (!doing.isEmpty()) { doing.forEach((task -> { AtomicBoolean canStart = new AtomicBoolean(false); while (!canStart.get()) { canStart.set(true); task.getDependsOns().forEach((dependency) -> { - if (!jobsDone.contains(dependency)) { + if (!this.jobsDone.contains(dependency)) { canStart.set(false); } }); @@ -86,13 +86,13 @@ public class AsyncTaskWorker { e.printStackTrace(); if (task.getImportance() == TaskImportance.REQUIRED) { Log.fatal(String.format("Task %s (%s) failed: %s", task.getTaskName(), task.getTaskDescription(), e.getMessage())); - if (exceptionRunnable != null) { - exceptionRunnable.onFatal(e); + if (this.exceptionRunnable != null) { + this.exceptionRunnable.onFatal(e); } throw new RuntimeException(e); } } - jobsDone.add(task.getTaskName()); + this.jobsDone.add(task.getTaskName()); latch.countDown(); }); doing.remove(task); @@ -108,7 +108,7 @@ public class AsyncTaskWorker { } public boolean isJobDone(String name) { - return jobsDone.contains(name); + return this.jobsDone.contains(name); } public void setFatalError(ExceptionRunnable exceptionRunnable) { @@ -116,7 +116,7 @@ public class AsyncTaskWorker { } public String getName() { - return name; + return this.name; } public void setName(String name) { diff --git a/src/main/java/de/bixilon/minosoft/util/task/Task.java b/src/main/java/de/bixilon/minosoft/util/task/Task.java index 220dab79e..e80507d8f 100644 --- a/src/main/java/de/bixilon/minosoft/util/task/Task.java +++ b/src/main/java/de/bixilon/minosoft/util/task/Task.java @@ -77,26 +77,26 @@ public class Task { } public TaskCallable getTask() { - return task; + return this.task; } public String getTaskName() { - return taskName; + return this.taskName; } public String getTaskDescription() { - return taskDescription; + return this.taskDescription; } public Priorities getPriority() { - return priority; + return this.priority; } public TaskImportance getImportance() { - return importance; + return this.importance; } public Set getDependsOns() { - return dependsOns; + return this.dependsOns; } }