From 4dcc723c9c4dd505061d3a6a1315ce855eb6c0e4 Mon Sep 17 00:00:00 2001 From: Intege-rs Date: Wed, 11 Feb 2026 18:06:52 -0500 Subject: [PATCH] 2026.02.11-255364b8e --- .../CameraShakePacketGenerator.java | 10 +- .../ViewBobbingPacketGenerator.java | 10 +- .../adventure/farming/FarmingUtil.java | 33 +- .../interactions/HarvestCropInteraction.java | 48 +- .../memories/memories/npc/NPCMemory.java | 100 +- .../memories/npc/NPCMemoryProvider.java | 4 +- .../adventure/memories/page/MemoriesPage.java | 4 +- .../adventure/objectives/ObjectivePlugin.java | 2 + .../ObjectiveLocationMarkerSystems.java | 2 + .../objectives/task/ObjectiveTask.java | 2 +- .../teleporter/TeleporterPlugin.java | 25 +- .../teleporter/component/Teleporter.java | 2 + .../page/TeleporterSettingsPage.java | 51 +- .../page/TeleporterSettingsPageSupplier.java | 11 +- .../system/TurnOffTeleportersSystem.java | 98 + .../asseteditor/AssetEditorPacketHandler.java | 7 +- .../asseteditor/AssetEditorPlugin.java | 24 +- .../datasource/StandardDataSource.java | 5 +- .../BuilderToolsPacketHandler.java | 1529 ++++++------ .../buildertools/BuilderToolsPlugin.java | 382 ++- .../PrototypePlayerBuilderToolSettings.java | 32 + .../commands/ContractSelectionCommand.java | 4 +- .../scriptedbrushes/BrushConfig.java | 2 +- .../operations/sequential/ShapeOperation.java | 2 +- .../creativehub/CreativeHubPlugin.java | 17 +- .../creativehub/command/HubCommand.java | 2 +- .../interactions/HubPortalInteraction.java | 72 +- .../systems/ReturnToHubButtonSystem.java | 66 + .../creativehub/ui/ReturnToHubButtonUI.java | 87 + .../hytale/builtin/fluid/FluidPlugin.java | 12 +- .../hytale/builtin/fluid/FluidSystems.java | 4 +- .../assets/density/MultiMixDensityAsset.java | 2 +- .../assets/patterns/CeilingPatternAsset.java | 4 +- .../newsystem/stages/NTerrainStage.java | 3 +- .../patterns/CeilingPattern.java | 46 - .../hytalegenerator/patterns/Pattern.java | 5 +- .../FieldFunctionPositionProvider.java | 1 + .../hytalegenerator/props/QueueProp.java | 4 +- .../props/prefab/PrefabProp.java | 4 +- .../builtin/instances/InstancesPlugin.java | 7 +- .../hytale/builtin/mounts/MountSystems.java | 7 +- .../builtin/mounts/NPCMountSystems.java | 3 + .../portals/ui/PortalDeviceSummonPage.java | 31 +- .../builtin/portals/ui/PortalSpawnFinder.java | 63 +- .../hytale/builtin/randomtick/RandomTick.java | 35 + .../builtin/randomtick/RandomTickPlugin.java | 36 + .../builtin/randomtick/RandomTickSystem.java | 114 + .../procedures/ChangeIntoBlockProcedure.java | 38 + .../procedures/SpreadToProcedure.java | 197 ++ .../variant/TeleportOtherToPlayerCommand.java | 90 +- .../hytale/builtin/worldgen/FeatureFlags.java | 19 - .../builtin/worldgen/WorldGenPlugin.java | 10 +- .../hytale/codec/builder/BuilderCodec.java | 2 +- .../hytale/common/util/StringUtil.java | 18 +- .../hypixel/hytale/math/util/ChunkUtil.java | 1 + .../hytale/procedurallib/file/FileIO.java | 8 +- .../protocol/ActiveAnimationsUpdate.java | 179 ++ .../hypixel/hytale/protocol/AudioUpdate.java | 124 + .../hytale/protocol/BenchRequirement.java | 241 +- .../hypixel/hytale/protocol/BlockUpdate.java | 79 + .../hypixel/hytale/protocol/CachedPacket.java | 15 +- .../hytale/protocol/CombatTextUpdate.java | 104 +- .../hytale/protocol/ComponentUpdate.java | 1510 ++--------- .../hytale/protocol/DynamicLightUpdate.java | 74 + .../hytale/protocol/EntityEffectsUpdate.java | 144 ++ .../hytale/protocol/EntityStatsUpdate.java | 193 ++ .../hypixel/hytale/protocol/EntityUpdate.java | 10 +- .../{Equipment.java => EquipmentUpdate.java} | 24 +- .../protocol/HitboxCollisionUpdate.java | 73 + .../hytale/protocol/IntangibleUpdate.java | 51 + ...Nameplate.java => InteractableUpdate.java} | 75 +- .../hytale/protocol/InteractionsUpdate.java | 241 ++ .../hytale/protocol/InvulnerableUpdate.java | 51 + .../hypixel/hytale/protocol/ItemUpdate.java | 96 + src/com/hypixel/hytale/protocol/Model.java | 156 +- .../hypixel/hytale/protocol/ModelUpdate.java | 122 + .../hytale/protocol/MountedUpdate.java | 9 +- .../hytale/protocol/MovementStatesUpdate.java | 74 + .../hytale/protocol/NameplateUpdate.java | 105 + .../hytale/protocol/NetworkChannel.java | 27 + .../hytale/protocol/NewSpawnUpdate.java | 51 + src/com/hypixel/hytale/protocol/Packet.java | 2 + .../hytale/protocol/PacketRegistry.java | 2219 +++++++++++++++-- .../hytale/protocol/PlayerSkinUpdate.java | 116 + .../hytale/protocol/PredictionUpdate.java | 76 + .../hypixel/hytale/protocol/PropUpdate.java | 51 + .../hytale/protocol/ProtocolSettings.java | 10 +- .../hytale/protocol/RepulsionUpdate.java | 73 + .../hytale/protocol/RespondToHitUpdate.java | 51 + .../hytale/protocol/ToClientPacket.java | 4 + .../hytale/protocol/ToServerPacket.java | 4 + .../hytale/protocol/TransformUpdate.java | 74 + .../hytale/protocol/UIComponentsUpdate.java | 124 + .../hypixel/hytale/protocol/io/PacketIO.java | 4 +- .../protocol/io/netty/PacketDecoder.java | 39 +- .../protocol/io/netty/PacketEncoder.java | 16 +- .../protocol/io/netty/ProtocolUtil.java | 2 + .../AssetEditorActivateButton.java | 9 +- .../AssetEditorAssetListSetup.java | 9 +- .../AssetEditorAssetListUpdate.java | 9 +- .../AssetEditorAssetPackSetup.java | 9 +- .../asseteditor/AssetEditorAssetUpdated.java | 9 +- .../asseteditor/AssetEditorAuthorization.java | 9 +- .../asseteditor/AssetEditorCapabilities.java | 9 +- .../asseteditor/AssetEditorCreateAsset.java | 9 +- .../AssetEditorCreateAssetPack.java | 9 +- .../AssetEditorCreateDirectory.java | 9 +- .../asseteditor/AssetEditorDeleteAsset.java | 9 +- .../AssetEditorDeleteAssetPack.java | 10 +- .../AssetEditorDeleteDirectory.java | 9 +- .../AssetEditorDiscardChanges.java | 9 +- .../AssetEditorEnableAssetPack.java | 149 -- .../AssetEditorExportAssetFinalize.java | 9 +- .../AssetEditorExportAssetInitialize.java | 9 +- .../AssetEditorExportAssetPart.java | 9 +- .../asseteditor/AssetEditorExportAssets.java | 9 +- .../AssetEditorExportComplete.java | 9 +- .../AssetEditorExportDeleteAssets.java | 9 +- .../asseteditor/AssetEditorFetchAsset.java | 9 +- .../AssetEditorFetchAssetReply.java | 9 +- .../AssetEditorFetchAutoCompleteData.java | 9 +- ...AssetEditorFetchAutoCompleteDataReply.java | 9 +- .../AssetEditorFetchJsonAssetWithParents.java | 9 +- ...tEditorFetchJsonAssetWithParentsReply.java | 9 +- .../AssetEditorFetchLastModifiedAssets.java | 9 +- .../asseteditor/AssetEditorInitialize.java | 9 +- .../AssetEditorJsonAssetUpdated.java | 9 +- .../AssetEditorLastModifiedAssets.java | 9 +- .../AssetEditorModifiedAssetsCount.java | 9 +- .../AssetEditorPopupNotification.java | 9 +- .../asseteditor/AssetEditorRebuildCaches.java | 12 +- .../asseteditor/AssetEditorRedoChanges.java | 9 +- .../asseteditor/AssetEditorRenameAsset.java | 9 +- .../AssetEditorRenameDirectory.java | 9 +- .../AssetEditorRequestChildrenList.java | 9 +- .../AssetEditorRequestChildrenListReply.java | 9 +- .../AssetEditorRequestDataset.java | 9 +- .../AssetEditorRequestDatasetReply.java | 9 +- .../asseteditor/AssetEditorSelectAsset.java | 9 +- .../asseteditor/AssetEditorSetGameTime.java | 9 +- .../AssetEditorSetupAssetTypes.java | 9 +- .../asseteditor/AssetEditorSetupSchemas.java | 9 +- ...tEditorSubscribeModifiedAssetsChanges.java | 9 +- .../asseteditor/AssetEditorUndoChanges.java | 9 +- .../asseteditor/AssetEditorUndoRedoReply.java | 9 +- .../asseteditor/AssetEditorUpdateAsset.java | 9 +- .../AssetEditorUpdateAssetPack.java | 10 +- .../AssetEditorUpdateJsonAsset.java | 9 +- .../AssetEditorUpdateModelPreview.java | 9 +- .../AssetEditorUpdateSecondsPerGameDay.java | 9 +- .../AssetEditorUpdateWeatherPreviewLock.java | 9 +- .../packets/asseteditor/FailureReply.java | 10 +- .../packets/asseteditor/SuccessReply.java | 10 +- .../assets/TrackOrUpdateObjective.java | 9 +- .../packets/assets/UntrackObjective.java | 9 +- .../packets/assets/UpdateAmbienceFX.java | 9 +- .../packets/assets/UpdateAudioCategories.java | 9 +- .../assets/UpdateBlockBreakingDecals.java | 9 +- .../packets/assets/UpdateBlockGroups.java | 9 +- .../packets/assets/UpdateBlockHitboxes.java | 9 +- .../assets/UpdateBlockParticleSets.java | 9 +- .../packets/assets/UpdateBlockSets.java | 9 +- .../packets/assets/UpdateBlockSoundSets.java | 9 +- .../packets/assets/UpdateBlockTypes.java | 9 +- .../packets/assets/UpdateCameraShake.java | 9 +- .../packets/assets/UpdateEntityEffects.java | 9 +- .../packets/assets/UpdateEntityStatTypes.java | 9 +- .../assets/UpdateEntityUIComponents.java | 9 +- .../packets/assets/UpdateEnvironments.java | 9 +- .../assets/UpdateEqualizerEffects.java | 9 +- .../assets/UpdateFieldcraftCategories.java | 9 +- .../packets/assets/UpdateFluidFX.java | 9 +- .../protocol/packets/assets/UpdateFluids.java | 9 +- .../assets/UpdateHitboxCollisionConfig.java | 9 +- .../packets/assets/UpdateInteractions.java | 9 +- .../packets/assets/UpdateItemCategories.java | 9 +- .../assets/UpdateItemPlayerAnimations.java | 9 +- .../packets/assets/UpdateItemQualities.java | 9 +- .../packets/assets/UpdateItemReticles.java | 9 +- .../packets/assets/UpdateItemSoundSets.java | 9 +- .../protocol/packets/assets/UpdateItems.java | 9 +- .../packets/assets/UpdateModelvfxs.java | 9 +- .../packets/assets/UpdateObjectiveTask.java | 9 +- .../assets/UpdateParticleSpawners.java | 9 +- .../packets/assets/UpdateParticleSystems.java | 9 +- .../assets/UpdateProjectileConfigs.java | 9 +- .../packets/assets/UpdateRecipes.java | 9 +- .../packets/assets/UpdateRepulsionConfig.java | 9 +- .../packets/assets/UpdateResourceTypes.java | 9 +- .../packets/assets/UpdateReverbEffects.java | 9 +- .../assets/UpdateRootInteractions.java | 9 +- .../packets/assets/UpdateSoundEvents.java | 9 +- .../packets/assets/UpdateSoundSets.java | 9 +- .../packets/assets/UpdateTagPatterns.java | 9 +- .../protocol/packets/assets/UpdateTrails.java | 9 +- .../packets/assets/UpdateTranslations.java | 9 +- .../assets/UpdateUnarmedInteractions.java | 9 +- .../packets/assets/UpdateViewBobbing.java | 9 +- .../packets/assets/UpdateWeathers.java | 9 +- .../protocol/packets/auth/AuthGrant.java | 9 +- .../protocol/packets/auth/AuthToken.java | 9 +- .../protocol/packets/auth/ClientReferral.java | 9 +- .../protocol/packets/auth/ConnectAccept.java | 9 +- .../packets/auth/PasswordAccepted.java | 9 +- .../packets/auth/PasswordRejected.java | 9 +- .../packets/auth/PasswordResponse.java | 9 +- .../packets/auth/ServerAuthToken.java | 9 +- .../hytale/protocol/packets/auth/Status.java | 252 -- .../buildertools/BuilderToolArgUpdate.java | 9 +- .../buildertools/BuilderToolEntityAction.java | 9 +- .../BuilderToolExtrudeAction.java | 9 +- .../BuilderToolGeneralAction.java | 9 +- .../buildertools/BuilderToolHideAnchors.java | 9 +- .../buildertools/BuilderToolLaserPointer.java | 9 +- .../buildertools/BuilderToolLineAction.java | 9 +- .../BuilderToolOnUseInteraction.java | 9 +- .../BuilderToolPasteClipboard.java | 9 +- .../BuilderToolRotateClipboard.java | 9 +- ...ilderToolSelectionToolAskForClipboard.java | 9 +- ...erToolSelectionToolReplyWithClipboard.java | 9 +- .../BuilderToolSelectionTransform.java | 181 +- .../BuilderToolSelectionUpdate.java | 9 +- .../BuilderToolSetEntityCollision.java | 9 +- .../BuilderToolSetEntityLight.java | 9 +- .../BuilderToolSetEntityPickupEnabled.java | 9 +- .../BuilderToolSetEntityScale.java | 9 +- .../BuilderToolSetEntityTransform.java | 9 +- .../buildertools/BuilderToolSetNPCDebug.java | 9 +- ...BuilderToolSetTransformationModeState.java | 9 +- .../buildertools/BuilderToolShowAnchor.java | 9 +- .../buildertools/BuilderToolStackArea.java | 9 +- .../buildertools/BuilderToolsSetSoundSet.java | 9 +- .../buildertools/PrefabUnselectPrefab.java | 9 +- .../packets/camera/CameraShakeEffect.java | 9 +- .../packets/camera/RequestFlyCameraMode.java | 9 +- .../packets/camera/SetFlyCameraMode.java | 9 +- .../packets/camera/SetServerCamera.java | 9 +- .../protocol/packets/connection/Connect.java | 9 +- .../packets/connection/Disconnect.java | 10 +- .../protocol/packets/connection/Ping.java | 9 +- .../protocol/packets/connection/Pong.java | 9 +- .../packets/entities/ApplyKnockback.java | 9 +- .../packets/entities/ChangeVelocity.java | 9 +- .../packets/entities/EntityUpdates.java | 9 +- .../packets/entities/MountMovement.java | 9 +- .../packets/entities/PlayAnimation.java | 9 +- .../packets/entities/SetEntitySeed.java | 9 +- .../packets/entities/SpawnModelParticles.java | 9 +- .../interaction/CancelInteractionChain.java | 9 +- .../packets/interaction/DismountNPC.java | 10 +- .../packets/interaction/MountNPC.java | 9 +- .../interaction/PlayInteractionFor.java | 9 +- .../interaction/SyncInteractionChains.java | 10 +- .../interface_/AddToServerPlayerList.java | 9 +- .../packets/interface_/ChatMessage.java | 9 +- .../packets/interface_/CustomHud.java | 9 +- .../packets/interface_/CustomPage.java | 9 +- .../packets/interface_/CustomPageEvent.java | 9 +- .../interface_/EditorBlocksChange.java | 9 +- .../packets/interface_/HideEventTitle.java | 9 +- .../packets/interface_/KillFeedMessage.java | 9 +- .../packets/interface_/Notification.java | 9 +- .../interface_/OpenChatWithCommand.java | 9 +- .../RemoveFromServerPlayerList.java | 9 +- .../interface_/ResetUserInterfaceState.java | 9 +- .../packets/interface_/ServerInfo.java | 9 +- .../packets/interface_/ServerMessage.java | 9 +- .../protocol/packets/interface_/SetPage.java | 9 +- .../packets/interface_/ShowEventTitle.java | 9 +- .../packets/interface_/UpdateAnchorUI.java | 401 +++ .../interface_/UpdateKnownRecipes.java | 9 +- .../packets/interface_/UpdateLanguage.java | 9 +- .../packets/interface_/UpdatePortal.java | 9 +- .../interface_/UpdateServerPlayerList.java | 9 +- .../UpdateServerPlayerListPing.java | 9 +- .../UpdateVisibleHudComponents.java | 9 +- .../packets/interface_/WorldSavingStatus.java | 9 +- .../packets/inventory/DropCreativeItem.java | 9 +- .../packets/inventory/DropItemStack.java | 9 +- .../packets/inventory/InventoryAction.java | 9 +- .../packets/inventory/MoveItemStack.java | 9 +- .../packets/inventory/SetActiveSlot.java | 10 +- .../packets/inventory/SetCreativeItem.java | 9 +- .../inventory/SmartGiveCreativeItem.java | 9 +- .../packets/inventory/SmartMoveItemStack.java | 10 +- .../inventory/SwitchHotbarBlockSet.java | 9 +- .../inventory/UpdatePlayerInventory.java | 9 +- .../machinima/RequestMachinimaActorModel.java | 9 +- .../machinima/SetMachinimaActorModel.java | 9 +- .../machinima/UpdateMachinimaScene.java | 10 +- .../packets/player/ClearDebugShapes.java | 9 +- .../packets/player/ClientMovement.java | 9 +- .../packets/player/ClientPlaceBlock.java | 9 +- .../protocol/packets/player/ClientReady.java | 9 +- .../packets/player/ClientTeleport.java | 9 +- .../protocol/packets/player/DamageInfo.java | 9 +- .../protocol/packets/player/DisplayDebug.java | 9 +- .../protocol/packets/player/JoinWorld.java | 9 +- .../protocol/packets/player/LoadHotbar.java | 9 +- .../packets/player/MouseInteraction.java | 9 +- .../packets/player/RemoveMapMarker.java | 9 +- .../protocol/packets/player/ReticleEvent.java | 9 +- .../protocol/packets/player/SaveHotbar.java | 9 +- .../player/SetBlockPlacementOverride.java | 9 +- .../protocol/packets/player/SetClientId.java | 9 +- .../protocol/packets/player/SetGameMode.java | 9 +- .../packets/player/SetMovementStates.java | 9 +- .../packets/player/SyncPlayerPreferences.java | 9 +- .../player/UpdateMemoriesFeatureStatus.java | 9 +- .../player/UpdateMovementSettings.java | 9 +- .../serveraccess/RequestServerAccess.java | 9 +- .../packets/serveraccess/SetServerAccess.java | 9 +- .../serveraccess/UpdateServerAccess.java | 9 +- .../protocol/packets/setup/AssetFinalize.java | 9 +- .../packets/setup/AssetInitialize.java | 9 +- .../protocol/packets/setup/AssetPart.java | 9 +- .../protocol/packets/setup/PlayerOptions.java | 9 +- .../protocol/packets/setup/RemoveAssets.java | 9 +- .../protocol/packets/setup/RequestAssets.java | 9 +- .../setup/RequestCommonAssetsRebuild.java | 9 +- .../protocol/packets/setup/ServerTags.java | 9 +- .../packets/setup/SetTimeDilation.java | 9 +- .../protocol/packets/setup/SetUpdateRate.java | 9 +- .../packets/setup/UpdateFeatures.java | 9 +- .../protocol/packets/setup/ViewRadius.java | 10 +- .../packets/setup/WorldLoadFinished.java | 9 +- .../packets/setup/WorldLoadProgress.java | 9 +- .../protocol/packets/setup/WorldSettings.java | 9 +- .../packets/window/ClientOpenWindow.java | 9 +- .../protocol/packets/window/CloseWindow.java | 10 +- .../protocol/packets/window/OpenWindow.java | 9 +- .../packets/window/SendWindowAction.java | 9 +- .../protocol/packets/window/UpdateWindow.java | 9 +- .../world/ClearEditorTimeOverride.java | 9 +- .../packets/world/PlaySoundEvent2D.java | 9 +- .../packets/world/PlaySoundEvent3D.java | 9 +- .../packets/world/PlaySoundEventEntity.java | 9 +- .../packets/world/ServerSetBlock.java | 9 +- .../packets/world/ServerSetBlocks.java | 9 +- .../packets/world/ServerSetFluid.java | 9 +- .../packets/world/ServerSetFluids.java | 9 +- .../packets/world/ServerSetPaused.java | 9 +- .../protocol/packets/world/SetChunk.java | 9 +- .../packets/world/SetChunkEnvironments.java | 9 +- .../packets/world/SetChunkHeightmap.java | 9 +- .../packets/world/SetChunkTintmap.java | 9 +- .../protocol/packets/world/SetFluids.java | 9 +- .../protocol/packets/world/SetPaused.java | 9 +- .../world/SpawnBlockParticleSystem.java | 9 +- .../packets/world/SpawnParticleSystem.java | 9 +- .../protocol/packets/world/UnloadChunk.java | 9 +- .../packets/world/UpdateBlockDamage.java | 9 +- .../world/UpdateEditorTimeOverride.java | 9 +- .../world/UpdateEditorWeatherOverride.java | 9 +- .../packets/world/UpdateEnvironmentMusic.java | 9 +- .../packets/world/UpdatePostFxSettings.java | 9 +- .../packets/world/UpdateSleepState.java | 9 +- .../packets/world/UpdateSunSettings.java | 9 +- .../protocol/packets/world/UpdateTime.java | 9 +- .../packets/world/UpdateTimeSettings.java | 9 +- .../protocol/packets/world/UpdateWeather.java | 9 +- .../packets/worldmap/ClearWorldMap.java | 9 +- .../packets/worldmap/CreateUserMarker.java | 9 +- .../worldmap/TeleportToWorldMapMarker.java | 9 +- .../worldmap/TeleportToWorldMapPosition.java | 9 +- .../packets/worldmap/UpdateWorldMap.java | 9 +- .../worldmap/UpdateWorldMapSettings.java | 9 +- .../worldmap/UpdateWorldMapVisible.java | 9 +- src/com/hypixel/hytale/registry/Registry.java | 10 + .../hypixel/hytale/server/core/Constants.java | 2 + .../hytale/server/core/HytaleServer.java | 6 + .../server/core/HytaleServerConfig.java | 292 +-- .../hytale/server/core/asset/AssetModule.java | 38 +- .../core/asset/AssetRegistryLoader.java | 6 +- .../server/core/asset/HytaleAssetStore.java | 22 +- .../core/asset/common/CommonAssetModule.java | 10 +- .../asset/packet/AssetPacketGenerator.java | 8 +- .../packet/DefaultAssetPacketGenerator.java | 12 +- .../packet/SimpleAssetPacketGenerator.java | 12 +- .../ambiencefx/AmbienceFXPacketGenerator.java | 8 +- .../AudioCategoryPacketGenerator.java | 10 +- .../BlockBreakingDecalPacketGenerator.java | 8 +- .../BlockBoundingBoxesPacketGenerator.java | 10 +- .../BlockParticleSetPacketGenerator.java | 8 +- .../blockset/BlockSetPacketGenerator.java | 10 +- .../BlockSoundSetPacketGenerator.java | 10 +- .../blocktick/config/RandomTickProcedure.java | 14 + .../blocktype/BlockGroupPacketGenerator.java | 8 +- .../blocktype/BlockTypePacketGenerator.java | 10 +- .../type/blocktype/config/BlockType.java | 13 + .../type/buildertool/config/BrushData.java | 2 +- .../EntityEffectPacketGenerator.java | 10 +- .../EnvironmentPacketGenerator.java | 8 +- .../EqualizerEffectPacketGenerator.java | 10 +- .../asset/type/fluid/FireFluidTicker.java | 2 +- .../type/fluid/FluidTypePacketGenerator.java | 8 +- .../type/fluidfx/FluidFXPacketGenerator.java | 8 +- .../FieldcraftCategoryPacketGenerator.java | 8 +- .../item/ItemCategoryPacketGenerator.java | 8 +- .../item/ResourceTypePacketGenerator.java | 8 +- .../type/item/config/CraftingRecipe.java | 6 +- .../core/asset/type/item/config/Item.java | 13 + .../ItemPlayerAnimationsPacketGenerator.java | 8 +- .../ItemSoundSetPacketGenerator.java | 10 +- .../core/asset/type/model/config/Model.java | 76 +- .../asset/type/model/config/ModelAsset.java | 30 +- .../type/model/config/ModelParticle.java | 18 +- .../modelvfx/ModelVFXPacketGenerator.java | 8 +- .../ParticleSpawnerPacketGenerator.java | 8 +- .../ParticleSystemPacketGenerator.java | 8 +- .../asset/type/portalworld/PortalSpawn.java | 69 - .../asset/type/portalworld/PortalType.java | 11 - .../ReverbEffectPacketGenerator.java | 10 +- .../soundevent/SoundEventPacketGenerator.java | 8 +- .../soundset/SoundSetPacketGenerator.java | 8 +- .../tagpattern/TagPatternPacketGenerator.java | 8 +- .../type/trail/TrailPacketGenerator.java | 8 +- .../type/weather/WeatherPacketGenerator.java | 8 +- .../command/commands/debug/AssetsCommand.java | 5 +- .../commands/debug/stresstest/Bot.java | 8 +- .../commands/player/camera/CameraDemo.java | 2 +- .../server/auth/AuthStatusCommand.java | 17 +- .../commands/utility/BackupCommand.java | 3 +- .../commands/utility/UIGalleryCommand.java | 49 + .../commands/utility/net/NetworkCommand.java | 176 ++ .../core/command/system/CommandManager.java | 2 + .../command/system/pages/CommandListPage.java | 12 +- .../command/system/pages/UIGalleryPage.java | 231 ++ .../server/core/config/BackupConfig.java | 172 ++ .../hytale/server/core/config/ModConfig.java | 46 + .../server/core/config/RateLimitConfig.java | 74 + .../server/core/config/UpdateConfig.java | 159 ++ .../server/core/entity/entities/Player.java | 4 +- .../entities/player/pages/PageManager.java | 9 +- .../movement/MovementStatesSystems.java | 6 +- .../entity/nameplate/NameplateSystems.java | 7 +- .../server/core/inventory/Inventory.java | 4 + .../hytale/server/core/io/PacketHandler.java | 143 +- .../core/io/PacketStatsRecorderImpl.java | 2 +- .../io/handlers/GenericPacketHandler.java | 16 +- .../core/io/handlers/IPacketHandler.java | 4 +- .../core/io/handlers/IWorldPacketHandler.java | 39 + .../io/handlers/InitialPacketHandler.java | 48 +- .../core/io/handlers/SetupPacketHandler.java | 43 +- .../io/handlers/game/GamePacketHandler.java | 197 +- .../login/AuthenticationPacketHandler.java | 8 +- .../io/handlers/login/HandshakeHandler.java | 67 +- .../handlers/login/PasswordPacketHandler.java | 18 +- .../io/netty/HytaleChannelInitializer.java | 34 +- .../server/core/io/netty/NettyUtil.java | 32 + .../core/io/netty/PlayerChannelHandler.java | 4 +- .../core/io/transport/QUICTransport.java | 7 +- .../anchoraction/AnchorActionHandler.java | 10 + .../anchoraction/AnchorActionModule.java | 83 + .../core/modules/block/BlockModule.java | 9 +- .../modules/blockhealth/BlockHealthChunk.java | 4 +- .../blockhealth/BlockHealthModule.java | 4 +- .../server/core/modules/debug/DebugUtils.java | 28 +- .../modules/entity/BlockEntitySystems.java | 8 +- .../core/modules/entity/EntityModule.java | 2 +- .../modules/entity/damage/DamageSystems.java | 9 +- .../modules/entity/damage/DeathSystems.java | 2 +- .../HitboxCollisionConfigPacketGenerator.java | 8 +- .../HitboxCollisionSystems.java | 6 +- .../core/modules/entity/item/ItemSystems.java | 8 +- .../modules/entity/player/ChunkTracker.java | 15 +- .../modules/entity/player/PlayerSystems.java | 84 +- .../RepulsionConfigPacketGenerator.java | 8 +- .../entity/repulsion/RepulsionSystems.java | 6 +- .../modules/entity/system/AudioSystems.java | 7 +- .../system/EntityInteractableSystems.java | 5 +- .../modules/entity/system/EntitySystems.java | 10 +- .../entity/system/IntangibleSystems.java | 5 +- .../entity/system/InvulnerableSystems.java | 5 +- .../modules/entity/system/ModelSystems.java | 16 +- .../entity/system/RespondToHitSystems.java | 5 +- .../entity/system/TransformSystems.java | 7 +- .../entity/tracker/EntityTrackerSystems.java | 7 +- .../tracker/LegacyEntityTrackerSystems.java | 41 +- .../modules/entitystats/EntityStatMap.java | 26 +- .../entitystats/EntityStatsSystems.java | 18 +- .../asset/EntityStatTypePacketGenerator.java | 10 +- .../modules/entityui/UIComponentSystems.java | 6 +- .../EntityUIComponentPacketGenerator.java | 10 +- .../InteractionPacketGenerator.java | 8 +- .../RootInteractionPacketGenerator.java | 8 +- .../UnarmedInteractionsPacketGenerator.java | 8 +- .../server/ModifyInventoryInteraction.java | 2 +- .../system/InteractionSystems.java | 7 +- .../item/CraftingRecipePacketGenerator.java | 8 +- .../modules/item/ItemPacketGenerator.java | 8 +- .../item/ItemQualityPacketGenerator.java | 10 +- .../ItemReticleConfigPacketGenerator.java | 10 +- .../modules/item/RecipePacketGenerator.java | 8 +- .../ProjectileConfigPacketGenerator.java | 8 +- .../system/PredictedProjectileSystems.java | 7 +- .../commands/PlayCommandBase.java | 5 +- .../hytale/server/core/plugin/JavaPlugin.java | 10 +- .../server/core/plugin/PluginManager.java | 7 +- .../core/plugin/commands/PluginCommand.java | 4 +- .../server/core/receiver/IPacketReceiver.java | 6 +- .../hytale/server/core/universe/Universe.java | 90 +- .../core/universe/world/PlayerUtil.java | 8 +- .../server/core/universe/world/World.java | 3 +- .../core/universe/world/WorldConfig.java | 8 +- .../core/universe/world/WorldMapTracker.java | 3 +- .../world/WorldNotificationHandler.java | 22 +- .../core/universe/world/chunk/BlockChunk.java | 4 +- .../world/chunk/BlockComponentChunk.java | 6 +- .../universe/world/chunk/EntityChunk.java | 7 +- .../world/chunk/section/BlockSection.java | 102 +- .../world/commands/WorldSettingsCommand.java | 4 +- .../block/bulk/BlockBulkFindHereCommand.java | 7 +- .../block/bulk/BlockBulkReplaceCommand.java | 4 +- .../world/commands/world/WorldCommand.java | 1 + .../commands/world/WorldRocksDbCommand.java | 44 + .../universe/world/meta/BlockStateModule.java | 6 +- .../world/meta/state/SendableBlockState.java | 6 +- .../universe/world/storage/ChunkStore.java | 68 +- .../provider/DefaultChunkStorageProvider.java | 44 +- .../provider/EmptyChunkStorageProvider.java | 21 +- .../provider/IChunkStorageProvider.java | 75 +- .../IndexedStorageChunkStorageProvider.java | 92 +- .../MigrationChunkStorageProvider.java | 46 +- .../provider/RocksDbChunkStorageProvider.java | 229 ++ .../server/core/update/UpdateModule.java | 31 +- .../server/core/update/UpdateService.java | 4 +- .../update/command/UpdateApplyCommand.java | 19 +- .../command/UpdatePatchlineCommand.java | 4 +- .../hytale/server/core/util/DumpUtil.java | 40 +- .../server/core/util/backup/BackupTask.java | 9 +- .../hypixel/hytale/server/flock/Flock.java | 15 + .../hytale/server/flock/FlockMembership.java | 54 +- .../server/flock/FlockMembershipSystems.java | 30 + .../hytale/server/flock/FlockPlugin.java | 1 + .../hytale/server/flock/FlockSystems.java | 148 ++ .../npc/blackboard/view/event/EventView.java | 2 +- .../audiovisual/ActionSpawnParticles.java | 30 +- .../builders/BuilderActionSpawnParticles.java | 16 + .../server/npc/role/RoleDebugFlags.java | 2 + .../server/npc/role/support/DebugSupport.java | 4 + .../server/npc/role/support/StateSupport.java | 39 +- .../server/npc/systems/RoleSystems.java | 113 +- .../system/ChunkSuppressionSystems.java | 16 +- .../system/SpawnSuppressionSystems.java | 2 +- .../world/system/WorldSpawningSystem.java | 43 +- .../worldgen/loader/AssetFileSystem.java | 47 +- .../loader/ChunkGeneratorJsonLoader.java | 24 +- .../worldgen/loader/WorldGenPrefabLoader.java | 5 +- src/manifests.json | 14 +- 550 files changed, 12847 insertions(+), 5414 deletions(-) create mode 100644 src/com/hypixel/hytale/builtin/adventure/teleporter/system/TurnOffTeleportersSystem.java create mode 100644 src/com/hypixel/hytale/builtin/creativehub/systems/ReturnToHubButtonSystem.java create mode 100644 src/com/hypixel/hytale/builtin/creativehub/ui/ReturnToHubButtonUI.java delete mode 100644 src/com/hypixel/hytale/builtin/hytalegenerator/patterns/CeilingPattern.java create mode 100644 src/com/hypixel/hytale/builtin/randomtick/RandomTick.java create mode 100644 src/com/hypixel/hytale/builtin/randomtick/RandomTickPlugin.java create mode 100644 src/com/hypixel/hytale/builtin/randomtick/RandomTickSystem.java create mode 100644 src/com/hypixel/hytale/builtin/randomtick/procedures/ChangeIntoBlockProcedure.java create mode 100644 src/com/hypixel/hytale/builtin/randomtick/procedures/SpreadToProcedure.java delete mode 100644 src/com/hypixel/hytale/builtin/worldgen/FeatureFlags.java create mode 100644 src/com/hypixel/hytale/protocol/ActiveAnimationsUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/AudioUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/BlockUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/DynamicLightUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/EntityEffectsUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/EntityStatsUpdate.java rename src/com/hypixel/hytale/protocol/{Equipment.java => EquipmentUpdate.java} (94%) create mode 100644 src/com/hypixel/hytale/protocol/HitboxCollisionUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/IntangibleUpdate.java rename src/com/hypixel/hytale/protocol/{Nameplate.java => InteractableUpdate.java} (51%) create mode 100644 src/com/hypixel/hytale/protocol/InteractionsUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/InvulnerableUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/ItemUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/ModelUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/MovementStatesUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/NameplateUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/NetworkChannel.java create mode 100644 src/com/hypixel/hytale/protocol/NewSpawnUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/PlayerSkinUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/PredictionUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/PropUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/RepulsionUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/RespondToHitUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/ToClientPacket.java create mode 100644 src/com/hypixel/hytale/protocol/ToServerPacket.java create mode 100644 src/com/hypixel/hytale/protocol/TransformUpdate.java create mode 100644 src/com/hypixel/hytale/protocol/UIComponentsUpdate.java delete mode 100644 src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorEnableAssetPack.java delete mode 100644 src/com/hypixel/hytale/protocol/packets/auth/Status.java create mode 100644 src/com/hypixel/hytale/protocol/packets/interface_/UpdateAnchorUI.java create mode 100644 src/com/hypixel/hytale/server/core/asset/type/blocktick/config/RandomTickProcedure.java delete mode 100644 src/com/hypixel/hytale/server/core/asset/type/portalworld/PortalSpawn.java create mode 100644 src/com/hypixel/hytale/server/core/command/commands/utility/UIGalleryCommand.java create mode 100644 src/com/hypixel/hytale/server/core/command/system/pages/UIGalleryPage.java create mode 100644 src/com/hypixel/hytale/server/core/config/BackupConfig.java create mode 100644 src/com/hypixel/hytale/server/core/config/ModConfig.java create mode 100644 src/com/hypixel/hytale/server/core/config/RateLimitConfig.java create mode 100644 src/com/hypixel/hytale/server/core/config/UpdateConfig.java create mode 100644 src/com/hypixel/hytale/server/core/io/handlers/IWorldPacketHandler.java create mode 100644 src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionHandler.java create mode 100644 src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionModule.java create mode 100644 src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldRocksDbCommand.java create mode 100644 src/com/hypixel/hytale/server/core/universe/world/storage/provider/RocksDbChunkStorageProvider.java diff --git a/src/com/hypixel/hytale/builtin/adventure/camera/asset/camerashake/CameraShakePacketGenerator.java b/src/com/hypixel/hytale/builtin/adventure/camera/asset/camerashake/CameraShakePacketGenerator.java index 6d4ee7fa..88328f81 100644 --- a/src/com/hypixel/hytale/builtin/adventure/camera/asset/camerashake/CameraShakePacketGenerator.java +++ b/src/com/hypixel/hytale/builtin/adventure/camera/asset/camerashake/CameraShakePacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.builtin.adventure.camera.asset.camerashake; import com.hypixel.hytale.assetstore.map.IndexedAssetMap; import com.hypixel.hytale.protocol.CachedPacket; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateCameraShake; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,17 +14,17 @@ import javax.annotation.Nonnull; public class CameraShakePacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map assets) { return toCachedPacket(UpdateType.Init, assetMap, assets); } @Nonnull - protected Packet generateUpdatePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map loadedAssets) { + protected ToClientPacket generateUpdatePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map loadedAssets) { return toCachedPacket(UpdateType.AddOrUpdate, assetMap, loadedAssets); } @Nonnull - protected Packet generateRemovePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Set removed) { + protected ToClientPacket generateRemovePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Set removed) { Int2ObjectOpenHashMap profiles = new Int2ObjectOpenHashMap<>(); for (String key : removed) { @@ -39,7 +39,7 @@ public class CameraShakePacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map assets ) { Int2ObjectOpenHashMap profiles = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/builtin/adventure/camera/asset/viewbobbing/ViewBobbingPacketGenerator.java b/src/com/hypixel/hytale/builtin/adventure/camera/asset/viewbobbing/ViewBobbingPacketGenerator.java index 82384cad..cecfedc9 100644 --- a/src/com/hypixel/hytale/builtin/adventure/camera/asset/viewbobbing/ViewBobbingPacketGenerator.java +++ b/src/com/hypixel/hytale/builtin/adventure/camera/asset/viewbobbing/ViewBobbingPacketGenerator.java @@ -3,7 +3,7 @@ package com.hypixel.hytale.builtin.adventure.camera.asset.viewbobbing; import com.hypixel.hytale.assetstore.AssetMap; import com.hypixel.hytale.protocol.CachedPacket; import com.hypixel.hytale.protocol.MovementType; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateViewBobbing; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -16,19 +16,19 @@ import javax.annotation.Nonnull; public class ViewBobbingPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull @Override - public Packet generateInitPacket(AssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(AssetMap assetMap, @Nonnull Map assets) { return toCachedPacket(UpdateType.Init, assets); } @Nonnull @Override - protected Packet generateUpdatePacket(AssetMap assetMap, @Nonnull Map loadedAssets) { + protected ToClientPacket generateUpdatePacket(AssetMap assetMap, @Nonnull Map loadedAssets) { return toCachedPacket(UpdateType.AddOrUpdate, loadedAssets); } @Nonnull @Override - protected Packet generateRemovePacket(AssetMap assetMap, @Nonnull Set removed) { + protected ToClientPacket generateRemovePacket(AssetMap assetMap, @Nonnull Set removed) { UpdateViewBobbing packet = new UpdateViewBobbing(); packet.type = UpdateType.Remove; packet.profiles = new EnumMap<>(MovementType.class); @@ -41,7 +41,7 @@ public class ViewBobbingPacketGenerator extends SimpleAssetPacketGenerator assets) { + protected static ToClientPacket toCachedPacket(@Nonnull UpdateType type, @Nonnull Map assets) { UpdateViewBobbing packet = new UpdateViewBobbing(); packet.type = type; packet.profiles = new EnumMap<>(MovementType.class); diff --git a/src/com/hypixel/hytale/builtin/adventure/farming/FarmingUtil.java b/src/com/hypixel/hytale/builtin/adventure/farming/FarmingUtil.java index f4b2fc1a..a4034352 100644 --- a/src/com/hypixel/hytale/builtin/adventure/farming/FarmingUtil.java +++ b/src/com/hypixel/hytale/builtin/adventure/farming/FarmingUtil.java @@ -172,7 +172,7 @@ public class FarmingUtil { } } - public static void harvest( + public static boolean harvest( @Nonnull World world, @Nonnull ComponentAccessor componentAccessor, @Nonnull Ref ref, @@ -180,9 +180,9 @@ public class FarmingUtil { int rotationIndex, @Nonnull Vector3i blockPosition ) { - if (world.getGameplayConfig().getWorldConfig().isBlockGatheringAllowed()) { - harvest0(componentAccessor, ref, blockType, rotationIndex, blockPosition); - } + return world.getGameplayConfig().getWorldConfig().isBlockGatheringAllowed() + ? harvest0(componentAccessor, ref, blockType, rotationIndex, blockPosition) + : false; } @Nullable @@ -212,24 +212,19 @@ public class FarmingUtil { @Nonnull Vector3i blockPosition ) { FarmingData farmingConfig = blockType.getFarming(); + boolean isFarmable = true; if (farmingConfig == null || farmingConfig.getStages() == null) { - return false; - } else if (blockType.getGathering().getHarvest() == null) { + isFarmable = false; + } + + if (blockType.getGathering().getHarvest() == null) { return false; } else { World world = store.getExternalData().getWorld(); Vector3d centerPosition = new Vector3d(); blockType.getBlockCenter(rotationIndex, centerPosition); centerPosition.add(blockPosition); - if (farmingConfig.getStageSetAfterHarvest() == null) { - giveDrops(store, ref, centerPosition, blockType); - WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z)); - if (chunk != null) { - chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z); - } - - return true; - } else { + if (isFarmable && farmingConfig.getStageSetAfterHarvest() != null) { giveDrops(store, ref, centerPosition, blockType); Map stageSets = farmingConfig.getStages(); FarmingStageData[] stages = stageSets.get(farmingConfig.getStartingStageSet()); @@ -307,6 +302,14 @@ public class FarmingUtil { return false; } } + } else { + giveDrops(store, ref, centerPosition, blockType); + WorldChunk chunk = world.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(blockPosition.x, blockPosition.z)); + if (chunk != null) { + chunk.breakBlock(blockPosition.x, blockPosition.y, blockPosition.z); + } + + return true; } } } diff --git a/src/com/hypixel/hytale/builtin/adventure/farming/interactions/HarvestCropInteraction.java b/src/com/hypixel/hytale/builtin/adventure/farming/interactions/HarvestCropInteraction.java index 28c5a8a1..e8e94f27 100644 --- a/src/com/hypixel/hytale/builtin/adventure/farming/interactions/HarvestCropInteraction.java +++ b/src/com/hypixel/hytale/builtin/adventure/farming/interactions/HarvestCropInteraction.java @@ -1,11 +1,14 @@ package com.hypixel.hytale.builtin.adventure.farming.interactions; import com.hypixel.hytale.builtin.adventure.farming.FarmingUtil; +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.builder.BuilderCodec; import com.hypixel.hytale.component.CommandBuffer; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.vector.Vector3i; +import com.hypixel.hytale.protocol.InteractionState; import com.hypixel.hytale.protocol.InteractionType; import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.entity.InteractionContext; @@ -27,7 +30,16 @@ public class HarvestCropInteraction extends SimpleBlockInteraction { HarvestCropInteraction.class, HarvestCropInteraction::new, SimpleBlockInteraction.CODEC ) .documentation("Harvests the resources from the target farmable block.") + .appendInherited( + new KeyedCodec<>("RequireNotBroken", Codec.BOOLEAN), + (interaction, s) -> interaction.requireNotBroken = s, + interaction -> interaction.requireNotBroken, + (interaction, parent) -> interaction.requireNotBroken = parent.requireNotBroken + ) + .documentation("If true, the interaction will fail if the held item is broken (durability = 0).") + .add() .build(); + protected boolean requireNotBroken = false; @Override protected void interactWithBlock( @@ -39,25 +51,31 @@ public class HarvestCropInteraction extends SimpleBlockInteraction { @Nonnull Vector3i targetBlock, @Nonnull CooldownHandler cooldownHandler ) { - Ref ref = context.getEntity(); - ChunkStore chunkStore = world.getChunkStore(); - long chunkIndex = ChunkUtil.indexChunkFromBlock(targetBlock.x, targetBlock.z); - Ref chunkRef = chunkStore.getChunkReference(chunkIndex); - if (chunkRef != null && chunkRef.isValid()) { - BlockChunk blockChunkComponent = chunkStore.getStore().getComponent(chunkRef, BlockChunk.getComponentType()); + if (this.requireNotBroken && itemInHand != null && itemInHand.isBroken()) { + context.getState().state = InteractionState.Failed; + } else { + Ref ref = context.getEntity(); + ChunkStore chunkStore = world.getChunkStore(); + long chunkIndex = ChunkUtil.indexChunkFromBlock(targetBlock.x, targetBlock.z); + Ref chunkRef = chunkStore.getChunkReference(chunkIndex); + if (chunkRef != null && chunkRef.isValid()) { + BlockChunk blockChunkComponent = chunkStore.getStore().getComponent(chunkRef, BlockChunk.getComponentType()); - assert blockChunkComponent != null; + assert blockChunkComponent != null; - BlockSection blockSection = blockChunkComponent.getSectionAtBlockY(targetBlock.y); - if (blockSection != null) { - WorldChunk worldChunkComponent = chunkStore.getStore().getComponent(chunkRef, WorldChunk.getComponentType()); + BlockSection blockSection = blockChunkComponent.getSectionAtBlockY(targetBlock.y); + if (blockSection != null) { + WorldChunk worldChunkComponent = chunkStore.getStore().getComponent(chunkRef, WorldChunk.getComponentType()); - assert worldChunkComponent != null; + assert worldChunkComponent != null; - BlockType blockType = worldChunkComponent.getBlockType(targetBlock); - if (blockType != null) { - int rotationIndex = blockSection.getRotationIndex(targetBlock.x, targetBlock.y, targetBlock.z); - FarmingUtil.harvest(world, commandBuffer, ref, blockType, rotationIndex, targetBlock); + BlockType blockType = worldChunkComponent.getBlockType(targetBlock); + if (blockType != null) { + int rotationIndex = blockSection.getRotationIndex(targetBlock.x, targetBlock.y, targetBlock.z); + if (!FarmingUtil.harvest(world, commandBuffer, ref, blockType, rotationIndex, targetBlock)) { + context.getState().state = InteractionState.Failed; + } + } } } } diff --git a/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemory.java b/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemory.java index 08daa96f..821be62d 100644 --- a/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemory.java +++ b/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemory.java @@ -35,7 +35,6 @@ import com.hypixel.hytale.server.core.modules.entity.component.TransformComponen import com.hypixel.hytale.server.core.modules.entity.item.ItemComponent; import com.hypixel.hytale.server.core.modules.entity.item.PickupItemComponent; import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId; -import com.hypixel.hytale.server.core.modules.i18n.I18nModule; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; @@ -62,12 +61,6 @@ public class NPCMemory extends Memory { .add() .append(new KeyedCodec<>("TranslationKey", Codec.STRING), (npcMemory, s) -> npcMemory.memoryTitleKey = s, npcMemory -> npcMemory.memoryTitleKey) .add() - .append( - new KeyedCodec<>("IsMemoriesNameOverridden", Codec.BOOLEAN), - (npcMemory, aBoolean) -> npcMemory.isMemoriesNameOverridden = aBoolean, - npcMemory -> npcMemory.isMemoriesNameOverridden - ) - .add() .append( new KeyedCodec<>("CapturedTimestamp", Codec.LONG), (npcMemory, aDouble) -> npcMemory.capturedTimestamp = aDouble, @@ -86,10 +79,8 @@ public class NPCMemory extends Memory { npcMemory -> npcMemory.foundLocationGeneralNameKey ) .add() - .afterDecode(NPCMemory::processConfig) .build(); private String npcRole; - private boolean isMemoriesNameOverridden; private long capturedTimestamp; private String foundLocationZoneNameKey; private String foundLocationGeneralNameKey; @@ -98,11 +89,9 @@ public class NPCMemory extends Memory { private NPCMemory() { } - public NPCMemory(@Nonnull String npcRole, @Nonnull String nameTranslationKey, boolean isMemoriesNameOverridden) { + public NPCMemory(@Nonnull String npcRole, @Nonnull String nameTranslationKey) { this.npcRole = npcRole; this.memoryTitleKey = nameTranslationKey; - this.isMemoriesNameOverridden = isMemoriesNameOverridden; - this.processConfig(); } @Override @@ -128,19 +117,6 @@ public class NPCMemory extends Memory { return "UI/Custom/Pages/Memories/npcs/" + this.npcRole + ".png"; } - public void processConfig() { - if (this.isMemoriesNameOverridden) { - this.memoryTitleKey = "server.npcRoles." + this.npcRole + ".name"; - if (I18nModule.get().getMessage("en-US", this.memoryTitleKey) == null) { - this.memoryTitleKey = "server.memories.names." + this.npcRole; - } - } - - if (this.memoryTitleKey == null || this.memoryTitleKey.isEmpty()) { - this.memoryTitleKey = "server.npcRoles." + this.npcRole + ".name"; - } - } - @Nonnull @Override public Message getUndiscoveredTooltipText() { @@ -177,15 +153,14 @@ public class NPCMemory extends Memory { return false; } else { NPCMemory npcMemory = (NPCMemory)o; - return this.isMemoriesNameOverridden == npcMemory.isMemoriesNameOverridden && Objects.equals(this.npcRole, npcMemory.npcRole); + return Objects.equals(this.npcRole, npcMemory.npcRole); } } @Override public int hashCode() { int result = super.hashCode(); - result = 31 * result + Objects.hashCode(this.npcRole); - return 31 * result + Boolean.hashCode(this.isMemoriesNameOverridden); + return 31 * result + Objects.hashCode(this.npcRole); } @Nonnull @@ -193,8 +168,6 @@ public class NPCMemory extends Memory { public String toString() { return "NPCMemory{npcRole='" + this.npcRole - + "', isMemoriesNameOverride=" - + this.isMemoriesNameOverridden + "', capturedTimestamp=" + this.capturedTimestamp + "', foundLocationZoneNameKey='" @@ -271,46 +244,41 @@ public class NPCMemory extends Memory { if (npcComponent != null) { Role role = npcComponent.getRole(); if (role != null && role.isMemory()) { - temp.isMemoriesNameOverridden = role.isMemoriesNameOverriden(); - temp.npcRole = temp.isMemoriesNameOverridden ? role.getMemoriesNameOverride() : npcComponent.getRoleName(); + String memoriesNameOverride = role.getMemoriesNameOverride(); + temp.npcRole = memoriesNameOverride != null && !memoriesNameOverride.isEmpty() ? memoriesNameOverride : npcComponent.getRoleName(); temp.memoryTitleKey = role.getNameTranslationKey(); temp.capturedTimestamp = System.currentTimeMillis(); temp.foundLocationGeneralNameKey = foundLocationZoneNameKey; - if (!memoriesPlugin.hasRecordedMemory(temp)) { - temp.processConfig(); - if (playerMemoriesComponent.recordMemory(temp)) { - NotificationUtil.sendNotification( - playerRefComponent.getPacketHandler(), - Message.translation("server.memories.general.collected").param("memoryTitle", Message.translation(temp.getTitle())), - null, - "NotificationIcons/MemoriesIcon.png" - ); - temp = new NPCMemory(); - TransformComponent npcTransformComponent = commandBuffer.getComponent(npcRef, TransformComponent.getComponentType()); - if (npcTransformComponent != null) { - MemoriesGameplayConfig memoriesGameplayConfig = MemoriesGameplayConfig.get( - store.getExternalData().getWorld().getGameplayConfig() - ); - if (memoriesGameplayConfig != null) { - ItemStack memoryItemStack = new ItemStack(memoriesGameplayConfig.getMemoriesCatchItemId()); - Vector3d memoryItemHolderPosition = npcTransformComponent.getPosition().clone(); - BoundingBox boundingBoxComponent = commandBuffer.getComponent(npcRef, BoundingBox.getComponentType()); - if (boundingBoxComponent != null) { - memoryItemHolderPosition.y = memoryItemHolderPosition.y + boundingBoxComponent.getBoundingBox().middleY(); - } - - Holder memoryItemHolder = ItemComponent.generatePickedUpItem( - memoryItemStack, memoryItemHolderPosition, commandBuffer, ref - ); - float memoryCatchItemLifetimeS = 0.62F; - PickupItemComponent pickupItemComponent = memoryItemHolder.getComponent(PickupItemComponent.getComponentType()); - - assert pickupItemComponent != null; - - pickupItemComponent.setInitialLifeTime(0.62F); - commandBuffer.addEntity(memoryItemHolder, AddReason.SPAWN); - displayCatchEntityParticles(memoriesGameplayConfig, memoryItemHolderPosition, npcRef, commandBuffer); + if (!memoriesPlugin.hasRecordedMemory(temp) && playerMemoriesComponent.recordMemory(temp)) { + NotificationUtil.sendNotification( + playerRefComponent.getPacketHandler(), + Message.translation("server.memories.general.collected").param("memoryTitle", Message.translation(temp.getTitle())), + null, + "NotificationIcons/MemoriesIcon.png" + ); + temp = new NPCMemory(); + TransformComponent npcTransformComponent = commandBuffer.getComponent(npcRef, TransformComponent.getComponentType()); + if (npcTransformComponent != null) { + MemoriesGameplayConfig memoriesGameplayConfig = MemoriesGameplayConfig.get(store.getExternalData().getWorld().getGameplayConfig()); + if (memoriesGameplayConfig != null) { + ItemStack memoryItemStack = new ItemStack(memoriesGameplayConfig.getMemoriesCatchItemId()); + Vector3d memoryItemHolderPosition = npcTransformComponent.getPosition().clone(); + BoundingBox boundingBoxComponent = commandBuffer.getComponent(npcRef, BoundingBox.getComponentType()); + if (boundingBoxComponent != null) { + memoryItemHolderPosition.y = memoryItemHolderPosition.y + boundingBoxComponent.getBoundingBox().middleY(); } + + Holder memoryItemHolder = ItemComponent.generatePickedUpItem( + memoryItemStack, memoryItemHolderPosition, commandBuffer, ref + ); + float memoryCatchItemLifetimeS = 0.62F; + PickupItemComponent pickupItemComponent = memoryItemHolder.getComponent(PickupItemComponent.getComponentType()); + + assert pickupItemComponent != null; + + pickupItemComponent.setInitialLifeTime(0.62F); + commandBuffer.addEntity(memoryItemHolder, AddReason.SPAWN); + displayCatchEntityParticles(memoriesGameplayConfig, memoryItemHolderPosition, npcRef, commandBuffer); } } } diff --git a/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemoryProvider.java b/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemoryProvider.java index 551e6bf7..37446185 100644 --- a/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemoryProvider.java +++ b/src/com/hypixel/hytale/builtin/adventure/memories/memories/npc/NPCMemoryProvider.java @@ -42,9 +42,9 @@ public class NPCMemoryProvider extends MemoryProvider { String translationKey = getNPCNameTranslationKey(builder); NPCMemory memory; if (memoriesNameOverride != null && !memoriesNameOverride.isEmpty()) { - memory = new NPCMemory(memoriesNameOverride, translationKey, true); + memory = new NPCMemory(memoriesNameOverride, translationKey); } else { - memory = new NPCMemory(builderInfo.getKeyName(), translationKey, false); + memory = new NPCMemory(builderInfo.getKeyName(), translationKey); } allMemories.computeIfAbsent(category, s -> new HashSet<>()).add(memory); diff --git a/src/com/hypixel/hytale/builtin/adventure/memories/page/MemoriesPage.java b/src/com/hypixel/hytale/builtin/adventure/memories/page/MemoriesPage.java index 68d7b787..9e4b057a 100644 --- a/src/com/hypixel/hytale/builtin/adventure/memories/page/MemoriesPage.java +++ b/src/com/hypixel/hytale/builtin/adventure/memories/page/MemoriesPage.java @@ -101,11 +101,11 @@ public class MemoriesPage extends InteractiveCustomUIPage pendingTeleportComponentType = PendingTeleport.getComponentType(); chunkStoreRegistry.registerSystem(new TeleporterPlugin.TeleporterOwnedWarpRefChangeSystem(this.teleporterComponentType)); chunkStoreRegistry.registerSystem(new TeleporterPlugin.TeleporterOwnedWarpRefSystem(this.teleporterComponentType)); - chunkStoreRegistry.registerSystem( - new CreateWarpWhenTeleporterPlacedSystem( - placedByInteractionComponentType, this.teleporterComponentType, blockStateInfoComponentType, playerRefComponentType - ) - ); + chunkStoreRegistry.registerSystem(new TurnOffTeleportersSystem()); + this.getChunkStoreRegistry() + .registerSystem( + new CreateWarpWhenTeleporterPlacedSystem( + placedByInteractionComponentType, this.teleporterComponentType, blockStateInfoComponentType, playerRefComponentType + ) + ); this.usedTeleporterComponentType = entityStoreRegistry.registerComponent(UsedTeleporter.class, UsedTeleporter::new); entityStoreRegistry.registerSystem( new ClearUsedTeleporterSystem( @@ -151,18 +154,6 @@ public class TeleporterPlugin extends JavaPlugin { public void onEntityAdded( @Nonnull Ref ref, @Nonnull AddReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer ) { - switch (reason) { - case LOAD: - Teleporter teleporterComponent = commandBuffer.getComponent(ref, this.teleporterComponentType); - if (teleporterComponent == null) { - return; - } else { - String ownedWarp = teleporterComponent.getOwnedWarp(); - if (ownedWarp != null && !ownedWarp.isEmpty() && !TeleportPlugin.get().getWarps().containsKey(ownedWarp.toLowerCase())) { - } - } - case SPAWN: - } } @Override diff --git a/src/com/hypixel/hytale/builtin/adventure/teleporter/component/Teleporter.java b/src/com/hypixel/hytale/builtin/adventure/teleporter/component/Teleporter.java index faef1456..18dea2c1 100644 --- a/src/com/hypixel/hytale/builtin/adventure/teleporter/component/Teleporter.java +++ b/src/com/hypixel/hytale/builtin/adventure/teleporter/component/Teleporter.java @@ -44,6 +44,8 @@ public class Teleporter implements Component { .documentation("The ID of the Word list to select default warp names from") .add() .build(); + public static final String ACTIVATE_STATE = "Active"; + public static final String INACTIVE_STATE = "default"; @Nullable private UUID worldUuid; @Nullable diff --git a/src/com/hypixel/hytale/builtin/adventure/teleporter/page/TeleporterSettingsPage.java b/src/com/hypixel/hytale/builtin/adventure/teleporter/page/TeleporterSettingsPage.java index 3199303a..5880bad8 100644 --- a/src/com/hypixel/hytale/builtin/adventure/teleporter/page/TeleporterSettingsPage.java +++ b/src/com/hypixel/hytale/builtin/adventure/teleporter/page/TeleporterSettingsPage.java @@ -2,6 +2,7 @@ package com.hypixel.hytale.builtin.adventure.teleporter.page; import com.hypixel.hytale.builtin.adventure.teleporter.component.Teleporter; import com.hypixel.hytale.builtin.adventure.teleporter.system.CreateWarpWhenTeleporterPlacedSystem; +import com.hypixel.hytale.builtin.adventure.teleporter.system.TurnOffTeleportersSystem; import com.hypixel.hytale.builtin.adventure.teleporter.util.CannedWarpNames; import com.hypixel.hytale.builtin.teleport.TeleportPlugin; import com.hypixel.hytale.builtin.teleport.Warp; @@ -11,13 +12,11 @@ import com.hypixel.hytale.codec.builder.BuilderCodec; import com.hypixel.hytale.codec.codecs.EnumCodec; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; -import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.vector.Transform; import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime; import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType; import com.hypixel.hytale.protocol.packets.interface_.Page; import com.hypixel.hytale.server.core.Message; -import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage; import com.hypixel.hytale.server.core.modules.block.BlockModule; @@ -34,6 +33,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; +import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -43,16 +43,11 @@ public class TeleporterSettingsPage extends InteractiveCustomUIPage blockRef; private final TeleporterSettingsPage.Mode mode; - @Nullable - private final String activeState; - public TeleporterSettingsPage( - @Nonnull PlayerRef playerRef, @Nonnull Ref blockRef, TeleporterSettingsPage.Mode mode, @Nullable String activeState - ) { + public TeleporterSettingsPage(@Nonnull PlayerRef playerRef, @Nonnull Ref blockRef, TeleporterSettingsPage.Mode mode) { super(playerRef, CustomPageLifetime.CanDismissOrCloseThroughInteraction, TeleporterSettingsPage.PageEventData.CODEC); this.blockRef = blockRef; this.mode = mode; - this.activeState = activeState; } @Override @@ -182,10 +177,6 @@ public class TeleporterSettingsPage extends InteractiveCustomUIPage("@World", Codec.STRING), (pageEventData, o) -> pageEventData.world = o, pageEventData -> pageEventData.world) .add() - .append(new KeyedCodec<>("@Warp", Codec.STRING), (pageEventData, o) -> pageEventData.warp = o, pageEventData -> pageEventData.warp) + .append( + new KeyedCodec<>("@Warp", Codec.STRING), (pageEventData, o) -> pageEventData.destinationWarp = o, pageEventData -> pageEventData.destinationWarp + ) .add() .append(new KeyedCodec<>("@NewWarp", Codec.STRING), (pageEventData, o) -> pageEventData.warpName = o, pageEventData -> pageEventData.warpName) .add() @@ -400,7 +381,7 @@ public class TeleporterSettingsPage extends InteractiveCustomUIPage supplier.mode = parent.mode ) .add() - .appendInherited( - new KeyedCodec<>("ActiveState", Codec.STRING), - (supplier, o) -> supplier.activeState = o, - supplier -> supplier.activeState, - (supplier, parent) -> supplier.activeState = parent.activeState - ) - .add() .build(); private boolean create = true; private TeleporterSettingsPage.Mode mode = TeleporterSettingsPage.Mode.FULL; - @Nullable - private String activeState; @Nullable @Override @@ -91,7 +82,7 @@ public class TeleporterSettingsPageSupplier implements OpenCustomUIInteraction.C blockRef = chunkComponentStore.addEntity(holder, AddReason.SPAWN); } - return blockRef != null && blockRef.isValid() ? new TeleporterSettingsPage(playerRef, blockRef, this.mode, this.activeState) : null; + return blockRef != null && blockRef.isValid() ? new TeleporterSettingsPage(playerRef, blockRef, this.mode) : null; } } } diff --git a/src/com/hypixel/hytale/builtin/adventure/teleporter/system/TurnOffTeleportersSystem.java b/src/com/hypixel/hytale/builtin/adventure/teleporter/system/TurnOffTeleportersSystem.java new file mode 100644 index 00000000..48cf552a --- /dev/null +++ b/src/com/hypixel/hytale/builtin/adventure/teleporter/system/TurnOffTeleportersSystem.java @@ -0,0 +1,98 @@ +package com.hypixel.hytale.builtin.adventure.teleporter.system; + +import com.hypixel.hytale.builtin.adventure.teleporter.component.Teleporter; +import com.hypixel.hytale.builtin.teleport.TeleportPlugin; +import com.hypixel.hytale.builtin.teleport.Warp; +import com.hypixel.hytale.component.AddReason; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.ComponentAccessor; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.RemoveReason; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.component.query.AndQuery; +import com.hypixel.hytale.component.query.Query; +import com.hypixel.hytale.component.system.RefSystem; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; +import com.hypixel.hytale.server.core.modules.block.BlockModule; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; + +public class TurnOffTeleportersSystem extends RefSystem { + public static final Query QUERY = Query.and(Teleporter.getComponentType(), BlockModule.BlockStateInfo.getComponentType()); + + @Override + public void onEntityAdded( + @Nonnull Ref ref, @Nonnull AddReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer + ) { + if (reason == AddReason.LOAD) { + updatePortalBlocksInWorld(store.getExternalData().getWorld()); + } + } + + @Override + public void onEntityRemove( + @Nonnull Ref ref, @Nonnull RemoveReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer + ) { + if (reason == RemoveReason.REMOVE) { + updatePortalBlocksInWorld(store.getExternalData().getWorld()); + } + } + + public static void updatePortalBlocksInWorld(World world) { + Store store = world.getChunkStore().getStore(); + AndQuery entityQuery = Query.and(Teleporter.getComponentType(), BlockModule.BlockStateInfo.getComponentType()); + store.forEachChunk(entityQuery, (archetypeChunk, commandBuffer) -> { + for (int i = 0; i < archetypeChunk.size(); i++) { + Ref ref = archetypeChunk.getReferenceTo(i); + updatePortalBlockInWorld(ref, commandBuffer); + } + }); + } + + private static void updatePortalBlockInWorld(Ref ref, ComponentAccessor store) { + if (ref.isValid()) { + Teleporter teleporter = store.getComponent(ref, Teleporter.getComponentType()); + BlockModule.BlockStateInfo blockState = store.getComponent(ref, BlockModule.BlockStateInfo.getComponentType()); + updatePortalBlockInWorld(store, teleporter, blockState); + } + } + + public static void updatePortalBlockInWorld(ComponentAccessor store, Teleporter teleporter, BlockModule.BlockStateInfo blockStateInfo) { + Ref chunkRef = blockStateInfo.getChunkRef(); + if (chunkRef.isValid()) { + WorldChunk worldChunkComponent = store.getComponent(chunkRef, WorldChunk.getComponentType()); + if (worldChunkComponent != null) { + int index = blockStateInfo.getIndex(); + int x = ChunkUtil.xFromBlockInColumn(index); + int y = ChunkUtil.yFromBlockInColumn(index); + int z = ChunkUtil.zFromBlockInColumn(index); + BlockType blockType = worldChunkComponent.getBlockType(x, y, z); + if (blockType != null) { + String warpId = teleporter.getWarp(); + Warp destinationWarp = warpId == null ? null : TeleportPlugin.get().getWarps().get(warpId); + String currentState = blockType.getStateForBlock(blockType); + String desiredState = destinationWarp == null ? "default" : "Active"; + if (!desiredState.equals(currentState)) { + worldChunkComponent.setBlockInteractionState(x, y, z, blockType, desiredState, false); + blockStateInfo.markNeedsSaving(store); + } + + if (destinationWarp == null) { + teleporter.setWarp(null); + blockStateInfo.markNeedsSaving(store); + } + } + } + } + } + + @NullableDecl + @Override + public Query getQuery() { + return QUERY; + } +} diff --git a/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPacketHandler.java b/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPacketHandler.java index 977f77a6..8b00e1ae 100644 --- a/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPacketHandler.java +++ b/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPacketHandler.java @@ -101,7 +101,7 @@ public class AssetEditorPacketHandler extends GenericPacketHandler { @Nonnull @Override public String getIdentifier() { - return "{Editor(" + NettyUtil.formatRemoteAddress(this.channel) + "), " + this.editorClient.getUuid() + ", " + this.editorClient.getUsername() + "}"; + return "{Editor(" + NettyUtil.formatRemoteAddress(this.getChannel()) + "), " + this.editorClient.getUuid() + ", " + this.editorClient.getUsername() + "}"; } @Override @@ -137,6 +137,7 @@ public class AssetEditorPacketHandler extends GenericPacketHandler { this.registerHandler(316, p -> this.handle((AssetEditorCreateAssetPack)p)); this.registerHandler(315, p -> this.handle((AssetEditorUpdateAssetPack)p)); this.registerHandler(317, p -> this.handle((AssetEditorDeleteAssetPack)p)); + this.registerHandler(232, p -> this.handle((UpdateLanguage)p)); } public void handle(@Nonnull AssetEditorSubscribeModifiedAssetsChanges packet) { @@ -400,11 +401,11 @@ public class AssetEditorPacketHandler extends GenericPacketHandler { "%s - %s at %s left with reason: %s - %s", this.editorClient.getUuid(), this.editorClient.getUsername(), - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), packet.type.name(), packet.reason ); - this.channel.close(); + this.getChannel().close(); } private boolean lacksPermission(int token) { diff --git a/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPlugin.java b/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPlugin.java index 5970710e..5f8e3721 100644 --- a/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPlugin.java +++ b/src/com/hypixel/hytale/builtin/asseteditor/AssetEditorPlugin.java @@ -38,7 +38,7 @@ import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.event.EventRegistry; import com.hypixel.hytale.event.IEventDispatcher; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorAsset; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorAssetListUpdate; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorAssetPackSetup; @@ -78,6 +78,7 @@ import com.hypixel.hytale.server.core.asset.AssetPackRegisterEvent; import com.hypixel.hytale.server.core.asset.AssetPackUnregisterEvent; import com.hypixel.hytale.server.core.asset.AssetRegistryLoader; import com.hypixel.hytale.server.core.asset.common.events.CommonAssetMonitorEvent; +import com.hypixel.hytale.server.core.config.ModConfig; import com.hypixel.hytale.server.core.io.PacketHandler; import com.hypixel.hytale.server.core.io.ServerManager; import com.hypixel.hytale.server.core.io.handlers.InitialPacketHandler; @@ -806,8 +807,8 @@ public class AssetEditorPlugin extends JavaPlugin { String newPackId = newPackIdentifier.toString(); Path packPath = dataSource.getRootPath(); HytaleServerConfig serverConfig = HytaleServer.get().getConfig(); - HytaleServerConfig.ModConfig.setBoot(serverConfig, newPackIdentifier, true); - Map modConfig = serverConfig.getModConfig(); + HytaleServerConfig.setBoot(serverConfig, newPackIdentifier, true); + Map modConfig = serverConfig.getModConfig(); modConfig.remove(PluginIdentifier.fromString(packId)); serverConfig.markChanged(); if (serverConfig.consumeHasChanged()) { @@ -816,7 +817,7 @@ public class AssetEditorPlugin extends JavaPlugin { AssetModule assetModule = AssetModule.get(); assetModule.unregisterPack(packId); - assetModule.registerPack(newPackId, packPath, manifest); + assetModule.registerPack(newPackId, packPath, manifest, false); } } } @@ -886,13 +887,13 @@ public class AssetEditorPlugin extends JavaPlugin { Path manifestPath = packPath.resolve("manifest.json"); BsonUtil.writeSync(manifestPath, PluginManifest.CODEC, manifest, this.getLogger()); HytaleServerConfig serverConfig = HytaleServer.get().getConfig(); - HytaleServerConfig.ModConfig.setBoot(serverConfig, new PluginIdentifier(manifest), true); + HytaleServerConfig.setBoot(serverConfig, new PluginIdentifier(manifest), true); serverConfig.markChanged(); if (serverConfig.consumeHasChanged()) { HytaleServerConfig.save(serverConfig).join(); } - AssetModule.get().registerPack(packId, packPath, manifest); + AssetModule.get().registerPack(packId, packPath, manifest, false); editorClient.sendSuccessReply(requestToken, Messages.PACK_CREATED); this.getLogger().at(Level.INFO).log("Created new pack: %s at %s", packId, packPath); } catch (IOException var12) { @@ -965,7 +966,7 @@ public class AssetEditorPlugin extends JavaPlugin { editorClient.getPacketHandler().write(new AssetEditorExportAssetInitialize(new AssetEditorAsset(null, assetPath.toPacket()), null, 0, false)); } else { byte[][] parts = ArrayUtil.split(bytes, 2621440); - Packet[] packets = new Packet[2 + parts.length]; + ToClientPacket[] packets = new ToClientPacket[2 + parts.length]; packets[0] = new AssetEditorExportAssetInitialize(new AssetEditorAsset(null, assetPath.toPacket()), null, bytes.length, false); for (int partIndex = 0; partIndex < parts.length; partIndex++) { @@ -1421,12 +1422,13 @@ public class AssetEditorPlugin extends JavaPlugin { editorClient.sendPopupNotification(AssetEditorPopupNotificationType.Error, Messages.REQUEST_CHILD_IDS_ASSET_TYPE_MISSING); } else { AssetStore assetStore = assetStoreTypeHandler.getAssetStore(); + AssetMap assetMap = assetStore.getAssetMap(); Object key = assetStore.decodeFilePathKey(assetPath.path()); - Set children = assetStore.getAssetMap().getChildren(key); + Set children = assetMap.getChildren(key); HashSet childrenIds = new HashSet(); if (children != null) { for (Object child : children) { - if (assetStore.getAssetMap().getPath(child) != null) { + if (assetMap.getPath(child) != null) { childrenIds.add(child.toString()); } } @@ -1796,13 +1798,13 @@ public class AssetEditorPlugin extends JavaPlugin { } } - private void sendPacketToAllEditorUsers(@Nonnull Packet packet) { + private void sendPacketToAllEditorUsers(@Nonnull ToClientPacket packet) { for (EditorClient editorClient : this.clientOpenAssetPathMapping.keySet()) { editorClient.getPacketHandler().write(packet); } } - private void sendPacketToAllEditorUsersExcept(@Nonnull Packet packet, EditorClient ignoreEditorClient) { + private void sendPacketToAllEditorUsersExcept(@Nonnull ToClientPacket packet, EditorClient ignoreEditorClient) { for (EditorClient editorClient : this.clientOpenAssetPathMapping.keySet()) { if (!editorClient.equals(ignoreEditorClient)) { editorClient.getPacketHandler().write(packet); diff --git a/src/com/hypixel/hytale/builtin/asseteditor/datasource/StandardDataSource.java b/src/com/hypixel/hytale/builtin/asseteditor/datasource/StandardDataSource.java index d71998ad..2b44a679 100644 --- a/src/com/hypixel/hytale/builtin/asseteditor/datasource/StandardDataSource.java +++ b/src/com/hypixel/hytale/builtin/asseteditor/datasource/StandardDataSource.java @@ -86,7 +86,10 @@ public class StandardDataSource implements DataSource { @Override public void shutdown() { - this.saveSchedule.cancel(false); + if (this.saveSchedule != null) { + this.saveSchedule.cancel(false); + } + this.saveRecentModifications(); } diff --git a/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPacketHandler.java b/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPacketHandler.java index f83af713..1c12ef5e 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPacketHandler.java +++ b/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPacketHandler.java @@ -8,7 +8,6 @@ import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.Axis; -import com.hypixel.hytale.math.matrix.Matrix4d; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; @@ -56,6 +55,7 @@ import com.hypixel.hytale.server.core.entity.UUIDComponent; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.inventory.ItemStack; import com.hypixel.hytale.server.core.io.handlers.IPacketHandler; +import com.hypixel.hytale.server.core.io.handlers.IWorldPacketHandler; import com.hypixel.hytale.server.core.io.handlers.SubPacketHandler; import com.hypixel.hytale.server.core.modules.entity.component.DynamicLight; import com.hypixel.hytale.server.core.modules.entity.component.EntityScaleComponent; @@ -69,546 +69,535 @@ import com.hypixel.hytale.server.core.modules.entity.hitboxcollision.HitboxColli import com.hypixel.hytale.server.core.modules.entity.hitboxcollision.HitboxCollisionConfig; import com.hypixel.hytale.server.core.modules.entity.item.PreventPickup; import com.hypixel.hytale.server.core.modules.interaction.Interactions; +import com.hypixel.hytale.server.core.permissions.PermissionsModule; import com.hypixel.hytale.server.core.prefab.selection.mask.BlockPattern; import com.hypixel.hytale.server.core.prefab.selection.standard.BlockSelection; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.logging.Level; import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.joml.Quaterniond; public class BuilderToolsPacketHandler implements SubPacketHandler { + @Nonnull private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); + @Nonnull + private static final String BUILDER_TOOL_ID_EXTRUDE = "Extrude"; + @Nonnull + private static final String BUILDER_TOOL_ID_SELECTION = "Selection"; + @Nonnull + private static final String BUILDER_TOOL_ID_LINE = "Line"; + @Nonnull + private static final Message MESSAGE_BUILDER_TOOLS_USAGE_DENIED = Message.translation("server.builderTools.usageDenied"); + @Nonnull private final IPacketHandler packetHandler; - public BuilderToolsPacketHandler(IPacketHandler packetHandler) { + public BuilderToolsPacketHandler(@Nonnull IPacketHandler packetHandler) { this.packetHandler = packetHandler; } + private static boolean hasPermission(@Nonnull PlayerRef playerRef) { + return hasPermission(playerRef, null); + } + + private static boolean hasPermission(@Nonnull PlayerRef playerRef, @Nullable String additionalPermission) { + UUID playerUuid = playerRef.getUuid(); + PermissionsModule permissionsModule = PermissionsModule.get(); + boolean hasBuilderToolsEditor = permissionsModule.hasPermission(playerUuid, "hytale.editor.builderTools"); + boolean hasAdditionalPerm = additionalPermission != null && permissionsModule.hasPermission(playerUuid, additionalPermission); + if (!hasBuilderToolsEditor && !hasAdditionalPerm) { + playerRef.sendMessage(MESSAGE_BUILDER_TOOLS_USAGE_DENIED); + return false; + } else { + return true; + } + } + @Override public void registerHandlers() { if (BuilderToolsPlugin.get().isDisabled()) { this.packetHandler.registerNoOpHandlers(400, 401, 412, 409, 403, 406, 407, 413, 414, 417); } else { - this.packetHandler.registerHandler(106, p -> this.handle((LoadHotbar)p)); - this.packetHandler.registerHandler(107, p -> this.handle((SaveHotbar)p)); - this.packetHandler.registerHandler(400, p -> this.handle((BuilderToolArgUpdate)p)); - this.packetHandler.registerHandler(401, p -> this.handle((BuilderToolEntityAction)p)); - this.packetHandler.registerHandler(412, p -> this.handle((BuilderToolGeneralAction)p)); - this.packetHandler.registerHandler(409, p -> this.handle((BuilderToolSelectionUpdate)p)); - this.packetHandler.registerHandler(403, p -> this.handle((BuilderToolExtrudeAction)p)); - this.packetHandler.registerHandler(406, p -> this.handle((BuilderToolRotateClipboard)p)); - this.packetHandler.registerHandler(407, p -> this.handle((BuilderToolPasteClipboard)p)); - this.packetHandler.registerHandler(413, p -> this.handle((BuilderToolOnUseInteraction)p)); - this.packetHandler.registerHandler(410, p -> this.handle((BuilderToolSelectionToolAskForClipboard)p)); - this.packetHandler.registerHandler(414, p -> this.handle((BuilderToolLineAction)p)); - this.packetHandler.registerHandler(402, p -> this.handle((BuilderToolSetEntityTransform)p)); - this.packetHandler.registerHandler(420, p -> this.handle((BuilderToolSetEntityScale)p)); - this.packetHandler.registerHandler(405, p -> this.handle((BuilderToolSelectionTransform)p)); - this.packetHandler.registerHandler(404, p -> this.handle((BuilderToolStackArea)p)); - this.packetHandler.registerHandler(408, p -> this.handle((BuilderToolSetTransformationModeState)p)); - this.packetHandler.registerHandler(417, p -> this.handle((PrefabUnselectPrefab)p)); - this.packetHandler.registerHandler(421, p -> this.handle((BuilderToolSetEntityPickupEnabled)p)); - this.packetHandler.registerHandler(422, p -> this.handle((BuilderToolSetEntityLight)p)); - this.packetHandler.registerHandler(423, p -> this.handle((BuilderToolSetNPCDebug)p)); - this.packetHandler.registerHandler(425, p -> this.handle((BuilderToolSetEntityCollision)p)); + IWorldPacketHandler.registerHandler(this.packetHandler, 106, this::handleLoadHotbar, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 107, this::handleSaveHotbar, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 401, this::handleBuilderToolEntityAction, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 402, this::handleBuilderToolSetEntityTransform, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 420, this::handleBuilderToolSetEntityScale, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler( + this.packetHandler, 408, this::handleBuilderToolSetTransformationModeState, BuilderToolsPacketHandler::hasPermission + ); + IWorldPacketHandler.registerHandler(this.packetHandler, 417, this::handlePrefabUnselectPrefab, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 421, this::handleBuilderToolSetEntityPickupEnabled, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 422, this::handleBuilderToolSetEntityLight, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 423, this::handleBuilderToolSetNPCDebug, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 425, this::handleBuilderToolSetEntityCollision, BuilderToolsPacketHandler::hasPermission); + IWorldPacketHandler.registerHandler(this.packetHandler, 400, this::handleBuilderToolArgUpdate, p -> hasPermission(p, "hytale.editor.brush.config")); + IWorldPacketHandler.registerHandler( + this.packetHandler, 409, this::handleBuilderToolSelectionUpdate, p -> hasPermission(p, "hytale.editor.selection.use") + ); + IWorldPacketHandler.registerHandler( + this.packetHandler, 403, this::handleBuilderToolExtrudeAction, p -> hasPermission(p, "hytale.editor.selection.modify") + ); + IWorldPacketHandler.registerHandler( + this.packetHandler, 406, this::handleBuilderToolRotateClipboard, p -> hasPermission(p, "hytale.editor.selection.clipboard") + ); + IWorldPacketHandler.registerHandler( + this.packetHandler, 407, this::handleBuilderToolPasteClipboard, p -> hasPermission(p, "hytale.editor.selection.clipboard") + ); + IWorldPacketHandler.registerHandler(this.packetHandler, 413, this::handleBuilderToolOnUseInteraction, p -> hasPermission(p, "hytale.editor.brush.use")); + IWorldPacketHandler.registerHandler( + this.packetHandler, 410, this::handleBuilderToolSelectionToolAskForClipboard, p -> hasPermission(p, "hytale.editor.selection.clipboard") + ); + IWorldPacketHandler.registerHandler(this.packetHandler, 414, this::handleBuilderToolLineAction, p -> hasPermission(p, "hytale.editor.brush.use")); + IWorldPacketHandler.registerHandler( + this.packetHandler, 405, this::handleBuilderToolSelectionTransform, p -> hasPermission(p, "hytale.editor.selection.clipboard") + ); + IWorldPacketHandler.registerHandler( + this.packetHandler, 404, this::handleBuilderToolStackArea, p -> hasPermission(p, "hytale.editor.selection.clipboard") + ); + IWorldPacketHandler.registerHandler(this.packetHandler, 412, this::handleBuilderToolGeneralAction); } } - static boolean hasPermission(@Nonnull Player player) { - if (!player.hasPermission("hytale.editor.builderTools")) { - player.sendMessage(Message.translation("server.builderTools.usageDenied")); - return false; - } else { - return true; + public void handleBuilderToolSetTransformationModeState( + @Nonnull BuilderToolSetTransformationModeState packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()).setInSelectionTransformationMode(packet.enabled); + } + + public void handleBuilderToolArgUpdate( + @Nonnull BuilderToolArgUpdate packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + BuilderToolsPlugin.get().onToolArgUpdate(playerRef, playerComponent, packet); } } - static boolean hasPermission(@Nonnull Player player, @Nonnull String permission) { - if (!player.hasPermission(permission) && !player.hasPermission("hytale.editor.builderTools")) { - player.sendMessage(Message.translation("server.builderTools.usageDenied")); - return false; - } else { - return true; + public void handleLoadHotbar( + @Nonnull LoadHotbar packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + playerComponent.getHotbarManager().loadHotbar(ref, packet.inventoryRow, store); } } - public void handle(@Nonnull BuilderToolSetTransformationModeState packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { + public void handleSaveHotbar( + @Nonnull SaveHotbar packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + playerComponent.getHotbarManager().saveHotbar(ref, packet.inventoryRow, store); + } + } + + public void handleBuilderToolEntityAction( + @Nonnull BuilderToolEntityAction packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + int targetId = packet.entityId; + Ref targetRef = world.getEntityStore().getRefFromNetworkId(targetId); + if (targetRef != null && targetRef.isValid()) { + Player targetPlayerComponent = store.getComponent(targetRef, Player.getComponentType()); + if (targetPlayerComponent != null) { + playerComponent.sendMessage(Message.translation("server.builderTools.entityTool.cannotTargetPlayer")); + } else { LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()).setInSelectionTransformationMode(packet.enabled); + switch (packet.action) { + case Freeze: + UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType()); + if (uuidComponent != null) { + CommandManager.get().handleCommand(playerComponent, "npc freeze --toggle --entity " + uuidComponent.getUuid()); + } + break; + case Clone: + world.execute(() -> EntityCloneCommand.cloneEntity(playerComponent, targetRef, store)); + break; + case Remove: + world.execute(() -> EntityRemoveCommand.removeEntity(ref, targetRef, store)); + } } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetTransformationModeState packet. Player ref is invalid!"); + } else { + playerComponent.sendMessage(Message.translation("server.general.entityNotFound").param("id", targetId)); + } } } - public void handle(@Nonnull BuilderToolArgUpdate packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.brush.config")) { - BuilderToolsPlugin.get().onToolArgUpdate(playerRef, playerComponent, packet); - } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolArgUpdate packet. Player ref is invalid!"); - } - } + public void handleBuilderToolGeneralAction( + @Nonnull BuilderToolGeneralAction packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + switch (packet.action) { + case HistoryUndo: + if (!hasPermission(playerRef, "hytale.editor.history")) { + return; + } - public void handle(@Nonnull LoadHotbar packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.undo(r, 1, componentAccessor)); + break; + case HistoryRedo: + if (!hasPermission(playerRef, "hytale.editor.history")) { + return; + } - assert playerComponent != null; + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.redo(r, 1, componentAccessor)); + break; + case SelectionCopy: + if (!hasPermission(playerRef, "hytale.editor.selection.clipboard")) { + return; + } - playerComponent.getHotbarManager().loadHotbar(ref, packet.inventoryRow, store); - }); - } else { - throw new RuntimeException("Unable to process LoadHotbar packet. Player ref is invalid!"); - } - } + CopyCommand.copySelection(ref, store); + break; + case SelectionPosition1: + case SelectionPosition2: + if (!hasPermission(playerRef, "hytale.editor.selection.use")) { + return; + } - public void handle(@Nonnull SaveHotbar packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); + TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType()); + if (transformComponent == null) { + return; + } - assert playerComponent != null; - - playerComponent.getHotbarManager().saveHotbar(ref, packet.inventoryRow, store); - }); - } else { - throw new RuntimeException("Unable to process SaveHotbar packet. Player ref is invalid!"); - } - } - - public void handle(@Nonnull BuilderToolEntityAction packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - int entityId = packet.entityId; - Ref entityReference = world.getEntityStore().getRefFromNetworkId(entityId); - if (entityReference == null) { - playerComponent.sendMessage(Message.translation("server.general.entityNotFound").param("id", entityId)); - } else { - Player targetPlayerComponent = store.getComponent(entityReference, Player.getComponentType()); - if (targetPlayerComponent != null) { - playerComponent.sendMessage(Message.translation("server.builderTools.entityTool.cannotTargetPlayer")); + BuilderToolsPlugin.BuilderState builderState = BuilderToolsPlugin.getState(playerComponent, playerRef); + Vector3d position = transformComponent.getPosition(); + Vector3i intTriple = new Vector3i(MathUtil.floor(position.getX()), MathUtil.floor(position.getY()), MathUtil.floor(position.getZ())); + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> { + if (packet.action == BuilderToolAction.SelectionPosition1) { + builderState.pos1(intTriple, componentAccessor); } else { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - switch (packet.action) { - case Freeze: - UUIDComponent uuidComponent = store.getComponent(entityReference, UUIDComponent.getComponentType()); - if (uuidComponent != null) { - CommandManager.get().handleCommand(playerComponent, "npc freeze --toggle --entity " + uuidComponent.getUuid()); - } - break; - case Clone: - world.execute(() -> EntityCloneCommand.cloneEntity(playerComponent, entityReference, store)); - break; - case Remove: - world.execute(() -> EntityRemoveCommand.removeEntity(ref, entityReference, store)); - } + builderState.pos2(intTriple, componentAccessor); } + }); + break; + case ActivateToolMode: + if (!hasPermission(playerRef, "hytale.editor.builderTools")) { + return; } - } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolEntityAction packet. Player ref is invalid!"); + + playerComponent.getInventory().setUsingToolsItem(true); + break; + case DeactivateToolMode: + if (!hasPermission(playerRef, "hytale.editor.builderTools")) { + return; + } + + playerComponent.getInventory().setUsingToolsItem(false); + } } } - public void handle(@Nonnull BuilderToolGeneralAction packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); + public void handleBuilderToolSelectionUpdate( + @Nonnull BuilderToolSelectionUpdate packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + BuilderToolsPlugin.addToQueue( + playerComponent, playerRef, (r, s, componentAccessor) -> s.update(packet.xMin, packet.yMin, packet.zMin, packet.xMax, packet.yMax, packet.zMax) + ); + } + } - assert playerComponent != null; + public void handleBuilderToolSelectionToolAskForClipboard( + @Nonnull BuilderToolSelectionToolAskForClipboard packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()); + BuilderToolsPlugin.addToQueue( + playerComponent, + playerRef, + (r, s, componentAccessor) -> { + BlockSelection selection = s.getSelection(); + if (selection != null) { + EditorBlocksChange editorPacket = selection.toPacket(); + BlockChange[] blocksChange = editorPacket.blocksChange; + prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange); + ArrayList fluidChanges = new ArrayList<>(); + int anchorX = selection.getAnchorX(); + int anchorY = selection.getAnchorY(); + int anchorZ = selection.getAnchorZ(); + selection.forEachFluid( + (x, y, z, fluidId, fluidLevel) -> fluidChanges.add( + new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel) + ) + ); + PrototypePlayerBuilderToolSettings.FluidChange[] fluidChangesArray = fluidChanges.toArray( + PrototypePlayerBuilderToolSettings.FluidChange[]::new + ); + prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChangesArray); + ArrayList entityChanges = new ArrayList<>(); + int selectionX = selection.getX(); + int selectionY = selection.getY(); + int selectionZ = selection.getZ(); + selection.forEachEntity( + holder -> { + TransformComponent transform = holder.getComponent(TransformComponent.getComponentType()); + if (transform != null && transform.getPosition() != null) { + Vector3d pos = transform.getPosition(); + entityChanges.add( + new PrototypePlayerBuilderToolSettings.EntityChange( + pos.getX() + selectionX, pos.getY() + selectionY, pos.getZ() + selectionZ, holder.clone() + ) + ); + } + } + ); + prototypeSettings.setEntityChangesForPlaySelectionToolPasteMode(entityChanges.toArray(PrototypePlayerBuilderToolSettings.EntityChange[]::new)); + FluidChange[] packetFluids = new FluidChange[fluidChangesArray.length]; + for (int i = 0; i < fluidChangesArray.length; i++) { + PrototypePlayerBuilderToolSettings.FluidChange fc = fluidChangesArray[i]; + packetFluids[i] = new FluidChange(fc.x(), fc.y(), fc.z(), fc.fluidId(), fc.fluidLevel()); + } + + playerRef.getPacketHandler().write(new BuilderToolSelectionToolReplyWithClipboard(blocksChange, packetFluids)); + } + } + ); + } + } + + private void handleBuilderToolSelectionTransform( + @Nonnull BuilderToolSelectionTransform packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + boolean keepEmptyBlocks = true; + BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); + if (builderTool != null && builderTool.getId().equals("Selection")) { + BuilderTool.ArgData args = builderTool.getItemArgData(playerComponent.getInventory().getItemInHand()); + if (args != null && args.tool() != null) { + keepEmptyBlocks = (Boolean)args.tool().getOrDefault("KeepEmptyBlocks", true); + } + } + + boolean finalKeepEmptyBlocks = keepEmptyBlocks; + Quaterniond rotation = new Quaterniond(packet.rotation.x, packet.rotation.y, packet.rotation.z, packet.rotation.w); + Vector3i translationOffset = new Vector3i(packet.translationOffset.x, packet.translationOffset.y, packet.translationOffset.z); + Vector3i initialSelectionMin = new Vector3i(packet.initialSelectionMin.x, packet.initialSelectionMin.y, packet.initialSelectionMin.z); + Vector3i initialSelectionMax = new Vector3i(packet.initialSelectionMax.x, packet.initialSelectionMax.y, packet.initialSelectionMax.z); + Vector3f rotationOrigin = new Vector3f(packet.initialRotationOrigin.x, packet.initialRotationOrigin.y, packet.initialRotationOrigin.z); + PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()); + BuilderToolsPlugin.addToQueue( + playerComponent, + playerRef, + (r, s, componentAccessor) -> { + int blockCount = s.getSelection().getSelectionVolume(); + boolean large = blockCount > 20000; + if (large) { + playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.warning")); + } + + if (prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode() == null) { + s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor); + List> lastTransformRefs = prototypeSettings.getLastTransformEntityRefs(); + HashSet> skipSet = lastTransformRefs != null ? new HashSet<>(lastTransformRefs) : null; + if (packet.cutOriginal) { + s.copyOrCut( + r, + initialSelectionMin.x, + initialSelectionMin.y, + initialSelectionMin.z, + initialSelectionMax.x, + initialSelectionMax.y, + initialSelectionMax.z, + 154, + null, + skipSet, + store + ); + } else { + s.copyOrCut( + r, + initialSelectionMin.x, + initialSelectionMin.y, + initialSelectionMin.z, + initialSelectionMax.x, + initialSelectionMax.y, + initialSelectionMax.z, + 152, + store + ); + } + + BlockSelection selection = s.getSelection(); + BlockChange[] blocksChange = selection.toPacket().blocksChange; + prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange); + ArrayList fluidChanges = new ArrayList<>(); + int anchorX = selection.getAnchorX(); + int anchorY = selection.getAnchorY(); + int anchorZ = selection.getAnchorZ(); + selection.forEachFluid( + (x, y, z, fluidId, fluidLevel) -> fluidChanges.add( + new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel) + ) + ); + prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChanges.toArray(PrototypePlayerBuilderToolSettings.FluidChange[]::new)); + ArrayList entityChanges = new ArrayList<>(); + int selectionX = selection.getX(); + int selectionY = selection.getY(); + int selectionZ = selection.getZ(); + selection.forEachEntity( + holder -> { + TransformComponent transform = holder.getComponent(TransformComponent.getComponentType()); + if (transform != null && transform.getPosition() != null) { + Vector3d pos = transform.getPosition(); + entityChanges.add( + new PrototypePlayerBuilderToolSettings.EntityChange( + pos.getX() + selectionX, pos.getY() + selectionY, pos.getZ() + selectionZ, holder.clone() + ) + ); + } + } + ); + prototypeSettings.setEntityChangesForPlaySelectionToolPasteMode(entityChanges.toArray(PrototypePlayerBuilderToolSettings.EntityChange[]::new)); + prototypeSettings.setBlockChangeOffsetOrigin(new Vector3i(selection.getX(), selection.getY(), selection.getZ())); + } + + Vector3i blockChangeOffsetOrigin = prototypeSettings.getBlockChangeOffsetOrigin(); + if (packet.initialPastePointForClipboardPaste != null) { + blockChangeOffsetOrigin = new Vector3i( + packet.initialPastePointForClipboardPaste.x, packet.initialPastePointForClipboardPaste.y, packet.initialPastePointForClipboardPaste.z + ); + } + + if (blockChangeOffsetOrigin == null) { + playerComponent.sendMessage(Message.translation("server.builderTools.selection.noBlockChangeOffsetOrigin")); + } else { + s.transformThenPasteClipboard( + prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode(), + prototypeSettings.getFluidChangesForPlaySelectionToolPasteMode(), + prototypeSettings.getEntityChangesForPlaySelectionToolPasteMode(), + rotation, + translationOffset, + rotationOrigin, + blockChangeOffsetOrigin, + finalKeepEmptyBlocks, + prototypeSettings, + componentAccessor + ); + s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor); + s.transformSelectionPoints(rotation, translationOffset, rotationOrigin); + if (large) { + playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.complete")); + } + + if (packet.isExitingTransformMode) { + prototypeSettings.setInSelectionTransformationMode(false); + } + } + } + ); + } + } + + public void handleBuilderToolExtrudeAction( + @Nonnull BuilderToolExtrudeAction packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); + if (builderTool != null && builderTool.getId().equals("Extrude")) { + ItemStack activeItemStack = playerComponent.getInventory().getItemInHand(); + BuilderTool.ArgData args = builderTool.getItemArgData(activeItemStack); + int extrudeDepth = (Integer)args.tool().get("ExtrudeDepth"); + int extrudeRadius = (Integer)args.tool().get("ExtrudeRadius"); + int blockId = ((BlockPattern)args.tool().get("ExtrudeMaterial")).firstBlock(); LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - switch (packet.action) { - case HistoryUndo: - if (!hasPermission(playerComponent, "hytale.editor.history")) { - return; - } - - BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.undo(r, 1, componentAccessor)); - break; - case HistoryRedo: - if (!hasPermission(playerComponent, "hytale.editor.history")) { - return; - } - - BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.redo(r, 1, componentAccessor)); - break; - case SelectionCopy: - if (!hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - return; - } - - CopyCommand.copySelection(ref, store); - break; - case SelectionPosition1: - case SelectionPosition2: - if (!hasPermission(playerComponent, "hytale.editor.selection.use")) { - return; - } - - TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType()); - BuilderToolsPlugin.BuilderState builderState = BuilderToolsPlugin.getState(playerComponent, playerRef); - Vector3d position = transformComponent.getPosition(); - Vector3i intTriple = new Vector3i(MathUtil.floor(position.getX()), MathUtil.floor(position.getY()), MathUtil.floor(position.getZ())); - BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> { - if (packet.action == BuilderToolAction.SelectionPosition1) { - builderState.pos1(intTriple, componentAccessor); - } else { - builderState.pos2(intTriple, componentAccessor); - } - }); - break; - case ActivateToolMode: - if (!hasPermission(playerComponent)) { - return; - } - - playerComponent.getInventory().setUsingToolsItem(true); - break; - case DeactivateToolMode: - if (!hasPermission(playerComponent)) { - return; - } - - playerComponent.getInventory().setUsingToolsItem(false); - } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolGeneralAction packet. Player ref is invalid!"); + BuilderToolsPlugin.addToQueue( + playerComponent, + playerRef, + (r, s, componentAccessor) -> s.extendFace( + packet.x, + packet.y, + packet.z, + packet.xNormal, + packet.yNormal, + packet.zNormal, + extrudeDepth, + extrudeRadius, + blockId, + null, + null, + componentAccessor + ) + ); + } } } - public void handle(@Nonnull BuilderToolSelectionUpdate packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.use")) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> s.update(packet.xMin, packet.yMin, packet.zMin, packet.xMax, packet.yMax, packet.zMax) - ); - } + public void handleBuilderToolStackArea( + @Nonnull BuilderToolStackArea packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + BuilderToolsPlugin.addToQueue( + playerComponent, + playerRef, + (r, s, componentAccessor) -> { + s.select( + this.fromBlockPosition(packet.selectionMin), + this.fromBlockPosition(packet.selectionMax), + "server.builderTools.selectReasons.extrude", + componentAccessor + ); + s.stack(r, new Vector3i(packet.xNormal, packet.yNormal, packet.zNormal), packet.numStacks, true, 0, componentAccessor); } ); - } else { - throw new RuntimeException("Unable to process BuilderToolSelectionUpdate packet. Player ref is invalid!"); - } - } - - public void handle(BuilderToolSelectionToolAskForClipboard packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> { - BlockSelection selection = s.getSelection(); - if (selection != null) { - EditorBlocksChange editorPacket = selection.toPacket(); - BlockChange[] blocksChange = editorPacket.blocksChange; - prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange); - ArrayList fluidChanges = new ArrayList<>(); - int anchorX = selection.getAnchorX(); - int anchorY = selection.getAnchorY(); - int anchorZ = selection.getAnchorZ(); - selection.forEachFluid( - (x, y, z, fluidId, fluidLevel) -> fluidChanges.add( - new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel) - ) - ); - PrototypePlayerBuilderToolSettings.FluidChange[] fluidChangesArray = fluidChanges.toArray( - PrototypePlayerBuilderToolSettings.FluidChange[]::new - ); - prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode(fluidChangesArray); - FluidChange[] packetFluids = new FluidChange[fluidChangesArray.length]; - - for (int i = 0; i < fluidChangesArray.length; i++) { - PrototypePlayerBuilderToolSettings.FluidChange fc = fluidChangesArray[i]; - packetFluids[i] = new FluidChange(fc.x(), fc.y(), fc.z(), fc.fluidId(), fc.fluidLevel()); - } - - playerRef.getPacketHandler().write(new BuilderToolSelectionToolReplyWithClipboard(blocksChange, packetFluids)); - } - } - ); - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolSelectionToolAskForClipboard packet. Player ref is invalid!"); - } - } - - public int toInt(float value) { - return (int)Math.floor(value + 0.1); - } - - private void handle(@Nonnull BuilderToolSelectionTransform packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - boolean keepEmptyBlocks = true; - BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); - if (builderTool != null && builderTool.getId().equals("Selection")) { - BuilderTool.ArgData args = builderTool.getItemArgData(playerComponent.getInventory().getItemInHand()); - if (args != null && args.tool() != null) { - keepEmptyBlocks = (Boolean)args.tool().getOrDefault("KeepEmptyBlocks", true); - } - } - - boolean finalKeepEmptyBlocks = keepEmptyBlocks; - float[] tmx = new float[16]; - - for (int i = 0; i < packet.transformationMatrix.length; i++) { - tmx[i] = this.toInt(packet.transformationMatrix[i]); - } - - Matrix4d transformationMatrix = new Matrix4d() - .assign( - tmx[0], tmx[4], tmx[8], tmx[12], tmx[1], tmx[5], tmx[9], tmx[13], tmx[2], tmx[6], tmx[10], tmx[14], tmx[3], tmx[7], tmx[11], tmx[15] - ); - Vector3i initialSelectionMin = new Vector3i(packet.initialSelectionMin.x, packet.initialSelectionMin.y, packet.initialSelectionMin.z); - Vector3i initialSelectionMax = new Vector3i(packet.initialSelectionMax.x, packet.initialSelectionMax.y, packet.initialSelectionMax.z); - Vector3f rotationOrigin = new Vector3f(packet.initialRotationOrigin.x, packet.initialRotationOrigin.y, packet.initialRotationOrigin.z); - PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(playerRef.getUuid()); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> { - int blockCount = s.getSelection().getSelectionVolume(); - boolean large = blockCount > 20000; - if (large) { - playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.warning")); - } - - if (prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode() == null) { - s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor); - if (packet.cutOriginal) { - s.copyOrCut( - r, - initialSelectionMin.x, - initialSelectionMin.y, - initialSelectionMin.z, - initialSelectionMax.x, - initialSelectionMax.y, - initialSelectionMax.z, - 138, - store - ); - } else { - s.copyOrCut( - r, - initialSelectionMin.x, - initialSelectionMin.y, - initialSelectionMin.z, - initialSelectionMax.x, - initialSelectionMax.y, - initialSelectionMax.z, - 136, - store - ); - } - - BlockSelection selection = s.getSelection(); - BlockChange[] blocksChange = selection.toPacket().blocksChange; - prototypeSettings.setBlockChangesForPlaySelectionToolPasteMode(blocksChange); - ArrayList fluidChanges = new ArrayList<>(); - int anchorX = selection.getAnchorX(); - int anchorY = selection.getAnchorY(); - int anchorZ = selection.getAnchorZ(); - selection.forEachFluid( - (x, y, z, fluidId, fluidLevel) -> fluidChanges.add( - new PrototypePlayerBuilderToolSettings.FluidChange(x - anchorX, y - anchorY, z - anchorZ, fluidId, fluidLevel) - ) - ); - prototypeSettings.setFluidChangesForPlaySelectionToolPasteMode( - fluidChanges.toArray(PrototypePlayerBuilderToolSettings.FluidChange[]::new) - ); - prototypeSettings.setBlockChangeOffsetOrigin(new Vector3i(selection.getX(), selection.getY(), selection.getZ())); - } - - Vector3i blockChangeOffsetOrigin = prototypeSettings.getBlockChangeOffsetOrigin(); - if (packet.initialPastePointForClipboardPaste != null) { - blockChangeOffsetOrigin = new Vector3i( - packet.initialPastePointForClipboardPaste.x, - packet.initialPastePointForClipboardPaste.y, - packet.initialPastePointForClipboardPaste.z - ); - } - - if (blockChangeOffsetOrigin == null) { - playerComponent.sendMessage(Message.translation("server.builderTools.selection.noBlockChangeOffsetOrigin")); - } else { - s.transformThenPasteClipboard( - prototypeSettings.getBlockChangesForPlaySelectionToolPasteMode(), - prototypeSettings.getFluidChangesForPlaySelectionToolPasteMode(), - transformationMatrix, - rotationOrigin, - blockChangeOffsetOrigin, - finalKeepEmptyBlocks, - componentAccessor - ); - s.select(initialSelectionMin, initialSelectionMax, "server.builderTools.selectReasons.selectionTranslatePacket", componentAccessor); - s.transformSelectionPoints(transformationMatrix, rotationOrigin); - if (large) { - playerComponent.sendMessage(Message.translation("server.builderTools.selection.large.complete")); - } - - if (packet.isExitingTransformMode) { - prototypeSettings.setInSelectionTransformationMode(false); - } - } - } - ); - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolSelectionTransform packet. Player ref is invalid!"); - } - } - - public void handle(@Nonnull BuilderToolExtrudeAction packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.modify")) { - BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); - if (builderTool != null && builderTool.getId().equals("Extrude")) { - ItemStack activeItemStack = playerComponent.getInventory().getItemInHand(); - BuilderTool.ArgData args = builderTool.getItemArgData(activeItemStack); - int extrudeDepth = (Integer)args.tool().get("ExtrudeDepth"); - int extrudeRadius = (Integer)args.tool().get("ExtrudeRadius"); - int blockId = ((BlockPattern)args.tool().get("ExtrudeMaterial")).firstBlock(); - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> s.extendFace( - packet.x, - packet.y, - packet.z, - packet.xNormal, - packet.yNormal, - packet.zNormal, - extrudeDepth, - extrudeRadius, - blockId, - null, - null, - componentAccessor - ) - ); - } - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolExtrudeAction packet. Player ref is invalid!"); - } - } - - public void handle(@Nonnull BuilderToolStackArea packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - - assert playerComponent != null; - - if (hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> { - s.select( - this.fromBlockPosition(packet.selectionMin), - this.fromBlockPosition(packet.selectionMax), - "server.builderTools.selectReasons.extrude", - componentAccessor - ); - s.stack(r, new Vector3i(packet.xNormal, packet.yNormal, packet.zNormal), packet.numStacks, true, 0, componentAccessor); - } - ); - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolStackArea packet. Player ref is invalid!"); } } @@ -617,362 +606,292 @@ public class BuilderToolsPacketHandler implements SubPacketHandler { return new Vector3i(position.x, position.y, position.z); } - public void handle(@Nonnull BuilderToolRotateClipboard packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - Axis axis = packet.axis == com.hypixel.hytale.protocol.packets.buildertools.Axis.X - ? Axis.X - : (packet.axis == com.hypixel.hytale.protocol.packets.buildertools.Axis.Y ? Axis.Y : Axis.Z); - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.rotate(r, axis, packet.angle, componentAccessor)); - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolPasteClipboard packet. Player ref is invalid!"); + public void handleBuilderToolRotateClipboard( + @Nonnull BuilderToolRotateClipboard packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + Axis axis = packet.axis == com.hypixel.hytale.protocol.packets.buildertools.Axis.X + ? Axis.X + : (packet.axis == com.hypixel.hytale.protocol.packets.buildertools.Axis.Y ? Axis.Y : Axis.Z); + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.rotate(r, axis, packet.angle, componentAccessor)); } } - public void handle(@Nonnull BuilderToolPasteClipboard packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.selection.clipboard")) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue( - playerComponent, playerRef, (r, s, componentAccessor) -> s.paste(r, packet.x, packet.y, packet.z, componentAccessor) - ); - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolPasteClipboard packet. Player ref is invalid!"); + public void handleBuilderToolPasteClipboard( + @Nonnull BuilderToolPasteClipboard packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.paste(r, packet.x, packet.y, packet.z, componentAccessor)); } } - public void handle(@Nonnull BuilderToolLineAction packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.brush.use")) { - BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); - if (builderTool != null && builderTool.getId().equals("Line")) { - BuilderTool.ArgData args = builderTool.getItemArgData(playerComponent.getInventory().getItemInHand()); - BrushData.Values brushData = args.brush(); - int lineWidth = (Integer)args.tool().get("bLineWidth"); - int lineHeight = (Integer)args.tool().get("cLineHeight"); - BrushShape lineShape = BrushShape.valueOf((String)args.tool().get("dLineShape")); - BrushOrigin lineOrigin = BrushOrigin.valueOf((String)args.tool().get("eLineOrigin")); - int lineWallThickness = (Integer)args.tool().get("fLineWallThickness"); - int lineSpacing = (Integer)args.tool().get("gLineSpacing"); - int lineDensity = (Integer)args.tool().get("hLineDensity"); - BlockPattern lineMaterial = (BlockPattern)args.tool().get("aLineMaterial"); - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue( - playerComponent, - playerRef, - (r, s, componentAccessor) -> s.editLine( - packet.xStart, - packet.yStart, - packet.zStart, - packet.xEnd, - packet.yEnd, - packet.zEnd, - lineMaterial, - lineWidth, - lineHeight, - lineWallThickness, - lineShape, - lineOrigin, - lineSpacing, - lineDensity, - ToolOperation.combineMasks(brushData, s.getGlobalMask()), - componentAccessor - ) - ); - } - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolLineAction packet. Player ref is invalid!"); - } - } - - public void handle(@Nonnull BuilderToolOnUseInteraction packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent, "hytale.editor.brush.use")) { + public void handleBuilderToolLineAction( + @Nonnull BuilderToolLineAction packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + BuilderTool builderTool = BuilderTool.getActiveBuilderTool(playerComponent); + if (builderTool != null && builderTool.getId().equals("Line")) { + BuilderTool.ArgData args = builderTool.getItemArgData(playerComponent.getInventory().getItemInHand()); + BrushData.Values brushData = args.brush(); + Map tool = args.tool(); + if (tool != null) { + int lineWidth = (Integer)tool.get("bLineWidth"); + int lineHeight = (Integer)tool.get("cLineHeight"); + BrushShape lineShape = BrushShape.valueOf((String)tool.get("dLineShape")); + BrushOrigin lineOrigin = BrushOrigin.valueOf((String)tool.get("eLineOrigin")); + int lineWallThickness = (Integer)tool.get("fLineWallThickness"); + int lineSpacing = (Integer)tool.get("gLineSpacing"); + int lineDensity = (Integer)tool.get("hLineDensity"); + BlockPattern lineMaterial = (BlockPattern)tool.get("aLineMaterial"); LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.edit(ref, packet, componentAccessor)); + BuilderToolsPlugin.addToQueue( + playerComponent, + playerRef, + (r, s, componentAccessor) -> s.editLine( + packet.xStart, + packet.yStart, + packet.zStart, + packet.xEnd, + packet.yEnd, + packet.zEnd, + lineMaterial, + lineWidth, + lineHeight, + lineWallThickness, + lineShape, + lineOrigin, + lineSpacing, + lineDensity, + ToolOperation.combineMasks(brushData, s.getGlobalMask()), + componentAccessor + ) + ); } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolOnUseInteraction packet. Player ref is invalid!"); + } } } - public void handle(@Nonnull BuilderToolSetEntityTransform packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute( - () -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - - assert playerComponent != null; - - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - TransformComponent transformComponent = store.getComponent(entityReference, TransformComponent.getComponentType()); - - assert transformComponent != null; - - HeadRotation headRotation = store.getComponent(entityReference, HeadRotation.getComponentType()); - ModelTransform modelTransform = packet.modelTransform; - if (modelTransform != null) { - boolean hasPosition = modelTransform.position != null; - boolean hasLookOrientation = modelTransform.lookOrientation != null; - boolean hasBodyOrientation = modelTransform.bodyOrientation != null; - if (hasPosition) { - transformComponent.getPosition().assign(modelTransform.position.x, modelTransform.position.y, modelTransform.position.z); - } - - if (hasLookOrientation && headRotation != null) { - headRotation.getRotation() - .assign(modelTransform.lookOrientation.pitch, modelTransform.lookOrientation.yaw, modelTransform.lookOrientation.roll); - } - - if (hasBodyOrientation) { - transformComponent.getRotation() - .assign(modelTransform.bodyOrientation.pitch, modelTransform.bodyOrientation.yaw, modelTransform.bodyOrientation.roll); - } - - if (hasPosition || hasLookOrientation || hasBodyOrientation) { - transformComponent.markChunkDirty(store); - } - } - } - } - } - ); - } else { - throw new RuntimeException("Unable to process BuilderToolSetEntityTransform packet. Player ref is invalid!"); + public void handleBuilderToolOnUseInteraction( + @Nonnull BuilderToolOnUseInteraction packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + BuilderToolsPlugin.addToQueue(playerComponent, playerRef, (r, s, componentAccessor) -> s.edit(ref, packet, componentAccessor)); } } - public void handle(@Nonnull PrefabUnselectPrefab packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); - PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager(); - PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerRef.getUuid()); - if (prefabEditSession == null) { - playerComponent.sendMessage(Message.translation("server.commands.editprefab.notInEditSession")); - } else { - if (prefabEditSession.clearSelectedPrefab(ref, store)) { - playerComponent.sendMessage(Message.translation("server.commands.editprefab.unselected")); - } else { - playerComponent.sendMessage(Message.translation("server.commands.editprefab.noPrefabSelected")); - } + public void handleBuilderToolSetEntityTransform( + @Nonnull BuilderToolSetEntityTransform packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + TransformComponent transformComponent = store.getComponent(targetRef, TransformComponent.getComponentType()); + if (transformComponent != null) { + HeadRotation headRotation = store.getComponent(targetRef, HeadRotation.getComponentType()); + ModelTransform modelTransform = packet.modelTransform; + if (modelTransform != null) { + boolean hasPosition = modelTransform.position != null; + boolean hasLookOrientation = modelTransform.lookOrientation != null; + boolean hasBodyOrientation = modelTransform.bodyOrientation != null; + if (hasPosition) { + transformComponent.getPosition().assign(modelTransform.position.x, modelTransform.position.y, modelTransform.position.z); + } + + if (hasLookOrientation && headRotation != null) { + headRotation.getRotation() + .assign(modelTransform.lookOrientation.pitch, modelTransform.lookOrientation.yaw, modelTransform.lookOrientation.roll); + } + + if (hasBodyOrientation) { + transformComponent.getRotation() + .assign(modelTransform.bodyOrientation.pitch, modelTransform.bodyOrientation.yaw, modelTransform.bodyOrientation.roll); + } + + if (hasPosition || hasLookOrientation || hasBodyOrientation) { + transformComponent.markChunkDirty(store); } } - }); - } else { - throw new RuntimeException("Unable to process PrefabUnselectPrefab packet. Player ref is invalid!"); + } } } - public void handle(@Nonnull BuilderToolSetEntityScale packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - PropComponent propComponent = store.getComponent(entityReference, PropComponent.getComponentType()); - if (propComponent != null) { - EntityScaleComponent scaleComponent = store.getComponent(entityReference, EntityScaleComponent.getComponentType()); - if (scaleComponent == null) { - scaleComponent = new EntityScaleComponent(packet.scale); - store.addComponent(entityReference, EntityScaleComponent.getComponentType(), scaleComponent); - } else { - scaleComponent.setScale(packet.scale); - } - } - } + public void handlePrefabUnselectPrefab( + @Nonnull PrefabUnselectPrefab packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + LOGGER.at(Level.INFO).log("%s: %s", this.packetHandler.getIdentifier(), packet); + PrefabEditSessionManager prefabEditSessionManager = BuilderToolsPlugin.get().getPrefabEditSessionManager(); + PrefabEditSession prefabEditSession = prefabEditSessionManager.getPrefabEditSession(playerRef.getUuid()); + if (prefabEditSession == null) { + playerComponent.sendMessage(Message.translation("server.commands.editprefab.notInEditSession")); + } else { + if (prefabEditSession.clearSelectedPrefab(ref, store)) { + playerComponent.sendMessage(Message.translation("server.commands.editprefab.unselected")); + } else { + playerComponent.sendMessage(Message.translation("server.commands.editprefab.noPrefabSelected")); } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetEntityScale packet. Player ref is invalid!"); + } } } - public void handle(@Nonnull BuilderToolSetEntityPickupEnabled packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - PropComponent propComponent = store.getComponent(entityReference, PropComponent.getComponentType()); - if (propComponent != null) { - if (packet.enabled) { - store.ensureComponent(entityReference, Interactable.getComponentType()); - if (store.getComponent(entityReference, PreventPickup.getComponentType()) != null) { - store.removeComponent(entityReference, PreventPickup.getComponentType()); - } - - Interactions interactionsComponent = store.getComponent(entityReference, Interactions.getComponentType()); - if (interactionsComponent == null) { - interactionsComponent = new Interactions(); - store.addComponent(entityReference, Interactions.getComponentType(), interactionsComponent); - } - - interactionsComponent.setInteractionId(InteractionType.Use, "*PickupItem"); - interactionsComponent.setInteractionHint("server.interactionHints.pickup"); - } else { - if (store.getComponent(entityReference, Interactable.getComponentType()) != null) { - store.removeComponent(entityReference, Interactable.getComponentType()); - } - - if (store.getComponent(entityReference, Interactions.getComponentType()) != null) { - store.removeComponent(entityReference, Interactions.getComponentType()); - } - - store.ensureComponent(entityReference, PreventPickup.getComponentType()); - } - } - } + public void handleBuilderToolSetEntityScale( + @Nonnull BuilderToolSetEntityScale packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + PropComponent propComponent = store.getComponent(targetRef, PropComponent.getComponentType()); + if (propComponent != null) { + EntityScaleComponent scaleComponent = store.getComponent(targetRef, EntityScaleComponent.getComponentType()); + if (scaleComponent == null) { + scaleComponent = new EntityScaleComponent(packet.scale); + store.addComponent(targetRef, EntityScaleComponent.getComponentType(), scaleComponent); + } else { + scaleComponent.setScale(packet.scale); } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetEntityPickupEnabled packet. Player ref is invalid!"); + } } } - public void handle(@Nonnull BuilderToolSetEntityLight packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - if (packet.light == null) { - store.removeComponent(entityReference, DynamicLight.getComponentType()); - store.removeComponent(entityReference, PersistentDynamicLight.getComponentType()); - } else { - ColorLight colorLight = new ColorLight(packet.light.radius, packet.light.red, packet.light.green, packet.light.blue); - store.putComponent(entityReference, DynamicLight.getComponentType(), new DynamicLight(colorLight)); - store.putComponent(entityReference, PersistentDynamicLight.getComponentType(), new PersistentDynamicLight(colorLight)); - } + public void handleBuilderToolSetEntityPickupEnabled( + @Nonnull BuilderToolSetEntityPickupEnabled packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + PropComponent propComponent = store.getComponent(targetRef, PropComponent.getComponentType()); + if (propComponent != null) { + if (packet.enabled) { + store.ensureComponent(targetRef, Interactable.getComponentType()); + if (store.getComponent(targetRef, PreventPickup.getComponentType()) != null) { + store.removeComponent(targetRef, PreventPickup.getComponentType()); } + + Interactions interactionsComponent = store.getComponent(targetRef, Interactions.getComponentType()); + if (interactionsComponent == null) { + interactionsComponent = new Interactions(); + store.addComponent(targetRef, Interactions.getComponentType(), interactionsComponent); + } + + interactionsComponent.setInteractionId(InteractionType.Use, "*PickupItem"); + interactionsComponent.setInteractionHint("server.interactionHints.pickup"); + } else { + if (store.getComponent(targetRef, Interactable.getComponentType()) != null) { + store.removeComponent(targetRef, Interactable.getComponentType()); + } + + if (store.getComponent(targetRef, Interactions.getComponentType()) != null) { + store.removeComponent(targetRef, Interactions.getComponentType()); + } + + store.ensureComponent(targetRef, PreventPickup.getComponentType()); } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetEntityLight packet. Player ref is invalid!"); + } } } - public void handle(@Nonnull BuilderToolSetNPCDebug packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - NPCMarkerComponent npcMarker = store.getComponent(entityReference, NPCMarkerComponent.getComponentType()); - if (npcMarker != null) { - UUIDComponent uuidComponent = store.getComponent(entityReference, UUIDComponent.getComponentType()); - if (uuidComponent != null) { - UUID uuid = uuidComponent.getUuid(); - String command = packet.enabled ? "npc debug set display --entity " + uuid : "npc debug clear --entity " + uuid; - CommandManager.get().handleCommand(playerComponent, command); - } - } - } - } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetNPCDebug packet. Player ref is invalid!"); + public void handleBuilderToolSetEntityLight( + @Nonnull BuilderToolSetEntityLight packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + if (packet.light == null) { + store.removeComponent(targetRef, DynamicLight.getComponentType()); + store.removeComponent(targetRef, PersistentDynamicLight.getComponentType()); + } else { + ColorLight colorLight = new ColorLight(packet.light.radius, packet.light.red, packet.light.green, packet.light.blue); + store.putComponent(targetRef, DynamicLight.getComponentType(), new DynamicLight(colorLight)); + store.putComponent(targetRef, PersistentDynamicLight.getComponentType(), new PersistentDynamicLight(colorLight)); + } } } - public void handle(@Nonnull BuilderToolSetEntityCollision packet) { - PlayerRef playerRef = this.packetHandler.getPlayerRef(); - Ref ref = playerRef.getReference(); - if (ref != null && ref.isValid()) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); - if (hasPermission(playerComponent)) { - Ref entityReference = world.getEntityStore().getRefFromNetworkId(packet.entityId); - if (entityReference != null) { - PropComponent propComponent = store.getComponent(entityReference, PropComponent.getComponentType()); - NPCMarkerComponent npcMarker = store.getComponent(entityReference, NPCMarkerComponent.getComponentType()); - if (propComponent != null || npcMarker != null) { - if (packet.collisionType != null && !packet.collisionType.isEmpty()) { - HitboxCollisionConfig hitboxCollisionConfig = HitboxCollisionConfig.getAssetMap().getAsset(packet.collisionType); - if (hitboxCollisionConfig != null) { - store.putComponent(entityReference, HitboxCollision.getComponentType(), new HitboxCollision(hitboxCollisionConfig)); - } - } else { - store.removeComponent(entityReference, HitboxCollision.getComponentType()); - } - } + public void handleBuilderToolSetNPCDebug( + @Nonnull BuilderToolSetNPCDebug packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (playerComponent != null) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + NPCMarkerComponent npcMarkerComponent = store.getComponent(targetRef, NPCMarkerComponent.getComponentType()); + if (npcMarkerComponent != null) { + UUIDComponent uuidComponent = store.getComponent(targetRef, UUIDComponent.getComponentType()); + if (uuidComponent != null) { + UUID uuid = uuidComponent.getUuid(); + String command = packet.enabled ? "npc debug set display --entity " + uuid : "npc debug clear --entity " + uuid; + CommandManager.get().handleCommand(playerComponent, command); } } - }); - } else { - throw new RuntimeException("Unable to process BuilderToolSetEntityCollision packet. Player ref is invalid!"); + } + } + } + + public void handleBuilderToolSetEntityCollision( + @Nonnull BuilderToolSetEntityCollision packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { + Ref targetRef = world.getEntityStore().getRefFromNetworkId(packet.entityId); + if (targetRef != null && targetRef.isValid()) { + PropComponent propComponent = store.getComponent(targetRef, PropComponent.getComponentType()); + NPCMarkerComponent npcMarkerComponent = store.getComponent(targetRef, NPCMarkerComponent.getComponentType()); + if (propComponent != null || npcMarkerComponent != null) { + if (packet.collisionType != null && !packet.collisionType.isEmpty()) { + HitboxCollisionConfig hitboxCollisionConfig = HitboxCollisionConfig.getAssetMap().getAsset(packet.collisionType); + if (hitboxCollisionConfig != null) { + store.putComponent(targetRef, HitboxCollision.getComponentType(), new HitboxCollision(hitboxCollisionConfig)); + } + } else { + store.removeComponent(targetRef, HitboxCollision.getComponentType()); + } + } } } } diff --git a/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPlugin.java b/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPlugin.java index 60fb6541..799406ac 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPlugin.java +++ b/src/com/hypixel/hytale/builtin/buildertools/BuilderToolsPlugin.java @@ -129,6 +129,7 @@ import com.hypixel.hytale.codec.codecs.array.ArrayCodec; import com.hypixel.hytale.codec.validation.Validators; import com.hypixel.hytale.common.util.CompletableFutureUtil; import com.hypixel.hytale.common.util.PathUtil; +import com.hypixel.hytale.component.AddReason; import com.hypixel.hytale.component.Archetype; import com.hypixel.hytale.component.CommandBuffer; import com.hypixel.hytale.component.ComponentAccessor; @@ -147,13 +148,11 @@ import com.hypixel.hytale.math.block.BlockCubeUtil; import com.hypixel.hytale.math.block.BlockSphereUtil; import com.hypixel.hytale.math.block.BlockUtil; import com.hypixel.hytale.math.iterator.LineIterator; -import com.hypixel.hytale.math.matrix.Matrix4d; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; import com.hypixel.hytale.math.vector.Vector3i; -import com.hypixel.hytale.math.vector.Vector4d; import com.hypixel.hytale.math.vector.VectorBoxUtil; import com.hypixel.hytale.metrics.MetricProvider; import com.hypixel.hytale.metrics.MetricResults; @@ -195,13 +194,17 @@ import com.hypixel.hytale.server.core.command.system.CommandManager; import com.hypixel.hytale.server.core.command.system.CommandRegistry; import com.hypixel.hytale.server.core.command.system.CommandSender; import com.hypixel.hytale.server.core.entity.UUIDComponent; +import com.hypixel.hytale.server.core.entity.entities.BlockEntity; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.event.events.player.PlayerConnectEvent; import com.hypixel.hytale.server.core.event.events.player.PlayerDisconnectEvent; import com.hypixel.hytale.server.core.inventory.ItemStack; import com.hypixel.hytale.server.core.inventory.container.ItemContainer; import com.hypixel.hytale.server.core.io.ServerManager; +import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; +import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; +import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId; import com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction; import com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction; import com.hypixel.hytale.server.core.modules.interaction.interaction.config.server.OpenCustomUIInteraction; @@ -223,7 +226,6 @@ import com.hypixel.hytale.server.core.prefab.selection.standard.FeedbackConsumer import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.SoundUtil; import com.hypixel.hytale.server.core.universe.world.World; -import com.hypixel.hytale.server.core.universe.world.accessor.BlockAccessor; import com.hypixel.hytale.server.core.universe.world.accessor.ChunkAccessor; import com.hypixel.hytale.server.core.universe.world.accessor.LocalCachedChunkAccessor; import com.hypixel.hytale.server.core.universe.world.accessor.OverridableChunkAccessor; @@ -280,6 +282,7 @@ import java.util.function.Predicate; import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.joml.Quaterniond; public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, MetricProvider { public static final String EDITOR_BLOCK = "Editor_Block"; @@ -912,15 +915,47 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, @Nonnull public BuilderToolsPlugin.ActionEntry restore(Ref ref, Player player, World world, ComponentAccessor componentAccessor) { List> collector = Collections.emptyList(); + List> recreatedEntityRefs = null; + if (this.action == BuilderToolsPlugin.Action.ROTATE) { + PrototypePlayerBuilderToolSettings protoSettings = ToolOperation.getOrCreatePrototypeSettings(player.getUuid()); + List> currentRefs = protoSettings.getLastTransformEntityRefs(); + if (currentRefs != null) { + Store entityStore = world.getEntityStore().getStore(); + + for (Ref currentRef : currentRefs) { + if (currentRef.isValid()) { + collector = (List>)(collector.isEmpty() ? new ObjectArrayList<>() : collector); + collector.add(new EntityRemoveSnapshot(currentRef)); + entityStore.removeEntity(currentRef, RemoveReason.UNLOAD); + } + } + + protoSettings.setLastTransformEntityRefs(null); + } + } for (SelectionSnapshot snapshot : this.snapshots) { - SelectionSnapshot nextSnapshot = snapshot.restore(ref, player, world, componentAccessor); - if (nextSnapshot != null) { - collector = (List>)(collector.isEmpty() ? new ObjectArrayList<>() : collector); - collector.add(nextSnapshot); + if (this.action != BuilderToolsPlugin.Action.ROTATE || !(snapshot instanceof EntityAddSnapshot)) { + SelectionSnapshot nextSnapshot = snapshot.restore(ref, player, world, componentAccessor); + if (nextSnapshot != null) { + collector = (List>)(collector.isEmpty() ? new ObjectArrayList<>() : collector); + collector.add(nextSnapshot); + if (nextSnapshot instanceof EntityAddSnapshot entityAddSnapshot) { + if (recreatedEntityRefs == null) { + recreatedEntityRefs = new ArrayList<>(); + } + + recreatedEntityRefs.add(entityAddSnapshot.getEntityRef()); + } + } } } + if (this.action == BuilderToolsPlugin.Action.ROTATE && recreatedEntityRefs != null && !recreatedEntityRefs.isEmpty()) { + PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(player.getUuid()); + prototypeSettings.setLastTransformEntityRefs(recreatedEntityRefs); + } + return new BuilderToolsPlugin.ActionEntry(this.action, collector); } } @@ -1925,88 +1960,94 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, this.pushHistory(BuilderToolsPlugin.Action.EXTRUDE, new BlockSelectionSnapshot(before)); BlockSelection after = new BlockSelection(totalBlocks, 0); after.copyPropertiesFrom(before); - this.extendFaceFindBlocks( - accessor, BlockType.getAssetMap(), before, after, x + normalX, y + normalY, z + normalZ, normalX, normalY, normalZ, extrudeDepth, blockId, min, max - ); - Vector3i offset = new Vector3i(0, 0, 0); - - for (int i = 0; i < extrudeDepth; i++) { - offset.x = normalX * i; - offset.y = normalY * i; - offset.z = normalZ * i; - after.placeNoReturn("Set", this.player, BuilderToolsPlugin.FEEDBACK_CONSUMER, world, offset, null, componentAccessor); + if (x >= min.getX() && x <= max.getX()) { + if (y >= min.getY() && y <= max.getY()) { + if (z >= min.getZ() && z <= max.getZ()) { + int testBlock = accessor.getBlock(x - normalX, y - normalY, z - normalZ); + BlockType testBlockType = BlockType.getAssetMap().getAsset(testBlock); + if (testBlockType != null && (testBlockType.getDrawType() == DrawType.Cube || testBlockType.getDrawType() == DrawType.CubeWithModel)) { + int xMod = Math.abs(normalX) == 1 ? 0 : 1; + int yMod = Math.abs(normalY) == 1 ? 0 : 1; + int zMod = Math.abs(normalZ) == 1 ? 0 : 1; + Vector3i surfaceMin = new Vector3i(x - radiusAllowed * xMod, y - radiusAllowed * yMod, z - radiusAllowed * zMod); + Vector3i surfaceMax = new Vector3i(x + radiusAllowed * xMod, y + radiusAllowed * yMod, z + radiusAllowed * zMod); + this.extendFaceFindBlocks(accessor, before, after, normalX, normalY, normalZ, extrudeDepth, blockId, min, max, surfaceMin, surfaceMax); + after.placeNoReturn("Set", this.player, BuilderToolsPlugin.FEEDBACK_CONSUMER, world, componentAccessor); + BuilderToolsPlugin.invalidateWorldMapForSelection(after, world); + long end = System.nanoTime(); + long diff = end - start; + BuilderToolsPlugin.get() + .getLogger() + .at(Level.FINE) + .log("Took: %dns (%dms) to execute set of %d blocks", diff, TimeUnit.NANOSECONDS.toMillis(diff), after.getBlockCount()); + this.sendUpdate(); + this.sendArea(); + } + } + } } - - BuilderToolsPlugin.invalidateWorldMapForSelection(after, world); - long end = System.nanoTime(); - long diff = end - start; - BuilderToolsPlugin.get() - .getLogger() - .at(Level.FINE) - .log("Took: %dns (%dms) to execute set of %d blocks", diff, TimeUnit.NANOSECONDS.toMillis(diff), after.getBlockCount()); - this.sendUpdate(); - this.sendArea(); } private void extendFaceFindBlocks( - @Nonnull ChunkAccessor accessor, - @Nonnull BlockTypeAssetMap assetMap, + @Nonnull LocalCachedChunkAccessor accessor, @Nonnull BlockSelection before, @Nonnull BlockSelection after, - int x, - int y, - int z, int normalX, int normalY, int normalZ, int extrudeDepth, int blockId, @Nonnull Vector3i min, - @Nonnull Vector3i max + @Nonnull Vector3i max, + @Nonnull Vector3i surfaceMin, + @Nonnull Vector3i surfaceMax ) { - if (x >= min.getX() && x <= max.getX()) { - if (y >= min.getY() && y <= max.getY()) { - if (z >= min.getZ() && z <= max.getZ()) { - int block = accessor.getBlock(x, y, z); - int testBlock = accessor.getBlock(x - normalX, y - normalY, z - normalZ); - BlockType testBlockType = assetMap.getAsset(testBlock); - if (testBlockType != null && (testBlockType.getDrawType() == DrawType.Cube || testBlockType.getDrawType() == DrawType.CubeWithModel)) { - if (!before.hasBlockAtWorldPos(x, y, z)) { - BlockAccessor blocks = accessor.getChunkIfInMemory(ChunkUtil.indexChunkFromBlock(x, z)); - if (blocks != null) { - before.addBlockAtWorldPos( - x, - y, - z, - block, - blocks.getRotationIndex(x, y, z), - blocks.getFiller(x, y, z), - blocks.getSupportValue(x, y, z), - blocks.getBlockComponentHolder(x, y, z) - ); - after.addBlockAtWorldPos(x, y, z, blockId, 0, 0, 0); + int xMin = surfaceMin.getX(); + int yMin = surfaceMin.getY(); + int zMin = surfaceMin.getZ(); + int xMax = surfaceMax.getX(); + int yMax = surfaceMax.getY(); + int zMax = surfaceMax.getZ(); - for (Vector3i side : Vector3i.BLOCK_SIDES) { - if ((normalX == 0 || side.getX() == 0) && (normalY == 0 || side.getY() == 0) && (normalZ == 0 || side.getZ() == 0)) { - this.extendFaceFindBlocks( - accessor, - assetMap, - before, - after, - x + side.getX(), - y + side.getY(), - z + side.getZ(), - normalX, - normalY, - normalZ, - extrudeDepth, - blockId, - min, - max - ); - } - } - } + for (int x = xMin; x <= xMax; x++) { + for (int z = zMin; z <= zMax; z++) { + WorldChunk chunk = accessor.getChunk(ChunkUtil.indexChunkFromBlock(x, z)); + + for (int y = yMax; y >= yMin; y--) { + int currentBlock = chunk.getBlock(x, y, z); + int currentFluid = chunk.getFluidId(x, y, z); + if (currentBlock > 0) { + int xRes = x + normalX; + int yRes = y + normalY; + int zRes = z + normalZ; + currentBlock = chunk.getBlock(xRes, yRes, zRes); + before.addBlockAtWorldPos( + xRes, + yRes, + zRes, + currentBlock, + chunk.getRotationIndex(xRes, yRes, zRes), + chunk.getFiller(xRes, yRes, zRes), + chunk.getSupportValue(xRes, yRes, zRes), + chunk.getBlockComponentHolder(xRes, yRes, zRes) + ); + after.addBlockAtWorldPos(xRes, yRes, zRes, blockId, 0, 0, 0); + + for (int i = 0; i < extrudeDepth; i++) { + int extrudedBlockX = xRes + normalX * i; + int extrudedBlockY = yRes + normalY * i; + int extrudedBlockZ = zRes + normalZ * i; + before.addBlockAtWorldPos( + extrudedBlockX, + extrudedBlockY, + extrudedBlockZ, + currentBlock, + chunk.getRotationIndex(extrudedBlockX, extrudedBlockY, extrudedBlockZ), + chunk.getFiller(extrudedBlockX, extrudedBlockY, extrudedBlockZ), + chunk.getSupportValue(extrudedBlockX, extrudedBlockY, extrudedBlockZ), + chunk.getBlockComponentHolder(extrudedBlockX, extrudedBlockY, extrudedBlockZ) + ); + after.addBlockAtWorldPos(extrudedBlockX, extrudedBlockY, extrudedBlockZ, blockId, 0, 0, 0); } } } @@ -2165,7 +2206,7 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, int settings, @Nonnull ComponentAccessor componentAccessor ) throws PrefabCopyException { - return this.copyOrCut(ref, xMin, yMin, zMin, xMax, yMax, zMax, settings, null, componentAccessor); + return this.copyOrCut(ref, xMin, yMin, zMin, xMax, yMax, zMax, settings, null, null, componentAccessor); } public int copyOrCut( @@ -2179,6 +2220,22 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, int settings, @Nullable Vector3i playerAnchor, @Nonnull ComponentAccessor componentAccessor + ) throws PrefabCopyException { + return this.copyOrCut(ref, xMin, yMin, zMin, xMax, yMax, zMax, settings, playerAnchor, null, componentAccessor); + } + + public int copyOrCut( + @Nonnull Ref ref, + int xMin, + int yMin, + int zMin, + int xMax, + int yMax, + int zMax, + int settings, + @Nullable Vector3i playerAnchor, + @Nullable Set> skipEntityRemoveSnapshotFor, + @Nonnull ComponentAccessor componentAccessor ) throws PrefabCopyException { World world = componentAccessor.getExternalData().getWorld(); long start = System.nanoTime(); @@ -2316,8 +2373,11 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, Holder holder = store.copyEntity(e); this.selection.addEntityFromWorld(holder); if (cut) { - snapshots.add(new EntityRemoveSnapshot(e)); - entitiesToRemove.add(e); + boolean shouldSkip = skipEntityRemoveSnapshotFor != null && skipEntityRemoveSnapshotFor.contains(e); + if (!shouldSkip) { + snapshots.add(new EntityRemoveSnapshot(e)); + entitiesToRemove.add(e); + } } }); if (cut && entitiesToRemove != null) { @@ -2433,36 +2493,48 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, return size; } - public static RotationTuple transformRotation(RotationTuple prevRot, Matrix4d transformationMatrix) { + public static RotationTuple transformRotation(RotationTuple prevRot, Quaterniond rotation) { Vector3f forwardVec = new Vector3f(1.0F, 0.0F, 0.0F); Vector3f upVec = new Vector3f(0.0F, 1.0F, 0.0F); forwardVec = Rotation.rotate(forwardVec, prevRot.yaw(), prevRot.pitch(), prevRot.roll()); upVec = Rotation.rotate(upVec, prevRot.yaw(), prevRot.pitch(), prevRot.roll()); - Vector3f newForward = transformationMatrix.multiplyDirection(forwardVec.toVector3d()).toVector3f(); - Vector3f newUp = transformationMatrix.multiplyDirection(upVec.toVector3d()).toVector3f(); + org.joml.Vector3d fwd = rotation.transform(new org.joml.Vector3d(forwardVec.x, forwardVec.y, forwardVec.z)); + org.joml.Vector3d up = rotation.transform(new org.joml.Vector3d(upVec.x, upVec.y, upVec.z)); + Vector3f newForward = new Vector3f((float)fwd.x, (float)fwd.y, (float)fwd.z); + Vector3f newUp = new Vector3f((float)up.x, (float)up.y, (float)up.z); float bestScore = Float.MIN_VALUE; RotationTuple bestRot = prevRot; - for (RotationTuple rotation : RotationTuple.VALUES) { - Vector3f rotForward = Rotation.rotate(new Vector3f(1.0F, 0.0F, 0.0F), rotation.yaw(), rotation.pitch(), rotation.roll()); - Vector3f rotUp = Rotation.rotate(new Vector3f(0.0F, 1.0F, 0.0F), rotation.yaw(), rotation.pitch(), rotation.roll()); + for (RotationTuple rot : RotationTuple.VALUES) { + Vector3f rotForward = Rotation.rotate(new Vector3f(1.0F, 0.0F, 0.0F), rot.yaw(), rot.pitch(), rot.roll()); + Vector3f rotUp = Rotation.rotate(new Vector3f(0.0F, 1.0F, 0.0F), rot.yaw(), rot.pitch(), rot.roll()); float score = rotForward.dot(newForward) + rotUp.dot(newUp); if (score > bestScore) { bestScore = score; - bestRot = rotation; + bestRot = rot; } } return bestRot; } + private void transformEntityRotation(Vector3f rotation, Quaterniond deltaQuat) { + Quaterniond originalQuat = new Quaterniond().rotationYXZ(rotation.y, rotation.x, rotation.z); + Quaterniond resultQuat = deltaQuat.mul(originalQuat, new Quaterniond()); + org.joml.Vector3d eulerAngles = resultQuat.getEulerAnglesYXZ(new org.joml.Vector3d()); + rotation.assign((float)eulerAngles.x, (float)eulerAngles.y, (float)eulerAngles.z); + } + public void transformThenPasteClipboard( @Nonnull BlockChange[] blockChanges, @Nullable PrototypePlayerBuilderToolSettings.FluidChange[] fluidChanges, - @Nonnull Matrix4d transformationMatrix, + @Nullable PrototypePlayerBuilderToolSettings.EntityChange[] entityChanges, + @Nonnull Quaterniond rotation, + @Nonnull Vector3i translationOffset, @Nonnull Vector3f rotationOrigin, @Nonnull Vector3i initialPastePoint, boolean keepEmptyBlocks, + @Nonnull PrototypePlayerBuilderToolSettings prototypeSettings, ComponentAccessor componentAccessor ) { World world = componentAccessor.getExternalData().getWorld(); @@ -2477,35 +2549,33 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, } } - Vector4d translationEndResult = new Vector4d(0.0, 0.0, 0.0, 1.0); - transformationMatrix.multiply(translationEndResult); - translationEndResult.x = translationEndResult.x + rotationOrigin.x; - translationEndResult.y = translationEndResult.y + rotationOrigin.y; - translationEndResult.z = translationEndResult.z + rotationOrigin.z; + int centerX = translationOffset.x + (int)rotationOrigin.x; + int centerY = translationOffset.y + (int)rotationOrigin.y; + int centerZ = translationOffset.z + (int)rotationOrigin.z; BlockSelection before = new BlockSelection(); - before.setPosition((int)translationEndResult.x, (int)translationEndResult.y, (int)translationEndResult.z); + before.setPosition(centerX, centerY, centerZ); BlockSelection after = new BlockSelection(before); - LocalCachedChunkAccessor accessor = LocalCachedChunkAccessor.atWorldCoords(world, (int)translationEndResult.x, (int)translationEndResult.z, 50); + LocalCachedChunkAccessor accessor = LocalCachedChunkAccessor.atWorldCoords(world, centerX, centerZ, 50); int minX = Integer.MAX_VALUE; int minY = Integer.MAX_VALUE; int minZ = Integer.MAX_VALUE; int maxX = Integer.MIN_VALUE; int maxY = Integer.MIN_VALUE; int maxZ = Integer.MIN_VALUE; - Vector4d mutable4d = new Vector4d(0.0, 0.0, 0.0, 1.0); + org.joml.Vector3d mutableVec = new org.joml.Vector3d(); for (BlockChange blockChangex : blockChanges) { - mutable4d.assign( + mutableVec.set( blockChangex.x - rotationOrigin.x + initialPastePoint.x + 0.5, blockChangex.y - rotationOrigin.y + initialPastePoint.y + 0.5 + yOffsetOutOfGround, - blockChangex.z - rotationOrigin.z + initialPastePoint.z + 0.5, - 1.0 + blockChangex.z - rotationOrigin.z + initialPastePoint.z + 0.5 ); - transformationMatrix.multiply(mutable4d); + rotation.transform(mutableVec); + mutableVec.add(translationOffset.x, translationOffset.y, translationOffset.z); Vector3i rotatedLocation = new Vector3i( - (int)Math.floor(mutable4d.x + 0.1 + rotationOrigin.x - 0.5), - (int)Math.floor(mutable4d.y + 0.1 + rotationOrigin.y - 0.5), - (int)Math.floor(mutable4d.z + 0.1 + rotationOrigin.z - 0.5) + (int)Math.floor(mutableVec.x + 0.1 + rotationOrigin.x - 0.5), + (int)Math.floor(mutableVec.y + 0.1 + rotationOrigin.y - 0.5), + (int)Math.floor(mutableVec.z + 0.1 + rotationOrigin.z - 0.5) ); minX = Math.min(minX, rotatedLocation.x); minY = Math.min(minY, rotatedLocation.y); @@ -2517,12 +2587,12 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, Holder holder = currentChunk.getBlockComponentHolder(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); int blockIdInRotatedLocation = currentChunk.getBlock(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); int filler = currentChunk.getFiller(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); - int rotation = currentChunk.getRotationIndex(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); - before.addBlockAtWorldPos(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z, blockIdInRotatedLocation, rotation, filler, 0, holder); + int blockRotation = currentChunk.getRotationIndex(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); + before.addBlockAtWorldPos(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z, blockIdInRotatedLocation, blockRotation, filler, 0, holder); int originalFluidId = currentChunk.getFluidId(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); byte originalFluidLevel = currentChunk.getFluidLevel(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z); before.addFluidAtWorldPos(rotatedLocation.x, rotatedLocation.y, rotatedLocation.z, originalFluidId, originalFluidLevel); - int newRotation = transformRotation(RotationTuple.get(blockChangex.rotation), transformationMatrix).index(); + int newRotation = transformRotation(RotationTuple.get(blockChangex.rotation), rotation).index(); int blockIdToPlace = blockChangex.block; if (blockChangex.block == 0 && keepEmptyBlocks) { blockIdToPlace = editorBlockPrefabAir; @@ -2557,27 +2627,92 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, int finalYOffsetOutOfGround = yOffsetOutOfGround; if (fluidChanges != null) { for (PrototypePlayerBuilderToolSettings.FluidChange fluidChange : fluidChanges) { - mutable4d.assign( + mutableVec.set( fluidChange.x() - rotationOrigin.x + initialPastePoint.x + 0.5, fluidChange.y() - rotationOrigin.y + initialPastePoint.y + 0.5 + finalYOffsetOutOfGround, - fluidChange.z() - rotationOrigin.z + initialPastePoint.z + 0.5, - 1.0 + fluidChange.z() - rotationOrigin.z + initialPastePoint.z + 0.5 ); - transformationMatrix.multiply(mutable4d); + rotation.transform(mutableVec); + mutableVec.add(translationOffset.x, translationOffset.y, translationOffset.z); Vector3i rotatedLocationx = new Vector3i( - (int)Math.floor(mutable4d.x + 0.1 + rotationOrigin.x - 0.5), - (int)Math.floor(mutable4d.y + 0.1 + rotationOrigin.y - 0.5), - (int)Math.floor(mutable4d.z + 0.1 + rotationOrigin.z - 0.5) + (int)Math.floor(mutableVec.x + 0.1 + rotationOrigin.x - 0.5), + (int)Math.floor(mutableVec.y + 0.1 + rotationOrigin.y - 0.5), + (int)Math.floor(mutableVec.z + 0.1 + rotationOrigin.z - 0.5) ); after.addFluidAtWorldPos(rotatedLocationx.x, rotatedLocationx.y, rotatedLocationx.z, fluidChange.fluidId(), fluidChange.fluidLevel()); } } + List> previousEntityRefs = prototypeSettings.getLastTransformEntityRefs(); + List previousEntitySnapshots = new ArrayList<>(); + if (previousEntityRefs != null) { + Store entityStore = world.getEntityStore().getStore(); + + for (Ref ref : previousEntityRefs) { + if (ref.isValid()) { + previousEntitySnapshots.add(new EntityRemoveSnapshot(ref)); + entityStore.removeEntity(ref, RemoveReason.UNLOAD); + } + } + } + + List> addedEntityRefs = new ArrayList<>(); + if (entityChanges != null && entityChanges.length > 0) { + org.joml.Vector3d mutableEntityPos = new org.joml.Vector3d(); + + for (PrototypePlayerBuilderToolSettings.EntityChange entityChange : entityChanges) { + boolean isBlockEntity = entityChange.entityHolder().getComponent(BlockEntity.getComponentType()) != null; + double blockCenterOffset = isBlockEntity ? 0.5 : 0.0; + mutableEntityPos.set( + entityChange.x() - rotationOrigin.x, + entityChange.y() + blockCenterOffset - rotationOrigin.y + finalYOffsetOutOfGround, + entityChange.z() - rotationOrigin.z + ); + rotation.transform(mutableEntityPos); + mutableEntityPos.add(translationOffset.x, translationOffset.y, translationOffset.z); + double newX = mutableEntityPos.x + rotationOrigin.x; + double newY = mutableEntityPos.y + rotationOrigin.y - blockCenterOffset; + double newZ = mutableEntityPos.z + rotationOrigin.z; + Holder clonedHolder = entityChange.entityHolder().clone(); + TransformComponent transformComponent = clonedHolder.getComponent(TransformComponent.getComponentType()); + if (transformComponent != null && transformComponent.getPosition() != null) { + transformComponent.getPosition().assign(newX, newY, newZ); + Vector3f entityRotation = transformComponent.getRotation(); + if (entityRotation != null) { + this.transformEntityRotation(entityRotation, rotation); + } + } + + HeadRotation headRotation = clonedHolder.getComponent(HeadRotation.getComponentType()); + if (headRotation != null && headRotation.getRotation() != null) { + this.transformEntityRotation(headRotation.getRotation(), rotation); + } + + clonedHolder.putComponent(UUIDComponent.getComponentType(), new UUIDComponent(UUID.randomUUID())); + clonedHolder.removeComponent(EntityTrackerSystems.Visible.getComponentType()); + clonedHolder.removeComponent(NetworkId.getComponentType()); + Ref entityRef = componentAccessor.addEntity(clonedHolder, AddReason.LOAD); + addedEntityRefs.add(entityRef); + } + } + if (minX != Integer.MAX_VALUE) { before.setSelectionArea(new Vector3i(minX, minY, minZ), new Vector3i(maxX, maxY, maxZ)); } - this.pushHistory(BuilderToolsPlugin.Action.ROTATE, new BlockSelectionSnapshot(before)); + prototypeSettings.setLastTransformEntityRefs(new ArrayList<>(addedEntityRefs)); + List> snapshots = new ObjectArrayList<>(addedEntityRefs.size() + previousEntitySnapshots.size() + 1); + + for (Ref entityRef : addedEntityRefs) { + snapshots.add(new EntityAddSnapshot(entityRef)); + } + + for (EntityRemoveSnapshot snapshot : previousEntitySnapshots) { + snapshots.add(snapshot); + } + + snapshots.add(new BlockSelectionSnapshot(before)); + this.pushHistory(BuilderToolsPlugin.Action.ROTATE, snapshots); after.placeNoReturn("Transform 1/1", this.player, BuilderToolsPlugin.FEEDBACK_CONSUMER, world, componentAccessor); BuilderToolsPlugin.invalidateWorldMapForSelection(after, world); long end = System.nanoTime(); @@ -2590,24 +2725,27 @@ public class BuilderToolsPlugin extends JavaPlugin implements SelectionProvider, this.sendArea(); } - public void transformSelectionPoints(@Nonnull Matrix4d transformationMatrix, @Nonnull Vector3f rotationOrigin) { - Vector3i newMin = this.transformBlockLocation(this.selection.getSelectionMin(), transformationMatrix, rotationOrigin); - Vector3i newMax = this.transformBlockLocation(this.selection.getSelectionMax(), transformationMatrix, rotationOrigin); + public void transformSelectionPoints(@Nonnull Quaterniond rotation, @Nonnull Vector3i translationOffset, @Nonnull Vector3f rotationOrigin) { + Vector3i newMin = this.transformBlockLocation(this.selection.getSelectionMin(), rotation, translationOffset, rotationOrigin); + Vector3i newMax = this.transformBlockLocation(this.selection.getSelectionMax(), rotation, translationOffset, rotationOrigin); this.selection.setSelectionArea(Vector3i.min(newMin, newMax), Vector3i.max(newMin, newMax)); this.sendUpdate(); this.sendArea(); } @Nonnull - public Vector3i transformBlockLocation(@Nonnull Vector3i blockLocation, @Nonnull Matrix4d transformationMatrix, @Nonnull Vector3f rotationOrigin) { - Vector4d relativeOffset = new Vector4d( - blockLocation.x - rotationOrigin.x + 0.5, blockLocation.y - rotationOrigin.y + 0.5, blockLocation.z - rotationOrigin.z + 0.5, 1.0 + public Vector3i transformBlockLocation( + @Nonnull Vector3i blockLocation, @Nonnull Quaterniond rotation, @Nonnull Vector3i translationOffset, @Nonnull Vector3f rotationOrigin + ) { + org.joml.Vector3d relative = new org.joml.Vector3d( + blockLocation.x - rotationOrigin.x + 0.5, blockLocation.y - rotationOrigin.y + 0.5, blockLocation.z - rotationOrigin.z + 0.5 ); - transformationMatrix.multiply(relativeOffset); + rotation.transform(relative); + relative.add(translationOffset.x, translationOffset.y, translationOffset.z); return new Vector3i( - (int)Math.floor(relativeOffset.x + rotationOrigin.x - 0.5 + 0.1), - (int)Math.floor(relativeOffset.y + rotationOrigin.y - 0.5 + 0.1), - (int)Math.floor(relativeOffset.z + rotationOrigin.z - 0.5 + 0.1) + (int)Math.floor(relative.x + rotationOrigin.x - 0.5 + 0.1), + (int)Math.floor(relative.y + rotationOrigin.y - 0.5 + 0.1), + (int)Math.floor(relative.z + rotationOrigin.z - 0.5 + 0.1) ); } diff --git a/src/com/hypixel/hytale/builtin/buildertools/PrototypePlayerBuilderToolSettings.java b/src/com/hypixel/hytale/builtin/buildertools/PrototypePlayerBuilderToolSettings.java index 7f22a4de..a1d9f7f2 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/PrototypePlayerBuilderToolSettings.java +++ b/src/com/hypixel/hytale/builtin/buildertools/PrototypePlayerBuilderToolSettings.java @@ -4,6 +4,7 @@ import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfig; import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfigCommandExecutor; import com.hypixel.hytale.builtin.buildertools.tooloperations.ToolOperation; import com.hypixel.hytale.component.ComponentAccessor; +import com.hypixel.hytale.component.Holder; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.math.block.BlockUtil; import com.hypixel.hytale.math.vector.Vector3i; @@ -14,6 +15,7 @@ import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import java.util.LinkedList; +import java.util.List; import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -38,9 +40,13 @@ public class PrototypePlayerBuilderToolSettings { @Nullable private PrototypePlayerBuilderToolSettings.FluidChange[] fluidChangesForPlaySelectionToolPasteMode = null; @Nullable + private PrototypePlayerBuilderToolSettings.EntityChange[] entityChangesForPlaySelectionToolPasteMode = null; + @Nullable private Vector3i lastBrushPosition = null; @Nullable private Vector3i blockChangeOffsetOrigin = null; + @Nullable + private List> lastTransformEntityRefs = null; public PrototypePlayerBuilderToolSettings(UUID player) { this.player = player; @@ -60,6 +66,7 @@ public class PrototypePlayerBuilderToolSettings { if (!this.isInSelectionTransformationMode) { this.blockChangesForPlaySelectionToolPasteMode = null; this.fluidChangesForPlaySelectionToolPasteMode = null; + this.entityChangesForPlaySelectionToolPasteMode = null; this.blockChangeOffsetOrigin = null; } } @@ -98,6 +105,15 @@ public class PrototypePlayerBuilderToolSettings { return this.fluidChangesForPlaySelectionToolPasteMode; } + public void setEntityChangesForPlaySelectionToolPasteMode(@Nullable PrototypePlayerBuilderToolSettings.EntityChange[] entityChanges) { + this.entityChangesForPlaySelectionToolPasteMode = entityChanges; + } + + @Nullable + public PrototypePlayerBuilderToolSettings.EntityChange[] getEntityChangesForPlaySelectionToolPasteMode() { + return this.entityChangesForPlaySelectionToolPasteMode; + } + public void setBlockChangeOffsetOrigin(@Nullable Vector3i blockChangeOffsetOrigin) { this.blockChangeOffsetOrigin = blockChangeOffsetOrigin; } @@ -107,6 +123,19 @@ public class PrototypePlayerBuilderToolSettings { return this.blockChangeOffsetOrigin; } + public void setLastTransformEntityRefs(@Nullable List> refs) { + this.lastTransformEntityRefs = refs; + } + + @Nullable + public List> getLastTransformEntityRefs() { + return this.lastTransformEntityRefs; + } + + public void clearLastTransformEntityRefs() { + this.lastTransformEntityRefs = null; + } + @Nonnull public LongOpenHashSet addIgnoredPaintOperation() { LongOpenHashSet longs = new LongOpenHashSet(); @@ -202,6 +231,9 @@ public class PrototypePlayerBuilderToolSettings { } } + public record EntityChange(double x, double y, double z, Holder entityHolder) { + } + public record FluidChange(int x, int y, int z, int fluidId, byte fluidLevel) { } } diff --git a/src/com/hypixel/hytale/builtin/buildertools/commands/ContractSelectionCommand.java b/src/com/hypixel/hytale/builtin/buildertools/commands/ContractSelectionCommand.java index 406959fd..77dcdf36 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/commands/ContractSelectionCommand.java +++ b/src/com/hypixel/hytale/builtin/buildertools/commands/ContractSelectionCommand.java @@ -25,7 +25,9 @@ public class ContractSelectionCommand extends AbstractPlayerCommand { @Nonnull private final RequiredArg distanceArg = this.withRequiredArg("distance", "server.commands.contract.arg.distance.desc", ArgTypes.INTEGER); @Nonnull - private final OptionalArg> axisArg = this.withListOptionalArg("axis", "command.contract.arg.axis.desc", ArgTypes.forEnum("Axis", Axis.class)); + private final OptionalArg> axisArg = this.withListOptionalArg( + "axis", "server.commands.contract.arg.axis.desc", ArgTypes.forEnum("Axis", Axis.class) + ); public ContractSelectionCommand() { super("contractSelection", "server.commands.contract.desc"); diff --git a/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/BrushConfig.java b/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/BrushConfig.java index 2d599776..9f6c493c 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/BrushConfig.java +++ b/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/BrushConfig.java @@ -89,7 +89,7 @@ public class BrushConfig { this.executionErrorMessage = null; this.originOffset = new Vector3i(0, 0, 0); this.originAfterOffset = null; - this.shape = BrushShape.Cube; + this.shape = BrushShape.Sphere; this.shapeWidth = 5; this.shapeHeight = 5; this.shapeThickness = 0; diff --git a/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/operations/sequential/ShapeOperation.java b/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/operations/sequential/ShapeOperation.java index 4be9ed6e..96ee9ebf 100644 --- a/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/operations/sequential/ShapeOperation.java +++ b/src/com/hypixel/hytale/builtin/buildertools/scriptedbrushes/operations/sequential/ShapeOperation.java @@ -20,7 +20,7 @@ public class ShapeOperation extends SequenceBrushOperation { .documentation("Changes the shape of the brush editing area") .build(); @Nonnull - public BrushShape brushShapeArg = BrushShape.Cube; + public BrushShape brushShapeArg = BrushShape.Sphere; public ShapeOperation() { super("Shape", "Changes the shape of the brush editing area", false); diff --git a/src/com/hypixel/hytale/builtin/creativehub/CreativeHubPlugin.java b/src/com/hypixel/hytale/builtin/creativehub/CreativeHubPlugin.java index f02046b0..9ba90fa2 100644 --- a/src/com/hypixel/hytale/builtin/creativehub/CreativeHubPlugin.java +++ b/src/com/hypixel/hytale/builtin/creativehub/CreativeHubPlugin.java @@ -4,6 +4,8 @@ import com.hypixel.hytale.builtin.creativehub.command.HubCommand; import com.hypixel.hytale.builtin.creativehub.config.CreativeHubEntityConfig; import com.hypixel.hytale.builtin.creativehub.config.CreativeHubWorldConfig; import com.hypixel.hytale.builtin.creativehub.interactions.HubPortalInteraction; +import com.hypixel.hytale.builtin.creativehub.systems.ReturnToHubButtonSystem; +import com.hypixel.hytale.builtin.creativehub.ui.ReturnToHubButtonUI; import com.hypixel.hytale.builtin.instances.InstancesPlugin; import com.hypixel.hytale.builtin.instances.config.InstanceEntityConfig; import com.hypixel.hytale.builtin.instances.config.InstanceWorldConfig; @@ -100,7 +102,10 @@ public class CreativeHubPlugin extends JavaPlugin { config -> { config.setUuid(UUID.randomUUID()); config.setDeleteOnRemove(false); - config.setDisplayName(WorldConfig.formatDisplayName(instanceAssetName)); + if (config.getDisplayName() == null) { + config.setDisplayName(WorldConfig.formatDisplayName(instanceAssetName)); + } + config.getPluginConfig().remove(InstanceWorldConfig.class); config.markChanged(); long start = System.nanoTime(); @@ -148,9 +153,11 @@ public class CreativeHubPlugin extends JavaPlugin { this.getCodecRegistry(WorldConfig.PLUGIN_CODEC).register(CreativeHubWorldConfig.class, "CreativeHub", CreativeHubWorldConfig.CODEC); this.creativeHubEntityConfigComponentType = this.getEntityStoreRegistry() .registerComponent(CreativeHubEntityConfig.class, "CreativeHub", CreativeHubEntityConfig.CODEC); + this.getEntityStoreRegistry().registerSystem(new ReturnToHubButtonSystem()); this.getEventRegistry().registerGlobal(PlayerConnectEvent.class, CreativeHubPlugin::onPlayerConnect); this.getEventRegistry().registerGlobal(RemoveWorldEvent.class, CreativeHubPlugin::onWorldRemove); this.getEventRegistry().registerGlobal(AddPlayerToWorldEvent.class, CreativeHubPlugin::onPlayerAddToWorld); + ReturnToHubButtonUI.register(); } private static void onWorldRemove(@Nonnull RemoveWorldEvent event) { @@ -212,9 +219,11 @@ public class CreativeHubPlugin extends JavaPlugin { World parentWorld = Universe.get().getWorld(hubEntityConfig.getParentHubWorldUuid()); if (parentWorld != null) { World hubInstance = get().getActiveHubInstance(parentWorld); - if (!world.equals(hubInstance)) { - PlayerRef playerRef = holder.getComponent(PlayerRef.getComponentType()); - if (playerRef != null) { + boolean isInHubInstance = world.equals(hubInstance); + PlayerRef playerRef = holder.getComponent(PlayerRef.getComponentType()); + if (playerRef != null) { + ReturnToHubButtonUI.send(playerRef, isInHubInstance); + if (!isInHubInstance) { world.execute(() -> playerRef.sendMessage(MESSAGE_HUB_RETURN_HINT)); } } diff --git a/src/com/hypixel/hytale/builtin/creativehub/command/HubCommand.java b/src/com/hypixel/hytale/builtin/creativehub/command/HubCommand.java index 282e87ab..8cc00547 100644 --- a/src/com/hypixel/hytale/builtin/creativehub/command/HubCommand.java +++ b/src/com/hypixel/hytale/builtin/creativehub/command/HubCommand.java @@ -27,7 +27,7 @@ public class HubCommand extends AbstractPlayerCommand { public HubCommand() { super("hub", "server.commands.hub.desc"); - this.addAliases("converge", "convergence"); + this.addAliases("cosmos", "crossroads"); this.setPermissionGroup(GameMode.Creative); } diff --git a/src/com/hypixel/hytale/builtin/creativehub/interactions/HubPortalInteraction.java b/src/com/hypixel/hytale/builtin/creativehub/interactions/HubPortalInteraction.java index ba5a5265..263314bb 100644 --- a/src/com/hypixel/hytale/builtin/creativehub/interactions/HubPortalInteraction.java +++ b/src/com/hypixel/hytale/builtin/creativehub/interactions/HubPortalInteraction.java @@ -159,47 +159,49 @@ public class HubPortalInteraction extends SimpleInstantInteraction { } else { UUID playerUUID = uuidComponent.getUuid(); CreativeHubEntityConfig hubEntityConfig = componentAccessor.getComponent(playerRef, CreativeHubEntityConfig.getComponentType()); - originalWorld.execute(playerRefComponent::removeFromStore); - worldFuture.orTimeout(1L, TimeUnit.MINUTES).thenCompose(world -> { - PlayerWorldData worldData = perWorldData.get(world.getName()); - if (worldData != null && worldData.getLastPosition() != null) { - return world.addPlayer(playerRefComponent, worldData.getLastPosition(), Boolean.TRUE, Boolean.FALSE); - } else { - ISpawnProvider spawnProvider = world.getWorldConfig().getSpawnProvider(); - Transform spawnPoint = spawnProvider != null ? spawnProvider.getSpawnPoint(world, playerUUID) : null; - return world.addPlayer(playerRefComponent, spawnPoint, Boolean.TRUE, Boolean.FALSE); - } - }).whenComplete((ret, ex) -> { - if (ex != null) { - LOGGER.at(Level.SEVERE).withCause(ex).log("Failed to teleport %s to permanent world", playerRefComponent.getUsername()); - } - - if (ret == null) { - if (originalWorld.isAlive()) { - originalWorld.addPlayer(playerRefComponent, originalPosition, Boolean.TRUE, Boolean.FALSE); + CompletableFuture.runAsync(playerRefComponent::removeFromStore, originalWorld) + .thenCombine(worldFuture.orTimeout(1L, TimeUnit.MINUTES), (v, world) -> (World)world) + .thenCompose(world -> { + PlayerWorldData worldData = perWorldData.get(world.getName()); + if (worldData != null && worldData.getLastPosition() != null) { + return world.addPlayer(playerRefComponent, worldData.getLastPosition(), Boolean.TRUE, Boolean.FALSE); } else { - if (hubEntityConfig != null && hubEntityConfig.getParentHubWorldUuid() != null) { - World parentWorld = Universe.get().getWorld(hubEntityConfig.getParentHubWorldUuid()); - if (parentWorld != null) { - CreativeHubWorldConfig parentHubConfig = CreativeHubWorldConfig.get(parentWorld.getWorldConfig()); - if (parentHubConfig != null && parentHubConfig.getStartupInstance() != null) { - World hubInstance = CreativeHubPlugin.get().getOrSpawnHubInstance(parentWorld, parentHubConfig, new Transform()); - hubInstance.addPlayer(playerRefComponent, null, Boolean.TRUE, Boolean.FALSE); - return; + ISpawnProvider spawnProvider = world.getWorldConfig().getSpawnProvider(); + Transform spawnPoint = spawnProvider != null ? spawnProvider.getSpawnPoint(world, playerUUID) : null; + return world.addPlayer(playerRefComponent, spawnPoint, Boolean.TRUE, Boolean.FALSE); + } + }) + .whenComplete((ret, ex) -> { + if (ex != null) { + LOGGER.at(Level.SEVERE).withCause(ex).log("Failed to teleport %s to permanent world", playerRefComponent.getUsername()); + } + + if (ret == null) { + if (originalWorld.isAlive()) { + originalWorld.addPlayer(playerRefComponent, originalPosition, Boolean.TRUE, Boolean.FALSE); + } else { + if (hubEntityConfig != null && hubEntityConfig.getParentHubWorldUuid() != null) { + World parentWorld = Universe.get().getWorld(hubEntityConfig.getParentHubWorldUuid()); + if (parentWorld != null) { + CreativeHubWorldConfig parentHubConfig = CreativeHubWorldConfig.get(parentWorld.getWorldConfig()); + if (parentHubConfig != null && parentHubConfig.getStartupInstance() != null) { + World hubInstance = CreativeHubPlugin.get().getOrSpawnHubInstance(parentWorld, parentHubConfig, new Transform()); + hubInstance.addPlayer(playerRefComponent, null, Boolean.TRUE, Boolean.FALSE); + return; + } } } - } - World defaultWorld = Universe.get().getDefaultWorld(); - if (defaultWorld != null) { - defaultWorld.addPlayer(playerRefComponent, null, Boolean.TRUE, Boolean.FALSE); - } else { - LOGGER.at(Level.SEVERE).log("No fallback world available for %s, disconnecting", playerRefComponent.getUsername()); - playerRefComponent.getPacketHandler().disconnect("Failed to teleport - no world available"); + World defaultWorld = Universe.get().getDefaultWorld(); + if (defaultWorld != null) { + defaultWorld.addPlayer(playerRefComponent, null, Boolean.TRUE, Boolean.FALSE); + } else { + LOGGER.at(Level.SEVERE).log("No fallback world available for %s, disconnecting", playerRefComponent.getUsername()); + playerRefComponent.getPacketHandler().disconnect("Failed to teleport - no world available"); + } } } - } - }); + }); } } } diff --git a/src/com/hypixel/hytale/builtin/creativehub/systems/ReturnToHubButtonSystem.java b/src/com/hypixel/hytale/builtin/creativehub/systems/ReturnToHubButtonSystem.java new file mode 100644 index 00000000..4d501946 --- /dev/null +++ b/src/com/hypixel/hytale/builtin/creativehub/systems/ReturnToHubButtonSystem.java @@ -0,0 +1,66 @@ +package com.hypixel.hytale.builtin.creativehub.systems; + +import com.hypixel.hytale.builtin.creativehub.CreativeHubPlugin; +import com.hypixel.hytale.builtin.creativehub.config.CreativeHubEntityConfig; +import com.hypixel.hytale.builtin.creativehub.ui.ReturnToHubButtonUI; +import com.hypixel.hytale.component.AddReason; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.RemoveReason; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.component.query.Query; +import com.hypixel.hytale.component.system.RefSystem; +import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.Universe; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.util.Optional; +import javax.annotation.Nonnull; + +public class ReturnToHubButtonSystem extends RefSystem { + @Override + public void onEntityAdded( + @Nonnull Ref ref, @Nonnull AddReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer + ) { + Optional isInChildWorld = this.getCreativeHubWorldStatus(store, commandBuffer, ref); + if (!isInChildWorld.isEmpty()) { + PlayerRef playerRef = commandBuffer.getComponent(ref, PlayerRef.getComponentType()); + boolean disabled = !isInChildWorld.get(); + ReturnToHubButtonUI.send(playerRef, disabled); + } + } + + @Override + public void onEntityRemove( + @Nonnull Ref ref, @Nonnull RemoveReason reason, @Nonnull Store store, @Nonnull CommandBuffer commandBuffer + ) { + if (!this.getCreativeHubWorldStatus(store, commandBuffer, ref).isEmpty()) { + PlayerRef playerRef = commandBuffer.getComponent(ref, PlayerRef.getComponentType()); + ReturnToHubButtonUI.clear(playerRef); + } + } + + @Override + public Query getQuery() { + return Query.and(Player.getComponentType(), PlayerRef.getComponentType()); + } + + private Optional getCreativeHubWorldStatus( + @Nonnull Store store, @Nonnull CommandBuffer commandBuffer, @Nonnull Ref ref + ) { + CreativeHubEntityConfig hubEntityConfig = commandBuffer.getComponent(ref, CreativeHubEntityConfig.getComponentType()); + if (hubEntityConfig != null && hubEntityConfig.getParentHubWorldUuid() != null) { + World parentWorld = Universe.get().getWorld(hubEntityConfig.getParentHubWorldUuid()); + if (parentWorld == null) { + return Optional.empty(); + } else { + World currentWorld = store.getExternalData().getWorld(); + World hubInstance = CreativeHubPlugin.get().getActiveHubInstance(parentWorld); + return Optional.of(!currentWorld.equals(hubInstance)); + } + } else { + return Optional.empty(); + } + } +} diff --git a/src/com/hypixel/hytale/builtin/creativehub/ui/ReturnToHubButtonUI.java b/src/com/hypixel/hytale/builtin/creativehub/ui/ReturnToHubButtonUI.java new file mode 100644 index 00000000..5153a45f --- /dev/null +++ b/src/com/hypixel/hytale/builtin/creativehub/ui/ReturnToHubButtonUI.java @@ -0,0 +1,87 @@ +package com.hypixel.hytale.builtin.creativehub.ui; + +import com.hypixel.hytale.builtin.creativehub.CreativeHubPlugin; +import com.hypixel.hytale.builtin.creativehub.config.CreativeHubEntityConfig; +import com.hypixel.hytale.builtin.creativehub.config.CreativeHubWorldConfig; +import com.hypixel.hytale.builtin.instances.InstancesPlugin; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.math.vector.Transform; +import com.hypixel.hytale.protocol.packets.interface_.CustomUIEventBindingType; +import com.hypixel.hytale.protocol.packets.interface_.UpdateAnchorUI; +import com.hypixel.hytale.server.core.modules.anchoraction.AnchorActionModule; +import com.hypixel.hytale.server.core.ui.builder.EventData; +import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder; +import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.Universe; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.spawn.ISpawnProvider; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public final class ReturnToHubButtonUI { + public static final String ANCHOR_ID = "MapServerContent"; + public static final String ACTION_RETURN_TO_HUB = "returnToHub"; + + private ReturnToHubButtonUI() { + } + + public static void register() { + AnchorActionModule.get().register("returnToHub", (playerRef, ref, store, data) -> executeReturnToHub(playerRef, ref, store)); + } + + public static void send(@Nonnull PlayerRef playerRef) { + send(playerRef, false); + } + + public static void send(@Nonnull PlayerRef playerRef, boolean disabled) { + UICommandBuilder commandBuilder = new UICommandBuilder(); + commandBuilder.append("Hud/ReturnToHubButton.ui"); + commandBuilder.set("#ReturnToHubButton.Disabled", disabled); + UIEventBuilder eventBuilder = new UIEventBuilder(); + if (!disabled) { + eventBuilder.addEventBinding(CustomUIEventBindingType.Activating, "#ReturnToHubButton", EventData.of("action", "returnToHub"), false); + } + + playerRef.getPacketHandler().writeNoCache(new UpdateAnchorUI("MapServerContent", true, commandBuilder.getCommands(), eventBuilder.getEvents())); + } + + public static void clear(@Nonnull PlayerRef playerRef) { + playerRef.getPacketHandler().writeNoCache(new UpdateAnchorUI("MapServerContent", true, null, null)); + } + + public static void executeReturnToHub(@Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull Store store) { + World parentWorld = findParentHubWorld(store, ref); + if (parentWorld != null) { + CreativeHubWorldConfig hubConfig = CreativeHubWorldConfig.get(parentWorld.getWorldConfig()); + if (hubConfig != null && hubConfig.getStartupInstance() != null) { + World world = store.getExternalData().getWorld(); + World currentHub = CreativeHubPlugin.get().getActiveHubInstance(parentWorld); + if (!world.equals(currentHub)) { + ISpawnProvider spawnProvider = parentWorld.getWorldConfig().getSpawnProvider(); + Transform returnPoint = spawnProvider != null ? spawnProvider.getSpawnPoint(parentWorld, playerRef.getUuid()) : new Transform(); + World hubInstance = CreativeHubPlugin.get().getOrSpawnHubInstance(parentWorld, hubConfig, returnPoint); + InstancesPlugin.teleportPlayerToInstance(ref, store, hubInstance, null); + } + } + } + } + + @Nullable + private static World findParentHubWorld(@Nonnull Store store, @Nonnull Ref ref) { + CreativeHubEntityConfig hubEntityConfig = store.getComponent(ref, CreativeHubEntityConfig.getComponentType()); + if (hubEntityConfig != null && hubEntityConfig.getParentHubWorldUuid() != null) { + World parentWorld = Universe.get().getWorld(hubEntityConfig.getParentHubWorldUuid()); + if (parentWorld != null) { + CreativeHubWorldConfig hubConfig = CreativeHubWorldConfig.get(parentWorld.getWorldConfig()); + if (hubConfig != null && hubConfig.getStartupInstance() != null) { + return parentWorld; + } + } + } + + return null; + } +} diff --git a/src/com/hypixel/hytale/builtin/fluid/FluidPlugin.java b/src/com/hypixel/hytale/builtin/fluid/FluidPlugin.java index dba4dc24..693c9328 100644 --- a/src/com/hypixel/hytale/builtin/fluid/FluidPlugin.java +++ b/src/com/hypixel/hytale/builtin/fluid/FluidPlugin.java @@ -108,21 +108,21 @@ public class FluidPlugin extends JavaPlugin { int y = ChunkUtil.minBlock(fluidSectionComponent.getY()) + ChunkUtil.yFromIndex(idx); int z = ChunkUtil.minBlock(fluidSectionComponent.getZ()) + ChunkUtil.zFromIndex(idx); boolean canSpread = ChunkUtil.isBorderBlock(x, z) - || fluidSectionComponent.getFluidId(x - 1, y, z) == 0 + || fluidSectionComponent.getFluidId(x - 1, y, z) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockSectionComponent.get(x - 1, y, z))) - || fluidSectionComponent.getFluidId(x + 1, y, z) == 0 + || fluidSectionComponent.getFluidId(x + 1, y, z) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockSectionComponent.get(x + 1, y, z))) - || fluidSectionComponent.getFluidId(x, y, z - 1) == 0 + || fluidSectionComponent.getFluidId(x, y, z - 1) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockSectionComponent.get(x, y, z - 1))) - || fluidSectionComponent.getFluidId(x, y, z + 1) == 0 + || fluidSectionComponent.getFluidId(x, y, z + 1) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockSectionComponent.get(x, y, z + 1))); if (y > 0) { if (ChunkUtil.chunkCoordinate(y) == ChunkUtil.chunkCoordinate(y - 1)) { - canSpread |= fluidSectionComponent.getFluidId(x, y - 1, z) == 0 + canSpread |= fluidSectionComponent.getFluidId(x, y - 1, z) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockSectionComponent.get(x, y - 1, z))); } else { FluidSection fluidSection2 = sections[i - 1].getComponent(FluidSection.getComponentType()); - canSpread |= fluidSection2.getFluidId(x, y - 1, z) == 0 + canSpread |= fluidSection2.getFluidId(x, y - 1, z) != fluidId && !FluidTicker.isSolid(blockMap.getAsset(blockChunkComponent.getBlock(x, y - 1, z))); } } diff --git a/src/com/hypixel/hytale/builtin/fluid/FluidSystems.java b/src/com/hypixel/hytale/builtin/fluid/FluidSystems.java index bf70935c..ab45517c 100644 --- a/src/com/hypixel/hytale/builtin/fluid/FluidSystems.java +++ b/src/com/hypixel/hytale/builtin/fluid/FluidSystems.java @@ -19,7 +19,7 @@ import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.component.system.tick.RunWhenPausedSystem; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.util.ChunkUtil; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.ServerSetFluid; import com.hypixel.hytale.protocol.packets.world.ServerSetFluids; import com.hypixel.hytale.protocol.packets.world.SetFluidCmd; @@ -109,7 +109,7 @@ public class FluidSystems { Store store, @Nonnull CommandBuffer commandBuffer, PlayerRef query, - @Nonnull List> results + @Nonnull List> results ) { ChunkColumn chunkColumnComponent = archetypeChunk.getComponent(index, this.chunkColumnComponentType); diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/assets/density/MultiMixDensityAsset.java b/src/com/hypixel/hytale/builtin/hytalegenerator/assets/density/MultiMixDensityAsset.java index 3e89d36e..ac09d7dc 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/assets/density/MultiMixDensityAsset.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/assets/density/MultiMixDensityAsset.java @@ -43,7 +43,7 @@ public class MultiMixDensityAsset extends DensityAsset { ArrayList keys = new ArrayList<>(this.keyAssets.length); for (MultiMixDensityAsset.KeyAsset keyAsset : this.keyAssets) { - if (keyAsset.densityIndex <= 0) { + if (keyAsset.densityIndex < 0) { keys.add(new MultiMixDensity.Key(keyAsset.value, null)); } else if (keyAsset.densityIndex >= densityInputs.size() - 1) { LoggerUtil.getLogger() diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/assets/patterns/CeilingPatternAsset.java b/src/com/hypixel/hytale/builtin/hytalegenerator/assets/patterns/CeilingPatternAsset.java index 5c0b6dd5..44d2cc87 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/assets/patterns/CeilingPatternAsset.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/assets/patterns/CeilingPatternAsset.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.builtin.hytalegenerator.assets.patterns; -import com.hypixel.hytale.builtin.hytalegenerator.patterns.CeilingPattern; import com.hypixel.hytale.builtin.hytalegenerator.patterns.Pattern; +import com.hypixel.hytale.builtin.hytalegenerator.patterns.SurfacePattern; import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.builder.BuilderCodec; import javax.annotation.Nonnull; @@ -27,7 +27,7 @@ public class CeilingPatternAsset extends PatternAsset { } else { Pattern ceilingPattern = this.ceiling.build(argument); Pattern originPattern = this.origin.build(argument); - return new CeilingPattern(ceilingPattern, originPattern); + return new SurfacePattern(ceilingPattern, originPattern, 0.0, 0.0, SurfacePattern.Facing.D, 0, 0); } } diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/newsystem/stages/NTerrainStage.java b/src/com/hypixel/hytale/builtin/hytalegenerator/newsystem/stages/NTerrainStage.java index 1403ad83..bb1921ed 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/newsystem/stages/NTerrainStage.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/newsystem/stages/NTerrainStage.java @@ -389,7 +389,6 @@ public class NTerrainStage implements NStage { for (int y = this.top; y >= this.bottom; y--) { position.y = y; positionAbove.y = y + 1; - positionBelow.y = y - 1; int i = y - this.bottom; float density = this.densityBuffer.get(position); boolean solidity = density > 0.0; @@ -415,6 +414,8 @@ public class NTerrainStage implements NStage { } for (int yx = this.bottom; yx <= this.top; yx++) { + position.y = yx; + positionBelow.y = yx - 1; int i = yx - this.bottom; double density = this.densityBuffer.get(position); boolean solidity = density > 0.0; diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/CeilingPattern.java b/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/CeilingPattern.java deleted file mode 100644 index f5e0823e..00000000 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/CeilingPattern.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.hypixel.hytale.builtin.hytalegenerator.patterns; - -import com.hypixel.hytale.builtin.hytalegenerator.bounds.SpaceSize; -import com.hypixel.hytale.math.vector.Vector3i; -import javax.annotation.Nonnull; - -public class CeilingPattern extends Pattern { - @Nonnull - private final Pattern ceilingPattern; - @Nonnull - private final Pattern airPattern; - @Nonnull - private final SpaceSize readSpaceSize; - @Nonnull - private final Vector3i rCeilingPosition; - @Nonnull - private final Pattern.Context rCeilingContext; - - public CeilingPattern(@Nonnull Pattern ceilingPattern, @Nonnull Pattern airPattern) { - this.ceilingPattern = ceilingPattern; - this.airPattern = airPattern; - SpaceSize ceilingSpace = ceilingPattern.readSpace(); - ceilingSpace.moveBy(new Vector3i(0, 1, 0)); - this.readSpaceSize = SpaceSize.merge(ceilingSpace, airPattern.readSpace()); - this.rCeilingPosition = new Vector3i(); - this.rCeilingContext = new Pattern.Context(); - } - - @Override - public boolean matches(@Nonnull Pattern.Context context) { - this.rCeilingPosition.assign(context.position); - if (context.materialSpace.isInsideSpace(context.position) && context.materialSpace.isInsideSpace(this.rCeilingPosition)) { - this.rCeilingContext.assign(context); - this.rCeilingContext.position = this.rCeilingPosition; - return this.airPattern.matches(context) && this.ceilingPattern.matches(this.rCeilingContext); - } else { - return false; - } - } - - @Nonnull - @Override - public SpaceSize readSpace() { - return this.readSpaceSize.clone(); - } -} diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/Pattern.java b/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/Pattern.java index e539c508..a034cb15 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/Pattern.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/patterns/Pattern.java @@ -1,6 +1,7 @@ package com.hypixel.hytale.builtin.hytalegenerator.patterns; import com.hypixel.hytale.builtin.hytalegenerator.bounds.SpaceSize; +import com.hypixel.hytale.builtin.hytalegenerator.datastructures.voxelspace.NullSpace; import com.hypixel.hytale.builtin.hytalegenerator.datastructures.voxelspace.VoxelSpace; import com.hypixel.hytale.builtin.hytalegenerator.material.Material; import com.hypixel.hytale.math.vector.Vector3i; @@ -49,12 +50,12 @@ public abstract class Pattern { public static class Context { @Nonnull public Vector3i position; - @Nullable + @Nonnull public VoxelSpace materialSpace; public Context() { this.position = new Vector3i(); - this.materialSpace = null; + this.materialSpace = NullSpace.instance(); } public Context(@Nonnull Vector3i position, @Nullable VoxelSpace materialSpace) { diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/positionproviders/FieldFunctionPositionProvider.java b/src/com/hypixel/hytale/builtin/hytalegenerator/positionproviders/FieldFunctionPositionProvider.java index 8a84a02c..8eb8d2b9 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/positionproviders/FieldFunctionPositionProvider.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/positionproviders/FieldFunctionPositionProvider.java @@ -38,6 +38,7 @@ public class FieldFunctionPositionProvider extends PositionProvider { for (FieldFunctionPositionProvider.Delimiter d : this.delimiters) { if (d.isInside(value)) { context.consumer.accept(p); + return; } } }; diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/props/QueueProp.java b/src/com/hypixel/hytale/builtin/hytalegenerator/props/QueueProp.java index 9277ec43..0fd43d1b 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/props/QueueProp.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/props/QueueProp.java @@ -59,7 +59,9 @@ public class QueueProp extends Prop { public void place(@Nonnull Prop.Context context) { QueueProp.QueueScanResult conditionalScanResult = QueueProp.QueueScanResult.cast(context.scanResult); if (!conditionalScanResult.isNegative()) { - conditionalScanResult.prop.place(context); + Prop.Context childContext = new Prop.Context(context); + childContext.scanResult = conditionalScanResult.propScanResult; + conditionalScanResult.prop.place(childContext); } } diff --git a/src/com/hypixel/hytale/builtin/hytalegenerator/props/prefab/PrefabProp.java b/src/com/hypixel/hytale/builtin/hytalegenerator/props/prefab/PrefabProp.java index 08c20a4c..56a554cd 100644 --- a/src/com/hypixel/hytale/builtin/hytalegenerator/props/prefab/PrefabProp.java +++ b/src/com/hypixel/hytale/builtin/hytalegenerator/props/prefab/PrefabProp.java @@ -293,7 +293,9 @@ public class PrefabProp extends Prop { Material worldMaterial = materialSpace.getContent(worldX, worldY, worldZ); int worldMaterialHash = worldMaterial.hashMaterialIds(); if (this.materialMask.canReplace(materialHash, worldMaterialHash)) { - materialSpace.set(material, worldX, worldY, worldZ); + if (filler == 0) { + materialSpace.set(material, worldX, worldY, worldZ); + } } } } diff --git a/src/com/hypixel/hytale/builtin/instances/InstancesPlugin.java b/src/com/hypixel/hytale/builtin/instances/InstancesPlugin.java index 64a11b1b..b083c6e6 100644 --- a/src/com/hypixel/hytale/builtin/instances/InstancesPlugin.java +++ b/src/com/hypixel/hytale/builtin/instances/InstancesPlugin.java @@ -179,7 +179,10 @@ public class InstancesPlugin extends JavaPlugin { SneakyThrow.sneakyFunction( config -> { config.setUuid(uuid); - config.setDisplayName(WorldConfig.formatDisplayName(name)); + if (config.getDisplayName() == null) { + config.setDisplayName(WorldConfig.formatDisplayName(name)); + } + InstanceWorldConfig instanceConfig = InstanceWorldConfig.ensureAndGet(config); instanceConfig.setReturnPoint( new WorldReturnPoint(forWorld.getWorldConfig().getUuid(), returnPoint, instanceConfig.shouldPreventReconnection()) @@ -576,7 +579,7 @@ public class InstancesPlugin extends JavaPlugin { Path instancePath = getInstanceAssetPath(name); Universe universe = Universe.get(); WorldConfig config = WorldConfig.load(instancePath.resolve("instance.bson")).join(); - IChunkStorageProvider storage = config.getChunkStorageProvider(); + IChunkStorageProvider storage = config.getChunkStorageProvider(); config.setChunkStorageProvider(new MigrationChunkStorageProvider(new IChunkStorageProvider[]{storage}, EmptyChunkStorageProvider.INSTANCE)); config.setResourceStorageProvider(EmptyResourceStorageProvider.INSTANCE); config.setUuid(UUID.randomUUID()); diff --git a/src/com/hypixel/hytale/builtin/mounts/MountSystems.java b/src/com/hypixel/hytale/builtin/mounts/MountSystems.java index fa022e04..0f76d43d 100644 --- a/src/com/hypixel/hytale/builtin/mounts/MountSystems.java +++ b/src/com/hypixel/hytale/builtin/mounts/MountSystems.java @@ -26,7 +26,6 @@ import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.vector.Vector3f; import com.hypixel.hytale.protocol.AnimationSlot; import com.hypixel.hytale.protocol.BlockMount; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.GameMode; import com.hypixel.hytale.protocol.MountController; @@ -855,8 +854,6 @@ public class MountSystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, @Nonnull MountedComponent component ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Mounted; Ref mountedToEntity = component.getMountedToEntity(); Ref mountedToBlock = component.getMountedToBlock(); Vector3f offset = component.getAttachmentOffset(); @@ -897,10 +894,8 @@ public class MountSystems { mountedUpdate = new MountedUpdate(0, netOffset, component.getControllerType(), blockMount); } - update.mounted = mountedUpdate; - for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { - viewer.queueUpdate(ref, update); + viewer.queueUpdate(ref, mountedUpdate); } } } diff --git a/src/com/hypixel/hytale/builtin/mounts/NPCMountSystems.java b/src/com/hypixel/hytale/builtin/mounts/NPCMountSystems.java index 2dbd4e7b..48c6e473 100644 --- a/src/com/hypixel/hytale/builtin/mounts/NPCMountSystems.java +++ b/src/com/hypixel/hytale/builtin/mounts/NPCMountSystems.java @@ -10,6 +10,7 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.protocol.packets.interaction.MountNPC; import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.modules.entity.component.Interactable; import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent; import com.hypixel.hytale.server.core.modules.entity.damage.DeathSystems; import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId; @@ -129,6 +130,7 @@ public class NPCMountSystems { if (playerComponent != null) { playerComponent.setMountEntityId(networkId); playerRef.getPacketHandler().write(packet); + commandBuffer.removeComponent(ref, Interactable.getComponentType()); } } } @@ -145,6 +147,7 @@ public class NPCMountSystems { RoleChangeSystem.requestRoleChange(ref, npcComponent.getRole(), mountComponent.getOriginalRoleIndex(), false, "Idle", null, store); commandBuffer.removeComponent(ref, this.mountComponentType); + commandBuffer.ensureComponent(ref, Interactable.getComponentType()); } @Override diff --git a/src/com/hypixel/hytale/builtin/portals/ui/PortalDeviceSummonPage.java b/src/com/hypixel/hytale/builtin/portals/ui/PortalDeviceSummonPage.java index 4deb8bc9..1e2fc6cd 100644 --- a/src/com/hypixel/hytale/builtin/portals/ui/PortalDeviceSummonPage.java +++ b/src/com/hypixel/hytale/builtin/portals/ui/PortalDeviceSummonPage.java @@ -30,7 +30,6 @@ import com.hypixel.hytale.server.core.asset.type.item.config.Item; import com.hypixel.hytale.server.core.asset.type.item.config.PortalKey; import com.hypixel.hytale.server.core.asset.type.portalworld.PillTag; import com.hypixel.hytale.server.core.asset.type.portalworld.PortalDescription; -import com.hypixel.hytale.server.core.asset.type.portalworld.PortalSpawn; import com.hypixel.hytale.server.core.asset.type.portalworld.PortalType; import com.hypixel.hytale.server.core.asset.util.ColorParseUtil; import com.hypixel.hytale.server.core.entity.UUIDComponent; @@ -52,6 +51,8 @@ import com.hypixel.hytale.server.core.universe.world.spawn.ISpawnProvider; import com.hypixel.hytale.server.core.universe.world.spawn.IndividualSpawnProvider; import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -280,8 +281,7 @@ public class PortalDeviceSummonPage extends InteractiveCustomUIPage spawnReturnPortal( @Nonnull World world, @Nonnull PortalWorld portalWorld, @Nonnull UUID sampleUuid, @Nonnull String portalBlockType ) { - PortalSpawn portalSpawn = portalWorld.getPortalType().getPortalSpawn(); - return getSpawnTransform(world, sampleUuid, portalSpawn) + return getSpawnTransform(world, sampleUuid) .thenCompose( spawnTransform -> { Vector3d spawnPoint = spawnTransform.getPosition(); @@ -312,21 +312,24 @@ public class PortalDeviceSummonPage extends InteractiveCustomUIPage getSpawnTransform(@Nonnull World world, @Nonnull UUID sampleUuid, @Nullable PortalSpawn portalSpawn) { + private static CompletableFuture getSpawnTransform(@Nonnull World world, @Nonnull UUID sampleUuid) { + return CompletableFuture.supplyAsync(() -> { + List hintedSpawns = fetchHintedSpawns(world, sampleUuid); + return PortalSpawnFinder.computeSpawnTransform(world, hintedSpawns); + }, world); + } + + private static List fetchHintedSpawns(World world, UUID sampleUuid) { ISpawnProvider spawnProvider = world.getWorldConfig().getSpawnProvider(); if (spawnProvider == null) { - return CompletableFuture.completedFuture(null); + return Collections.emptyList(); } else { - Transform worldSpawnPoint = spawnProvider.getSpawnPoint(world, sampleUuid); - if (portalSpawn == null) { - Transform uppedSpawnPoint = worldSpawnPoint.clone(); - uppedSpawnPoint.getPosition().add(0.0, 0.5, 0.0); - return CompletableFuture.completedFuture(uppedSpawnPoint); + Transform[] spawnTransforms = spawnProvider.getSpawnPoints(); + if (spawnTransforms != null && spawnTransforms.length > 0) { + return Arrays.stream(spawnTransforms).map(Transform::getPosition).toList(); } else { - return CompletableFuture.supplyAsync(() -> { - Transform computedSpawn = PortalSpawnFinder.computeSpawnTransform(world, portalSpawn); - return computedSpawn == null ? worldSpawnPoint : computedSpawn; - }, world); + Transform spawnPoint = spawnProvider.getSpawnPoint(world, sampleUuid); + return spawnPoint != null ? Collections.singletonList(spawnPoint.getPosition()) : Collections.emptyList(); } } } diff --git a/src/com/hypixel/hytale/builtin/portals/ui/PortalSpawnFinder.java b/src/com/hypixel/hytale/builtin/portals/ui/PortalSpawnFinder.java index 3c5e8496..feb736b8 100644 --- a/src/com/hypixel/hytale/builtin/portals/ui/PortalSpawnFinder.java +++ b/src/com/hypixel/hytale/builtin/portals/ui/PortalSpawnFinder.java @@ -1,6 +1,5 @@ package com.hypixel.hytale.builtin.portals.ui; -import com.hypixel.hytale.builtin.portals.utils.posqueries.generators.SearchCircular; import com.hypixel.hytale.builtin.portals.utils.posqueries.predicates.FitsAPortal; import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.Ref; @@ -10,10 +9,7 @@ import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.vector.Transform; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; -import com.hypixel.hytale.math.vector.Vector3i; -import com.hypixel.hytale.protocol.BlockMaterial; import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; -import com.hypixel.hytale.server.core.asset.type.portalworld.PortalSpawn; import com.hypixel.hytale.server.core.modules.collision.WorldUtil; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.chunk.BlockChunk; @@ -21,22 +17,27 @@ import com.hypixel.hytale.server.core.universe.world.chunk.ChunkColumn; import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk; import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection; import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; -import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.Nullable; public final class PortalSpawnFinder { + private static final int MAX_ATTEMPTS_PER_WORLD = 10; + private static final int QUALITY_ATTEMPTS = 2; + private static final int CHECKS_PER_CHUNK = 8; + private static final Vector3d FALLBACK_POSITION = Vector3d.ZERO; + @Nullable - public static Transform computeSpawnTransform(@Nonnull World world, @Nonnull PortalSpawn config) { - Vector3d spawn = findSpawnByThrowingDarts(world, config); + public static Transform computeSpawnTransform(@Nonnull World world, @Nonnull List hintedSpawns) { + Vector3d spawn = guesstimateFromHints(world, hintedSpawns); if (spawn == null) { - spawn = findFallbackPositionOnGround(world, config); - HytaleLogger.getLogger().at(Level.INFO).log("Had to use fallback spawn for portal spawn"); + spawn = findFallbackPositionOnGround(world); + HytaleLogger.getLogger().atWarning().log("Had to use fallback spawn for portal spawn (10 attempts)"); } if (spawn == null) { - HytaleLogger.getLogger().at(Level.INFO).log("Both dart and fallback spawn finder failed for portal spawn"); + HytaleLogger.getLogger().atWarning().log("Both dart and fallback spawn finder failed for portal spawn"); return null; } else { Vector3f direction = Vector3f.lookAt(spawn).scale(-1.0F); @@ -47,27 +48,17 @@ public final class PortalSpawnFinder { } @Nullable - private static Vector3d findSpawnByThrowingDarts(@Nonnull World world, @Nonnull PortalSpawn config) { - Vector3d center = config.getCenter().toVector3d(); - center.setY(config.getCheckSpawnY()); - int halfwayThrows = config.getChunkDartThrows() / 2; - - for (int chunkDart = 0; chunkDart < config.getChunkDartThrows(); chunkDart++) { - Vector3d pointd = new SearchCircular(config.getMinRadius(), config.getMaxRadius(), 1).execute(world, center).orElse(null); - if (pointd != null) { - Vector3i point = pointd.toVector3i(); - WorldChunk chunk = world.getChunk(ChunkUtil.indexChunkFromBlock(point.x, point.z)); - BlockType firstBlock = chunk.getBlockType(point.x, point.y, point.z); - if (firstBlock != null) { - BlockMaterial firstBlockMat = firstBlock.getMaterial(); - if (firstBlockMat != BlockMaterial.Solid) { - boolean checkIfPortalFitsNice = chunkDart < halfwayThrows; - Vector3d spawn = findGroundWithinChunk(chunk, config, checkIfPortalFitsNice); - if (spawn != null) { - HytaleLogger.getLogger().at(Level.INFO).log("Found fragment spawn at " + spawn + " after " + (chunkDart + 1) + " chunk scan(s)"); - return spawn; - } - } + private static Vector3d guesstimateFromHints(World world, List hintedSpawns) { + for (int i = 0; i < Math.min(hintedSpawns.size(), 10); i++) { + Vector3d hintedSpawn = hintedSpawns.get(i); + WorldChunk chunk = world.getChunk(ChunkUtil.indexChunkFromBlock(hintedSpawn.x, hintedSpawn.z)); + if (chunk != null) { + boolean quality = i < 2; + int scanHeight = quality ? (int)hintedSpawn.y : 319; + Vector3d spawn = findGroundWithinChunk(chunk, scanHeight, quality); + if (spawn != null) { + HytaleLogger.getLogger().atInfo().log("Found portal spawn " + spawn + " on attempt #" + (i + 1) + " quality=" + quality); + return spawn; } } } @@ -76,15 +67,15 @@ public final class PortalSpawnFinder { } @Nullable - private static Vector3d findGroundWithinChunk(@Nonnull WorldChunk chunk, @Nonnull PortalSpawn config, boolean checkIfPortalFitsNice) { + private static Vector3d findGroundWithinChunk(@Nonnull WorldChunk chunk, int scanHeight, boolean checkIfPortalFitsNice) { int chunkBlockX = ChunkUtil.minBlock(chunk.getX()); int chunkBlockZ = ChunkUtil.minBlock(chunk.getZ()); ThreadLocalRandom random = ThreadLocalRandom.current(); - for (int i = 0; i < config.getChecksPerChunk(); i++) { + for (int i = 0; i < 8; i++) { int x = chunkBlockX + random.nextInt(2, 14); int z = chunkBlockZ + random.nextInt(2, 14); - Vector3d point = findWithGroundBelow(chunk, x, config.getCheckSpawnY(), z, config.getScanHeight(), false); + Vector3d point = findWithGroundBelow(chunk, x, scanHeight, z, scanHeight, false); if (point != null && (!checkIfPortalFitsNice || FitsAPortal.check(chunk.getWorld(), point))) { return point; } @@ -160,8 +151,8 @@ public final class PortalSpawnFinder { } @Nullable - private static Vector3d findFallbackPositionOnGround(@Nonnull World world, @Nonnull PortalSpawn config) { - Vector3i center = config.getCenter(); + private static Vector3d findFallbackPositionOnGround(@Nonnull World world) { + Vector3d center = FALLBACK_POSITION.clone(); long chunkIndex = ChunkUtil.indexChunkFromBlock(center.x, center.z); WorldChunk centerChunk = world.getChunk(chunkIndex); return centerChunk == null ? null : findWithGroundBelow(centerChunk, 0, 319, 0, 319, true); diff --git a/src/com/hypixel/hytale/builtin/randomtick/RandomTick.java b/src/com/hypixel/hytale/builtin/randomtick/RandomTick.java new file mode 100644 index 00000000..90cc31a7 --- /dev/null +++ b/src/com/hypixel/hytale/builtin/randomtick/RandomTick.java @@ -0,0 +1,35 @@ +package com.hypixel.hytale.builtin.randomtick; + +import com.hypixel.hytale.component.Resource; +import com.hypixel.hytale.component.ResourceType; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import java.util.Random; +import javax.annotation.Nullable; + +public class RandomTick implements Resource { + private int blocksPerSectionPerTickStable = 1; + private int blocksPerSectionPerTickUnstable = 3; + private Random random = new Random(); + + public static ResourceType getResourceType() { + return RandomTickPlugin.get().getRandomTickResourceType(); + } + + public int getBlocksPerSectionPerTickStable() { + return this.blocksPerSectionPerTickStable; + } + + public int getBlocksPerSectionPerTickUnstable() { + return this.blocksPerSectionPerTickUnstable; + } + + public Random getRandom() { + return this.random; + } + + @Nullable + @Override + public Resource clone() { + return new RandomTick(); + } +} diff --git a/src/com/hypixel/hytale/builtin/randomtick/RandomTickPlugin.java b/src/com/hypixel/hytale/builtin/randomtick/RandomTickPlugin.java new file mode 100644 index 00000000..3c4266dd --- /dev/null +++ b/src/com/hypixel/hytale/builtin/randomtick/RandomTickPlugin.java @@ -0,0 +1,36 @@ +package com.hypixel.hytale.builtin.randomtick; + +import com.hypixel.hytale.builtin.randomtick.procedures.ChangeIntoBlockProcedure; +import com.hypixel.hytale.builtin.randomtick.procedures.SpreadToProcedure; +import com.hypixel.hytale.component.ResourceType; +import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure; +import com.hypixel.hytale.server.core.plugin.JavaPlugin; +import com.hypixel.hytale.server.core.plugin.JavaPluginInit; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import javax.annotation.Nonnull; + +public class RandomTickPlugin extends JavaPlugin { + private static RandomTickPlugin INSTANCE; + private ResourceType randomTickResourceType; + + public static RandomTickPlugin get() { + return INSTANCE; + } + + public RandomTickPlugin(@Nonnull JavaPluginInit init) { + super(init); + INSTANCE = this; + } + + @Override + protected void setup() { + this.randomTickResourceType = this.getChunkStoreRegistry().registerResource(RandomTick.class, RandomTick::new); + this.getChunkStoreRegistry().registerSystem(new RandomTickSystem()); + RandomTickProcedure.CODEC.register("ChangeIntoBlock", ChangeIntoBlockProcedure.class, ChangeIntoBlockProcedure.CODEC); + RandomTickProcedure.CODEC.register("SpreadTo", SpreadToProcedure.class, SpreadToProcedure.CODEC); + } + + public ResourceType getRandomTickResourceType() { + return this.randomTickResourceType; + } +} diff --git a/src/com/hypixel/hytale/builtin/randomtick/RandomTickSystem.java b/src/com/hypixel/hytale/builtin/randomtick/RandomTickSystem.java new file mode 100644 index 00000000..7adc4a26 --- /dev/null +++ b/src/com/hypixel/hytale/builtin/randomtick/RandomTickSystem.java @@ -0,0 +1,114 @@ +package com.hypixel.hytale.builtin.randomtick; + +import com.hypixel.hytale.assetstore.map.BlockTypeAssetMap; +import com.hypixel.hytale.component.ArchetypeChunk; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.ComponentType; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.component.query.Query; +import com.hypixel.hytale.component.system.tick.EntityTickingSystem; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.math.util.HashUtil; +import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection; +import com.hypixel.hytale.server.core.universe.world.chunk.section.ChunkSection; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import java.util.Random; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class RandomTickSystem extends EntityTickingSystem { + private final ComponentType blockSelectionComponentType = BlockSection.getComponentType(); + private final ComponentType chunkSectionComponentType = ChunkSection.getComponentType(); + private final Query query = Query.and(this.blockSelectionComponentType, this.chunkSectionComponentType); + + @Override + public void tick( + float dt, + int index, + @Nonnull ArchetypeChunk archetypeChunk, + @Nonnull Store store, + @Nonnull CommandBuffer commandBuffer + ) { + BlockSection blockSection = archetypeChunk.getComponent(index, this.blockSelectionComponentType); + + assert blockSection != null; + + if (!blockSection.isSolidAir()) { + ChunkSection chunkSection = archetypeChunk.getComponent(index, this.chunkSectionComponentType); + + assert chunkSection != null; + + RandomTick config = commandBuffer.getResource(RandomTick.getResourceType()); + World world = store.getExternalData().getWorld(); + int interval = 32768 / config.getBlocksPerSectionPerTickStable(); + long baseSeed = HashUtil.hash(world.getTick() / interval, chunkSection.getX(), chunkSection.getY(), chunkSection.getZ()); + long randomSeed = (baseSeed << 1 | 1L) & 32767L; + long randomSeed2 = baseSeed >> 16 & 32767L; + long startIndex = world.getTick() % interval * config.getBlocksPerSectionPerTickStable(); + BlockTypeAssetMap assetMap = BlockType.getAssetMap(); + + for (int i = 0; i < config.getBlocksPerSectionPerTickStable(); i++) { + int blockIndex = (int)((startIndex + i) * randomSeed + randomSeed2 & 32767L); + int localX = ChunkUtil.xFromIndex(blockIndex); + int localY = ChunkUtil.yFromIndex(blockIndex); + int localZ = ChunkUtil.zFromIndex(blockIndex); + int blockId = blockSection.get(blockIndex); + if (blockId != 0) { + BlockType blockType = assetMap.getAsset(blockId); + if (blockType != null) { + RandomTickProcedure randomTickProcedure = blockType.getRandomTickProcedure(); + if (randomTickProcedure != null) { + randomTickProcedure.onRandomTick( + store, + commandBuffer, + blockSection, + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getX(), localX), + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getY(), localY), + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getZ(), localZ), + blockId, + blockType + ); + } + } + } + } + + Random rng = config.getRandom(); + + for (int ix = 0; ix < config.getBlocksPerSectionPerTickUnstable(); ix++) { + int blockIndex = rng.nextInt(32768); + int localX = ChunkUtil.xFromIndex(blockIndex); + int localY = ChunkUtil.yFromIndex(blockIndex); + int localZ = ChunkUtil.zFromIndex(blockIndex); + int blockId = blockSection.get(blockIndex); + if (blockId != 0) { + BlockType blockType = assetMap.getAsset(blockId); + if (blockType != null) { + RandomTickProcedure randomTickProcedure = blockType.getRandomTickProcedure(); + if (randomTickProcedure != null) { + randomTickProcedure.onRandomTick( + store, + commandBuffer, + blockSection, + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getX(), localX), + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getY(), localY), + ChunkUtil.worldCoordFromLocalCoord(chunkSection.getZ(), localZ), + blockId, + blockType + ); + } + } + } + } + } + } + + @Nullable + @Override + public Query getQuery() { + return this.query; + } +} diff --git a/src/com/hypixel/hytale/builtin/randomtick/procedures/ChangeIntoBlockProcedure.java b/src/com/hypixel/hytale/builtin/randomtick/procedures/ChangeIntoBlockProcedure.java new file mode 100644 index 00000000..43bd817f --- /dev/null +++ b/src/com/hypixel/hytale/builtin/randomtick/procedures/ChangeIntoBlockProcedure.java @@ -0,0 +1,38 @@ +package com.hypixel.hytale.builtin.randomtick.procedures; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; +import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; + +public class ChangeIntoBlockProcedure implements RandomTickProcedure { + public static final BuilderCodec CODEC = BuilderCodec.builder(ChangeIntoBlockProcedure.class, ChangeIntoBlockProcedure::new) + .appendInherited(new KeyedCodec<>("TargetBlock", Codec.STRING), (o, i) -> o.targetBlock = i, o -> o.targetBlock, (o, p) -> o.targetBlock = p.targetBlock) + .addValidatorLate(() -> BlockType.VALIDATOR_CACHE.getValidator().late()) + .add() + .build(); + private String targetBlock; + + @Override + public void onRandomTick( + Store store, + CommandBuffer commandBuffer, + BlockSection blockSection, + int worldX, + int worldY, + int worldZ, + int blockId, + BlockType blockType + ) { + int targetBlockId = BlockType.getAssetMap().getIndex(this.targetBlock); + if (targetBlockId != Integer.MIN_VALUE) { + blockSection.set(ChunkUtil.indexBlock(worldX, worldY, worldZ), targetBlockId, 0, 0); + } + } +} diff --git a/src/com/hypixel/hytale/builtin/randomtick/procedures/SpreadToProcedure.java b/src/com/hypixel/hytale/builtin/randomtick/procedures/SpreadToProcedure.java new file mode 100644 index 00000000..a2e1724a --- /dev/null +++ b/src/com/hypixel/hytale/builtin/randomtick/procedures/SpreadToProcedure.java @@ -0,0 +1,197 @@ +package com.hypixel.hytale.builtin.randomtick.procedures; + +import com.hypixel.hytale.assetstore.AssetRegistry; +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.codec.codecs.array.ArrayCodec; +import com.hypixel.hytale.codec.validation.Validators; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.math.vector.Vector3i; +import com.hypixel.hytale.protocol.BlockMaterial; +import com.hypixel.hytale.protocol.DrawType; +import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; +import com.hypixel.hytale.server.core.modules.time.WorldTimeResource; +import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import it.unimi.dsi.fastutil.ints.IntSet; + +public class SpreadToProcedure implements RandomTickProcedure { + public static final BuilderCodec CODEC = BuilderCodec.builder(SpreadToProcedure.class, SpreadToProcedure::new) + .appendInherited( + new KeyedCodec<>("SpreadDirections", new ArrayCodec<>(Vector3i.CODEC, Vector3i[]::new)), + (o, i) -> o.spreadDirections = i, + o -> o.spreadDirections, + (o, p) -> o.spreadDirections = p.spreadDirections + ) + .documentation("The directions this block can spread in.") + .addValidator(Validators.nonNull()) + .add() + .appendInherited(new KeyedCodec<>("MinY", Codec.INTEGER), (o, i) -> o.minY = i, o -> o.minY, (o, p) -> o.minY = p.minY) + .documentation( + "The minimum Y level this block can spread to, relative to the current block. For example, a value of -1 means the block can spread to blocks one level below it." + ) + .add() + .appendInherited(new KeyedCodec<>("MaxY", Codec.INTEGER), (o, i) -> o.maxY = i, o -> o.maxY, (o, p) -> o.maxY = p.maxY) + .documentation( + "The maximum Y level this block can spread to, relative to the current block. For example, a value of 1 means the block can spread to blocks one level above it." + ) + .add() + .appendInherited(new KeyedCodec<>("AllowedTag", Codec.STRING), (o, i) -> { + o.allowedTag = i; + o.allowedTagIndex = AssetRegistry.getOrCreateTagIndex(i); + }, o -> o.allowedTag, (o, p) -> { + o.allowedTag = p.allowedTag; + o.allowedTagIndex = p.allowedTagIndex; + }) + .documentation("The asset tag that the block can spread to.") + .addValidator(Validators.nonNull()) + .add() + .appendInherited( + new KeyedCodec<>("RequireEmptyAboveTarget", Codec.BOOLEAN), + (o, i) -> o.requireEmptyAboveTarget = i, + o -> o.requireEmptyAboveTarget, + (o, p) -> o.requireEmptyAboveTarget = p.requireEmptyAboveTarget + ) + .documentation("Whether the block requires an empty block above the target block to spread.") + .add() + .appendInherited( + new KeyedCodec<>("RequiredLightLevel", Codec.INTEGER), + (o, i) -> o.requiredLightLevel = i, + o -> o.requiredLightLevel, + (o, p) -> o.requiredLightLevel = p.requiredLightLevel + ) + .documentation("The minimum light level required for the block to spread.") + .addValidator(Validators.range(0, 15)) + .add() + .appendInherited( + new KeyedCodec<>("RevertBlock", Codec.STRING), (o, i) -> o.revertBlock = i, o -> o.revertBlock, (o, p) -> o.revertBlock = p.revertBlock + ) + .documentation("If specified, the block will revert to this block if it is covered by another block.") + .addValidatorLate(() -> BlockType.VALIDATOR_CACHE.getValidator().late()) + .add() + .build(); + private Vector3i[] spreadDirections; + private int minY = 0; + private int maxY = 0; + private String allowedTag; + private int allowedTagIndex = Integer.MIN_VALUE; + private boolean requireEmptyAboveTarget = true; + private int requiredLightLevel = 6; + private String revertBlock; + + @Override + public void onRandomTick( + Store store, + CommandBuffer commandBuffer, + BlockSection blockSection, + int worldX, + int worldY, + int worldZ, + int blockId, + BlockType blockType + ) { + IntSet validSpreadTargets = BlockType.getAssetMap().getIndexesForTag(this.allowedTagIndex); + WorldTimeResource worldTimeResource = commandBuffer.getExternalData() + .getWorld() + .getEntityStore() + .getStore() + .getResource(WorldTimeResource.getResourceType()); + double sunlightFactor = worldTimeResource.getSunlightFactor(); + BlockSection aboveSection = blockSection; + if (!ChunkUtil.isSameChunkSection(worldX, worldY, worldZ, worldX, worldY + 1, worldZ)) { + Ref aboveChunk = store.getExternalData() + .getChunkSectionReference( + commandBuffer, ChunkUtil.chunkCoordinate(worldX), ChunkUtil.chunkCoordinate(worldY + 1), ChunkUtil.chunkCoordinate(worldZ) + ); + if (aboveChunk == null) { + return; + } + + BlockSection aboveBlockSection = commandBuffer.getComponent(aboveChunk, BlockSection.getComponentType()); + if (aboveBlockSection == null) { + return; + } + + aboveSection = aboveBlockSection; + } + + int aboveIndex = ChunkUtil.indexBlock(worldX, worldY + 1, worldZ); + if (this.revertBlock != null) { + int blockAtAboveId = aboveSection.get(aboveIndex); + BlockType blockAtAbove = BlockType.getAssetMap().getAsset(blockAtAboveId); + if (blockAtAbove != null && (blockAtAbove.getDrawType() == DrawType.Cube || blockAtAbove.getDrawType() == DrawType.CubeWithModel)) { + int revert = BlockType.getAssetMap().getIndex(this.revertBlock); + if (revert != Integer.MIN_VALUE) { + blockSection.set(worldX, worldY, worldZ, revert, 0, 0); + return; + } + } + } + + int skyLight = (int)(aboveSection.getLocalLight().getSkyLight(aboveIndex) * sunlightFactor); + int blockLevel = aboveSection.getLocalLight().getBlockLightIntensity(aboveIndex); + int lightLevel = Math.max(skyLight, blockLevel); + if (lightLevel >= this.requiredLightLevel) { + for (int y = this.minY; y <= this.maxY; y++) { + for (Vector3i direction : this.spreadDirections) { + int targetX = worldX + direction.x; + int targetY = worldY + direction.y + y; + int targetZ = worldZ + direction.z; + BlockSection targetBlockSection = blockSection; + if (!ChunkUtil.isSameChunkSection(worldX, worldY, worldZ, targetX, targetY, targetZ)) { + Ref otherChunk = store.getExternalData() + .getChunkSectionReference( + commandBuffer, ChunkUtil.chunkCoordinate(targetX), ChunkUtil.chunkCoordinate(targetY), ChunkUtil.chunkCoordinate(targetZ) + ); + if (otherChunk == null) { + continue; + } + + targetBlockSection = commandBuffer.getComponent(otherChunk, BlockSection.getComponentType()); + if (targetBlockSection == null) { + continue; + } + } + + int targetIndex = ChunkUtil.indexBlock(targetX, targetY, targetZ); + int targetBlockId = targetBlockSection.get(targetIndex); + if (validSpreadTargets.contains(targetBlockId)) { + if (this.requireEmptyAboveTarget) { + int aboveTargetBlockId; + if (ChunkUtil.isSameChunkSection(targetX, targetY, targetZ, targetX, targetY + 1, targetZ)) { + aboveTargetBlockId = targetBlockSection.get(ChunkUtil.indexBlock(targetX, targetY + 1, targetZ)); + } else { + Ref aboveChunkx = store.getExternalData() + .getChunkSectionReference( + commandBuffer, ChunkUtil.chunkCoordinate(targetX), ChunkUtil.chunkCoordinate(targetY + 1), ChunkUtil.chunkCoordinate(targetZ) + ); + if (aboveChunkx == null) { + continue; + } + + BlockSection aboveBlockSection = commandBuffer.getComponent(aboveChunkx, BlockSection.getComponentType()); + if (aboveBlockSection == null) { + continue; + } + + aboveTargetBlockId = aboveBlockSection.get(ChunkUtil.indexBlock(targetX, targetY + 1, targetZ)); + } + + BlockType aboveBlockType = BlockType.getAssetMap().getAsset(aboveTargetBlockId); + if (aboveBlockType == null || aboveBlockType.getMaterial() != BlockMaterial.Empty) { + continue; + } + } + + targetBlockSection.set(targetIndex, blockId, 0, 0); + } + } + } + } + } +} diff --git a/src/com/hypixel/hytale/builtin/teleport/commands/teleport/variant/TeleportOtherToPlayerCommand.java b/src/com/hypixel/hytale/builtin/teleport/commands/teleport/variant/TeleportOtherToPlayerCommand.java index 608a13f9..1a0143eb 100644 --- a/src/com/hypixel/hytale/builtin/teleport/commands/teleport/variant/TeleportOtherToPlayerCommand.java +++ b/src/com/hypixel/hytale/builtin/teleport/commands/teleport/variant/TeleportOtherToPlayerCommand.java @@ -51,57 +51,69 @@ public class TeleportOtherToPlayerCommand extends CommandBase { World targetWorld = targetStore.getExternalData().getWorld(); sourceWorld.execute( () -> { - TransformComponent transformComponent = sourceStore.getComponent(sourceRef, TransformComponent.getComponentType()); + if (!sourceRef.isValid()) { + context.sendMessage(MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD); + } else if (!targetRef.isValid()) { + context.sendMessage(MESSAGE_COMMANDS_ERRORS_TARGET_NOT_IN_WORLD); + } else { + TransformComponent transformComponent = sourceStore.getComponent(sourceRef, TransformComponent.getComponentType()); - assert transformComponent != null; + assert transformComponent != null; - HeadRotation headRotationComponent = sourceStore.getComponent(sourceRef, HeadRotation.getComponentType()); + HeadRotation headRotationComponent = sourceStore.getComponent(sourceRef, HeadRotation.getComponentType()); - assert headRotationComponent != null; + assert headRotationComponent != null; - Vector3d pos = transformComponent.getPosition().clone(); - Vector3f rotation = headRotationComponent.getRotation().clone(); - targetWorld.execute( - () -> { - TransformComponent targetTransformComponent = targetStore.getComponent(targetRef, TransformComponent.getComponentType()); + Vector3d pos = transformComponent.getPosition().clone(); + Vector3f rotation = headRotationComponent.getRotation().clone(); + targetWorld.execute( + () -> { + TransformComponent targetTransformComponent = targetStore.getComponent(targetRef, TransformComponent.getComponentType()); - assert targetTransformComponent != null; + assert targetTransformComponent != null; - HeadRotation targetHeadRotationComponent = targetStore.getComponent(targetRef, HeadRotation.getComponentType()); + HeadRotation targetHeadRotationComponent = targetStore.getComponent(targetRef, HeadRotation.getComponentType()); - assert targetHeadRotationComponent != null; + assert targetHeadRotationComponent != null; - Vector3d targetPosition = targetTransformComponent.getPosition().clone(); - Vector3f targetHeadRotation = targetHeadRotationComponent.getRotation().clone(); - Transform targetTransform = new Transform(targetPosition, targetHeadRotation); - sourceWorld.execute( - () -> { - Teleport teleportComponent = Teleport.createForPlayer(targetWorld, targetTransform); - sourceStore.addComponent(sourceRef, Teleport.getComponentType(), teleportComponent); - PlayerRef sourcePlayerRefComponent = sourceStore.getComponent(sourceRef, PlayerRef.getComponentType()); + Vector3d targetPosition = targetTransformComponent.getPosition().clone(); + Vector3f targetHeadRotation = targetHeadRotationComponent.getRotation().clone(); + Transform targetTransform = new Transform(targetPosition, targetHeadRotation); + sourceWorld.execute( + () -> { + if (!sourceRef.isValid()) { + context.sendMessage(MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD); + } else if (!targetRef.isValid()) { + context.sendMessage(MESSAGE_COMMANDS_ERRORS_TARGET_NOT_IN_WORLD); + } else { + Teleport teleportComponent = Teleport.createForPlayer(targetWorld, targetTransform); + sourceStore.addComponent(sourceRef, Teleport.getComponentType(), teleportComponent); + PlayerRef sourcePlayerRefComponent = sourceStore.getComponent(sourceRef, PlayerRef.getComponentType()); - assert sourcePlayerRefComponent != null; + assert sourcePlayerRefComponent != null; - PlayerRef targetPlayerRefComponent = targetStore.getComponent(targetRef, PlayerRef.getComponentType()); + PlayerRef targetPlayerRefComponent = targetStore.getComponent(targetRef, PlayerRef.getComponentType()); - assert targetPlayerRefComponent != null; + assert targetPlayerRefComponent != null; - context.sendMessage( - Message.translation("server.commands.teleport.teleportedOtherToPlayer") - .param("targetName", sourcePlayerRefComponent.getUsername()) - .param("toName", targetPlayerRefComponent.getUsername()) - ); - sourceStore.ensureAndGetComponent(sourceRef, TeleportHistory.getComponentType()) - .append( - sourceWorld, - pos, - rotation, - "Teleport to " + targetPlayerRefComponent.getUsername() + " by " + context.sender().getDisplayName() - ); - } - ); - } - ); + context.sendMessage( + Message.translation("server.commands.teleport.teleportedOtherToPlayer") + .param("targetName", sourcePlayerRefComponent.getUsername()) + .param("toName", targetPlayerRefComponent.getUsername()) + ); + sourceStore.ensureAndGetComponent(sourceRef, TeleportHistory.getComponentType()) + .append( + sourceWorld, + pos, + rotation, + "Teleport to " + targetPlayerRefComponent.getUsername() + " by " + context.sender().getDisplayName() + ); + } + } + ); + } + ); + } } ); } else { diff --git a/src/com/hypixel/hytale/builtin/worldgen/FeatureFlags.java b/src/com/hypixel/hytale/builtin/worldgen/FeatureFlags.java deleted file mode 100644 index 9062c106..00000000 --- a/src/com/hypixel/hytale/builtin/worldgen/FeatureFlags.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hypixel.hytale.builtin.worldgen; - -import com.hypixel.hytale.server.worldgen.util.LogUtil; -import java.util.logging.Level; -import javax.annotation.Nonnull; - -public interface FeatureFlags { - @Deprecated(since = "2026-01-19", forRemoval = true) - boolean VERSION_OVERRIDES = of("hytale.worldgen.version_overrides"); - - static boolean of(@Nonnull String featureFlag) { - if (System.getProperty(featureFlag) == null && System.getenv(featureFlag) == null) { - return false; - } else { - LogUtil.getLogger().at(Level.INFO).log("Feature %s is enabled.", featureFlag); - return true; - } - } -} diff --git a/src/com/hypixel/hytale/builtin/worldgen/WorldGenPlugin.java b/src/com/hypixel/hytale/builtin/worldgen/WorldGenPlugin.java index 631b2cb2..4fae40a9 100644 --- a/src/com/hypixel/hytale/builtin/worldgen/WorldGenPlugin.java +++ b/src/com/hypixel/hytale/builtin/worldgen/WorldGenPlugin.java @@ -49,15 +49,17 @@ public class WorldGenPlugin extends JavaPlugin { instance = this; this.getEntityStoreRegistry().registerSystem(new BiomeDataSystem()); IWorldGenProvider.CODEC.register(Priority.DEFAULT.before(1), "Hytale", HytaleWorldGenProvider.class, HytaleWorldGenProvider.CODEC); - FileIO.setDefaultRoot(AssetModule.get().getBaseAssetPack().getRoot()); - if (FeatureFlags.VERSION_OVERRIDES) { - AssetModule assets = AssetModule.get(); + AssetModule assets = AssetModule.get(); + if (assets.getAssetPacks().isEmpty()) { + this.getLogger().at(Level.SEVERE).log("No asset packs loaded"); + } else { + FileIO.setDefaultRoot(assets.getBaseAssetPack().getRoot()); List packs = loadVersionPacks(assets); Object2ObjectOpenHashMap versions = new Object2ObjectOpenHashMap<>(); for (WorldGenPlugin.Version version : packs) { validateVersion(version, packs); - assets.registerPack(version.getPackName(), version.path, version.manifest); + assets.registerPack(version.getPackName(), version.path, version.manifest, false); Semver latest = versions.get(version.name); if (latest == null || version.manifest.getVersion().compareTo(latest) > 0) { versions.put(version.name, version.manifest.getVersion()); diff --git a/src/com/hypixel/hytale/codec/builder/BuilderCodec.java b/src/com/hypixel/hytale/codec/builder/BuilderCodec.java index 4bd7fa24..a3da8812 100644 --- a/src/com/hypixel/hytale/codec/builder/BuilderCodec.java +++ b/src/com/hypixel/hytale/codec/builder/BuilderCodec.java @@ -315,7 +315,7 @@ public class BuilderCodec implements Codec, DirectDecodeCodec, RawJsonC } } - public void decodeJson0(@Nonnull RawJsonReader reader, T t, ExtraInfo extraInfo) throws IOException { + private void decodeJson0(@Nonnull RawJsonReader reader, T t, ExtraInfo extraInfo) throws IOException { reader.expect('{'); reader.consumeWhiteSpace(); if (!reader.tryConsume('}')) { diff --git a/src/com/hypixel/hytale/common/util/StringUtil.java b/src/com/hypixel/hytale/common/util/StringUtil.java index 2264031a..a47de5f0 100644 --- a/src/com/hypixel/hytale/common/util/StringUtil.java +++ b/src/com/hypixel/hytale/common/util/StringUtil.java @@ -426,15 +426,19 @@ public class StringUtil { public static String toPaddedBinaryString(int val) { byte[] buf = new byte[]{48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48}; int leadingZeros = Integer.numberOfLeadingZeros(val); - int mag = 32 - leadingZeros; - int pos = Math.max(mag, 1); + if (leadingZeros == 32) { + return new String(buf, 0); + } else { + int mag = 32 - leadingZeros; + int pos = Math.max(mag, 1); - do { - buf[leadingZeros + --pos] = (byte)(48 + (val & 1)); - val >>>= 1; - } while (pos > 0); + do { + buf[leadingZeros + --pos] = (byte)(48 + (val & 1)); + val >>>= 1; + } while (pos > 0); - return new String(buf, 0); + return new String(buf, 0); + } } @Nonnull diff --git a/src/com/hypixel/hytale/math/util/ChunkUtil.java b/src/com/hypixel/hytale/math/util/ChunkUtil.java index 457f6fa9..f839c931 100644 --- a/src/com/hypixel/hytale/math/util/ChunkUtil.java +++ b/src/com/hypixel/hytale/math/util/ChunkUtil.java @@ -13,6 +13,7 @@ public class ChunkUtil { public static final int SIZE_COLUMNS = 1024; public static final int SIZE_COLUMNS_MASK = 1023; public static final int SIZE_BLOCKS = 32768; + public static final int SIZE_BLOCKS_MASK = 32767; public static final int BITS2 = 10; public static final int NON_CHUNK_MASK = -32; public static final int HEIGHT_SECTIONS = 10; diff --git a/src/com/hypixel/hytale/procedurallib/file/FileIO.java b/src/com/hypixel/hytale/procedurallib/file/FileIO.java index 5b55c3b7..3e9b6de0 100644 --- a/src/com/hypixel/hytale/procedurallib/file/FileIO.java +++ b/src/com/hypixel/hytale/procedurallib/file/FileIO.java @@ -29,7 +29,7 @@ public interface FileIO { } @Nonnull - static FileIOSystem openFileIOSystem(@Nonnull FileIOSystem fs) { + static FS openFileIOSystem(@Nonnull FS fs) { FileIOSystem.Provider.set(fs); return fs; } @@ -71,16 +71,20 @@ public interface FileIO { Path assetDirPath = relativize(path, fs.baseRoot()); ObjectArrayList paths = new ObjectArrayList<>(); ObjectOpenHashSet visited = new ObjectOpenHashSet<>(); + ObjectOpenHashSet disabled = new ObjectOpenHashSet<>(); for (Path root : fs.roots().paths) { Path rootAssetDirPath = append(root, assetDirPath); if (Files.exists(rootAssetDirPath) && Files.isDirectory(rootAssetDirPath)) { try (DirectoryStream dirStream = Files.newDirectoryStream(rootAssetDirPath)) { + visited.addAll(disabled); + disabled.clear(); + for (Path filepath : dirStream) { AssetPath assetPath = AssetPath.fromAbsolute(root, filepath); AssetPath disabledPath = disableOp.apply(assetPath); if (disabledPath != assetPath) { - visited.add(disabledPath); + disabled.add(disabledPath); } else if (matcher.test(assetPath) && visited.add(assetPath)) { paths.add(assetPath); } diff --git a/src/com/hypixel/hytale/protocol/ActiveAnimationsUpdate.java b/src/com/hypixel/hytale/protocol/ActiveAnimationsUpdate.java new file mode 100644 index 00000000..6280900a --- /dev/null +++ b/src/com/hypixel/hytale/protocol/ActiveAnimationsUpdate.java @@ -0,0 +1,179 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.PacketIO; +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import javax.annotation.Nonnull; + +public class ActiveAnimationsUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 1677721600; + @Nonnull + public String[] activeAnimations = new String[0]; + + public ActiveAnimationsUpdate() { + } + + public ActiveAnimationsUpdate(@Nonnull String[] activeAnimations) { + this.activeAnimations = activeAnimations; + } + + public ActiveAnimationsUpdate(@Nonnull ActiveAnimationsUpdate other) { + this.activeAnimations = other.activeAnimations; + } + + @Nonnull + public static ActiveAnimationsUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + ActiveAnimationsUpdate obj = new ActiveAnimationsUpdate(); + int pos = offset + 0; + int activeAnimationsCount = VarInt.peek(buf, pos); + if (activeAnimationsCount < 0) { + throw ProtocolException.negativeLength("ActiveAnimations", activeAnimationsCount); + } else if (activeAnimationsCount > 4096000) { + throw ProtocolException.arrayTooLong("ActiveAnimations", activeAnimationsCount, 4096000); + } else { + pos += VarInt.size(activeAnimationsCount); + int activeAnimationsBitfieldSize = (activeAnimationsCount + 7) / 8; + byte[] activeAnimationsBitfield = PacketIO.readBytes(buf, pos, activeAnimationsBitfieldSize); + pos += activeAnimationsBitfieldSize; + obj.activeAnimations = new String[activeAnimationsCount]; + + for (int i = 0; i < activeAnimationsCount; i++) { + if ((activeAnimationsBitfield[i / 8] & 1 << i % 8) != 0) { + int strLen = VarInt.peek(buf, pos); + if (strLen < 0) { + throw ProtocolException.negativeLength("activeAnimations[" + i + "]", strLen); + } + + if (strLen > 4096000) { + throw ProtocolException.stringTooLong("activeAnimations[" + i + "]", strLen, 4096000); + } + + int strVarLen = VarInt.length(buf, pos); + obj.activeAnimations[i] = PacketIO.readVarString(buf, pos); + pos += strVarLen + strLen; + } + } + + return obj; + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int arrLen = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos); + int bitfieldSize = (arrLen + 7) / 8; + byte[] bitfield = PacketIO.readBytes(buf, pos, bitfieldSize); + pos += bitfieldSize; + + for (int i = 0; i < arrLen; i++) { + if ((bitfield[i / 8] & 1 << i % 8) != 0) { + int sl = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos) + sl; + } + } + + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + if (this.activeAnimations.length > 4096000) { + throw ProtocolException.arrayTooLong("ActiveAnimations", this.activeAnimations.length, 4096000); + } else { + VarInt.write(buf, this.activeAnimations.length); + int activeAnimationsBitfieldSize = (this.activeAnimations.length + 7) / 8; + byte[] activeAnimationsBitfield = new byte[activeAnimationsBitfieldSize]; + + for (int i = 0; i < this.activeAnimations.length; i++) { + if (this.activeAnimations[i] != null) { + activeAnimationsBitfield[i / 8] = (byte)(activeAnimationsBitfield[i / 8] | (byte)(1 << i % 8)); + } + } + + buf.writeBytes(activeAnimationsBitfield); + + for (int ix = 0; ix < this.activeAnimations.length; ix++) { + if (this.activeAnimations[ix] != null) { + PacketIO.writeVarString(buf, this.activeAnimations[ix], 4096000); + } + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 0; + int activeAnimationsSize = 0; + + for (String elem : this.activeAnimations) { + if (elem != null) { + activeAnimationsSize += PacketIO.stringSize(elem); + } + } + + return size + VarInt.size(this.activeAnimations.length) + (this.activeAnimations.length + 7) / 8 + activeAnimationsSize; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int activeAnimationsCount = VarInt.peek(buffer, pos); + if (activeAnimationsCount < 0) { + return ValidationResult.error("Invalid array count for ActiveAnimations"); + } else if (activeAnimationsCount > 4096000) { + return ValidationResult.error("ActiveAnimations exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + + for (int i = 0; i < activeAnimationsCount; i++) { + int strLen = VarInt.peek(buffer, pos); + if (strLen < 0) { + return ValidationResult.error("Invalid string length in ActiveAnimations"); + } + + pos += VarInt.length(buffer, pos); + pos += strLen; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading string in ActiveAnimations"); + } + } + + return ValidationResult.OK; + } + } + } + + public ActiveAnimationsUpdate clone() { + ActiveAnimationsUpdate copy = new ActiveAnimationsUpdate(); + copy.activeAnimations = Arrays.copyOf(this.activeAnimations, this.activeAnimations.length); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof ActiveAnimationsUpdate other ? Arrays.equals((Object[])this.activeAnimations, (Object[])other.activeAnimations) : false; + } + } + + @Override + public int hashCode() { + int result = 1; + return 31 * result + Arrays.hashCode((Object[])this.activeAnimations); + } +} diff --git a/src/com/hypixel/hytale/protocol/AudioUpdate.java b/src/com/hypixel/hytale/protocol/AudioUpdate.java new file mode 100644 index 00000000..786e85cf --- /dev/null +++ b/src/com/hypixel/hytale/protocol/AudioUpdate.java @@ -0,0 +1,124 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import javax.annotation.Nonnull; + +public class AudioUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 16384005; + @Nonnull + public int[] soundEventIds = new int[0]; + + public AudioUpdate() { + } + + public AudioUpdate(@Nonnull int[] soundEventIds) { + this.soundEventIds = soundEventIds; + } + + public AudioUpdate(@Nonnull AudioUpdate other) { + this.soundEventIds = other.soundEventIds; + } + + @Nonnull + public static AudioUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + AudioUpdate obj = new AudioUpdate(); + int pos = offset + 0; + int soundEventIdsCount = VarInt.peek(buf, pos); + if (soundEventIdsCount < 0) { + throw ProtocolException.negativeLength("SoundEventIds", soundEventIdsCount); + } else if (soundEventIdsCount > 4096000) { + throw ProtocolException.arrayTooLong("SoundEventIds", soundEventIdsCount, 4096000); + } else { + int soundEventIdsVarLen = VarInt.size(soundEventIdsCount); + if (pos + soundEventIdsVarLen + soundEventIdsCount * 4L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("SoundEventIds", pos + soundEventIdsVarLen + soundEventIdsCount * 4, buf.readableBytes()); + } else { + pos += soundEventIdsVarLen; + obj.soundEventIds = new int[soundEventIdsCount]; + + for (int i = 0; i < soundEventIdsCount; i++) { + obj.soundEventIds[i] = buf.getIntLE(pos + i * 4); + } + + pos += soundEventIdsCount * 4; + return obj; + } + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int arrLen = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos) + arrLen * 4; + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + if (this.soundEventIds.length > 4096000) { + throw ProtocolException.arrayTooLong("SoundEventIds", this.soundEventIds.length, 4096000); + } else { + VarInt.write(buf, this.soundEventIds.length); + + for (int item : this.soundEventIds) { + buf.writeIntLE(item); + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 0; + return size + VarInt.size(this.soundEventIds.length) + this.soundEventIds.length * 4; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int soundEventIdsCount = VarInt.peek(buffer, pos); + if (soundEventIdsCount < 0) { + return ValidationResult.error("Invalid array count for SoundEventIds"); + } else if (soundEventIdsCount > 4096000) { + return ValidationResult.error("SoundEventIds exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + pos += soundEventIdsCount * 4; + return pos > buffer.writerIndex() ? ValidationResult.error("Buffer overflow reading SoundEventIds") : ValidationResult.OK; + } + } + } + + public AudioUpdate clone() { + AudioUpdate copy = new AudioUpdate(); + copy.soundEventIds = Arrays.copyOf(this.soundEventIds, this.soundEventIds.length); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof AudioUpdate other ? Arrays.equals(this.soundEventIds, other.soundEventIds) : false; + } + } + + @Override + public int hashCode() { + int result = 1; + return 31 * result + Arrays.hashCode(this.soundEventIds); + } +} diff --git a/src/com/hypixel/hytale/protocol/BenchRequirement.java b/src/com/hypixel/hytale/protocol/BenchRequirement.java index 446ddc96..81b44dd0 100644 --- a/src/com/hypixel/hytale/protocol/BenchRequirement.java +++ b/src/com/hypixel/hytale/protocol/BenchRequirement.java @@ -18,8 +18,8 @@ public class BenchRequirement { public static final int MAX_SIZE = 1677721600; @Nonnull public BenchType type = BenchType.Crafting; - @Nullable - public String id; + @Nonnull + public String id = ""; @Nullable public String[] categories; public int requiredTierLevel; @@ -27,7 +27,7 @@ public class BenchRequirement { public BenchRequirement() { } - public BenchRequirement(@Nonnull BenchType type, @Nullable String id, @Nullable String[] categories, int requiredTierLevel) { + public BenchRequirement(@Nonnull BenchType type, @Nonnull String id, @Nullable String[] categories, int requiredTierLevel) { this.type = type; this.id = id; this.categories = categories; @@ -47,84 +47,77 @@ public class BenchRequirement { byte nullBits = buf.getByte(offset); obj.type = BenchType.fromValue(buf.getByte(offset + 1)); obj.requiredTierLevel = buf.getIntLE(offset + 2); - if ((nullBits & 1) != 0) { - int varPos0 = offset + 14 + buf.getIntLE(offset + 6); - int idLen = VarInt.peek(buf, varPos0); - if (idLen < 0) { - throw ProtocolException.negativeLength("Id", idLen); - } - - if (idLen > 4096000) { - throw ProtocolException.stringTooLong("Id", idLen, 4096000); - } - + int varPos0 = offset + 14 + buf.getIntLE(offset + 6); + int idLen = VarInt.peek(buf, varPos0); + if (idLen < 0) { + throw ProtocolException.negativeLength("Id", idLen); + } else if (idLen > 4096000) { + throw ProtocolException.stringTooLong("Id", idLen, 4096000); + } else { obj.id = PacketIO.readVarString(buf, varPos0, PacketIO.UTF8); - } - - if ((nullBits & 2) != 0) { - int varPos1 = offset + 14 + buf.getIntLE(offset + 10); - int categoriesCount = VarInt.peek(buf, varPos1); - if (categoriesCount < 0) { - throw ProtocolException.negativeLength("Categories", categoriesCount); - } - - if (categoriesCount > 4096000) { - throw ProtocolException.arrayTooLong("Categories", categoriesCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos1); - if (varPos1 + varIntLen + categoriesCount * 1L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("Categories", varPos1 + varIntLen + categoriesCount * 1, buf.readableBytes()); - } - - obj.categories = new String[categoriesCount]; - int elemPos = varPos1 + varIntLen; - - for (int i = 0; i < categoriesCount; i++) { - int strLen = VarInt.peek(buf, elemPos); - if (strLen < 0) { - throw ProtocolException.negativeLength("categories[" + i + "]", strLen); + if ((nullBits & 1) != 0) { + varPos0 = offset + 14 + buf.getIntLE(offset + 10); + idLen = VarInt.peek(buf, varPos0); + if (idLen < 0) { + throw ProtocolException.negativeLength("Categories", idLen); } - if (strLen > 4096000) { - throw ProtocolException.stringTooLong("categories[" + i + "]", strLen, 4096000); + if (idLen > 4096000) { + throw ProtocolException.arrayTooLong("Categories", idLen, 4096000); } - int strVarLen = VarInt.length(buf, elemPos); - obj.categories[i] = PacketIO.readVarString(buf, elemPos); - elemPos += strVarLen + strLen; - } - } + int varIntLen = VarInt.length(buf, varPos0); + if (varPos0 + varIntLen + idLen * 1L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("Categories", varPos0 + varIntLen + idLen * 1, buf.readableBytes()); + } - return obj; + obj.categories = new String[idLen]; + int elemPos = varPos0 + varIntLen; + + for (int i = 0; i < idLen; i++) { + int strLen = VarInt.peek(buf, elemPos); + if (strLen < 0) { + throw ProtocolException.negativeLength("categories[" + i + "]", strLen); + } + + if (strLen > 4096000) { + throw ProtocolException.stringTooLong("categories[" + i + "]", strLen, 4096000); + } + + int strVarLen = VarInt.length(buf, elemPos); + obj.categories[i] = PacketIO.readVarString(buf, elemPos); + elemPos += strVarLen + strLen; + } + } + + return obj; + } } public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { byte nullBits = buf.getByte(offset); int maxEnd = 14; - if ((nullBits & 1) != 0) { - int fieldOffset0 = buf.getIntLE(offset + 6); - int pos0 = offset + 14 + fieldOffset0; - int sl = VarInt.peek(buf, pos0); - pos0 += VarInt.length(buf, pos0) + sl; - if (pos0 - offset > maxEnd) { - maxEnd = pos0 - offset; - } + int fieldOffset0 = buf.getIntLE(offset + 6); + int pos0 = offset + 14 + fieldOffset0; + int sl = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0) + sl; + if (pos0 - offset > maxEnd) { + maxEnd = pos0 - offset; } - if ((nullBits & 2) != 0) { - int fieldOffset1 = buf.getIntLE(offset + 10); - int pos1 = offset + 14 + fieldOffset1; - int arrLen = VarInt.peek(buf, pos1); - pos1 += VarInt.length(buf, pos1); + if ((nullBits & 1) != 0) { + fieldOffset0 = buf.getIntLE(offset + 10); + pos0 = offset + 14 + fieldOffset0; + sl = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0); - for (int i = 0; i < arrLen; i++) { - int sl = VarInt.peek(buf, pos1); - pos1 += VarInt.length(buf, pos1) + sl; + for (int i = 0; i < sl; i++) { + int slx = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0) + slx; } - if (pos1 - offset > maxEnd) { - maxEnd = pos1 - offset; + if (pos0 - offset > maxEnd) { + maxEnd = pos0 - offset; } } @@ -134,12 +127,8 @@ public class BenchRequirement { public void serialize(@Nonnull ByteBuf buf) { int startPos = buf.writerIndex(); byte nullBits = 0; - if (this.id != null) { - nullBits = (byte)(nullBits | 1); - } - if (this.categories != null) { - nullBits = (byte)(nullBits | 2); + nullBits = (byte)(nullBits | 1); } buf.writeByte(nullBits); @@ -150,13 +139,8 @@ public class BenchRequirement { int categoriesOffsetSlot = buf.writerIndex(); buf.writeIntLE(0); int varBlockStart = buf.writerIndex(); - if (this.id != null) { - buf.setIntLE(idOffsetSlot, buf.writerIndex() - varBlockStart); - PacketIO.writeVarString(buf, this.id, 4096000); - } else { - buf.setIntLE(idOffsetSlot, -1); - } - + buf.setIntLE(idOffsetSlot, buf.writerIndex() - varBlockStart); + PacketIO.writeVarString(buf, this.id, 4096000); if (this.categories != null) { buf.setIntLE(categoriesOffsetSlot, buf.writerIndex() - varBlockStart); if (this.categories.length > 4096000) { @@ -175,10 +159,7 @@ public class BenchRequirement { public int computeSize() { int size = 14; - if (this.id != null) { - size += PacketIO.stringSize(this.id); - } - + size += PacketIO.stringSize(this.id); if (this.categories != null) { int categoriesSize = 0; @@ -197,70 +178,66 @@ public class BenchRequirement { return ValidationResult.error("Buffer too small: expected at least 14 bytes"); } else { byte nullBits = buffer.getByte(offset); - if ((nullBits & 1) != 0) { - int idOffset = buffer.getIntLE(offset + 6); - if (idOffset < 0) { - return ValidationResult.error("Invalid offset for Id"); - } - + int idOffset = buffer.getIntLE(offset + 6); + if (idOffset < 0) { + return ValidationResult.error("Invalid offset for Id"); + } else { int pos = offset + 14 + idOffset; if (pos >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Id"); - } + } else { + int idLen = VarInt.peek(buffer, pos); + if (idLen < 0) { + return ValidationResult.error("Invalid string length for Id"); + } else if (idLen > 4096000) { + return ValidationResult.error("Id exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + pos += idLen; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading Id"); + } else { + if ((nullBits & 1) != 0) { + idOffset = buffer.getIntLE(offset + 10); + if (idOffset < 0) { + return ValidationResult.error("Invalid offset for Categories"); + } - int idLen = VarInt.peek(buffer, pos); - if (idLen < 0) { - return ValidationResult.error("Invalid string length for Id"); - } + pos = offset + 14 + idOffset; + if (pos >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for Categories"); + } - if (idLen > 4096000) { - return ValidationResult.error("Id exceeds max length 4096000"); - } + idLen = VarInt.peek(buffer, pos); + if (idLen < 0) { + return ValidationResult.error("Invalid array count for Categories"); + } - pos += VarInt.length(buffer, pos); - pos += idLen; - if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Id"); - } - } + if (idLen > 4096000) { + return ValidationResult.error("Categories exceeds max length 4096000"); + } - if ((nullBits & 2) != 0) { - int categoriesOffset = buffer.getIntLE(offset + 10); - if (categoriesOffset < 0) { - return ValidationResult.error("Invalid offset for Categories"); - } + pos += VarInt.length(buffer, pos); - int posx = offset + 14 + categoriesOffset; - if (posx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Categories"); - } + for (int i = 0; i < idLen; i++) { + int strLen = VarInt.peek(buffer, pos); + if (strLen < 0) { + return ValidationResult.error("Invalid string length in Categories"); + } - int categoriesCount = VarInt.peek(buffer, posx); - if (categoriesCount < 0) { - return ValidationResult.error("Invalid array count for Categories"); - } + pos += VarInt.length(buffer, pos); + pos += strLen; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading string in Categories"); + } + } + } - if (categoriesCount > 4096000) { - return ValidationResult.error("Categories exceeds max length 4096000"); - } - - posx += VarInt.length(buffer, posx); - - for (int i = 0; i < categoriesCount; i++) { - int strLen = VarInt.peek(buffer, posx); - if (strLen < 0) { - return ValidationResult.error("Invalid string length in Categories"); - } - - posx += VarInt.length(buffer, posx); - posx += strLen; - if (posx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading string in Categories"); + return ValidationResult.OK; + } } } } - - return ValidationResult.OK; } } diff --git a/src/com/hypixel/hytale/protocol/BlockUpdate.java b/src/com/hypixel/hytale/protocol/BlockUpdate.java new file mode 100644 index 00000000..44c27935 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/BlockUpdate.java @@ -0,0 +1,79 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class BlockUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 8; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 8; + public static final int MAX_SIZE = 8; + public int blockId; + public float entityScale; + + public BlockUpdate() { + } + + public BlockUpdate(int blockId, float entityScale) { + this.blockId = blockId; + this.entityScale = entityScale; + } + + public BlockUpdate(@Nonnull BlockUpdate other) { + this.blockId = other.blockId; + this.entityScale = other.entityScale; + } + + @Nonnull + public static BlockUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + BlockUpdate obj = new BlockUpdate(); + obj.blockId = buf.getIntLE(offset + 0); + obj.entityScale = buf.getFloatLE(offset + 4); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 8; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + buf.writeIntLE(this.blockId); + buf.writeFloatLE(this.entityScale); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 8; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 8 ? ValidationResult.error("Buffer too small: expected at least 8 bytes") : ValidationResult.OK; + } + + public BlockUpdate clone() { + BlockUpdate copy = new BlockUpdate(); + copy.blockId = this.blockId; + copy.entityScale = this.entityScale; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return !(obj instanceof BlockUpdate other) ? false : this.blockId == other.blockId && this.entityScale == other.entityScale; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.blockId, this.entityScale); + } +} diff --git a/src/com/hypixel/hytale/protocol/CachedPacket.java b/src/com/hypixel/hytale/protocol/CachedPacket.java index 86859f65..4f66f968 100644 --- a/src/com/hypixel/hytale/protocol/CachedPacket.java +++ b/src/com/hypixel/hytale/protocol/CachedPacket.java @@ -4,24 +4,26 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import javax.annotation.Nonnull; -public final class CachedPacket implements Packet, AutoCloseable { +public final class CachedPacket implements ToClientPacket, AutoCloseable { private final Class packetType; private final int packetId; + private final NetworkChannel packetChannel; private final ByteBuf cachedBytes; - private CachedPacket(Class packetType, int packetId, ByteBuf cachedBytes) { + private CachedPacket(Class packetType, int packetId, NetworkChannel packetChannel, ByteBuf cachedBytes) { this.packetType = packetType; this.packetId = packetId; + this.packetChannel = packetChannel; this.cachedBytes = cachedBytes; } - public static CachedPacket cache(@Nonnull T packet) { + public static CachedPacket cache(@Nonnull T packet) { if (packet instanceof CachedPacket) { throw new IllegalArgumentException("Cannot cache a CachedPacket"); } else { ByteBuf buf = Unpooled.buffer(); packet.serialize(buf); - return new CachedPacket<>((Class)packet.getClass(), packet.getId(), buf); + return new CachedPacket<>((Class)packet.getClass(), packet.getId(), packet.getChannel(), buf); } } @@ -30,6 +32,11 @@ public final class CachedPacket implements Packet, AutoCloseab return this.packetId; } + @Override + public NetworkChannel getChannel() { + return this.packetChannel; + } + @Override public void serialize(@Nonnull ByteBuf buf) { if (this.cachedBytes.refCnt() <= 0) { diff --git a/src/com/hypixel/hytale/protocol/CombatTextUpdate.java b/src/com/hypixel/hytale/protocol/CombatTextUpdate.java index e58bab3e..64226c32 100644 --- a/src/com/hypixel/hytale/protocol/CombatTextUpdate.java +++ b/src/com/hypixel/hytale/protocol/CombatTextUpdate.java @@ -7,22 +7,21 @@ import com.hypixel.hytale.protocol.io.VarInt; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -import javax.annotation.Nullable; -public class CombatTextUpdate { - public static final int NULLABLE_BIT_FIELD_SIZE = 1; - public static final int FIXED_BLOCK_SIZE = 5; +public class CombatTextUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 4; public static final int VARIABLE_FIELD_COUNT = 1; - public static final int VARIABLE_BLOCK_START = 5; - public static final int MAX_SIZE = 16384010; + public static final int VARIABLE_BLOCK_START = 4; + public static final int MAX_SIZE = 16384009; public float hitAngleDeg; - @Nullable - public String text; + @Nonnull + public String text = ""; public CombatTextUpdate() { } - public CombatTextUpdate(float hitAngleDeg, @Nullable String text) { + public CombatTextUpdate(float hitAngleDeg, @Nonnull String text) { this.hitAngleDeg = hitAngleDeg; this.text = text; } @@ -35,84 +34,57 @@ public class CombatTextUpdate { @Nonnull public static CombatTextUpdate deserialize(@Nonnull ByteBuf buf, int offset) { CombatTextUpdate obj = new CombatTextUpdate(); - byte nullBits = buf.getByte(offset); - obj.hitAngleDeg = buf.getFloatLE(offset + 1); - int pos = offset + 5; - if ((nullBits & 1) != 0) { - int textLen = VarInt.peek(buf, pos); - if (textLen < 0) { - throw ProtocolException.negativeLength("Text", textLen); - } - - if (textLen > 4096000) { - throw ProtocolException.stringTooLong("Text", textLen, 4096000); - } - + obj.hitAngleDeg = buf.getFloatLE(offset + 0); + int pos = offset + 4; + int textLen = VarInt.peek(buf, pos); + if (textLen < 0) { + throw ProtocolException.negativeLength("Text", textLen); + } else if (textLen > 4096000) { + throw ProtocolException.stringTooLong("Text", textLen, 4096000); + } else { int textVarLen = VarInt.length(buf, pos); obj.text = PacketIO.readVarString(buf, pos, PacketIO.UTF8); pos += textVarLen + textLen; + return obj; } - - return obj; } public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { - byte nullBits = buf.getByte(offset); - int pos = offset + 5; - if ((nullBits & 1) != 0) { - int sl = VarInt.peek(buf, pos); - pos += VarInt.length(buf, pos) + sl; - } - + int pos = offset + 4; + int sl = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos) + sl; return pos - offset; } - public void serialize(@Nonnull ByteBuf buf) { - byte nullBits = 0; - if (this.text != null) { - nullBits = (byte)(nullBits | 1); - } - - buf.writeByte(nullBits); + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); buf.writeFloatLE(this.hitAngleDeg); - if (this.text != null) { - PacketIO.writeVarString(buf, this.text, 4096000); - } + PacketIO.writeVarString(buf, this.text, 4096000); + return buf.writerIndex() - startPos; } + @Override public int computeSize() { - int size = 5; - if (this.text != null) { - size += PacketIO.stringSize(this.text); - } - - return size; + int size = 4; + return size + PacketIO.stringSize(this.text); } public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 5) { - return ValidationResult.error("Buffer too small: expected at least 5 bytes"); + if (buffer.readableBytes() - offset < 4) { + return ValidationResult.error("Buffer too small: expected at least 4 bytes"); } else { - byte nullBits = buffer.getByte(offset); - int pos = offset + 5; - if ((nullBits & 1) != 0) { - int textLen = VarInt.peek(buffer, pos); - if (textLen < 0) { - return ValidationResult.error("Invalid string length for Text"); - } - - if (textLen > 4096000) { - return ValidationResult.error("Text exceeds max length 4096000"); - } - + int pos = offset + 4; + int textLen = VarInt.peek(buffer, pos); + if (textLen < 0) { + return ValidationResult.error("Invalid string length for Text"); + } else if (textLen > 4096000) { + return ValidationResult.error("Text exceeds max length 4096000"); + } else { pos += VarInt.length(buffer, pos); pos += textLen; - if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Text"); - } + return pos > buffer.writerIndex() ? ValidationResult.error("Buffer overflow reading Text") : ValidationResult.OK; } - - return ValidationResult.OK; } } diff --git a/src/com/hypixel/hytale/protocol/ComponentUpdate.java b/src/com/hypixel/hytale/protocol/ComponentUpdate.java index dc8628b4..618cf515 100644 --- a/src/com/hypixel/hytale/protocol/ComponentUpdate.java +++ b/src/com/hypixel/hytale/protocol/ComponentUpdate.java @@ -1,1372 +1,190 @@ package com.hypixel.hytale.protocol; -import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; import io.netty.buffer.ByteBuf; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; -import java.util.Map.Entry; import javax.annotation.Nonnull; -import javax.annotation.Nullable; -public class ComponentUpdate { - public static final int NULLABLE_BIT_FIELD_SIZE = 3; - public static final int FIXED_BLOCK_SIZE = 160; - public static final int VARIABLE_FIELD_COUNT = 13; - public static final int VARIABLE_BLOCK_START = 212; - public static final int MAX_SIZE = 1677721600; - @Nonnull - public ComponentUpdateType type = ComponentUpdateType.Nameplate; - @Nullable - public Nameplate nameplate; - @Nullable - public int[] entityUIComponents; - @Nullable - public CombatTextUpdate combatTextUpdate; - @Nullable - public Model model; - @Nullable - public PlayerSkin skin; - @Nullable - public ItemWithAllMetadata item; - public int blockId; - public float entityScale; - @Nullable - public Equipment equipment; - @Nullable - public Map entityStatUpdates; - @Nullable - public ModelTransform transform; - @Nullable - public MovementStates movementStates; - @Nullable - public EntityEffectUpdate[] entityEffectUpdates; - @Nullable - public Map interactions; - @Nullable - public ColorLight dynamicLight; - public int hitboxCollisionConfigIndex; - public int repulsionConfigIndex; - @Nonnull - public UUID predictionId = new UUID(0L, 0L); - @Nullable - public int[] soundEventIds; - @Nullable - public String interactionHint; - @Nullable - public MountedUpdate mounted; - @Nullable - public String[] activeAnimations; - public boolean isProp; - - public ComponentUpdate() { - } - - public ComponentUpdate( - @Nonnull ComponentUpdateType type, - @Nullable Nameplate nameplate, - @Nullable int[] entityUIComponents, - @Nullable CombatTextUpdate combatTextUpdate, - @Nullable Model model, - @Nullable PlayerSkin skin, - @Nullable ItemWithAllMetadata item, - int blockId, - float entityScale, - @Nullable Equipment equipment, - @Nullable Map entityStatUpdates, - @Nullable ModelTransform transform, - @Nullable MovementStates movementStates, - @Nullable EntityEffectUpdate[] entityEffectUpdates, - @Nullable Map interactions, - @Nullable ColorLight dynamicLight, - int hitboxCollisionConfigIndex, - int repulsionConfigIndex, - @Nonnull UUID predictionId, - @Nullable int[] soundEventIds, - @Nullable String interactionHint, - @Nullable MountedUpdate mounted, - @Nullable String[] activeAnimations, - boolean isProp - ) { - this.type = type; - this.nameplate = nameplate; - this.entityUIComponents = entityUIComponents; - this.combatTextUpdate = combatTextUpdate; - this.model = model; - this.skin = skin; - this.item = item; - this.blockId = blockId; - this.entityScale = entityScale; - this.equipment = equipment; - this.entityStatUpdates = entityStatUpdates; - this.transform = transform; - this.movementStates = movementStates; - this.entityEffectUpdates = entityEffectUpdates; - this.interactions = interactions; - this.dynamicLight = dynamicLight; - this.hitboxCollisionConfigIndex = hitboxCollisionConfigIndex; - this.repulsionConfigIndex = repulsionConfigIndex; - this.predictionId = predictionId; - this.soundEventIds = soundEventIds; - this.interactionHint = interactionHint; - this.mounted = mounted; - this.activeAnimations = activeAnimations; - this.isProp = isProp; - } - - public ComponentUpdate(@Nonnull ComponentUpdate other) { - this.type = other.type; - this.nameplate = other.nameplate; - this.entityUIComponents = other.entityUIComponents; - this.combatTextUpdate = other.combatTextUpdate; - this.model = other.model; - this.skin = other.skin; - this.item = other.item; - this.blockId = other.blockId; - this.entityScale = other.entityScale; - this.equipment = other.equipment; - this.entityStatUpdates = other.entityStatUpdates; - this.transform = other.transform; - this.movementStates = other.movementStates; - this.entityEffectUpdates = other.entityEffectUpdates; - this.interactions = other.interactions; - this.dynamicLight = other.dynamicLight; - this.hitboxCollisionConfigIndex = other.hitboxCollisionConfigIndex; - this.repulsionConfigIndex = other.repulsionConfigIndex; - this.predictionId = other.predictionId; - this.soundEventIds = other.soundEventIds; - this.interactionHint = other.interactionHint; - this.mounted = other.mounted; - this.activeAnimations = other.activeAnimations; - this.isProp = other.isProp; - } +public abstract class ComponentUpdate { + public static final int MAX_SIZE = 1677721605; @Nonnull public static ComponentUpdate deserialize(@Nonnull ByteBuf buf, int offset) { - ComponentUpdate obj = new ComponentUpdate(); - byte[] nullBits = PacketIO.readBytes(buf, offset, 3); - obj.type = ComponentUpdateType.fromValue(buf.getByte(offset + 3)); - obj.blockId = buf.getIntLE(offset + 4); - obj.entityScale = buf.getFloatLE(offset + 8); - if ((nullBits[0] & 1) != 0) { - obj.transform = ModelTransform.deserialize(buf, offset + 12); - } + int typeId = VarInt.peek(buf, offset); + int typeIdLen = VarInt.length(buf, offset); - if ((nullBits[0] & 2) != 0) { - obj.movementStates = MovementStates.deserialize(buf, offset + 61); - } - - if ((nullBits[0] & 4) != 0) { - obj.dynamicLight = ColorLight.deserialize(buf, offset + 83); - } - - obj.hitboxCollisionConfigIndex = buf.getIntLE(offset + 87); - obj.repulsionConfigIndex = buf.getIntLE(offset + 91); - obj.predictionId = PacketIO.readUUID(buf, offset + 95); - if ((nullBits[0] & 8) != 0) { - obj.mounted = MountedUpdate.deserialize(buf, offset + 111); - } - - obj.isProp = buf.getByte(offset + 159) != 0; - if ((nullBits[0] & 16) != 0) { - int varPos0 = offset + 212 + buf.getIntLE(offset + 160); - obj.nameplate = Nameplate.deserialize(buf, varPos0); - } - - if ((nullBits[0] & 32) != 0) { - int varPos1 = offset + 212 + buf.getIntLE(offset + 164); - int entityUIComponentsCount = VarInt.peek(buf, varPos1); - if (entityUIComponentsCount < 0) { - throw ProtocolException.negativeLength("EntityUIComponents", entityUIComponentsCount); - } - - if (entityUIComponentsCount > 4096000) { - throw ProtocolException.arrayTooLong("EntityUIComponents", entityUIComponentsCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos1); - if (varPos1 + varIntLen + entityUIComponentsCount * 4L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("EntityUIComponents", varPos1 + varIntLen + entityUIComponentsCount * 4, buf.readableBytes()); - } - - obj.entityUIComponents = new int[entityUIComponentsCount]; - - for (int i = 0; i < entityUIComponentsCount; i++) { - obj.entityUIComponents[i] = buf.getIntLE(varPos1 + varIntLen + i * 4); - } - } - - if ((nullBits[0] & 64) != 0) { - int varPos2 = offset + 212 + buf.getIntLE(offset + 168); - obj.combatTextUpdate = CombatTextUpdate.deserialize(buf, varPos2); - } - - if ((nullBits[0] & 128) != 0) { - int varPos3 = offset + 212 + buf.getIntLE(offset + 172); - obj.model = Model.deserialize(buf, varPos3); - } - - if ((nullBits[1] & 1) != 0) { - int varPos4 = offset + 212 + buf.getIntLE(offset + 176); - obj.skin = PlayerSkin.deserialize(buf, varPos4); - } - - if ((nullBits[1] & 2) != 0) { - int varPos5 = offset + 212 + buf.getIntLE(offset + 180); - obj.item = ItemWithAllMetadata.deserialize(buf, varPos5); - } - - if ((nullBits[1] & 4) != 0) { - int varPos6 = offset + 212 + buf.getIntLE(offset + 184); - obj.equipment = Equipment.deserialize(buf, varPos6); - } - - if ((nullBits[1] & 8) != 0) { - int varPos7 = offset + 212 + buf.getIntLE(offset + 188); - int entityStatUpdatesCount = VarInt.peek(buf, varPos7); - if (entityStatUpdatesCount < 0) { - throw ProtocolException.negativeLength("EntityStatUpdates", entityStatUpdatesCount); - } - - if (entityStatUpdatesCount > 4096000) { - throw ProtocolException.dictionaryTooLarge("EntityStatUpdates", entityStatUpdatesCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos7); - obj.entityStatUpdates = new HashMap<>(entityStatUpdatesCount); - int dictPos = varPos7 + varIntLen; - - for (int i = 0; i < entityStatUpdatesCount; i++) { - int key = buf.getIntLE(dictPos); - dictPos += 4; - int valLen = VarInt.peek(buf, dictPos); - if (valLen < 0) { - throw ProtocolException.negativeLength("val", valLen); - } - - if (valLen > 64) { - throw ProtocolException.arrayTooLong("val", valLen, 64); - } - - int valVarLen = VarInt.length(buf, dictPos); - if (dictPos + valVarLen + valLen * 13L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("val", dictPos + valVarLen + valLen * 13, buf.readableBytes()); - } - - dictPos += valVarLen; - EntityStatUpdate[] val = new EntityStatUpdate[valLen]; - - for (int valIdx = 0; valIdx < valLen; valIdx++) { - val[valIdx] = EntityStatUpdate.deserialize(buf, dictPos); - dictPos += EntityStatUpdate.computeBytesConsumed(buf, dictPos); - } - - if (obj.entityStatUpdates.put(key, val) != null) { - throw ProtocolException.duplicateKey("entityStatUpdates", key); - } - } - } - - if ((nullBits[1] & 16) != 0) { - int varPos8 = offset + 212 + buf.getIntLE(offset + 192); - int entityEffectUpdatesCount = VarInt.peek(buf, varPos8); - if (entityEffectUpdatesCount < 0) { - throw ProtocolException.negativeLength("EntityEffectUpdates", entityEffectUpdatesCount); - } - - if (entityEffectUpdatesCount > 4096000) { - throw ProtocolException.arrayTooLong("EntityEffectUpdates", entityEffectUpdatesCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos8); - if (varPos8 + varIntLen + entityEffectUpdatesCount * 12L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("EntityEffectUpdates", varPos8 + varIntLen + entityEffectUpdatesCount * 12, buf.readableBytes()); - } - - obj.entityEffectUpdates = new EntityEffectUpdate[entityEffectUpdatesCount]; - int elemPos = varPos8 + varIntLen; - - for (int i = 0; i < entityEffectUpdatesCount; i++) { - obj.entityEffectUpdates[i] = EntityEffectUpdate.deserialize(buf, elemPos); - elemPos += EntityEffectUpdate.computeBytesConsumed(buf, elemPos); - } - } - - if ((nullBits[1] & 32) != 0) { - int varPos9 = offset + 212 + buf.getIntLE(offset + 196); - int interactionsCount = VarInt.peek(buf, varPos9); - if (interactionsCount < 0) { - throw ProtocolException.negativeLength("Interactions", interactionsCount); - } - - if (interactionsCount > 4096000) { - throw ProtocolException.dictionaryTooLarge("Interactions", interactionsCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos9); - obj.interactions = new HashMap<>(interactionsCount); - int dictPos = varPos9 + varIntLen; - - for (int i = 0; i < interactionsCount; i++) { - InteractionType keyx = InteractionType.fromValue(buf.getByte(dictPos)); - int val = buf.getIntLE(++dictPos); - dictPos += 4; - if (obj.interactions.put(keyx, val) != null) { - throw ProtocolException.duplicateKey("interactions", keyx); - } - } - } - - if ((nullBits[1] & 64) != 0) { - int varPos10 = offset + 212 + buf.getIntLE(offset + 200); - int soundEventIdsCount = VarInt.peek(buf, varPos10); - if (soundEventIdsCount < 0) { - throw ProtocolException.negativeLength("SoundEventIds", soundEventIdsCount); - } - - if (soundEventIdsCount > 4096000) { - throw ProtocolException.arrayTooLong("SoundEventIds", soundEventIdsCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos10); - if (varPos10 + varIntLen + soundEventIdsCount * 4L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("SoundEventIds", varPos10 + varIntLen + soundEventIdsCount * 4, buf.readableBytes()); - } - - obj.soundEventIds = new int[soundEventIdsCount]; - - for (int ix = 0; ix < soundEventIdsCount; ix++) { - obj.soundEventIds[ix] = buf.getIntLE(varPos10 + varIntLen + ix * 4); - } - } - - if ((nullBits[1] & 128) != 0) { - int varPos11 = offset + 212 + buf.getIntLE(offset + 204); - int interactionHintLen = VarInt.peek(buf, varPos11); - if (interactionHintLen < 0) { - throw ProtocolException.negativeLength("InteractionHint", interactionHintLen); - } - - if (interactionHintLen > 4096000) { - throw ProtocolException.stringTooLong("InteractionHint", interactionHintLen, 4096000); - } - - obj.interactionHint = PacketIO.readVarString(buf, varPos11, PacketIO.UTF8); - } - - if ((nullBits[2] & 1) != 0) { - int varPos12 = offset + 212 + buf.getIntLE(offset + 208); - int activeAnimationsCount = VarInt.peek(buf, varPos12); - if (activeAnimationsCount < 0) { - throw ProtocolException.negativeLength("ActiveAnimations", activeAnimationsCount); - } - - if (activeAnimationsCount > 4096000) { - throw ProtocolException.arrayTooLong("ActiveAnimations", activeAnimationsCount, 4096000); - } - - int varIntLen = VarInt.length(buf, varPos12); - int activeAnimationsBitfieldSize = (activeAnimationsCount + 7) / 8; - byte[] activeAnimationsBitfield = PacketIO.readBytes(buf, varPos12 + varIntLen, activeAnimationsBitfieldSize); - obj.activeAnimations = new String[activeAnimationsCount]; - int elemPos = varPos12 + varIntLen + activeAnimationsBitfieldSize; - - for (int ix = 0; ix < activeAnimationsCount; ix++) { - if ((activeAnimationsBitfield[ix / 8] & 1 << ix % 8) != 0) { - int strLen = VarInt.peek(buf, elemPos); - if (strLen < 0) { - throw ProtocolException.negativeLength("activeAnimations[" + ix + "]", strLen); - } - - if (strLen > 4096000) { - throw ProtocolException.stringTooLong("activeAnimations[" + ix + "]", strLen, 4096000); - } - - int strVarLen = VarInt.length(buf, elemPos); - obj.activeAnimations[ix] = PacketIO.readVarString(buf, elemPos); - elemPos += strVarLen + strLen; - } - } - } - - return obj; + return (ComponentUpdate)(switch (typeId) { + case 0 -> NameplateUpdate.deserialize(buf, offset + typeIdLen); + case 1 -> UIComponentsUpdate.deserialize(buf, offset + typeIdLen); + case 2 -> CombatTextUpdate.deserialize(buf, offset + typeIdLen); + case 3 -> ModelUpdate.deserialize(buf, offset + typeIdLen); + case 4 -> PlayerSkinUpdate.deserialize(buf, offset + typeIdLen); + case 5 -> ItemUpdate.deserialize(buf, offset + typeIdLen); + case 6 -> BlockUpdate.deserialize(buf, offset + typeIdLen); + case 7 -> EquipmentUpdate.deserialize(buf, offset + typeIdLen); + case 8 -> EntityStatsUpdate.deserialize(buf, offset + typeIdLen); + case 9 -> TransformUpdate.deserialize(buf, offset + typeIdLen); + case 10 -> MovementStatesUpdate.deserialize(buf, offset + typeIdLen); + case 11 -> EntityEffectsUpdate.deserialize(buf, offset + typeIdLen); + case 12 -> InteractionsUpdate.deserialize(buf, offset + typeIdLen); + case 13 -> DynamicLightUpdate.deserialize(buf, offset + typeIdLen); + case 14 -> InteractableUpdate.deserialize(buf, offset + typeIdLen); + case 15 -> IntangibleUpdate.deserialize(buf, offset + typeIdLen); + case 16 -> InvulnerableUpdate.deserialize(buf, offset + typeIdLen); + case 17 -> RespondToHitUpdate.deserialize(buf, offset + typeIdLen); + case 18 -> HitboxCollisionUpdate.deserialize(buf, offset + typeIdLen); + case 19 -> RepulsionUpdate.deserialize(buf, offset + typeIdLen); + case 20 -> PredictionUpdate.deserialize(buf, offset + typeIdLen); + case 21 -> AudioUpdate.deserialize(buf, offset + typeIdLen); + case 22 -> MountedUpdate.deserialize(buf, offset + typeIdLen); + case 23 -> NewSpawnUpdate.deserialize(buf, offset + typeIdLen); + case 24 -> ActiveAnimationsUpdate.deserialize(buf, offset + typeIdLen); + case 25 -> PropUpdate.deserialize(buf, offset + typeIdLen); + default -> throw ProtocolException.unknownPolymorphicType("ComponentUpdate", typeId); + }); } public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { - byte[] nullBits = PacketIO.readBytes(buf, offset, 3); - int maxEnd = 212; - if ((nullBits[0] & 16) != 0) { - int fieldOffset0 = buf.getIntLE(offset + 160); - int pos0 = offset + 212 + fieldOffset0; - pos0 += Nameplate.computeBytesConsumed(buf, pos0); - if (pos0 - offset > maxEnd) { - maxEnd = pos0 - offset; - } - } + int typeId = VarInt.peek(buf, offset); + int typeIdLen = VarInt.length(buf, offset); - if ((nullBits[0] & 32) != 0) { - int fieldOffset1 = buf.getIntLE(offset + 164); - int pos1 = offset + 212 + fieldOffset1; - int arrLen = VarInt.peek(buf, pos1); - pos1 += VarInt.length(buf, pos1) + arrLen * 4; - if (pos1 - offset > maxEnd) { - maxEnd = pos1 - offset; - } - } - - if ((nullBits[0] & 64) != 0) { - int fieldOffset2 = buf.getIntLE(offset + 168); - int pos2 = offset + 212 + fieldOffset2; - pos2 += CombatTextUpdate.computeBytesConsumed(buf, pos2); - if (pos2 - offset > maxEnd) { - maxEnd = pos2 - offset; - } - } - - if ((nullBits[0] & 128) != 0) { - int fieldOffset3 = buf.getIntLE(offset + 172); - int pos3 = offset + 212 + fieldOffset3; - pos3 += Model.computeBytesConsumed(buf, pos3); - if (pos3 - offset > maxEnd) { - maxEnd = pos3 - offset; - } - } - - if ((nullBits[1] & 1) != 0) { - int fieldOffset4 = buf.getIntLE(offset + 176); - int pos4 = offset + 212 + fieldOffset4; - pos4 += PlayerSkin.computeBytesConsumed(buf, pos4); - if (pos4 - offset > maxEnd) { - maxEnd = pos4 - offset; - } - } - - if ((nullBits[1] & 2) != 0) { - int fieldOffset5 = buf.getIntLE(offset + 180); - int pos5 = offset + 212 + fieldOffset5; - pos5 += ItemWithAllMetadata.computeBytesConsumed(buf, pos5); - if (pos5 - offset > maxEnd) { - maxEnd = pos5 - offset; - } - } - - if ((nullBits[1] & 4) != 0) { - int fieldOffset6 = buf.getIntLE(offset + 184); - int pos6 = offset + 212 + fieldOffset6; - pos6 += Equipment.computeBytesConsumed(buf, pos6); - if (pos6 - offset > maxEnd) { - maxEnd = pos6 - offset; - } - } - - if ((nullBits[1] & 8) != 0) { - int fieldOffset7 = buf.getIntLE(offset + 188); - int pos7 = offset + 212 + fieldOffset7; - int dictLen = VarInt.peek(buf, pos7); - pos7 += VarInt.length(buf, pos7); - - for (int i = 0; i < dictLen; i++) { - pos7 += 4; - int al = VarInt.peek(buf, pos7); - pos7 += VarInt.length(buf, pos7); - - for (int j = 0; j < al; j++) { - pos7 += EntityStatUpdate.computeBytesConsumed(buf, pos7); - } - } - - if (pos7 - offset > maxEnd) { - maxEnd = pos7 - offset; - } - } - - if ((nullBits[1] & 16) != 0) { - int fieldOffset8 = buf.getIntLE(offset + 192); - int pos8 = offset + 212 + fieldOffset8; - int arrLen = VarInt.peek(buf, pos8); - pos8 += VarInt.length(buf, pos8); - - for (int i = 0; i < arrLen; i++) { - pos8 += EntityEffectUpdate.computeBytesConsumed(buf, pos8); - } - - if (pos8 - offset > maxEnd) { - maxEnd = pos8 - offset; - } - } - - if ((nullBits[1] & 32) != 0) { - int fieldOffset9 = buf.getIntLE(offset + 196); - int pos9 = offset + 212 + fieldOffset9; - int dictLen = VarInt.peek(buf, pos9); - pos9 += VarInt.length(buf, pos9); - - for (int i = 0; i < dictLen; i++) { - pos9 = ++pos9 + 4; - } - - if (pos9 - offset > maxEnd) { - maxEnd = pos9 - offset; - } - } - - if ((nullBits[1] & 64) != 0) { - int fieldOffset10 = buf.getIntLE(offset + 200); - int pos10 = offset + 212 + fieldOffset10; - int arrLen = VarInt.peek(buf, pos10); - pos10 += VarInt.length(buf, pos10) + arrLen * 4; - if (pos10 - offset > maxEnd) { - maxEnd = pos10 - offset; - } - } - - if ((nullBits[1] & 128) != 0) { - int fieldOffset11 = buf.getIntLE(offset + 204); - int pos11 = offset + 212 + fieldOffset11; - int sl = VarInt.peek(buf, pos11); - pos11 += VarInt.length(buf, pos11) + sl; - if (pos11 - offset > maxEnd) { - maxEnd = pos11 - offset; - } - } - - if ((nullBits[2] & 1) != 0) { - int fieldOffset12 = buf.getIntLE(offset + 208); - int pos12 = offset + 212 + fieldOffset12; - int arrLen = VarInt.peek(buf, pos12); - pos12 += VarInt.length(buf, pos12); - int bitfieldSize = (arrLen + 7) / 8; - byte[] bitfield = PacketIO.readBytes(buf, pos12, bitfieldSize); - pos12 += bitfieldSize; - - for (int i = 0; i < arrLen; i++) { - if ((bitfield[i / 8] & 1 << i % 8) != 0) { - int sl = VarInt.peek(buf, pos12); - pos12 += VarInt.length(buf, pos12) + sl; - } - } - - if (pos12 - offset > maxEnd) { - maxEnd = pos12 - offset; - } - } - - return maxEnd; + return typeIdLen + switch (typeId) { + case 0 -> NameplateUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 1 -> UIComponentsUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 2 -> CombatTextUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 3 -> ModelUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 4 -> PlayerSkinUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 5 -> ItemUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 6 -> BlockUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 7 -> EquipmentUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 8 -> EntityStatsUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 9 -> TransformUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 10 -> MovementStatesUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 11 -> EntityEffectsUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 12 -> InteractionsUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 13 -> DynamicLightUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 14 -> InteractableUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 15 -> IntangibleUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 16 -> InvulnerableUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 17 -> RespondToHitUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 18 -> HitboxCollisionUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 19 -> RepulsionUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 20 -> PredictionUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 21 -> AudioUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 22 -> MountedUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 23 -> NewSpawnUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 24 -> ActiveAnimationsUpdate.computeBytesConsumed(buf, offset + typeIdLen); + case 25 -> PropUpdate.computeBytesConsumed(buf, offset + typeIdLen); + default -> throw ProtocolException.unknownPolymorphicType("ComponentUpdate", typeId); + }; } - public void serialize(@Nonnull ByteBuf buf) { + public int getTypeId() { + if (this instanceof NameplateUpdate sub) { + return 0; + } else if (this instanceof UIComponentsUpdate sub) { + return 1; + } else if (this instanceof CombatTextUpdate sub) { + return 2; + } else if (this instanceof ModelUpdate sub) { + return 3; + } else if (this instanceof PlayerSkinUpdate sub) { + return 4; + } else if (this instanceof ItemUpdate sub) { + return 5; + } else if (this instanceof BlockUpdate sub) { + return 6; + } else if (this instanceof EquipmentUpdate sub) { + return 7; + } else if (this instanceof EntityStatsUpdate sub) { + return 8; + } else if (this instanceof TransformUpdate sub) { + return 9; + } else if (this instanceof MovementStatesUpdate sub) { + return 10; + } else if (this instanceof EntityEffectsUpdate sub) { + return 11; + } else if (this instanceof InteractionsUpdate sub) { + return 12; + } else if (this instanceof DynamicLightUpdate sub) { + return 13; + } else if (this instanceof InteractableUpdate sub) { + return 14; + } else if (this instanceof IntangibleUpdate sub) { + return 15; + } else if (this instanceof InvulnerableUpdate sub) { + return 16; + } else if (this instanceof RespondToHitUpdate sub) { + return 17; + } else if (this instanceof HitboxCollisionUpdate sub) { + return 18; + } else if (this instanceof RepulsionUpdate sub) { + return 19; + } else if (this instanceof PredictionUpdate sub) { + return 20; + } else if (this instanceof AudioUpdate sub) { + return 21; + } else if (this instanceof MountedUpdate sub) { + return 22; + } else if (this instanceof NewSpawnUpdate sub) { + return 23; + } else if (this instanceof ActiveAnimationsUpdate sub) { + return 24; + } else if (this instanceof PropUpdate sub) { + return 25; + } else { + throw new IllegalStateException("Unknown subtype: " + this.getClass().getName()); + } + } + + public abstract int serialize(@Nonnull ByteBuf var1); + + public abstract int computeSize(); + + public int serializeWithTypeId(@Nonnull ByteBuf buf) { int startPos = buf.writerIndex(); - byte[] nullBits = new byte[3]; - if (this.transform != null) { - nullBits[0] = (byte)(nullBits[0] | 1); - } - - if (this.movementStates != null) { - nullBits[0] = (byte)(nullBits[0] | 2); - } - - if (this.dynamicLight != null) { - nullBits[0] = (byte)(nullBits[0] | 4); - } - - if (this.mounted != null) { - nullBits[0] = (byte)(nullBits[0] | 8); - } - - if (this.nameplate != null) { - nullBits[0] = (byte)(nullBits[0] | 16); - } - - if (this.entityUIComponents != null) { - nullBits[0] = (byte)(nullBits[0] | 32); - } - - if (this.combatTextUpdate != null) { - nullBits[0] = (byte)(nullBits[0] | 64); - } - - if (this.model != null) { - nullBits[0] = (byte)(nullBits[0] | 128); - } - - if (this.skin != null) { - nullBits[1] = (byte)(nullBits[1] | 1); - } - - if (this.item != null) { - nullBits[1] = (byte)(nullBits[1] | 2); - } - - if (this.equipment != null) { - nullBits[1] = (byte)(nullBits[1] | 4); - } - - if (this.entityStatUpdates != null) { - nullBits[1] = (byte)(nullBits[1] | 8); - } - - if (this.entityEffectUpdates != null) { - nullBits[1] = (byte)(nullBits[1] | 16); - } - - if (this.interactions != null) { - nullBits[1] = (byte)(nullBits[1] | 32); - } - - if (this.soundEventIds != null) { - nullBits[1] = (byte)(nullBits[1] | 64); - } - - if (this.interactionHint != null) { - nullBits[1] = (byte)(nullBits[1] | 128); - } - - if (this.activeAnimations != null) { - nullBits[2] = (byte)(nullBits[2] | 1); - } - - buf.writeBytes(nullBits); - buf.writeByte(this.type.getValue()); - buf.writeIntLE(this.blockId); - buf.writeFloatLE(this.entityScale); - if (this.transform != null) { - this.transform.serialize(buf); - } else { - buf.writeZero(49); - } - - if (this.movementStates != null) { - this.movementStates.serialize(buf); - } else { - buf.writeZero(22); - } - - if (this.dynamicLight != null) { - this.dynamicLight.serialize(buf); - } else { - buf.writeZero(4); - } - - buf.writeIntLE(this.hitboxCollisionConfigIndex); - buf.writeIntLE(this.repulsionConfigIndex); - PacketIO.writeUUID(buf, this.predictionId); - if (this.mounted != null) { - this.mounted.serialize(buf); - } else { - buf.writeZero(48); - } - - buf.writeByte(this.isProp ? 1 : 0); - int nameplateOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int entityUIComponentsOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int combatTextUpdateOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int modelOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int skinOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int itemOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int equipmentOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int entityStatUpdatesOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int entityEffectUpdatesOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int interactionsOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int soundEventIdsOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int interactionHintOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int activeAnimationsOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int varBlockStart = buf.writerIndex(); - if (this.nameplate != null) { - buf.setIntLE(nameplateOffsetSlot, buf.writerIndex() - varBlockStart); - this.nameplate.serialize(buf); - } else { - buf.setIntLE(nameplateOffsetSlot, -1); - } - - if (this.entityUIComponents != null) { - buf.setIntLE(entityUIComponentsOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.entityUIComponents.length > 4096000) { - throw ProtocolException.arrayTooLong("EntityUIComponents", this.entityUIComponents.length, 4096000); - } - - VarInt.write(buf, this.entityUIComponents.length); - - for (int item : this.entityUIComponents) { - buf.writeIntLE(item); - } - } else { - buf.setIntLE(entityUIComponentsOffsetSlot, -1); - } - - if (this.combatTextUpdate != null) { - buf.setIntLE(combatTextUpdateOffsetSlot, buf.writerIndex() - varBlockStart); - this.combatTextUpdate.serialize(buf); - } else { - buf.setIntLE(combatTextUpdateOffsetSlot, -1); - } - - if (this.model != null) { - buf.setIntLE(modelOffsetSlot, buf.writerIndex() - varBlockStart); - this.model.serialize(buf); - } else { - buf.setIntLE(modelOffsetSlot, -1); - } - - if (this.skin != null) { - buf.setIntLE(skinOffsetSlot, buf.writerIndex() - varBlockStart); - this.skin.serialize(buf); - } else { - buf.setIntLE(skinOffsetSlot, -1); - } - - if (this.item != null) { - buf.setIntLE(itemOffsetSlot, buf.writerIndex() - varBlockStart); - this.item.serialize(buf); - } else { - buf.setIntLE(itemOffsetSlot, -1); - } - - if (this.equipment != null) { - buf.setIntLE(equipmentOffsetSlot, buf.writerIndex() - varBlockStart); - this.equipment.serialize(buf); - } else { - buf.setIntLE(equipmentOffsetSlot, -1); - } - - if (this.entityStatUpdates != null) { - buf.setIntLE(entityStatUpdatesOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.entityStatUpdates.size() > 4096000) { - throw ProtocolException.dictionaryTooLarge("EntityStatUpdates", this.entityStatUpdates.size(), 4096000); - } - - VarInt.write(buf, this.entityStatUpdates.size()); - - for (Entry e : this.entityStatUpdates.entrySet()) { - buf.writeIntLE(e.getKey()); - VarInt.write(buf, e.getValue().length); - - for (EntityStatUpdate arrItem : e.getValue()) { - arrItem.serialize(buf); - } - } - } else { - buf.setIntLE(entityStatUpdatesOffsetSlot, -1); - } - - if (this.entityEffectUpdates != null) { - buf.setIntLE(entityEffectUpdatesOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.entityEffectUpdates.length > 4096000) { - throw ProtocolException.arrayTooLong("EntityEffectUpdates", this.entityEffectUpdates.length, 4096000); - } - - VarInt.write(buf, this.entityEffectUpdates.length); - - for (EntityEffectUpdate item : this.entityEffectUpdates) { - item.serialize(buf); - } - } else { - buf.setIntLE(entityEffectUpdatesOffsetSlot, -1); - } - - if (this.interactions != null) { - buf.setIntLE(interactionsOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.interactions.size() > 4096000) { - throw ProtocolException.dictionaryTooLarge("Interactions", this.interactions.size(), 4096000); - } - - VarInt.write(buf, this.interactions.size()); - - for (Entry e : this.interactions.entrySet()) { - buf.writeByte(e.getKey().getValue()); - buf.writeIntLE(e.getValue()); - } - } else { - buf.setIntLE(interactionsOffsetSlot, -1); - } - - if (this.soundEventIds != null) { - buf.setIntLE(soundEventIdsOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.soundEventIds.length > 4096000) { - throw ProtocolException.arrayTooLong("SoundEventIds", this.soundEventIds.length, 4096000); - } - - VarInt.write(buf, this.soundEventIds.length); - - for (int item : this.soundEventIds) { - buf.writeIntLE(item); - } - } else { - buf.setIntLE(soundEventIdsOffsetSlot, -1); - } - - if (this.interactionHint != null) { - buf.setIntLE(interactionHintOffsetSlot, buf.writerIndex() - varBlockStart); - PacketIO.writeVarString(buf, this.interactionHint, 4096000); - } else { - buf.setIntLE(interactionHintOffsetSlot, -1); - } - - if (this.activeAnimations != null) { - buf.setIntLE(activeAnimationsOffsetSlot, buf.writerIndex() - varBlockStart); - if (this.activeAnimations.length > 4096000) { - throw ProtocolException.arrayTooLong("ActiveAnimations", this.activeAnimations.length, 4096000); - } - - VarInt.write(buf, this.activeAnimations.length); - int activeAnimationsBitfieldSize = (this.activeAnimations.length + 7) / 8; - byte[] activeAnimationsBitfield = new byte[activeAnimationsBitfieldSize]; - - for (int i = 0; i < this.activeAnimations.length; i++) { - if (this.activeAnimations[i] != null) { - activeAnimationsBitfield[i / 8] = (byte)(activeAnimationsBitfield[i / 8] | (byte)(1 << i % 8)); - } - } - - buf.writeBytes(activeAnimationsBitfield); - - for (int ix = 0; ix < this.activeAnimations.length; ix++) { - if (this.activeAnimations[ix] != null) { - PacketIO.writeVarString(buf, this.activeAnimations[ix], 4096000); - } - } - } else { - buf.setIntLE(activeAnimationsOffsetSlot, -1); - } + VarInt.write(buf, this.getTypeId()); + this.serialize(buf); + return buf.writerIndex() - startPos; } - public int computeSize() { - int size = 212; - if (this.nameplate != null) { - size += this.nameplate.computeSize(); - } - - if (this.entityUIComponents != null) { - size += VarInt.size(this.entityUIComponents.length) + this.entityUIComponents.length * 4; - } - - if (this.combatTextUpdate != null) { - size += this.combatTextUpdate.computeSize(); - } - - if (this.model != null) { - size += this.model.computeSize(); - } - - if (this.skin != null) { - size += this.skin.computeSize(); - } - - if (this.item != null) { - size += this.item.computeSize(); - } - - if (this.equipment != null) { - size += this.equipment.computeSize(); - } - - if (this.entityStatUpdates != null) { - int entityStatUpdatesSize = 0; - - for (Entry kvp : this.entityStatUpdates.entrySet()) { - entityStatUpdatesSize += 4 + VarInt.size(kvp.getValue().length) + Arrays.stream(kvp.getValue()).mapToInt(inner -> inner.computeSize()).sum(); - } - - size += VarInt.size(this.entityStatUpdates.size()) + entityStatUpdatesSize; - } - - if (this.entityEffectUpdates != null) { - int entityEffectUpdatesSize = 0; - - for (EntityEffectUpdate elem : this.entityEffectUpdates) { - entityEffectUpdatesSize += elem.computeSize(); - } - - size += VarInt.size(this.entityEffectUpdates.length) + entityEffectUpdatesSize; - } - - if (this.interactions != null) { - size += VarInt.size(this.interactions.size()) + this.interactions.size() * 5; - } - - if (this.soundEventIds != null) { - size += VarInt.size(this.soundEventIds.length) + this.soundEventIds.length * 4; - } - - if (this.interactionHint != null) { - size += PacketIO.stringSize(this.interactionHint); - } - - if (this.activeAnimations != null) { - int activeAnimationsSize = 0; - - for (String elem : this.activeAnimations) { - if (elem != null) { - activeAnimationsSize += PacketIO.stringSize(elem); - } - } - - size += VarInt.size(this.activeAnimations.length) + (this.activeAnimations.length + 7) / 8 + activeAnimationsSize; - } - - return size; + public int computeSizeWithTypeId() { + return VarInt.size(this.getTypeId()) + this.computeSize(); } public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 212) { - return ValidationResult.error("Buffer too small: expected at least 212 bytes"); - } else { - byte[] nullBits = PacketIO.readBytes(buffer, offset, 3); - if ((nullBits[0] & 16) != 0) { - int nameplateOffset = buffer.getIntLE(offset + 160); - if (nameplateOffset < 0) { - return ValidationResult.error("Invalid offset for Nameplate"); - } - - int pos = offset + 212 + nameplateOffset; - if (pos >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Nameplate"); - } - - ValidationResult nameplateResult = Nameplate.validateStructure(buffer, pos); - if (!nameplateResult.isValid()) { - return ValidationResult.error("Invalid Nameplate: " + nameplateResult.error()); - } - - pos += Nameplate.computeBytesConsumed(buffer, pos); - } - - if ((nullBits[0] & 32) != 0) { - int entityUIComponentsOffset = buffer.getIntLE(offset + 164); - if (entityUIComponentsOffset < 0) { - return ValidationResult.error("Invalid offset for EntityUIComponents"); - } - - int posx = offset + 212 + entityUIComponentsOffset; - if (posx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for EntityUIComponents"); - } - - int entityUIComponentsCount = VarInt.peek(buffer, posx); - if (entityUIComponentsCount < 0) { - return ValidationResult.error("Invalid array count for EntityUIComponents"); - } - - if (entityUIComponentsCount > 4096000) { - return ValidationResult.error("EntityUIComponents exceeds max length 4096000"); - } - - posx += VarInt.length(buffer, posx); - posx += entityUIComponentsCount * 4; - if (posx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading EntityUIComponents"); - } - } - - if ((nullBits[0] & 64) != 0) { - int combatTextUpdateOffset = buffer.getIntLE(offset + 168); - if (combatTextUpdateOffset < 0) { - return ValidationResult.error("Invalid offset for CombatTextUpdate"); - } - - int posxx = offset + 212 + combatTextUpdateOffset; - if (posxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for CombatTextUpdate"); - } - - ValidationResult combatTextUpdateResult = CombatTextUpdate.validateStructure(buffer, posxx); - if (!combatTextUpdateResult.isValid()) { - return ValidationResult.error("Invalid CombatTextUpdate: " + combatTextUpdateResult.error()); - } - - posxx += CombatTextUpdate.computeBytesConsumed(buffer, posxx); - } - - if ((nullBits[0] & 128) != 0) { - int modelOffset = buffer.getIntLE(offset + 172); - if (modelOffset < 0) { - return ValidationResult.error("Invalid offset for Model"); - } - - int posxxx = offset + 212 + modelOffset; - if (posxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Model"); - } - - ValidationResult modelResult = Model.validateStructure(buffer, posxxx); - if (!modelResult.isValid()) { - return ValidationResult.error("Invalid Model: " + modelResult.error()); - } - - posxxx += Model.computeBytesConsumed(buffer, posxxx); - } - - if ((nullBits[1] & 1) != 0) { - int skinOffset = buffer.getIntLE(offset + 176); - if (skinOffset < 0) { - return ValidationResult.error("Invalid offset for Skin"); - } - - int posxxxx = offset + 212 + skinOffset; - if (posxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Skin"); - } - - ValidationResult skinResult = PlayerSkin.validateStructure(buffer, posxxxx); - if (!skinResult.isValid()) { - return ValidationResult.error("Invalid Skin: " + skinResult.error()); - } - - posxxxx += PlayerSkin.computeBytesConsumed(buffer, posxxxx); - } - - if ((nullBits[1] & 2) != 0) { - int itemOffset = buffer.getIntLE(offset + 180); - if (itemOffset < 0) { - return ValidationResult.error("Invalid offset for Item"); - } - - int posxxxxx = offset + 212 + itemOffset; - if (posxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Item"); - } - - ValidationResult itemResult = ItemWithAllMetadata.validateStructure(buffer, posxxxxx); - if (!itemResult.isValid()) { - return ValidationResult.error("Invalid Item: " + itemResult.error()); - } - - posxxxxx += ItemWithAllMetadata.computeBytesConsumed(buffer, posxxxxx); - } - - if ((nullBits[1] & 4) != 0) { - int equipmentOffset = buffer.getIntLE(offset + 184); - if (equipmentOffset < 0) { - return ValidationResult.error("Invalid offset for Equipment"); - } - - int posxxxxxx = offset + 212 + equipmentOffset; - if (posxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Equipment"); - } - - ValidationResult equipmentResult = Equipment.validateStructure(buffer, posxxxxxx); - if (!equipmentResult.isValid()) { - return ValidationResult.error("Invalid Equipment: " + equipmentResult.error()); - } - - posxxxxxx += Equipment.computeBytesConsumed(buffer, posxxxxxx); - } - - if ((nullBits[1] & 8) != 0) { - int entityStatUpdatesOffset = buffer.getIntLE(offset + 188); - if (entityStatUpdatesOffset < 0) { - return ValidationResult.error("Invalid offset for EntityStatUpdates"); - } - - int posxxxxxxx = offset + 212 + entityStatUpdatesOffset; - if (posxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for EntityStatUpdates"); - } - - int entityStatUpdatesCount = VarInt.peek(buffer, posxxxxxxx); - if (entityStatUpdatesCount < 0) { - return ValidationResult.error("Invalid dictionary count for EntityStatUpdates"); - } - - if (entityStatUpdatesCount > 4096000) { - return ValidationResult.error("EntityStatUpdates exceeds max length 4096000"); - } - - posxxxxxxx += VarInt.length(buffer, posxxxxxxx); - - for (int i = 0; i < entityStatUpdatesCount; i++) { - posxxxxxxx += 4; - if (posxxxxxxx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading key"); - } - - int valueArrCount = VarInt.peek(buffer, posxxxxxxx); - if (valueArrCount < 0) { - return ValidationResult.error("Invalid array count for value"); - } - - posxxxxxxx += VarInt.length(buffer, posxxxxxxx); - - for (int valueArrIdx = 0; valueArrIdx < valueArrCount; valueArrIdx++) { - posxxxxxxx += EntityStatUpdate.computeBytesConsumed(buffer, posxxxxxxx); - } - } - } - - if ((nullBits[1] & 16) != 0) { - int entityEffectUpdatesOffset = buffer.getIntLE(offset + 192); - if (entityEffectUpdatesOffset < 0) { - return ValidationResult.error("Invalid offset for EntityEffectUpdates"); - } - - int posxxxxxxxx = offset + 212 + entityEffectUpdatesOffset; - if (posxxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for EntityEffectUpdates"); - } - - int entityEffectUpdatesCount = VarInt.peek(buffer, posxxxxxxxx); - if (entityEffectUpdatesCount < 0) { - return ValidationResult.error("Invalid array count for EntityEffectUpdates"); - } - - if (entityEffectUpdatesCount > 4096000) { - return ValidationResult.error("EntityEffectUpdates exceeds max length 4096000"); - } - - posxxxxxxxx += VarInt.length(buffer, posxxxxxxxx); - - for (int i = 0; i < entityEffectUpdatesCount; i++) { - ValidationResult structResult = EntityEffectUpdate.validateStructure(buffer, posxxxxxxxx); - if (!structResult.isValid()) { - return ValidationResult.error("Invalid EntityEffectUpdate in EntityEffectUpdates[" + i + "]: " + structResult.error()); - } - - posxxxxxxxx += EntityEffectUpdate.computeBytesConsumed(buffer, posxxxxxxxx); - } - } - - if ((nullBits[1] & 32) != 0) { - int interactionsOffset = buffer.getIntLE(offset + 196); - if (interactionsOffset < 0) { - return ValidationResult.error("Invalid offset for Interactions"); - } - - int posxxxxxxxxx = offset + 212 + interactionsOffset; - if (posxxxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Interactions"); - } - - int interactionsCount = VarInt.peek(buffer, posxxxxxxxxx); - if (interactionsCount < 0) { - return ValidationResult.error("Invalid dictionary count for Interactions"); - } - - if (interactionsCount > 4096000) { - return ValidationResult.error("Interactions exceeds max length 4096000"); - } - - posxxxxxxxxx += VarInt.length(buffer, posxxxxxxxxx); - - for (int i = 0; i < interactionsCount; i++) { - posxxxxxxxxx = ++posxxxxxxxxx + 4; - if (posxxxxxxxxx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading value"); - } - } - } - - if ((nullBits[1] & 64) != 0) { - int soundEventIdsOffset = buffer.getIntLE(offset + 200); - if (soundEventIdsOffset < 0) { - return ValidationResult.error("Invalid offset for SoundEventIds"); - } - - int posxxxxxxxxxx = offset + 212 + soundEventIdsOffset; - if (posxxxxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for SoundEventIds"); - } - - int soundEventIdsCount = VarInt.peek(buffer, posxxxxxxxxxx); - if (soundEventIdsCount < 0) { - return ValidationResult.error("Invalid array count for SoundEventIds"); - } - - if (soundEventIdsCount > 4096000) { - return ValidationResult.error("SoundEventIds exceeds max length 4096000"); - } - - posxxxxxxxxxx += VarInt.length(buffer, posxxxxxxxxxx); - posxxxxxxxxxx += soundEventIdsCount * 4; - if (posxxxxxxxxxx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading SoundEventIds"); - } - } - - if ((nullBits[1] & 128) != 0) { - int interactionHintOffset = buffer.getIntLE(offset + 204); - if (interactionHintOffset < 0) { - return ValidationResult.error("Invalid offset for InteractionHint"); - } - - int posxxxxxxxxxxx = offset + 212 + interactionHintOffset; - if (posxxxxxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for InteractionHint"); - } - - int interactionHintLen = VarInt.peek(buffer, posxxxxxxxxxxx); - if (interactionHintLen < 0) { - return ValidationResult.error("Invalid string length for InteractionHint"); - } - - if (interactionHintLen > 4096000) { - return ValidationResult.error("InteractionHint exceeds max length 4096000"); - } - - posxxxxxxxxxxx += VarInt.length(buffer, posxxxxxxxxxxx); - posxxxxxxxxxxx += interactionHintLen; - if (posxxxxxxxxxxx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading InteractionHint"); - } - } - - if ((nullBits[2] & 1) != 0) { - int activeAnimationsOffset = buffer.getIntLE(offset + 208); - if (activeAnimationsOffset < 0) { - return ValidationResult.error("Invalid offset for ActiveAnimations"); - } - - int posxxxxxxxxxxxx = offset + 212 + activeAnimationsOffset; - if (posxxxxxxxxxxxx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for ActiveAnimations"); - } - - int activeAnimationsCount = VarInt.peek(buffer, posxxxxxxxxxxxx); - if (activeAnimationsCount < 0) { - return ValidationResult.error("Invalid array count for ActiveAnimations"); - } - - if (activeAnimationsCount > 4096000) { - return ValidationResult.error("ActiveAnimations exceeds max length 4096000"); - } - - posxxxxxxxxxxxx += VarInt.length(buffer, posxxxxxxxxxxxx); - - for (int ix = 0; ix < activeAnimationsCount; ix++) { - int strLen = VarInt.peek(buffer, posxxxxxxxxxxxx); - if (strLen < 0) { - return ValidationResult.error("Invalid string length in ActiveAnimations"); - } - - posxxxxxxxxxxxx += VarInt.length(buffer, posxxxxxxxxxxxx); - posxxxxxxxxxxxx += strLen; - if (posxxxxxxxxxxxx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading string in ActiveAnimations"); - } - } - } - - return ValidationResult.OK; - } - } - - public ComponentUpdate clone() { - ComponentUpdate copy = new ComponentUpdate(); - copy.type = this.type; - copy.nameplate = this.nameplate != null ? this.nameplate.clone() : null; - copy.entityUIComponents = this.entityUIComponents != null ? Arrays.copyOf(this.entityUIComponents, this.entityUIComponents.length) : null; - copy.combatTextUpdate = this.combatTextUpdate != null ? this.combatTextUpdate.clone() : null; - copy.model = this.model != null ? this.model.clone() : null; - copy.skin = this.skin != null ? this.skin.clone() : null; - copy.item = this.item != null ? this.item.clone() : null; - copy.blockId = this.blockId; - copy.entityScale = this.entityScale; - copy.equipment = this.equipment != null ? this.equipment.clone() : null; - if (this.entityStatUpdates != null) { - Map m = new HashMap<>(); - - for (Entry e : this.entityStatUpdates.entrySet()) { - m.put(e.getKey(), Arrays.stream(e.getValue()).map(x -> x.clone()).toArray(EntityStatUpdate[]::new)); - } - - copy.entityStatUpdates = m; - } - - copy.transform = this.transform != null ? this.transform.clone() : null; - copy.movementStates = this.movementStates != null ? this.movementStates.clone() : null; - copy.entityEffectUpdates = this.entityEffectUpdates != null - ? Arrays.stream(this.entityEffectUpdates).map(ex -> ex.clone()).toArray(EntityEffectUpdate[]::new) - : null; - copy.interactions = this.interactions != null ? new HashMap<>(this.interactions) : null; - copy.dynamicLight = this.dynamicLight != null ? this.dynamicLight.clone() : null; - copy.hitboxCollisionConfigIndex = this.hitboxCollisionConfigIndex; - copy.repulsionConfigIndex = this.repulsionConfigIndex; - copy.predictionId = this.predictionId; - copy.soundEventIds = this.soundEventIds != null ? Arrays.copyOf(this.soundEventIds, this.soundEventIds.length) : null; - copy.interactionHint = this.interactionHint; - copy.mounted = this.mounted != null ? this.mounted.clone() : null; - copy.activeAnimations = this.activeAnimations != null ? Arrays.copyOf(this.activeAnimations, this.activeAnimations.length) : null; - copy.isProp = this.isProp; - return copy; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else { - return !(obj instanceof ComponentUpdate other) - ? false - : Objects.equals(this.type, other.type) - && Objects.equals(this.nameplate, other.nameplate) - && Arrays.equals(this.entityUIComponents, other.entityUIComponents) - && Objects.equals(this.combatTextUpdate, other.combatTextUpdate) - && Objects.equals(this.model, other.model) - && Objects.equals(this.skin, other.skin) - && Objects.equals(this.item, other.item) - && this.blockId == other.blockId - && this.entityScale == other.entityScale - && Objects.equals(this.equipment, other.equipment) - && Objects.equals(this.entityStatUpdates, other.entityStatUpdates) - && Objects.equals(this.transform, other.transform) - && Objects.equals(this.movementStates, other.movementStates) - && Arrays.equals((Object[])this.entityEffectUpdates, (Object[])other.entityEffectUpdates) - && Objects.equals(this.interactions, other.interactions) - && Objects.equals(this.dynamicLight, other.dynamicLight) - && this.hitboxCollisionConfigIndex == other.hitboxCollisionConfigIndex - && this.repulsionConfigIndex == other.repulsionConfigIndex - && Objects.equals(this.predictionId, other.predictionId) - && Arrays.equals(this.soundEventIds, other.soundEventIds) - && Objects.equals(this.interactionHint, other.interactionHint) - && Objects.equals(this.mounted, other.mounted) - && Arrays.equals((Object[])this.activeAnimations, (Object[])other.activeAnimations) - && this.isProp == other.isProp; - } - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + Objects.hashCode(this.type); - result = 31 * result + Objects.hashCode(this.nameplate); - result = 31 * result + Arrays.hashCode(this.entityUIComponents); - result = 31 * result + Objects.hashCode(this.combatTextUpdate); - result = 31 * result + Objects.hashCode(this.model); - result = 31 * result + Objects.hashCode(this.skin); - result = 31 * result + Objects.hashCode(this.item); - result = 31 * result + Integer.hashCode(this.blockId); - result = 31 * result + Float.hashCode(this.entityScale); - result = 31 * result + Objects.hashCode(this.equipment); - result = 31 * result + Objects.hashCode(this.entityStatUpdates); - result = 31 * result + Objects.hashCode(this.transform); - result = 31 * result + Objects.hashCode(this.movementStates); - result = 31 * result + Arrays.hashCode((Object[])this.entityEffectUpdates); - result = 31 * result + Objects.hashCode(this.interactions); - result = 31 * result + Objects.hashCode(this.dynamicLight); - result = 31 * result + Integer.hashCode(this.hitboxCollisionConfigIndex); - result = 31 * result + Integer.hashCode(this.repulsionConfigIndex); - result = 31 * result + Objects.hashCode(this.predictionId); - result = 31 * result + Arrays.hashCode(this.soundEventIds); - result = 31 * result + Objects.hashCode(this.interactionHint); - result = 31 * result + Objects.hashCode(this.mounted); - result = 31 * result + Arrays.hashCode((Object[])this.activeAnimations); - return 31 * result + Boolean.hashCode(this.isProp); + int typeId = VarInt.peek(buffer, offset); + int typeIdLen = VarInt.length(buffer, offset); + + return switch (typeId) { + case 0 -> NameplateUpdate.validateStructure(buffer, offset + typeIdLen); + case 1 -> UIComponentsUpdate.validateStructure(buffer, offset + typeIdLen); + case 2 -> CombatTextUpdate.validateStructure(buffer, offset + typeIdLen); + case 3 -> ModelUpdate.validateStructure(buffer, offset + typeIdLen); + case 4 -> PlayerSkinUpdate.validateStructure(buffer, offset + typeIdLen); + case 5 -> ItemUpdate.validateStructure(buffer, offset + typeIdLen); + case 6 -> BlockUpdate.validateStructure(buffer, offset + typeIdLen); + case 7 -> EquipmentUpdate.validateStructure(buffer, offset + typeIdLen); + case 8 -> EntityStatsUpdate.validateStructure(buffer, offset + typeIdLen); + case 9 -> TransformUpdate.validateStructure(buffer, offset + typeIdLen); + case 10 -> MovementStatesUpdate.validateStructure(buffer, offset + typeIdLen); + case 11 -> EntityEffectsUpdate.validateStructure(buffer, offset + typeIdLen); + case 12 -> InteractionsUpdate.validateStructure(buffer, offset + typeIdLen); + case 13 -> DynamicLightUpdate.validateStructure(buffer, offset + typeIdLen); + case 14 -> InteractableUpdate.validateStructure(buffer, offset + typeIdLen); + case 15 -> IntangibleUpdate.validateStructure(buffer, offset + typeIdLen); + case 16 -> InvulnerableUpdate.validateStructure(buffer, offset + typeIdLen); + case 17 -> RespondToHitUpdate.validateStructure(buffer, offset + typeIdLen); + case 18 -> HitboxCollisionUpdate.validateStructure(buffer, offset + typeIdLen); + case 19 -> RepulsionUpdate.validateStructure(buffer, offset + typeIdLen); + case 20 -> PredictionUpdate.validateStructure(buffer, offset + typeIdLen); + case 21 -> AudioUpdate.validateStructure(buffer, offset + typeIdLen); + case 22 -> MountedUpdate.validateStructure(buffer, offset + typeIdLen); + case 23 -> NewSpawnUpdate.validateStructure(buffer, offset + typeIdLen); + case 24 -> ActiveAnimationsUpdate.validateStructure(buffer, offset + typeIdLen); + case 25 -> PropUpdate.validateStructure(buffer, offset + typeIdLen); + default -> ValidationResult.error("Unknown polymorphic type ID " + typeId + " for ComponentUpdate"); + }; } } diff --git a/src/com/hypixel/hytale/protocol/DynamicLightUpdate.java b/src/com/hypixel/hytale/protocol/DynamicLightUpdate.java new file mode 100644 index 00000000..dad76a9d --- /dev/null +++ b/src/com/hypixel/hytale/protocol/DynamicLightUpdate.java @@ -0,0 +1,74 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class DynamicLightUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 4; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 4; + public static final int MAX_SIZE = 4; + @Nonnull + public ColorLight dynamicLight = new ColorLight(); + + public DynamicLightUpdate() { + } + + public DynamicLightUpdate(@Nonnull ColorLight dynamicLight) { + this.dynamicLight = dynamicLight; + } + + public DynamicLightUpdate(@Nonnull DynamicLightUpdate other) { + this.dynamicLight = other.dynamicLight; + } + + @Nonnull + public static DynamicLightUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + DynamicLightUpdate obj = new DynamicLightUpdate(); + obj.dynamicLight = ColorLight.deserialize(buf, offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 4; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + this.dynamicLight.serialize(buf); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 4; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 4 ? ValidationResult.error("Buffer too small: expected at least 4 bytes") : ValidationResult.OK; + } + + public DynamicLightUpdate clone() { + DynamicLightUpdate copy = new DynamicLightUpdate(); + copy.dynamicLight = this.dynamicLight.clone(); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof DynamicLightUpdate other ? Objects.equals(this.dynamicLight, other.dynamicLight) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.dynamicLight); + } +} diff --git a/src/com/hypixel/hytale/protocol/EntityEffectsUpdate.java b/src/com/hypixel/hytale/protocol/EntityEffectsUpdate.java new file mode 100644 index 00000000..9cb51e13 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/EntityEffectsUpdate.java @@ -0,0 +1,144 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import javax.annotation.Nonnull; + +public class EntityEffectsUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 1677721600; + @Nonnull + public EntityEffectUpdate[] entityEffectUpdates = new EntityEffectUpdate[0]; + + public EntityEffectsUpdate() { + } + + public EntityEffectsUpdate(@Nonnull EntityEffectUpdate[] entityEffectUpdates) { + this.entityEffectUpdates = entityEffectUpdates; + } + + public EntityEffectsUpdate(@Nonnull EntityEffectsUpdate other) { + this.entityEffectUpdates = other.entityEffectUpdates; + } + + @Nonnull + public static EntityEffectsUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + EntityEffectsUpdate obj = new EntityEffectsUpdate(); + int pos = offset + 0; + int entityEffectUpdatesCount = VarInt.peek(buf, pos); + if (entityEffectUpdatesCount < 0) { + throw ProtocolException.negativeLength("EntityEffectUpdates", entityEffectUpdatesCount); + } else if (entityEffectUpdatesCount > 4096000) { + throw ProtocolException.arrayTooLong("EntityEffectUpdates", entityEffectUpdatesCount, 4096000); + } else { + int entityEffectUpdatesVarLen = VarInt.size(entityEffectUpdatesCount); + if (pos + entityEffectUpdatesVarLen + entityEffectUpdatesCount * 12L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("EntityEffectUpdates", pos + entityEffectUpdatesVarLen + entityEffectUpdatesCount * 12, buf.readableBytes()); + } else { + pos += entityEffectUpdatesVarLen; + obj.entityEffectUpdates = new EntityEffectUpdate[entityEffectUpdatesCount]; + + for (int i = 0; i < entityEffectUpdatesCount; i++) { + obj.entityEffectUpdates[i] = EntityEffectUpdate.deserialize(buf, pos); + pos += EntityEffectUpdate.computeBytesConsumed(buf, pos); + } + + return obj; + } + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int arrLen = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos); + + for (int i = 0; i < arrLen; i++) { + pos += EntityEffectUpdate.computeBytesConsumed(buf, pos); + } + + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + if (this.entityEffectUpdates.length > 4096000) { + throw ProtocolException.arrayTooLong("EntityEffectUpdates", this.entityEffectUpdates.length, 4096000); + } else { + VarInt.write(buf, this.entityEffectUpdates.length); + + for (EntityEffectUpdate item : this.entityEffectUpdates) { + item.serialize(buf); + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 0; + int entityEffectUpdatesSize = 0; + + for (EntityEffectUpdate elem : this.entityEffectUpdates) { + entityEffectUpdatesSize += elem.computeSize(); + } + + return size + VarInt.size(this.entityEffectUpdates.length) + entityEffectUpdatesSize; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int entityEffectUpdatesCount = VarInt.peek(buffer, pos); + if (entityEffectUpdatesCount < 0) { + return ValidationResult.error("Invalid array count for EntityEffectUpdates"); + } else if (entityEffectUpdatesCount > 4096000) { + return ValidationResult.error("EntityEffectUpdates exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + + for (int i = 0; i < entityEffectUpdatesCount; i++) { + ValidationResult structResult = EntityEffectUpdate.validateStructure(buffer, pos); + if (!structResult.isValid()) { + return ValidationResult.error("Invalid EntityEffectUpdate in EntityEffectUpdates[" + i + "]: " + structResult.error()); + } + + pos += EntityEffectUpdate.computeBytesConsumed(buffer, pos); + } + + return ValidationResult.OK; + } + } + } + + public EntityEffectsUpdate clone() { + EntityEffectsUpdate copy = new EntityEffectsUpdate(); + copy.entityEffectUpdates = Arrays.stream(this.entityEffectUpdates).map(e -> e.clone()).toArray(EntityEffectUpdate[]::new); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof EntityEffectsUpdate other ? Arrays.equals((Object[])this.entityEffectUpdates, (Object[])other.entityEffectUpdates) : false; + } + } + + @Override + public int hashCode() { + int result = 1; + return 31 * result + Arrays.hashCode((Object[])this.entityEffectUpdates); + } +} diff --git a/src/com/hypixel/hytale/protocol/EntityStatsUpdate.java b/src/com/hypixel/hytale/protocol/EntityStatsUpdate.java new file mode 100644 index 00000000..1a762299 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/EntityStatsUpdate.java @@ -0,0 +1,193 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Map.Entry; +import javax.annotation.Nonnull; + +public class EntityStatsUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 1677721600; + @Nonnull + public Map entityStatUpdates = new HashMap<>(); + + public EntityStatsUpdate() { + } + + public EntityStatsUpdate(@Nonnull Map entityStatUpdates) { + this.entityStatUpdates = entityStatUpdates; + } + + public EntityStatsUpdate(@Nonnull EntityStatsUpdate other) { + this.entityStatUpdates = other.entityStatUpdates; + } + + @Nonnull + public static EntityStatsUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + EntityStatsUpdate obj = new EntityStatsUpdate(); + int pos = offset + 0; + int entityStatUpdatesCount = VarInt.peek(buf, pos); + if (entityStatUpdatesCount < 0) { + throw ProtocolException.negativeLength("EntityStatUpdates", entityStatUpdatesCount); + } else if (entityStatUpdatesCount > 4096000) { + throw ProtocolException.dictionaryTooLarge("EntityStatUpdates", entityStatUpdatesCount, 4096000); + } else { + pos += VarInt.size(entityStatUpdatesCount); + obj.entityStatUpdates = new HashMap<>(entityStatUpdatesCount); + + for (int i = 0; i < entityStatUpdatesCount; i++) { + int key = buf.getIntLE(pos); + pos += 4; + int valLen = VarInt.peek(buf, pos); + if (valLen < 0) { + throw ProtocolException.negativeLength("val", valLen); + } + + if (valLen > 64) { + throw ProtocolException.arrayTooLong("val", valLen, 64); + } + + int valVarLen = VarInt.length(buf, pos); + if (pos + valVarLen + valLen * 13L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("val", pos + valVarLen + valLen * 13, buf.readableBytes()); + } + + pos += valVarLen; + EntityStatUpdate[] val = new EntityStatUpdate[valLen]; + + for (int valIdx = 0; valIdx < valLen; valIdx++) { + val[valIdx] = EntityStatUpdate.deserialize(buf, pos); + pos += EntityStatUpdate.computeBytesConsumed(buf, pos); + } + + if (obj.entityStatUpdates.put(key, val) != null) { + throw ProtocolException.duplicateKey("entityStatUpdates", key); + } + } + + return obj; + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int dictLen = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos); + + for (int i = 0; i < dictLen; i++) { + pos += 4; + int al = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos); + + for (int j = 0; j < al; j++) { + pos += EntityStatUpdate.computeBytesConsumed(buf, pos); + } + } + + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + if (this.entityStatUpdates.size() > 4096000) { + throw ProtocolException.dictionaryTooLarge("EntityStatUpdates", this.entityStatUpdates.size(), 4096000); + } else { + VarInt.write(buf, this.entityStatUpdates.size()); + + for (Entry e : this.entityStatUpdates.entrySet()) { + buf.writeIntLE(e.getKey()); + VarInt.write(buf, e.getValue().length); + + for (EntityStatUpdate arrItem : e.getValue()) { + arrItem.serialize(buf); + } + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 0; + int entityStatUpdatesSize = 0; + + for (Entry kvp : this.entityStatUpdates.entrySet()) { + entityStatUpdatesSize += 4 + VarInt.size(kvp.getValue().length) + Arrays.stream(kvp.getValue()).mapToInt(inner -> inner.computeSize()).sum(); + } + + return size + VarInt.size(this.entityStatUpdates.size()) + entityStatUpdatesSize; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int entityStatUpdatesCount = VarInt.peek(buffer, pos); + if (entityStatUpdatesCount < 0) { + return ValidationResult.error("Invalid dictionary count for EntityStatUpdates"); + } else if (entityStatUpdatesCount > 4096000) { + return ValidationResult.error("EntityStatUpdates exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + + for (int i = 0; i < entityStatUpdatesCount; i++) { + pos += 4; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading key"); + } + + int valueArrCount = VarInt.peek(buffer, pos); + if (valueArrCount < 0) { + return ValidationResult.error("Invalid array count for value"); + } + + pos += VarInt.length(buffer, pos); + + for (int valueArrIdx = 0; valueArrIdx < valueArrCount; valueArrIdx++) { + pos += EntityStatUpdate.computeBytesConsumed(buffer, pos); + } + } + + return ValidationResult.OK; + } + } + } + + public EntityStatsUpdate clone() { + EntityStatsUpdate copy = new EntityStatsUpdate(); + Map m = new HashMap<>(); + + for (Entry e : this.entityStatUpdates.entrySet()) { + m.put(e.getKey(), Arrays.stream(e.getValue()).map(x -> x.clone()).toArray(EntityStatUpdate[]::new)); + } + + copy.entityStatUpdates = m; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof EntityStatsUpdate other ? Objects.equals(this.entityStatUpdates, other.entityStatUpdates) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.entityStatUpdates); + } +} diff --git a/src/com/hypixel/hytale/protocol/EntityUpdate.java b/src/com/hypixel/hytale/protocol/EntityUpdate.java index 541dbf04..a9fbd756 100644 --- a/src/com/hypixel/hytale/protocol/EntityUpdate.java +++ b/src/com/hypixel/hytale/protocol/EntityUpdate.java @@ -77,8 +77,8 @@ public class EntityUpdate { } int varIntLen = VarInt.length(buf, varPos1); - if (varPos1 + varIntLen + updatesCount * 160L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall("Updates", varPos1 + varIntLen + updatesCount * 160, buf.readableBytes()); + if (varPos1 + varIntLen + updatesCount * 1L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("Updates", varPos1 + varIntLen + updatesCount * 1, buf.readableBytes()); } obj.updates = new ComponentUpdate[updatesCount]; @@ -166,7 +166,7 @@ public class EntityUpdate { VarInt.write(buf, this.updates.length); for (ComponentUpdate item : this.updates) { - item.serialize(buf); + item.serializeWithTypeId(buf); } } else { buf.setIntLE(updatesOffsetSlot, -1); @@ -183,7 +183,7 @@ public class EntityUpdate { int updatesSize = 0; for (ComponentUpdate elem : this.updates) { - updatesSize += elem.computeSize(); + updatesSize += elem.computeSizeWithTypeId(); } size += VarInt.size(this.updates.length) + updatesSize; @@ -264,7 +264,7 @@ public class EntityUpdate { EntityUpdate copy = new EntityUpdate(); copy.networkId = this.networkId; copy.removed = this.removed != null ? Arrays.copyOf(this.removed, this.removed.length) : null; - copy.updates = this.updates != null ? Arrays.stream(this.updates).map(e -> e.clone()).toArray(ComponentUpdate[]::new) : null; + copy.updates = this.updates != null ? Arrays.copyOf(this.updates, this.updates.length) : null; return copy; } diff --git a/src/com/hypixel/hytale/protocol/Equipment.java b/src/com/hypixel/hytale/protocol/EquipmentUpdate.java similarity index 94% rename from src/com/hypixel/hytale/protocol/Equipment.java rename to src/com/hypixel/hytale/protocol/EquipmentUpdate.java index cfd76d8d..6b2763aa 100644 --- a/src/com/hypixel/hytale/protocol/Equipment.java +++ b/src/com/hypixel/hytale/protocol/EquipmentUpdate.java @@ -10,7 +10,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Equipment { +public class EquipmentUpdate extends ComponentUpdate { public static final int NULLABLE_BIT_FIELD_SIZE = 1; public static final int FIXED_BLOCK_SIZE = 1; public static final int VARIABLE_FIELD_COUNT = 3; @@ -23,24 +23,24 @@ public class Equipment { @Nullable public String leftHandItemId; - public Equipment() { + public EquipmentUpdate() { } - public Equipment(@Nullable String[] armorIds, @Nullable String rightHandItemId, @Nullable String leftHandItemId) { + public EquipmentUpdate(@Nullable String[] armorIds, @Nullable String rightHandItemId, @Nullable String leftHandItemId) { this.armorIds = armorIds; this.rightHandItemId = rightHandItemId; this.leftHandItemId = leftHandItemId; } - public Equipment(@Nonnull Equipment other) { + public EquipmentUpdate(@Nonnull EquipmentUpdate other) { this.armorIds = other.armorIds; this.rightHandItemId = other.rightHandItemId; this.leftHandItemId = other.leftHandItemId; } @Nonnull - public static Equipment deserialize(@Nonnull ByteBuf buf, int offset) { - Equipment obj = new Equipment(); + public static EquipmentUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + EquipmentUpdate obj = new EquipmentUpdate(); byte nullBits = buf.getByte(offset); if ((nullBits & 1) != 0) { int varPos0 = offset + 13 + buf.getIntLE(offset + 1); @@ -150,7 +150,8 @@ public class Equipment { return maxEnd; } - public void serialize(@Nonnull ByteBuf buf) { + @Override + public int serialize(@Nonnull ByteBuf buf) { int startPos = buf.writerIndex(); byte nullBits = 0; if (this.armorIds != null) { @@ -201,8 +202,11 @@ public class Equipment { } else { buf.setIntLE(leftHandItemIdOffsetSlot, -1); } + + return buf.writerIndex() - startPos; } + @Override public int computeSize() { int size = 13; if (this.armorIds != null) { @@ -325,8 +329,8 @@ public class Equipment { } } - public Equipment clone() { - Equipment copy = new Equipment(); + public EquipmentUpdate clone() { + EquipmentUpdate copy = new EquipmentUpdate(); copy.armorIds = this.armorIds != null ? Arrays.copyOf(this.armorIds, this.armorIds.length) : null; copy.rightHandItemId = this.rightHandItemId; copy.leftHandItemId = this.leftHandItemId; @@ -338,7 +342,7 @@ public class Equipment { if (this == obj) { return true; } else { - return !(obj instanceof Equipment other) + return !(obj instanceof EquipmentUpdate other) ? false : Arrays.equals((Object[])this.armorIds, (Object[])other.armorIds) && Objects.equals(this.rightHandItemId, other.rightHandItemId) diff --git a/src/com/hypixel/hytale/protocol/HitboxCollisionUpdate.java b/src/com/hypixel/hytale/protocol/HitboxCollisionUpdate.java new file mode 100644 index 00000000..afd4cc40 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/HitboxCollisionUpdate.java @@ -0,0 +1,73 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class HitboxCollisionUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 4; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 4; + public static final int MAX_SIZE = 4; + public int hitboxCollisionConfigIndex; + + public HitboxCollisionUpdate() { + } + + public HitboxCollisionUpdate(int hitboxCollisionConfigIndex) { + this.hitboxCollisionConfigIndex = hitboxCollisionConfigIndex; + } + + public HitboxCollisionUpdate(@Nonnull HitboxCollisionUpdate other) { + this.hitboxCollisionConfigIndex = other.hitboxCollisionConfigIndex; + } + + @Nonnull + public static HitboxCollisionUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + HitboxCollisionUpdate obj = new HitboxCollisionUpdate(); + obj.hitboxCollisionConfigIndex = buf.getIntLE(offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 4; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + buf.writeIntLE(this.hitboxCollisionConfigIndex); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 4; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 4 ? ValidationResult.error("Buffer too small: expected at least 4 bytes") : ValidationResult.OK; + } + + public HitboxCollisionUpdate clone() { + HitboxCollisionUpdate copy = new HitboxCollisionUpdate(); + copy.hitboxCollisionConfigIndex = this.hitboxCollisionConfigIndex; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof HitboxCollisionUpdate other ? this.hitboxCollisionConfigIndex == other.hitboxCollisionConfigIndex : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.hitboxCollisionConfigIndex); + } +} diff --git a/src/com/hypixel/hytale/protocol/IntangibleUpdate.java b/src/com/hypixel/hytale/protocol/IntangibleUpdate.java new file mode 100644 index 00000000..a8a40ddb --- /dev/null +++ b/src/com/hypixel/hytale/protocol/IntangibleUpdate.java @@ -0,0 +1,51 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import javax.annotation.Nonnull; + +public class IntangibleUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 0; + + @Nonnull + public static IntangibleUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + return new IntangibleUpdate(); + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 0; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 0; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 0 ? ValidationResult.error("Buffer too small: expected at least 0 bytes") : ValidationResult.OK; + } + + public IntangibleUpdate clone() { + return new IntangibleUpdate(); + } + + @Override + public boolean equals(Object obj) { + return this == obj ? true : obj instanceof IntangibleUpdate other; + } + + @Override + public int hashCode() { + return 0; + } +} diff --git a/src/com/hypixel/hytale/protocol/Nameplate.java b/src/com/hypixel/hytale/protocol/InteractableUpdate.java similarity index 51% rename from src/com/hypixel/hytale/protocol/Nameplate.java rename to src/com/hypixel/hytale/protocol/InteractableUpdate.java index 1055645e..bc9f101f 100644 --- a/src/com/hypixel/hytale/protocol/Nameplate.java +++ b/src/com/hypixel/hytale/protocol/InteractableUpdate.java @@ -9,44 +9,44 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Nameplate { +public class InteractableUpdate extends ComponentUpdate { public static final int NULLABLE_BIT_FIELD_SIZE = 1; public static final int FIXED_BLOCK_SIZE = 1; public static final int VARIABLE_FIELD_COUNT = 1; public static final int VARIABLE_BLOCK_START = 1; public static final int MAX_SIZE = 16384006; @Nullable - public String text; + public String interactionHint; - public Nameplate() { + public InteractableUpdate() { } - public Nameplate(@Nullable String text) { - this.text = text; + public InteractableUpdate(@Nullable String interactionHint) { + this.interactionHint = interactionHint; } - public Nameplate(@Nonnull Nameplate other) { - this.text = other.text; + public InteractableUpdate(@Nonnull InteractableUpdate other) { + this.interactionHint = other.interactionHint; } @Nonnull - public static Nameplate deserialize(@Nonnull ByteBuf buf, int offset) { - Nameplate obj = new Nameplate(); + public static InteractableUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + InteractableUpdate obj = new InteractableUpdate(); byte nullBits = buf.getByte(offset); int pos = offset + 1; if ((nullBits & 1) != 0) { - int textLen = VarInt.peek(buf, pos); - if (textLen < 0) { - throw ProtocolException.negativeLength("Text", textLen); + int interactionHintLen = VarInt.peek(buf, pos); + if (interactionHintLen < 0) { + throw ProtocolException.negativeLength("InteractionHint", interactionHintLen); } - if (textLen > 4096000) { - throw ProtocolException.stringTooLong("Text", textLen, 4096000); + if (interactionHintLen > 4096000) { + throw ProtocolException.stringTooLong("InteractionHint", interactionHintLen, 4096000); } - int textVarLen = VarInt.length(buf, pos); - obj.text = PacketIO.readVarString(buf, pos, PacketIO.UTF8); - pos += textVarLen + textLen; + int interactionHintVarLen = VarInt.length(buf, pos); + obj.interactionHint = PacketIO.readVarString(buf, pos, PacketIO.UTF8); + pos += interactionHintVarLen + interactionHintLen; } return obj; @@ -63,22 +63,27 @@ public class Nameplate { return pos - offset; } - public void serialize(@Nonnull ByteBuf buf) { + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); byte nullBits = 0; - if (this.text != null) { + if (this.interactionHint != null) { nullBits = (byte)(nullBits | 1); } buf.writeByte(nullBits); - if (this.text != null) { - PacketIO.writeVarString(buf, this.text, 4096000); + if (this.interactionHint != null) { + PacketIO.writeVarString(buf, this.interactionHint, 4096000); } + + return buf.writerIndex() - startPos; } + @Override public int computeSize() { int size = 1; - if (this.text != null) { - size += PacketIO.stringSize(this.text); + if (this.interactionHint != null) { + size += PacketIO.stringSize(this.interactionHint); } return size; @@ -91,19 +96,19 @@ public class Nameplate { byte nullBits = buffer.getByte(offset); int pos = offset + 1; if ((nullBits & 1) != 0) { - int textLen = VarInt.peek(buffer, pos); - if (textLen < 0) { - return ValidationResult.error("Invalid string length for Text"); + int interactionHintLen = VarInt.peek(buffer, pos); + if (interactionHintLen < 0) { + return ValidationResult.error("Invalid string length for InteractionHint"); } - if (textLen > 4096000) { - return ValidationResult.error("Text exceeds max length 4096000"); + if (interactionHintLen > 4096000) { + return ValidationResult.error("InteractionHint exceeds max length 4096000"); } pos += VarInt.length(buffer, pos); - pos += textLen; + pos += interactionHintLen; if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Text"); + return ValidationResult.error("Buffer overflow reading InteractionHint"); } } @@ -111,9 +116,9 @@ public class Nameplate { } } - public Nameplate clone() { - Nameplate copy = new Nameplate(); - copy.text = this.text; + public InteractableUpdate clone() { + InteractableUpdate copy = new InteractableUpdate(); + copy.interactionHint = this.interactionHint; return copy; } @@ -122,12 +127,12 @@ public class Nameplate { if (this == obj) { return true; } else { - return obj instanceof Nameplate other ? Objects.equals(this.text, other.text) : false; + return obj instanceof InteractableUpdate other ? Objects.equals(this.interactionHint, other.interactionHint) : false; } } @Override public int hashCode() { - return Objects.hash(this.text); + return Objects.hash(this.interactionHint); } } diff --git a/src/com/hypixel/hytale/protocol/InteractionsUpdate.java b/src/com/hypixel/hytale/protocol/InteractionsUpdate.java new file mode 100644 index 00000000..e4b1ff8c --- /dev/null +++ b/src/com/hypixel/hytale/protocol/InteractionsUpdate.java @@ -0,0 +1,241 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.PacketIO; +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Map.Entry; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class InteractionsUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 1; + public static final int FIXED_BLOCK_SIZE = 1; + public static final int VARIABLE_FIELD_COUNT = 2; + public static final int VARIABLE_BLOCK_START = 9; + public static final int MAX_SIZE = 36864019; + @Nonnull + public Map interactions = new HashMap<>(); + @Nullable + public String interactionHint; + + public InteractionsUpdate() { + } + + public InteractionsUpdate(@Nonnull Map interactions, @Nullable String interactionHint) { + this.interactions = interactions; + this.interactionHint = interactionHint; + } + + public InteractionsUpdate(@Nonnull InteractionsUpdate other) { + this.interactions = other.interactions; + this.interactionHint = other.interactionHint; + } + + @Nonnull + public static InteractionsUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + InteractionsUpdate obj = new InteractionsUpdate(); + byte nullBits = buf.getByte(offset); + int varPos0 = offset + 9 + buf.getIntLE(offset + 1); + int interactionsCount = VarInt.peek(buf, varPos0); + if (interactionsCount < 0) { + throw ProtocolException.negativeLength("Interactions", interactionsCount); + } else if (interactionsCount > 4096000) { + throw ProtocolException.dictionaryTooLarge("Interactions", interactionsCount, 4096000); + } else { + int varIntLen = VarInt.length(buf, varPos0); + obj.interactions = new HashMap<>(interactionsCount); + int dictPos = varPos0 + varIntLen; + + for (int i = 0; i < interactionsCount; i++) { + InteractionType key = InteractionType.fromValue(buf.getByte(dictPos)); + int val = buf.getIntLE(++dictPos); + dictPos += 4; + if (obj.interactions.put(key, val) != null) { + throw ProtocolException.duplicateKey("interactions", key); + } + } + + if ((nullBits & 1) != 0) { + varPos0 = offset + 9 + buf.getIntLE(offset + 5); + interactionsCount = VarInt.peek(buf, varPos0); + if (interactionsCount < 0) { + throw ProtocolException.negativeLength("InteractionHint", interactionsCount); + } + + if (interactionsCount > 4096000) { + throw ProtocolException.stringTooLong("InteractionHint", interactionsCount, 4096000); + } + + obj.interactionHint = PacketIO.readVarString(buf, varPos0, PacketIO.UTF8); + } + + return obj; + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + byte nullBits = buf.getByte(offset); + int maxEnd = 9; + int fieldOffset0 = buf.getIntLE(offset + 1); + int pos0 = offset + 9 + fieldOffset0; + int dictLen = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0); + + for (int i = 0; i < dictLen; i++) { + pos0 = ++pos0 + 4; + } + + if (pos0 - offset > maxEnd) { + maxEnd = pos0 - offset; + } + + if ((nullBits & 1) != 0) { + fieldOffset0 = buf.getIntLE(offset + 5); + pos0 = offset + 9 + fieldOffset0; + dictLen = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0) + dictLen; + if (pos0 - offset > maxEnd) { + maxEnd = pos0 - offset; + } + } + + return maxEnd; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + byte nullBits = 0; + if (this.interactionHint != null) { + nullBits = (byte)(nullBits | 1); + } + + buf.writeByte(nullBits); + int interactionsOffsetSlot = buf.writerIndex(); + buf.writeIntLE(0); + int interactionHintOffsetSlot = buf.writerIndex(); + buf.writeIntLE(0); + int varBlockStart = buf.writerIndex(); + buf.setIntLE(interactionsOffsetSlot, buf.writerIndex() - varBlockStart); + if (this.interactions.size() > 4096000) { + throw ProtocolException.dictionaryTooLarge("Interactions", this.interactions.size(), 4096000); + } else { + VarInt.write(buf, this.interactions.size()); + + for (Entry e : this.interactions.entrySet()) { + buf.writeByte(e.getKey().getValue()); + buf.writeIntLE(e.getValue()); + } + + if (this.interactionHint != null) { + buf.setIntLE(interactionHintOffsetSlot, buf.writerIndex() - varBlockStart); + PacketIO.writeVarString(buf, this.interactionHint, 4096000); + } else { + buf.setIntLE(interactionHintOffsetSlot, -1); + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 9; + size += VarInt.size(this.interactions.size()) + this.interactions.size() * 5; + if (this.interactionHint != null) { + size += PacketIO.stringSize(this.interactionHint); + } + + return size; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 9) { + return ValidationResult.error("Buffer too small: expected at least 9 bytes"); + } else { + byte nullBits = buffer.getByte(offset); + int interactionsOffset = buffer.getIntLE(offset + 1); + if (interactionsOffset < 0) { + return ValidationResult.error("Invalid offset for Interactions"); + } else { + int pos = offset + 9 + interactionsOffset; + if (pos >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for Interactions"); + } else { + int interactionsCount = VarInt.peek(buffer, pos); + if (interactionsCount < 0) { + return ValidationResult.error("Invalid dictionary count for Interactions"); + } else if (interactionsCount > 4096000) { + return ValidationResult.error("Interactions exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + + for (int i = 0; i < interactionsCount; i++) { + pos = ++pos + 4; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading value"); + } + } + + if ((nullBits & 1) != 0) { + interactionsOffset = buffer.getIntLE(offset + 5); + if (interactionsOffset < 0) { + return ValidationResult.error("Invalid offset for InteractionHint"); + } + + pos = offset + 9 + interactionsOffset; + if (pos >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for InteractionHint"); + } + + interactionsCount = VarInt.peek(buffer, pos); + if (interactionsCount < 0) { + return ValidationResult.error("Invalid string length for InteractionHint"); + } + + if (interactionsCount > 4096000) { + return ValidationResult.error("InteractionHint exceeds max length 4096000"); + } + + pos += VarInt.length(buffer, pos); + pos += interactionsCount; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading InteractionHint"); + } + } + + return ValidationResult.OK; + } + } + } + } + } + + public InteractionsUpdate clone() { + InteractionsUpdate copy = new InteractionsUpdate(); + copy.interactions = new HashMap<>(this.interactions); + copy.interactionHint = this.interactionHint; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return !(obj instanceof InteractionsUpdate other) + ? false + : Objects.equals(this.interactions, other.interactions) && Objects.equals(this.interactionHint, other.interactionHint); + } + } + + @Override + public int hashCode() { + return Objects.hash(this.interactions, this.interactionHint); + } +} diff --git a/src/com/hypixel/hytale/protocol/InvulnerableUpdate.java b/src/com/hypixel/hytale/protocol/InvulnerableUpdate.java new file mode 100644 index 00000000..d09e52e1 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/InvulnerableUpdate.java @@ -0,0 +1,51 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import javax.annotation.Nonnull; + +public class InvulnerableUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 0; + + @Nonnull + public static InvulnerableUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + return new InvulnerableUpdate(); + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 0; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 0; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 0 ? ValidationResult.error("Buffer too small: expected at least 0 bytes") : ValidationResult.OK; + } + + public InvulnerableUpdate clone() { + return new InvulnerableUpdate(); + } + + @Override + public boolean equals(Object obj) { + return this == obj ? true : obj instanceof InvulnerableUpdate other; + } + + @Override + public int hashCode() { + return 0; + } +} diff --git a/src/com/hypixel/hytale/protocol/ItemUpdate.java b/src/com/hypixel/hytale/protocol/ItemUpdate.java new file mode 100644 index 00000000..4367e454 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/ItemUpdate.java @@ -0,0 +1,96 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class ItemUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 4; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 4; + public static final int MAX_SIZE = 32768044; + @Nonnull + public ItemWithAllMetadata item = new ItemWithAllMetadata(); + public float entityScale; + + public ItemUpdate() { + } + + public ItemUpdate(@Nonnull ItemWithAllMetadata item, float entityScale) { + this.item = item; + this.entityScale = entityScale; + } + + public ItemUpdate(@Nonnull ItemUpdate other) { + this.item = other.item; + this.entityScale = other.entityScale; + } + + @Nonnull + public static ItemUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + ItemUpdate obj = new ItemUpdate(); + obj.entityScale = buf.getFloatLE(offset + 0); + int pos = offset + 4; + obj.item = ItemWithAllMetadata.deserialize(buf, pos); + pos += ItemWithAllMetadata.computeBytesConsumed(buf, pos); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 4; + pos += ItemWithAllMetadata.computeBytesConsumed(buf, pos); + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + buf.writeFloatLE(this.entityScale); + this.item.serialize(buf); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + int size = 4; + return size + this.item.computeSize(); + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 4) { + return ValidationResult.error("Buffer too small: expected at least 4 bytes"); + } else { + int pos = offset + 4; + ValidationResult itemResult = ItemWithAllMetadata.validateStructure(buffer, pos); + if (!itemResult.isValid()) { + return ValidationResult.error("Invalid Item: " + itemResult.error()); + } else { + pos += ItemWithAllMetadata.computeBytesConsumed(buffer, pos); + return ValidationResult.OK; + } + } + } + + public ItemUpdate clone() { + ItemUpdate copy = new ItemUpdate(); + copy.item = this.item.clone(); + copy.entityScale = this.entityScale; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return !(obj instanceof ItemUpdate other) ? false : Objects.equals(this.item, other.item) && this.entityScale == other.entityScale; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.item, this.entityScale); + } +} diff --git a/src/com/hypixel/hytale/protocol/Model.java b/src/com/hypixel/hytale/protocol/Model.java index c84a02d8..09270fd6 100644 --- a/src/com/hypixel/hytale/protocol/Model.java +++ b/src/com/hypixel/hytale/protocol/Model.java @@ -15,9 +15,9 @@ import javax.annotation.Nullable; public class Model { public static final int NULLABLE_BIT_FIELD_SIZE = 2; - public static final int FIXED_BLOCK_SIZE = 43; + public static final int FIXED_BLOCK_SIZE = 51; public static final int VARIABLE_FIELD_COUNT = 12; - public static final int VARIABLE_BLOCK_START = 91; + public static final int VARIABLE_BLOCK_START = 99; public static final int MAX_SIZE = 1677721600; @Nullable public String assetId; @@ -34,6 +34,8 @@ public class Model { public float scale; public float eyeHeight; public float crouchOffset; + public float sittingOffset; + public float sleepingOffset; @Nullable public Map animationSets; @Nullable @@ -66,6 +68,8 @@ public class Model { float scale, float eyeHeight, float crouchOffset, + float sittingOffset, + float sleepingOffset, @Nullable Map animationSets, @Nullable ModelAttachment[] attachments, @Nullable Hitbox hitbox, @@ -85,6 +89,8 @@ public class Model { this.scale = scale; this.eyeHeight = eyeHeight; this.crouchOffset = crouchOffset; + this.sittingOffset = sittingOffset; + this.sleepingOffset = sleepingOffset; this.animationSets = animationSets; this.attachments = attachments; this.hitbox = hitbox; @@ -106,6 +112,8 @@ public class Model { this.scale = other.scale; this.eyeHeight = other.eyeHeight; this.crouchOffset = other.crouchOffset; + this.sittingOffset = other.sittingOffset; + this.sleepingOffset = other.sleepingOffset; this.animationSets = other.animationSets; this.attachments = other.attachments; this.hitbox = other.hitbox; @@ -124,17 +132,19 @@ public class Model { obj.scale = buf.getFloatLE(offset + 2); obj.eyeHeight = buf.getFloatLE(offset + 6); obj.crouchOffset = buf.getFloatLE(offset + 10); + obj.sittingOffset = buf.getFloatLE(offset + 14); + obj.sleepingOffset = buf.getFloatLE(offset + 18); if ((nullBits[0] & 1) != 0) { - obj.hitbox = Hitbox.deserialize(buf, offset + 14); + obj.hitbox = Hitbox.deserialize(buf, offset + 22); } if ((nullBits[0] & 2) != 0) { - obj.light = ColorLight.deserialize(buf, offset + 38); + obj.light = ColorLight.deserialize(buf, offset + 46); } - obj.phobia = Phobia.fromValue(buf.getByte(offset + 42)); + obj.phobia = Phobia.fromValue(buf.getByte(offset + 50)); if ((nullBits[0] & 4) != 0) { - int varPos0 = offset + 91 + buf.getIntLE(offset + 43); + int varPos0 = offset + 99 + buf.getIntLE(offset + 51); int assetIdLen = VarInt.peek(buf, varPos0); if (assetIdLen < 0) { throw ProtocolException.negativeLength("AssetId", assetIdLen); @@ -148,7 +158,7 @@ public class Model { } if ((nullBits[0] & 8) != 0) { - int varPos1 = offset + 91 + buf.getIntLE(offset + 47); + int varPos1 = offset + 99 + buf.getIntLE(offset + 55); int pathLen = VarInt.peek(buf, varPos1); if (pathLen < 0) { throw ProtocolException.negativeLength("Path", pathLen); @@ -162,7 +172,7 @@ public class Model { } if ((nullBits[0] & 16) != 0) { - int varPos2 = offset + 91 + buf.getIntLE(offset + 51); + int varPos2 = offset + 99 + buf.getIntLE(offset + 59); int textureLen = VarInt.peek(buf, varPos2); if (textureLen < 0) { throw ProtocolException.negativeLength("Texture", textureLen); @@ -176,7 +186,7 @@ public class Model { } if ((nullBits[0] & 32) != 0) { - int varPos3 = offset + 91 + buf.getIntLE(offset + 55); + int varPos3 = offset + 99 + buf.getIntLE(offset + 63); int gradientSetLen = VarInt.peek(buf, varPos3); if (gradientSetLen < 0) { throw ProtocolException.negativeLength("GradientSet", gradientSetLen); @@ -190,7 +200,7 @@ public class Model { } if ((nullBits[0] & 64) != 0) { - int varPos4 = offset + 91 + buf.getIntLE(offset + 59); + int varPos4 = offset + 99 + buf.getIntLE(offset + 67); int gradientIdLen = VarInt.peek(buf, varPos4); if (gradientIdLen < 0) { throw ProtocolException.negativeLength("GradientId", gradientIdLen); @@ -204,12 +214,12 @@ public class Model { } if ((nullBits[0] & 128) != 0) { - int varPos5 = offset + 91 + buf.getIntLE(offset + 63); + int varPos5 = offset + 99 + buf.getIntLE(offset + 71); obj.camera = CameraSettings.deserialize(buf, varPos5); } if ((nullBits[1] & 1) != 0) { - int varPos6 = offset + 91 + buf.getIntLE(offset + 67); + int varPos6 = offset + 99 + buf.getIntLE(offset + 75); int animationSetsCount = VarInt.peek(buf, varPos6); if (animationSetsCount < 0) { throw ProtocolException.negativeLength("AnimationSets", animationSetsCount); @@ -245,7 +255,7 @@ public class Model { } if ((nullBits[1] & 2) != 0) { - int varPos7 = offset + 91 + buf.getIntLE(offset + 71); + int varPos7 = offset + 99 + buf.getIntLE(offset + 79); int attachmentsCount = VarInt.peek(buf, varPos7); if (attachmentsCount < 0) { throw ProtocolException.negativeLength("Attachments", attachmentsCount); @@ -270,7 +280,7 @@ public class Model { } if ((nullBits[1] & 4) != 0) { - int varPos8 = offset + 91 + buf.getIntLE(offset + 75); + int varPos8 = offset + 99 + buf.getIntLE(offset + 83); int particlesCount = VarInt.peek(buf, varPos8); if (particlesCount < 0) { throw ProtocolException.negativeLength("Particles", particlesCount); @@ -295,7 +305,7 @@ public class Model { } if ((nullBits[1] & 8) != 0) { - int varPos9 = offset + 91 + buf.getIntLE(offset + 79); + int varPos9 = offset + 99 + buf.getIntLE(offset + 87); int trailsCount = VarInt.peek(buf, varPos9); if (trailsCount < 0) { throw ProtocolException.negativeLength("Trails", trailsCount); @@ -320,7 +330,7 @@ public class Model { } if ((nullBits[1] & 16) != 0) { - int varPos10 = offset + 91 + buf.getIntLE(offset + 83); + int varPos10 = offset + 99 + buf.getIntLE(offset + 91); int detailBoxesCount = VarInt.peek(buf, varPos10); if (detailBoxesCount < 0) { throw ProtocolException.negativeLength("DetailBoxes", detailBoxesCount); @@ -376,7 +386,7 @@ public class Model { } if ((nullBits[1] & 32) != 0) { - int varPos11 = offset + 91 + buf.getIntLE(offset + 87); + int varPos11 = offset + 99 + buf.getIntLE(offset + 95); obj.phobiaModel = deserialize(buf, varPos11); } @@ -385,10 +395,10 @@ public class Model { public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { byte[] nullBits = PacketIO.readBytes(buf, offset, 2); - int maxEnd = 91; + int maxEnd = 99; if ((nullBits[0] & 4) != 0) { - int fieldOffset0 = buf.getIntLE(offset + 43); - int pos0 = offset + 91 + fieldOffset0; + int fieldOffset0 = buf.getIntLE(offset + 51); + int pos0 = offset + 99 + fieldOffset0; int sl = VarInt.peek(buf, pos0); pos0 += VarInt.length(buf, pos0) + sl; if (pos0 - offset > maxEnd) { @@ -397,8 +407,8 @@ public class Model { } if ((nullBits[0] & 8) != 0) { - int fieldOffset1 = buf.getIntLE(offset + 47); - int pos1 = offset + 91 + fieldOffset1; + int fieldOffset1 = buf.getIntLE(offset + 55); + int pos1 = offset + 99 + fieldOffset1; int sl = VarInt.peek(buf, pos1); pos1 += VarInt.length(buf, pos1) + sl; if (pos1 - offset > maxEnd) { @@ -407,8 +417,8 @@ public class Model { } if ((nullBits[0] & 16) != 0) { - int fieldOffset2 = buf.getIntLE(offset + 51); - int pos2 = offset + 91 + fieldOffset2; + int fieldOffset2 = buf.getIntLE(offset + 59); + int pos2 = offset + 99 + fieldOffset2; int sl = VarInt.peek(buf, pos2); pos2 += VarInt.length(buf, pos2) + sl; if (pos2 - offset > maxEnd) { @@ -417,8 +427,8 @@ public class Model { } if ((nullBits[0] & 32) != 0) { - int fieldOffset3 = buf.getIntLE(offset + 55); - int pos3 = offset + 91 + fieldOffset3; + int fieldOffset3 = buf.getIntLE(offset + 63); + int pos3 = offset + 99 + fieldOffset3; int sl = VarInt.peek(buf, pos3); pos3 += VarInt.length(buf, pos3) + sl; if (pos3 - offset > maxEnd) { @@ -427,8 +437,8 @@ public class Model { } if ((nullBits[0] & 64) != 0) { - int fieldOffset4 = buf.getIntLE(offset + 59); - int pos4 = offset + 91 + fieldOffset4; + int fieldOffset4 = buf.getIntLE(offset + 67); + int pos4 = offset + 99 + fieldOffset4; int sl = VarInt.peek(buf, pos4); pos4 += VarInt.length(buf, pos4) + sl; if (pos4 - offset > maxEnd) { @@ -437,8 +447,8 @@ public class Model { } if ((nullBits[0] & 128) != 0) { - int fieldOffset5 = buf.getIntLE(offset + 63); - int pos5 = offset + 91 + fieldOffset5; + int fieldOffset5 = buf.getIntLE(offset + 71); + int pos5 = offset + 99 + fieldOffset5; pos5 += CameraSettings.computeBytesConsumed(buf, pos5); if (pos5 - offset > maxEnd) { maxEnd = pos5 - offset; @@ -446,8 +456,8 @@ public class Model { } if ((nullBits[1] & 1) != 0) { - int fieldOffset6 = buf.getIntLE(offset + 67); - int pos6 = offset + 91 + fieldOffset6; + int fieldOffset6 = buf.getIntLE(offset + 75); + int pos6 = offset + 99 + fieldOffset6; int dictLen = VarInt.peek(buf, pos6); pos6 += VarInt.length(buf, pos6); @@ -463,8 +473,8 @@ public class Model { } if ((nullBits[1] & 2) != 0) { - int fieldOffset7 = buf.getIntLE(offset + 71); - int pos7 = offset + 91 + fieldOffset7; + int fieldOffset7 = buf.getIntLE(offset + 79); + int pos7 = offset + 99 + fieldOffset7; int arrLen = VarInt.peek(buf, pos7); pos7 += VarInt.length(buf, pos7); @@ -478,8 +488,8 @@ public class Model { } if ((nullBits[1] & 4) != 0) { - int fieldOffset8 = buf.getIntLE(offset + 75); - int pos8 = offset + 91 + fieldOffset8; + int fieldOffset8 = buf.getIntLE(offset + 83); + int pos8 = offset + 99 + fieldOffset8; int arrLen = VarInt.peek(buf, pos8); pos8 += VarInt.length(buf, pos8); @@ -493,8 +503,8 @@ public class Model { } if ((nullBits[1] & 8) != 0) { - int fieldOffset9 = buf.getIntLE(offset + 79); - int pos9 = offset + 91 + fieldOffset9; + int fieldOffset9 = buf.getIntLE(offset + 87); + int pos9 = offset + 99 + fieldOffset9; int arrLen = VarInt.peek(buf, pos9); pos9 += VarInt.length(buf, pos9); @@ -508,8 +518,8 @@ public class Model { } if ((nullBits[1] & 16) != 0) { - int fieldOffset10 = buf.getIntLE(offset + 83); - int pos10 = offset + 91 + fieldOffset10; + int fieldOffset10 = buf.getIntLE(offset + 91); + int pos10 = offset + 99 + fieldOffset10; int dictLen = VarInt.peek(buf, pos10); pos10 += VarInt.length(buf, pos10); @@ -530,8 +540,8 @@ public class Model { } if ((nullBits[1] & 32) != 0) { - int fieldOffset11 = buf.getIntLE(offset + 87); - int pos11 = offset + 91 + fieldOffset11; + int fieldOffset11 = buf.getIntLE(offset + 95); + int pos11 = offset + 99 + fieldOffset11; pos11 += computeBytesConsumed(buf, pos11); if (pos11 - offset > maxEnd) { maxEnd = pos11 - offset; @@ -604,6 +614,8 @@ public class Model { buf.writeFloatLE(this.scale); buf.writeFloatLE(this.eyeHeight); buf.writeFloatLE(this.crouchOffset); + buf.writeFloatLE(this.sittingOffset); + buf.writeFloatLE(this.sleepingOffset); if (this.hitbox != null) { this.hitbox.serialize(buf); } else { @@ -774,7 +786,7 @@ public class Model { } public int computeSize() { - int size = 91; + int size = 99; if (this.assetId != null) { size += PacketIO.stringSize(this.assetId); } @@ -857,17 +869,17 @@ public class Model { } public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 91) { - return ValidationResult.error("Buffer too small: expected at least 91 bytes"); + if (buffer.readableBytes() - offset < 99) { + return ValidationResult.error("Buffer too small: expected at least 99 bytes"); } else { byte[] nullBits = PacketIO.readBytes(buffer, offset, 2); if ((nullBits[0] & 4) != 0) { - int assetIdOffset = buffer.getIntLE(offset + 43); + int assetIdOffset = buffer.getIntLE(offset + 51); if (assetIdOffset < 0) { return ValidationResult.error("Invalid offset for AssetId"); } - int pos = offset + 91 + assetIdOffset; + int pos = offset + 99 + assetIdOffset; if (pos >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for AssetId"); } @@ -889,12 +901,12 @@ public class Model { } if ((nullBits[0] & 8) != 0) { - int pathOffset = buffer.getIntLE(offset + 47); + int pathOffset = buffer.getIntLE(offset + 55); if (pathOffset < 0) { return ValidationResult.error("Invalid offset for Path"); } - int posx = offset + 91 + pathOffset; + int posx = offset + 99 + pathOffset; if (posx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Path"); } @@ -916,12 +928,12 @@ public class Model { } if ((nullBits[0] & 16) != 0) { - int textureOffset = buffer.getIntLE(offset + 51); + int textureOffset = buffer.getIntLE(offset + 59); if (textureOffset < 0) { return ValidationResult.error("Invalid offset for Texture"); } - int posxx = offset + 91 + textureOffset; + int posxx = offset + 99 + textureOffset; if (posxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Texture"); } @@ -943,12 +955,12 @@ public class Model { } if ((nullBits[0] & 32) != 0) { - int gradientSetOffset = buffer.getIntLE(offset + 55); + int gradientSetOffset = buffer.getIntLE(offset + 63); if (gradientSetOffset < 0) { return ValidationResult.error("Invalid offset for GradientSet"); } - int posxxx = offset + 91 + gradientSetOffset; + int posxxx = offset + 99 + gradientSetOffset; if (posxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for GradientSet"); } @@ -970,12 +982,12 @@ public class Model { } if ((nullBits[0] & 64) != 0) { - int gradientIdOffset = buffer.getIntLE(offset + 59); + int gradientIdOffset = buffer.getIntLE(offset + 67); if (gradientIdOffset < 0) { return ValidationResult.error("Invalid offset for GradientId"); } - int posxxxx = offset + 91 + gradientIdOffset; + int posxxxx = offset + 99 + gradientIdOffset; if (posxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for GradientId"); } @@ -997,12 +1009,12 @@ public class Model { } if ((nullBits[0] & 128) != 0) { - int cameraOffset = buffer.getIntLE(offset + 63); + int cameraOffset = buffer.getIntLE(offset + 71); if (cameraOffset < 0) { return ValidationResult.error("Invalid offset for Camera"); } - int posxxxxx = offset + 91 + cameraOffset; + int posxxxxx = offset + 99 + cameraOffset; if (posxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Camera"); } @@ -1016,12 +1028,12 @@ public class Model { } if ((nullBits[1] & 1) != 0) { - int animationSetsOffset = buffer.getIntLE(offset + 67); + int animationSetsOffset = buffer.getIntLE(offset + 75); if (animationSetsOffset < 0) { return ValidationResult.error("Invalid offset for AnimationSets"); } - int posxxxxxx = offset + 91 + animationSetsOffset; + int posxxxxxx = offset + 99 + animationSetsOffset; if (posxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for AnimationSets"); } @@ -1058,12 +1070,12 @@ public class Model { } if ((nullBits[1] & 2) != 0) { - int attachmentsOffset = buffer.getIntLE(offset + 71); + int attachmentsOffset = buffer.getIntLE(offset + 79); if (attachmentsOffset < 0) { return ValidationResult.error("Invalid offset for Attachments"); } - int posxxxxxxx = offset + 91 + attachmentsOffset; + int posxxxxxxx = offset + 99 + attachmentsOffset; if (posxxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Attachments"); } @@ -1090,12 +1102,12 @@ public class Model { } if ((nullBits[1] & 4) != 0) { - int particlesOffset = buffer.getIntLE(offset + 75); + int particlesOffset = buffer.getIntLE(offset + 83); if (particlesOffset < 0) { return ValidationResult.error("Invalid offset for Particles"); } - int posxxxxxxxx = offset + 91 + particlesOffset; + int posxxxxxxxx = offset + 99 + particlesOffset; if (posxxxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Particles"); } @@ -1122,12 +1134,12 @@ public class Model { } if ((nullBits[1] & 8) != 0) { - int trailsOffset = buffer.getIntLE(offset + 79); + int trailsOffset = buffer.getIntLE(offset + 87); if (trailsOffset < 0) { return ValidationResult.error("Invalid offset for Trails"); } - int posxxxxxxxxx = offset + 91 + trailsOffset; + int posxxxxxxxxx = offset + 99 + trailsOffset; if (posxxxxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for Trails"); } @@ -1154,12 +1166,12 @@ public class Model { } if ((nullBits[1] & 16) != 0) { - int detailBoxesOffset = buffer.getIntLE(offset + 83); + int detailBoxesOffset = buffer.getIntLE(offset + 91); if (detailBoxesOffset < 0) { return ValidationResult.error("Invalid offset for DetailBoxes"); } - int posxxxxxxxxxx = offset + 91 + detailBoxesOffset; + int posxxxxxxxxxx = offset + 99 + detailBoxesOffset; if (posxxxxxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for DetailBoxes"); } @@ -1205,12 +1217,12 @@ public class Model { } if ((nullBits[1] & 32) != 0) { - int phobiaModelOffset = buffer.getIntLE(offset + 87); + int phobiaModelOffset = buffer.getIntLE(offset + 95); if (phobiaModelOffset < 0) { return ValidationResult.error("Invalid offset for PhobiaModel"); } - int posxxxxxxxxxxx = offset + 91 + phobiaModelOffset; + int posxxxxxxxxxxx = offset + 99 + phobiaModelOffset; if (posxxxxxxxxxxx >= buffer.writerIndex()) { return ValidationResult.error("Offset out of bounds for PhobiaModel"); } @@ -1238,6 +1250,8 @@ public class Model { copy.scale = this.scale; copy.eyeHeight = this.eyeHeight; copy.crouchOffset = this.crouchOffset; + copy.sittingOffset = this.sittingOffset; + copy.sleepingOffset = this.sleepingOffset; if (this.animationSets != null) { Map m = new HashMap<>(); @@ -1284,6 +1298,8 @@ public class Model { && this.scale == other.scale && this.eyeHeight == other.eyeHeight && this.crouchOffset == other.crouchOffset + && this.sittingOffset == other.sittingOffset + && this.sleepingOffset == other.sleepingOffset && Objects.equals(this.animationSets, other.animationSets) && Arrays.equals((Object[])this.attachments, (Object[])other.attachments) && Objects.equals(this.hitbox, other.hitbox) @@ -1308,6 +1324,8 @@ public class Model { result = 31 * result + Float.hashCode(this.scale); result = 31 * result + Float.hashCode(this.eyeHeight); result = 31 * result + Float.hashCode(this.crouchOffset); + result = 31 * result + Float.hashCode(this.sittingOffset); + result = 31 * result + Float.hashCode(this.sleepingOffset); result = 31 * result + Objects.hashCode(this.animationSets); result = 31 * result + Arrays.hashCode((Object[])this.attachments); result = 31 * result + Objects.hashCode(this.hitbox); diff --git a/src/com/hypixel/hytale/protocol/ModelUpdate.java b/src/com/hypixel/hytale/protocol/ModelUpdate.java new file mode 100644 index 00000000..c8b67a39 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/ModelUpdate.java @@ -0,0 +1,122 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ModelUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 1; + public static final int FIXED_BLOCK_SIZE = 5; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 5; + public static final int MAX_SIZE = 1677721600; + @Nullable + public Model model; + public float entityScale; + + public ModelUpdate() { + } + + public ModelUpdate(@Nullable Model model, float entityScale) { + this.model = model; + this.entityScale = entityScale; + } + + public ModelUpdate(@Nonnull ModelUpdate other) { + this.model = other.model; + this.entityScale = other.entityScale; + } + + @Nonnull + public static ModelUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + ModelUpdate obj = new ModelUpdate(); + byte nullBits = buf.getByte(offset); + obj.entityScale = buf.getFloatLE(offset + 1); + int pos = offset + 5; + if ((nullBits & 1) != 0) { + obj.model = Model.deserialize(buf, pos); + pos += Model.computeBytesConsumed(buf, pos); + } + + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + byte nullBits = buf.getByte(offset); + int pos = offset + 5; + if ((nullBits & 1) != 0) { + pos += Model.computeBytesConsumed(buf, pos); + } + + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + byte nullBits = 0; + if (this.model != null) { + nullBits = (byte)(nullBits | 1); + } + + buf.writeByte(nullBits); + buf.writeFloatLE(this.entityScale); + if (this.model != null) { + this.model.serialize(buf); + } + + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + int size = 5; + if (this.model != null) { + size += this.model.computeSize(); + } + + return size; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 5) { + return ValidationResult.error("Buffer too small: expected at least 5 bytes"); + } else { + byte nullBits = buffer.getByte(offset); + int pos = offset + 5; + if ((nullBits & 1) != 0) { + ValidationResult modelResult = Model.validateStructure(buffer, pos); + if (!modelResult.isValid()) { + return ValidationResult.error("Invalid Model: " + modelResult.error()); + } + + pos += Model.computeBytesConsumed(buffer, pos); + } + + return ValidationResult.OK; + } + } + + public ModelUpdate clone() { + ModelUpdate copy = new ModelUpdate(); + copy.model = this.model != null ? this.model.clone() : null; + copy.entityScale = this.entityScale; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return !(obj instanceof ModelUpdate other) ? false : Objects.equals(this.model, other.model) && this.entityScale == other.entityScale; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.model, this.entityScale); + } +} diff --git a/src/com/hypixel/hytale/protocol/MountedUpdate.java b/src/com/hypixel/hytale/protocol/MountedUpdate.java index 31d35e1d..22332a03 100644 --- a/src/com/hypixel/hytale/protocol/MountedUpdate.java +++ b/src/com/hypixel/hytale/protocol/MountedUpdate.java @@ -6,7 +6,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class MountedUpdate { +public class MountedUpdate extends ComponentUpdate { public static final int NULLABLE_BIT_FIELD_SIZE = 1; public static final int FIXED_BLOCK_SIZE = 48; public static final int VARIABLE_FIELD_COUNT = 0; @@ -58,7 +58,9 @@ public class MountedUpdate { return 48; } - public void serialize(@Nonnull ByteBuf buf) { + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); byte nullBits = 0; if (this.attachmentOffset != null) { nullBits = (byte)(nullBits | 1); @@ -82,8 +84,11 @@ public class MountedUpdate { } else { buf.writeZero(30); } + + return buf.writerIndex() - startPos; } + @Override public int computeSize() { return 48; } diff --git a/src/com/hypixel/hytale/protocol/MovementStatesUpdate.java b/src/com/hypixel/hytale/protocol/MovementStatesUpdate.java new file mode 100644 index 00000000..0ef57666 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/MovementStatesUpdate.java @@ -0,0 +1,74 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class MovementStatesUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 22; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 22; + public static final int MAX_SIZE = 22; + @Nonnull + public MovementStates movementStates = new MovementStates(); + + public MovementStatesUpdate() { + } + + public MovementStatesUpdate(@Nonnull MovementStates movementStates) { + this.movementStates = movementStates; + } + + public MovementStatesUpdate(@Nonnull MovementStatesUpdate other) { + this.movementStates = other.movementStates; + } + + @Nonnull + public static MovementStatesUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + MovementStatesUpdate obj = new MovementStatesUpdate(); + obj.movementStates = MovementStates.deserialize(buf, offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 22; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + this.movementStates.serialize(buf); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 22; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 22 ? ValidationResult.error("Buffer too small: expected at least 22 bytes") : ValidationResult.OK; + } + + public MovementStatesUpdate clone() { + MovementStatesUpdate copy = new MovementStatesUpdate(); + copy.movementStates = this.movementStates.clone(); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof MovementStatesUpdate other ? Objects.equals(this.movementStates, other.movementStates) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.movementStates); + } +} diff --git a/src/com/hypixel/hytale/protocol/NameplateUpdate.java b/src/com/hypixel/hytale/protocol/NameplateUpdate.java new file mode 100644 index 00000000..69de5d1f --- /dev/null +++ b/src/com/hypixel/hytale/protocol/NameplateUpdate.java @@ -0,0 +1,105 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.PacketIO; +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class NameplateUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 16384005; + @Nonnull + public String text = ""; + + public NameplateUpdate() { + } + + public NameplateUpdate(@Nonnull String text) { + this.text = text; + } + + public NameplateUpdate(@Nonnull NameplateUpdate other) { + this.text = other.text; + } + + @Nonnull + public static NameplateUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + NameplateUpdate obj = new NameplateUpdate(); + int pos = offset + 0; + int textLen = VarInt.peek(buf, pos); + if (textLen < 0) { + throw ProtocolException.negativeLength("Text", textLen); + } else if (textLen > 4096000) { + throw ProtocolException.stringTooLong("Text", textLen, 4096000); + } else { + int textVarLen = VarInt.length(buf, pos); + obj.text = PacketIO.readVarString(buf, pos, PacketIO.UTF8); + pos += textVarLen + textLen; + return obj; + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int sl = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos) + sl; + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + PacketIO.writeVarString(buf, this.text, 4096000); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + int size = 0; + return size + PacketIO.stringSize(this.text); + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int textLen = VarInt.peek(buffer, pos); + if (textLen < 0) { + return ValidationResult.error("Invalid string length for Text"); + } else if (textLen > 4096000) { + return ValidationResult.error("Text exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + pos += textLen; + return pos > buffer.writerIndex() ? ValidationResult.error("Buffer overflow reading Text") : ValidationResult.OK; + } + } + } + + public NameplateUpdate clone() { + NameplateUpdate copy = new NameplateUpdate(); + copy.text = this.text; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof NameplateUpdate other ? Objects.equals(this.text, other.text) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.text); + } +} diff --git a/src/com/hypixel/hytale/protocol/NetworkChannel.java b/src/com/hypixel/hytale/protocol/NetworkChannel.java new file mode 100644 index 00000000..c605e321 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/NetworkChannel.java @@ -0,0 +1,27 @@ +package com.hypixel.hytale.protocol; + +public enum NetworkChannel { + Default(0), + Chunks(1), + WorldMap(2); + + public static final NetworkChannel[] VALUES = values(); + public static final int COUNT = VALUES.length; + private final int value; + + private NetworkChannel(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } + + public static NetworkChannel fromValue(int value) { + if (value >= 0 && value < VALUES.length) { + return VALUES[value]; + } else { + throw new IllegalArgumentException("Invalid network channel: " + value); + } + } +} diff --git a/src/com/hypixel/hytale/protocol/NewSpawnUpdate.java b/src/com/hypixel/hytale/protocol/NewSpawnUpdate.java new file mode 100644 index 00000000..09a0de4d --- /dev/null +++ b/src/com/hypixel/hytale/protocol/NewSpawnUpdate.java @@ -0,0 +1,51 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import javax.annotation.Nonnull; + +public class NewSpawnUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 0; + + @Nonnull + public static NewSpawnUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + return new NewSpawnUpdate(); + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 0; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 0; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 0 ? ValidationResult.error("Buffer too small: expected at least 0 bytes") : ValidationResult.OK; + } + + public NewSpawnUpdate clone() { + return new NewSpawnUpdate(); + } + + @Override + public boolean equals(Object obj) { + return this == obj ? true : obj instanceof NewSpawnUpdate other; + } + + @Override + public int hashCode() { + return 0; + } +} diff --git a/src/com/hypixel/hytale/protocol/Packet.java b/src/com/hypixel/hytale/protocol/Packet.java index 673767ab..bd23ee0d 100644 --- a/src/com/hypixel/hytale/protocol/Packet.java +++ b/src/com/hypixel/hytale/protocol/Packet.java @@ -6,6 +6,8 @@ import javax.annotation.Nonnull; public interface Packet { int getId(); + NetworkChannel getChannel(); + void serialize(@Nonnull ByteBuf var1); int computeSize(); diff --git a/src/com/hypixel/hytale/protocol/PacketRegistry.java b/src/com/hypixel/hytale/protocol/PacketRegistry.java index b3a7379e..2e06be79 100644 --- a/src/com/hypixel/hytale/protocol/PacketRegistry.java +++ b/src/com/hypixel/hytale/protocol/PacketRegistry.java @@ -15,7 +15,6 @@ import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorDeleteAsset; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorDeleteAssetPack; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorDeleteDirectory; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorDiscardChanges; -import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorEnableAssetPack; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorExportAssetFinalize; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorExportAssetInitialize; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorExportAssetPart; @@ -34,7 +33,6 @@ import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorJsonAssetUpdat import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorLastModifiedAssets; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorModifiedAssetsCount; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorPopupNotification; -import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRebuildCaches; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRedoChanges; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRenameAsset; import com.hypixel.hytale.protocol.packets.asseteditor.AssetEditorRenameDirectory; @@ -111,7 +109,6 @@ import com.hypixel.hytale.protocol.packets.auth.PasswordAccepted; import com.hypixel.hytale.protocol.packets.auth.PasswordRejected; import com.hypixel.hytale.protocol.packets.auth.PasswordResponse; import com.hypixel.hytale.protocol.packets.auth.ServerAuthToken; -import com.hypixel.hytale.protocol.packets.auth.Status; import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolArgUpdate; import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolEntityAction; import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolExtrudeAction; @@ -173,6 +170,7 @@ import com.hypixel.hytale.protocol.packets.interface_.ServerInfo; import com.hypixel.hytale.protocol.packets.interface_.ServerMessage; import com.hypixel.hytale.protocol.packets.interface_.SetPage; import com.hypixel.hytale.protocol.packets.interface_.ShowEventTitle; +import com.hypixel.hytale.protocol.packets.interface_.UpdateAnchorUI; import com.hypixel.hytale.protocol.packets.interface_.UpdateKnownRecipes; import com.hypixel.hytale.protocol.packets.interface_.UpdateLanguage; import com.hypixel.hytale.protocol.packets.interface_.UpdatePortal; @@ -281,6 +279,8 @@ import javax.annotation.Nullable; public final class PacketRegistry { private static final Map BY_ID = new HashMap<>(); + private static final Map TO_SERVER_BY_ID = new HashMap<>(); + private static final Map TO_CLIENT_BY_ID = new HashMap<>(); private static final Map BY_ID_UNMODIFIABLE = Collections.unmodifiableMap(BY_ID); private static final Map, Integer> BY_TYPE = new HashMap<>(); @@ -288,6 +288,8 @@ public final class PacketRegistry { } private static void register( + PacketRegistry.PacketDirection direction, + NetworkChannel channel, int id, String name, Class type, @@ -301,15 +303,32 @@ public final class PacketRegistry { if (existing != null) { throw new IllegalStateException("Duplicate packet ID " + id + ": '" + name + "' conflicts with '" + existing.name() + "'"); } else { - PacketRegistry.PacketInfo info = new PacketRegistry.PacketInfo(id, name, type, fixedBlockSize, maxSize, compressed, validate, deserialize); + PacketRegistry.PacketInfo info = new PacketRegistry.PacketInfo(id, name, channel, type, fixedBlockSize, maxSize, compressed, validate, deserialize); + switch (direction) { + case ToServer: + TO_SERVER_BY_ID.put(id, info); + break; + case ToClient: + TO_CLIENT_BY_ID.put(id, info); + break; + case Both: + TO_SERVER_BY_ID.put(id, info); + TO_CLIENT_BY_ID.put(id, info); + } + BY_ID.put(id, info); BY_TYPE.put(type, id); } } @Nullable - public static PacketRegistry.PacketInfo getById(int id) { - return BY_ID.get(id); + public static PacketRegistry.PacketInfo getToServerPacketById(int id) { + return TO_SERVER_BY_ID.get(id); + } + + @Nullable + public static PacketRegistry.PacketInfo getToClientPacketById(int id) { + return TO_CLIENT_BY_ID.get(id); } @Nullable @@ -323,28 +342,231 @@ public final class PacketRegistry { } static { - register(0, "Connect", Connect.class, 46, 38013, false, Connect::validateStructure, Connect::deserialize); - register(1, "Disconnect", Disconnect.class, 2, 16384007, false, Disconnect::validateStructure, Disconnect::deserialize); - register(2, "Ping", Ping.class, 29, 29, false, Ping::validateStructure, Ping::deserialize); - register(3, "Pong", Pong.class, 20, 20, false, Pong::validateStructure, Pong::deserialize); - register(10, "Status", Status.class, 9, 2587, false, Status::validateStructure, Status::deserialize); - register(11, "AuthGrant", AuthGrant.class, 1, 49171, false, AuthGrant::validateStructure, AuthGrant::deserialize); - register(12, "AuthToken", AuthToken.class, 1, 49171, false, AuthToken::validateStructure, AuthToken::deserialize); - register(13, "ServerAuthToken", ServerAuthToken.class, 1, 32851, false, ServerAuthToken::validateStructure, ServerAuthToken::deserialize); - register(14, "ConnectAccept", ConnectAccept.class, 1, 70, false, ConnectAccept::validateStructure, ConnectAccept::deserialize); - register(15, "PasswordResponse", PasswordResponse.class, 1, 70, false, PasswordResponse::validateStructure, PasswordResponse::deserialize); - register(16, "PasswordAccepted", PasswordAccepted.class, 0, 0, false, PasswordAccepted::validateStructure, PasswordAccepted::deserialize); - register(17, "PasswordRejected", PasswordRejected.class, 5, 74, false, PasswordRejected::validateStructure, PasswordRejected::deserialize); - register(18, "ClientReferral", ClientReferral.class, 1, 5141, false, ClientReferral::validateStructure, ClientReferral::deserialize); - register(20, "WorldSettings", WorldSettings.class, 5, 1677721600, true, WorldSettings::validateStructure, WorldSettings::deserialize); - register(21, "WorldLoadProgress", WorldLoadProgress.class, 9, 1677721600, false, WorldLoadProgress::validateStructure, WorldLoadProgress::deserialize); - register(22, "WorldLoadFinished", WorldLoadFinished.class, 0, 0, false, WorldLoadFinished::validateStructure, WorldLoadFinished::deserialize); - register(23, "RequestAssets", RequestAssets.class, 1, 1677721600, true, RequestAssets::validateStructure, RequestAssets::deserialize); - register(24, "AssetInitialize", AssetInitialize.class, 4, 2121, false, AssetInitialize::validateStructure, AssetInitialize::deserialize); - register(25, "AssetPart", AssetPart.class, 1, 4096006, true, AssetPart::validateStructure, AssetPart::deserialize); - register(26, "AssetFinalize", AssetFinalize.class, 0, 0, false, AssetFinalize::validateStructure, AssetFinalize::deserialize); - register(27, "RemoveAssets", RemoveAssets.class, 1, 1677721600, false, RemoveAssets::validateStructure, RemoveAssets::deserialize); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 0, + "Connect", + Connect.class, + 46, + 38013, + false, + Connect::validateStructure, + Connect::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 1, + "Disconnect", + Disconnect.class, + 2, + 16384007, + false, + Disconnect::validateStructure, + Disconnect::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, NetworkChannel.Default, 2, "Ping", Ping.class, 29, 29, false, Ping::validateStructure, Ping::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, NetworkChannel.Default, 3, "Pong", Pong.class, 20, 20, false, Pong::validateStructure, Pong::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 11, + "AuthGrant", + AuthGrant.class, + 1, + 49171, + false, + AuthGrant::validateStructure, + AuthGrant::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 12, + "AuthToken", + AuthToken.class, + 1, + 49171, + false, + AuthToken::validateStructure, + AuthToken::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 13, + "ServerAuthToken", + ServerAuthToken.class, + 1, + 32851, + false, + ServerAuthToken::validateStructure, + ServerAuthToken::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 14, + "ConnectAccept", + ConnectAccept.class, + 1, + 70, + false, + ConnectAccept::validateStructure, + ConnectAccept::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 15, + "PasswordResponse", + PasswordResponse.class, + 1, + 70, + false, + PasswordResponse::validateStructure, + PasswordResponse::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 16, + "PasswordAccepted", + PasswordAccepted.class, + 0, + 0, + false, + PasswordAccepted::validateStructure, + PasswordAccepted::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 17, + "PasswordRejected", + PasswordRejected.class, + 5, + 74, + false, + PasswordRejected::validateStructure, + PasswordRejected::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 18, + "ClientReferral", + ClientReferral.class, + 1, + 5141, + false, + ClientReferral::validateStructure, + ClientReferral::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 20, + "WorldSettings", + WorldSettings.class, + 5, + 1677721600, + true, + WorldSettings::validateStructure, + WorldSettings::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 21, + "WorldLoadProgress", + WorldLoadProgress.class, + 9, + 1677721600, + false, + WorldLoadProgress::validateStructure, + WorldLoadProgress::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 22, + "WorldLoadFinished", + WorldLoadFinished.class, + 0, + 0, + false, + WorldLoadFinished::validateStructure, + WorldLoadFinished::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 23, + "RequestAssets", + RequestAssets.class, + 1, + 1677721600, + true, + RequestAssets::validateStructure, + RequestAssets::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 24, + "AssetInitialize", + AssetInitialize.class, + 4, + 2121, + false, + AssetInitialize::validateStructure, + AssetInitialize::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 25, + "AssetPart", + AssetPart.class, + 1, + 4096006, + true, + AssetPart::validateStructure, + AssetPart::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 26, + "AssetFinalize", + AssetFinalize.class, + 0, + 0, + false, + AssetFinalize::validateStructure, + AssetFinalize::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 27, + "RemoveAssets", + RemoveAssets.class, + 1, + 1677721600, + false, + RemoveAssets::validateStructure, + RemoveAssets::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 28, "RequestCommonAssetsRebuild", RequestCommonAssetsRebuild.class, @@ -354,17 +576,105 @@ public final class PacketRegistry { RequestCommonAssetsRebuild::validateStructure, RequestCommonAssetsRebuild::deserialize ); - register(29, "SetUpdateRate", SetUpdateRate.class, 4, 4, false, SetUpdateRate::validateStructure, SetUpdateRate::deserialize); - register(30, "SetTimeDilation", SetTimeDilation.class, 4, 4, false, SetTimeDilation::validateStructure, SetTimeDilation::deserialize); - register(31, "UpdateFeatures", UpdateFeatures.class, 1, 8192006, false, UpdateFeatures::validateStructure, UpdateFeatures::deserialize); - register(32, "ViewRadius", ViewRadius.class, 4, 4, false, ViewRadius::validateStructure, ViewRadius::deserialize); - register(33, "PlayerOptions", PlayerOptions.class, 1, 327680184, false, PlayerOptions::validateStructure, PlayerOptions::deserialize); - register(34, "ServerTags", ServerTags.class, 1, 1677721600, false, ServerTags::validateStructure, ServerTags::deserialize); - register(40, "UpdateBlockTypes", UpdateBlockTypes.class, 10, 1677721600, true, UpdateBlockTypes::validateStructure, UpdateBlockTypes::deserialize); register( - 41, "UpdateBlockHitboxes", UpdateBlockHitboxes.class, 6, 1677721600, true, UpdateBlockHitboxes::validateStructure, UpdateBlockHitboxes::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 29, + "SetUpdateRate", + SetUpdateRate.class, + 4, + 4, + false, + SetUpdateRate::validateStructure, + SetUpdateRate::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 30, + "SetTimeDilation", + SetTimeDilation.class, + 4, + 4, + false, + SetTimeDilation::validateStructure, + SetTimeDilation::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 31, + "UpdateFeatures", + UpdateFeatures.class, + 1, + 8192006, + false, + UpdateFeatures::validateStructure, + UpdateFeatures::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 32, + "ViewRadius", + ViewRadius.class, + 4, + 4, + false, + ViewRadius::validateStructure, + ViewRadius::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 33, + "PlayerOptions", + PlayerOptions.class, + 1, + 327680184, + false, + PlayerOptions::validateStructure, + PlayerOptions::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 34, + "ServerTags", + ServerTags.class, + 1, + 1677721600, + false, + ServerTags::validateStructure, + ServerTags::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 40, + "UpdateBlockTypes", + UpdateBlockTypes.class, + 10, + 1677721600, + true, + UpdateBlockTypes::validateStructure, + UpdateBlockTypes::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 41, + "UpdateBlockHitboxes", + UpdateBlockHitboxes.class, + 6, + 1677721600, + true, + UpdateBlockHitboxes::validateStructure, + UpdateBlockHitboxes::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 42, "UpdateBlockSoundSets", UpdateBlockSoundSets.class, @@ -375,9 +685,20 @@ public final class PacketRegistry { UpdateBlockSoundSets::deserialize ); register( - 43, "UpdateItemSoundSets", UpdateItemSoundSets.class, 6, 1677721600, true, UpdateItemSoundSets::validateStructure, UpdateItemSoundSets::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 43, + "UpdateItemSoundSets", + UpdateItemSoundSets.class, + 6, + 1677721600, + true, + UpdateItemSoundSets::validateStructure, + UpdateItemSoundSets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 44, "UpdateBlockParticleSets", UpdateBlockParticleSets.class, @@ -388,6 +709,8 @@ public final class PacketRegistry { UpdateBlockParticleSets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 45, "UpdateBlockBreakingDecals", UpdateBlockBreakingDecals.class, @@ -397,10 +720,45 @@ public final class PacketRegistry { UpdateBlockBreakingDecals::validateStructure, UpdateBlockBreakingDecals::deserialize ); - register(46, "UpdateBlockSets", UpdateBlockSets.class, 2, 1677721600, true, UpdateBlockSets::validateStructure, UpdateBlockSets::deserialize); - register(47, "UpdateWeathers", UpdateWeathers.class, 6, 1677721600, true, UpdateWeathers::validateStructure, UpdateWeathers::deserialize); - register(48, "UpdateTrails", UpdateTrails.class, 2, 1677721600, true, UpdateTrails::validateStructure, UpdateTrails::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 46, + "UpdateBlockSets", + UpdateBlockSets.class, + 2, + 1677721600, + true, + UpdateBlockSets::validateStructure, + UpdateBlockSets::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 47, + "UpdateWeathers", + UpdateWeathers.class, + 6, + 1677721600, + true, + UpdateWeathers::validateStructure, + UpdateWeathers::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 48, + "UpdateTrails", + UpdateTrails.class, + 2, + 1677721600, + true, + UpdateTrails::validateStructure, + UpdateTrails::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 49, "UpdateParticleSystems", UpdateParticleSystems.class, @@ -411,6 +769,8 @@ public final class PacketRegistry { UpdateParticleSystems::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 50, "UpdateParticleSpawners", UpdateParticleSpawners.class, @@ -421,9 +781,20 @@ public final class PacketRegistry { UpdateParticleSpawners::deserialize ); register( - 51, "UpdateEntityEffects", UpdateEntityEffects.class, 6, 1677721600, true, UpdateEntityEffects::validateStructure, UpdateEntityEffects::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 51, + "UpdateEntityEffects", + UpdateEntityEffects.class, + 6, + 1677721600, + true, + UpdateEntityEffects::validateStructure, + UpdateEntityEffects::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 52, "UpdateItemPlayerAnimations", UpdateItemPlayerAnimations.class, @@ -433,12 +804,45 @@ public final class PacketRegistry { UpdateItemPlayerAnimations::validateStructure, UpdateItemPlayerAnimations::deserialize ); - register(53, "UpdateModelvfxs", UpdateModelvfxs.class, 6, 1677721600, true, UpdateModelvfxs::validateStructure, UpdateModelvfxs::deserialize); - register(54, "UpdateItems", UpdateItems.class, 4, 1677721600, true, UpdateItems::validateStructure, UpdateItems::deserialize); register( - 55, "UpdateItemQualities", UpdateItemQualities.class, 6, 1677721600, true, UpdateItemQualities::validateStructure, UpdateItemQualities::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 53, + "UpdateModelvfxs", + UpdateModelvfxs.class, + 6, + 1677721600, + true, + UpdateModelvfxs::validateStructure, + UpdateModelvfxs::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 54, + "UpdateItems", + UpdateItems.class, + 4, + 1677721600, + true, + UpdateItems::validateStructure, + UpdateItems::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 55, + "UpdateItemQualities", + UpdateItemQualities.class, + 6, + 1677721600, + true, + UpdateItemQualities::validateStructure, + UpdateItemQualities::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 56, "UpdateItemCategories", UpdateItemCategories.class, @@ -448,8 +852,21 @@ public final class PacketRegistry { UpdateItemCategories::validateStructure, UpdateItemCategories::deserialize ); - register(57, "UpdateItemReticles", UpdateItemReticles.class, 6, 1677721600, true, UpdateItemReticles::validateStructure, UpdateItemReticles::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 57, + "UpdateItemReticles", + UpdateItemReticles.class, + 6, + 1677721600, + true, + UpdateItemReticles::validateStructure, + UpdateItemReticles::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 58, "UpdateFieldcraftCategories", UpdateFieldcraftCategories.class, @@ -460,16 +877,104 @@ public final class PacketRegistry { UpdateFieldcraftCategories::deserialize ); register( - 59, "UpdateResourceTypes", UpdateResourceTypes.class, 2, 1677721600, true, UpdateResourceTypes::validateStructure, UpdateResourceTypes::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 59, + "UpdateResourceTypes", + UpdateResourceTypes.class, + 2, + 1677721600, + true, + UpdateResourceTypes::validateStructure, + UpdateResourceTypes::deserialize ); - register(60, "UpdateRecipes", UpdateRecipes.class, 2, 1677721600, true, UpdateRecipes::validateStructure, UpdateRecipes::deserialize); - register(61, "UpdateEnvironments", UpdateEnvironments.class, 7, 1677721600, true, UpdateEnvironments::validateStructure, UpdateEnvironments::deserialize); - register(62, "UpdateAmbienceFX", UpdateAmbienceFX.class, 6, 1677721600, true, UpdateAmbienceFX::validateStructure, UpdateAmbienceFX::deserialize); - register(63, "UpdateFluidFX", UpdateFluidFX.class, 6, 1677721600, true, UpdateFluidFX::validateStructure, UpdateFluidFX::deserialize); - register(64, "UpdateTranslations", UpdateTranslations.class, 2, 1677721600, true, UpdateTranslations::validateStructure, UpdateTranslations::deserialize); - register(65, "UpdateSoundEvents", UpdateSoundEvents.class, 6, 1677721600, true, UpdateSoundEvents::validateStructure, UpdateSoundEvents::deserialize); - register(66, "UpdateInteractions", UpdateInteractions.class, 6, 1677721600, true, UpdateInteractions::validateStructure, UpdateInteractions::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 60, + "UpdateRecipes", + UpdateRecipes.class, + 2, + 1677721600, + true, + UpdateRecipes::validateStructure, + UpdateRecipes::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 61, + "UpdateEnvironments", + UpdateEnvironments.class, + 7, + 1677721600, + true, + UpdateEnvironments::validateStructure, + UpdateEnvironments::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 62, + "UpdateAmbienceFX", + UpdateAmbienceFX.class, + 6, + 1677721600, + true, + UpdateAmbienceFX::validateStructure, + UpdateAmbienceFX::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 63, + "UpdateFluidFX", + UpdateFluidFX.class, + 6, + 1677721600, + true, + UpdateFluidFX::validateStructure, + UpdateFluidFX::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 64, + "UpdateTranslations", + UpdateTranslations.class, + 2, + 1677721600, + true, + UpdateTranslations::validateStructure, + UpdateTranslations::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 65, + "UpdateSoundEvents", + UpdateSoundEvents.class, + 6, + 1677721600, + true, + UpdateSoundEvents::validateStructure, + UpdateSoundEvents::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 66, + "UpdateInteractions", + UpdateInteractions.class, + 6, + 1677721600, + true, + UpdateInteractions::validateStructure, + UpdateInteractions::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 67, "UpdateRootInteractions", UpdateRootInteractions.class, @@ -480,6 +985,8 @@ public final class PacketRegistry { UpdateRootInteractions::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 68, "UpdateUnarmedInteractions", UpdateUnarmedInteractions.class, @@ -490,6 +997,8 @@ public final class PacketRegistry { UpdateUnarmedInteractions::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 69, "TrackOrUpdateObjective", TrackOrUpdateObjective.class, @@ -499,11 +1008,33 @@ public final class PacketRegistry { TrackOrUpdateObjective::validateStructure, TrackOrUpdateObjective::deserialize ); - register(70, "UntrackObjective", UntrackObjective.class, 16, 16, false, UntrackObjective::validateStructure, UntrackObjective::deserialize); register( - 71, "UpdateObjectiveTask", UpdateObjectiveTask.class, 21, 1677721600, false, UpdateObjectiveTask::validateStructure, UpdateObjectiveTask::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 70, + "UntrackObjective", + UntrackObjective.class, + 16, + 16, + false, + UntrackObjective::validateStructure, + UntrackObjective::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 71, + "UpdateObjectiveTask", + UpdateObjectiveTask.class, + 21, + 1677721600, + false, + UpdateObjectiveTask::validateStructure, + UpdateObjectiveTask::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 72, "UpdateEntityStatTypes", UpdateEntityStatTypes.class, @@ -514,6 +1045,8 @@ public final class PacketRegistry { UpdateEntityStatTypes::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 73, "UpdateEntityUIComponents", UpdateEntityUIComponents.class, @@ -524,6 +1057,8 @@ public final class PacketRegistry { UpdateEntityUIComponents::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 74, "UpdateHitboxCollisionConfig", UpdateHitboxCollisionConfig.class, @@ -534,6 +1069,8 @@ public final class PacketRegistry { UpdateHitboxCollisionConfig::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 75, "UpdateRepulsionConfig", UpdateRepulsionConfig.class, @@ -543,11 +1080,57 @@ public final class PacketRegistry { UpdateRepulsionConfig::validateStructure, UpdateRepulsionConfig::deserialize ); - register(76, "UpdateViewBobbing", UpdateViewBobbing.class, 2, 1677721600, true, UpdateViewBobbing::validateStructure, UpdateViewBobbing::deserialize); - register(77, "UpdateCameraShake", UpdateCameraShake.class, 2, 1677721600, true, UpdateCameraShake::validateStructure, UpdateCameraShake::deserialize); - register(78, "UpdateBlockGroups", UpdateBlockGroups.class, 2, 1677721600, true, UpdateBlockGroups::validateStructure, UpdateBlockGroups::deserialize); - register(79, "UpdateSoundSets", UpdateSoundSets.class, 6, 1677721600, true, UpdateSoundSets::validateStructure, UpdateSoundSets::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 76, + "UpdateViewBobbing", + UpdateViewBobbing.class, + 2, + 1677721600, + true, + UpdateViewBobbing::validateStructure, + UpdateViewBobbing::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 77, + "UpdateCameraShake", + UpdateCameraShake.class, + 2, + 1677721600, + true, + UpdateCameraShake::validateStructure, + UpdateCameraShake::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 78, + "UpdateBlockGroups", + UpdateBlockGroups.class, + 2, + 1677721600, + true, + UpdateBlockGroups::validateStructure, + UpdateBlockGroups::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 79, + "UpdateSoundSets", + UpdateSoundSets.class, + 6, + 1677721600, + true, + UpdateSoundSets::validateStructure, + UpdateSoundSets::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 80, "UpdateAudioCategories", UpdateAudioCategories.class, @@ -558,9 +1141,20 @@ public final class PacketRegistry { UpdateAudioCategories::deserialize ); register( - 81, "UpdateReverbEffects", UpdateReverbEffects.class, 6, 1677721600, true, UpdateReverbEffects::validateStructure, UpdateReverbEffects::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 81, + "UpdateReverbEffects", + UpdateReverbEffects.class, + 6, + 1677721600, + true, + UpdateReverbEffects::validateStructure, + UpdateReverbEffects::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 82, "UpdateEqualizerEffects", UpdateEqualizerEffects.class, @@ -570,9 +1164,33 @@ public final class PacketRegistry { UpdateEqualizerEffects::validateStructure, UpdateEqualizerEffects::deserialize ); - register(83, "UpdateFluids", UpdateFluids.class, 6, 1677721600, true, UpdateFluids::validateStructure, UpdateFluids::deserialize); - register(84, "UpdateTagPatterns", UpdateTagPatterns.class, 6, 1677721600, true, UpdateTagPatterns::validateStructure, UpdateTagPatterns::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 83, + "UpdateFluids", + UpdateFluids.class, + 6, + 1677721600, + true, + UpdateFluids::validateStructure, + UpdateFluids::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 84, + "UpdateTagPatterns", + UpdateTagPatterns.class, + 6, + 1677721600, + true, + UpdateTagPatterns::validateStructure, + UpdateTagPatterns::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 85, "UpdateProjectileConfigs", UpdateProjectileConfigs.class, @@ -582,10 +1200,45 @@ public final class PacketRegistry { UpdateProjectileConfigs::validateStructure, UpdateProjectileConfigs::deserialize ); - register(100, "SetClientId", SetClientId.class, 4, 4, false, SetClientId::validateStructure, SetClientId::deserialize); - register(101, "SetGameMode", SetGameMode.class, 1, 1, false, SetGameMode::validateStructure, SetGameMode::deserialize); - register(102, "SetMovementStates", SetMovementStates.class, 2, 2, false, SetMovementStates::validateStructure, SetMovementStates::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 100, + "SetClientId", + SetClientId.class, + 4, + 4, + false, + SetClientId::validateStructure, + SetClientId::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 101, + "SetGameMode", + SetGameMode.class, + 1, + 1, + false, + SetGameMode::validateStructure, + SetGameMode::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 102, + "SetMovementStates", + SetMovementStates.class, + 2, + 2, + false, + SetMovementStates::validateStructure, + SetMovementStates::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 103, "SetBlockPlacementOverride", SetBlockPlacementOverride.class, @@ -595,13 +1248,81 @@ public final class PacketRegistry { SetBlockPlacementOverride::validateStructure, SetBlockPlacementOverride::deserialize ); - register(104, "JoinWorld", JoinWorld.class, 18, 18, false, JoinWorld::validateStructure, JoinWorld::deserialize); - register(105, "ClientReady", ClientReady.class, 2, 2, false, ClientReady::validateStructure, ClientReady::deserialize); - register(106, "LoadHotbar", LoadHotbar.class, 1, 1, false, LoadHotbar::validateStructure, LoadHotbar::deserialize); - register(107, "SaveHotbar", SaveHotbar.class, 1, 1, false, SaveHotbar::validateStructure, SaveHotbar::deserialize); - register(108, "ClientMovement", ClientMovement.class, 153, 153, false, ClientMovement::validateStructure, ClientMovement::deserialize); - register(109, "ClientTeleport", ClientTeleport.class, 52, 52, false, ClientTeleport::validateStructure, ClientTeleport::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 104, + "JoinWorld", + JoinWorld.class, + 18, + 18, + false, + JoinWorld::validateStructure, + JoinWorld::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 105, + "ClientReady", + ClientReady.class, + 2, + 2, + false, + ClientReady::validateStructure, + ClientReady::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 106, + "LoadHotbar", + LoadHotbar.class, + 1, + 1, + false, + LoadHotbar::validateStructure, + LoadHotbar::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 107, + "SaveHotbar", + SaveHotbar.class, + 1, + 1, + false, + SaveHotbar::validateStructure, + SaveHotbar::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 108, + "ClientMovement", + ClientMovement.class, + 153, + 153, + false, + ClientMovement::validateStructure, + ClientMovement::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 109, + "ClientTeleport", + ClientTeleport.class, + 52, + 52, + false, + ClientTeleport::validateStructure, + ClientTeleport::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 110, "UpdateMovementSettings", UpdateMovementSettings.class, @@ -611,16 +1332,93 @@ public final class PacketRegistry { UpdateMovementSettings::validateStructure, UpdateMovementSettings::deserialize ); - register(111, "MouseInteraction", MouseInteraction.class, 44, 20480071, false, MouseInteraction::validateStructure, MouseInteraction::deserialize); - register(112, "DamageInfo", DamageInfo.class, 29, 32768048, false, DamageInfo::validateStructure, DamageInfo::deserialize); - register(113, "ReticleEvent", ReticleEvent.class, 4, 4, false, ReticleEvent::validateStructure, ReticleEvent::deserialize); - register(114, "DisplayDebug", DisplayDebug.class, 23, 32768041, false, DisplayDebug::validateStructure, DisplayDebug::deserialize); - register(115, "ClearDebugShapes", ClearDebugShapes.class, 0, 0, false, ClearDebugShapes::validateStructure, ClearDebugShapes::deserialize); register( - 116, "SyncPlayerPreferences", SyncPlayerPreferences.class, 12, 12, false, SyncPlayerPreferences::validateStructure, SyncPlayerPreferences::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 111, + "MouseInteraction", + MouseInteraction.class, + 44, + 20480071, + false, + MouseInteraction::validateStructure, + MouseInteraction::deserialize ); - register(117, "ClientPlaceBlock", ClientPlaceBlock.class, 20, 20, false, ClientPlaceBlock::validateStructure, ClientPlaceBlock::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 112, + "DamageInfo", + DamageInfo.class, + 29, + 32768048, + false, + DamageInfo::validateStructure, + DamageInfo::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 113, + "ReticleEvent", + ReticleEvent.class, + 4, + 4, + false, + ReticleEvent::validateStructure, + ReticleEvent::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 114, + "DisplayDebug", + DisplayDebug.class, + 23, + 32768041, + false, + DisplayDebug::validateStructure, + DisplayDebug::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 115, + "ClearDebugShapes", + ClearDebugShapes.class, + 0, + 0, + false, + ClearDebugShapes::validateStructure, + ClearDebugShapes::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 116, + "SyncPlayerPreferences", + SyncPlayerPreferences.class, + 12, + 12, + false, + SyncPlayerPreferences::validateStructure, + SyncPlayerPreferences::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 117, + "ClientPlaceBlock", + ClientPlaceBlock.class, + 20, + 20, + false, + ClientPlaceBlock::validateStructure, + ClientPlaceBlock::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 118, "UpdateMemoriesFeatureStatus", UpdateMemoriesFeatureStatus.class, @@ -630,23 +1428,177 @@ public final class PacketRegistry { UpdateMemoriesFeatureStatus::validateStructure, UpdateMemoriesFeatureStatus::deserialize ); - register(119, "RemoveMapMarker", RemoveMapMarker.class, 1, 16384006, false, RemoveMapMarker::validateStructure, RemoveMapMarker::deserialize); - register(131, "SetChunk", SetChunk.class, 13, 12288040, true, SetChunk::validateStructure, SetChunk::deserialize); - register(132, "SetChunkHeightmap", SetChunkHeightmap.class, 9, 4096014, true, SetChunkHeightmap::validateStructure, SetChunkHeightmap::deserialize); - register(133, "SetChunkTintmap", SetChunkTintmap.class, 9, 4096014, true, SetChunkTintmap::validateStructure, SetChunkTintmap::deserialize); register( - 134, "SetChunkEnvironments", SetChunkEnvironments.class, 9, 4096014, true, SetChunkEnvironments::validateStructure, SetChunkEnvironments::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 119, + "RemoveMapMarker", + RemoveMapMarker.class, + 1, + 16384006, + false, + RemoveMapMarker::validateStructure, + RemoveMapMarker::deserialize ); - register(135, "UnloadChunk", UnloadChunk.class, 8, 8, false, UnloadChunk::validateStructure, UnloadChunk::deserialize); - register(136, "SetFluids", SetFluids.class, 13, 4096018, true, SetFluids::validateStructure, SetFluids::deserialize); - register(140, "ServerSetBlock", ServerSetBlock.class, 19, 19, false, ServerSetBlock::validateStructure, ServerSetBlock::deserialize); - register(141, "ServerSetBlocks", ServerSetBlocks.class, 12, 36864017, false, ServerSetBlocks::validateStructure, ServerSetBlocks::deserialize); - register(142, "ServerSetFluid", ServerSetFluid.class, 17, 17, false, ServerSetFluid::validateStructure, ServerSetFluid::deserialize); - register(143, "ServerSetFluids", ServerSetFluids.class, 12, 28672017, false, ServerSetFluids::validateStructure, ServerSetFluids::deserialize); - register(144, "UpdateBlockDamage", UpdateBlockDamage.class, 21, 21, false, UpdateBlockDamage::validateStructure, UpdateBlockDamage::deserialize); - register(145, "UpdateTimeSettings", UpdateTimeSettings.class, 10, 10, false, UpdateTimeSettings::validateStructure, UpdateTimeSettings::deserialize); - register(146, "UpdateTime", UpdateTime.class, 13, 13, false, UpdateTime::validateStructure, UpdateTime::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 131, + "SetChunk", + SetChunk.class, + 13, + 12288040, + true, + SetChunk::validateStructure, + SetChunk::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 132, + "SetChunkHeightmap", + SetChunkHeightmap.class, + 9, + 4096014, + true, + SetChunkHeightmap::validateStructure, + SetChunkHeightmap::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 133, + "SetChunkTintmap", + SetChunkTintmap.class, + 9, + 4096014, + true, + SetChunkTintmap::validateStructure, + SetChunkTintmap::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 134, + "SetChunkEnvironments", + SetChunkEnvironments.class, + 9, + 4096014, + true, + SetChunkEnvironments::validateStructure, + SetChunkEnvironments::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 135, + "UnloadChunk", + UnloadChunk.class, + 8, + 8, + false, + UnloadChunk::validateStructure, + UnloadChunk::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 136, + "SetFluids", + SetFluids.class, + 13, + 4096018, + true, + SetFluids::validateStructure, + SetFluids::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 140, + "ServerSetBlock", + ServerSetBlock.class, + 19, + 19, + false, + ServerSetBlock::validateStructure, + ServerSetBlock::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 141, + "ServerSetBlocks", + ServerSetBlocks.class, + 12, + 36864017, + false, + ServerSetBlocks::validateStructure, + ServerSetBlocks::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 142, + "ServerSetFluid", + ServerSetFluid.class, + 17, + 17, + false, + ServerSetFluid::validateStructure, + ServerSetFluid::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 143, + "ServerSetFluids", + ServerSetFluids.class, + 12, + 28672017, + false, + ServerSetFluids::validateStructure, + ServerSetFluids::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Chunks, + 144, + "UpdateBlockDamage", + UpdateBlockDamage.class, + 21, + 21, + false, + UpdateBlockDamage::validateStructure, + UpdateBlockDamage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 145, + "UpdateTimeSettings", + UpdateTimeSettings.class, + 10, + 10, + false, + UpdateTimeSettings::validateStructure, + UpdateTimeSettings::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 146, + "UpdateTime", + UpdateTime.class, + 13, + 13, + false, + UpdateTime::validateStructure, + UpdateTime::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 147, "UpdateEditorTimeOverride", UpdateEditorTimeOverride.class, @@ -657,6 +1609,8 @@ public final class PacketRegistry { UpdateEditorTimeOverride::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 148, "ClearEditorTimeOverride", ClearEditorTimeOverride.class, @@ -666,8 +1620,21 @@ public final class PacketRegistry { ClearEditorTimeOverride::validateStructure, ClearEditorTimeOverride::deserialize ); - register(149, "UpdateWeather", UpdateWeather.class, 8, 8, false, UpdateWeather::validateStructure, UpdateWeather::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 149, + "UpdateWeather", + UpdateWeather.class, + 8, + 8, + false, + UpdateWeather::validateStructure, + UpdateWeather::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 150, "UpdateEditorWeatherOverride", UpdateEditorWeatherOverride.class, @@ -678,6 +1645,8 @@ public final class PacketRegistry { UpdateEditorWeatherOverride::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 151, "UpdateEnvironmentMusic", UpdateEnvironmentMusic.class, @@ -688,9 +1657,20 @@ public final class PacketRegistry { UpdateEnvironmentMusic::deserialize ); register( - 152, "SpawnParticleSystem", SpawnParticleSystem.class, 44, 16384049, false, SpawnParticleSystem::validateStructure, SpawnParticleSystem::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 152, + "SpawnParticleSystem", + SpawnParticleSystem.class, + 44, + 16384049, + false, + SpawnParticleSystem::validateStructure, + SpawnParticleSystem::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 153, "SpawnBlockParticleSystem", SpawnBlockParticleSystem.class, @@ -700,24 +1680,165 @@ public final class PacketRegistry { SpawnBlockParticleSystem::validateStructure, SpawnBlockParticleSystem::deserialize ); - register(154, "PlaySoundEvent2D", PlaySoundEvent2D.class, 13, 13, false, PlaySoundEvent2D::validateStructure, PlaySoundEvent2D::deserialize); - register(155, "PlaySoundEvent3D", PlaySoundEvent3D.class, 38, 38, false, PlaySoundEvent3D::validateStructure, PlaySoundEvent3D::deserialize); register( - 156, "PlaySoundEventEntity", PlaySoundEventEntity.class, 16, 16, false, PlaySoundEventEntity::validateStructure, PlaySoundEventEntity::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 154, + "PlaySoundEvent2D", + PlaySoundEvent2D.class, + 13, + 13, + false, + PlaySoundEvent2D::validateStructure, + PlaySoundEvent2D::deserialize ); - register(157, "UpdateSleepState", UpdateSleepState.class, 36, 65536050, false, UpdateSleepState::validateStructure, UpdateSleepState::deserialize); - register(158, "SetPaused", SetPaused.class, 1, 1, false, SetPaused::validateStructure, SetPaused::deserialize); - register(159, "ServerSetPaused", ServerSetPaused.class, 1, 1, false, ServerSetPaused::validateStructure, ServerSetPaused::deserialize); - register(160, "SetEntitySeed", SetEntitySeed.class, 4, 4, false, SetEntitySeed::validateStructure, SetEntitySeed::deserialize); - register(161, "EntityUpdates", EntityUpdates.class, 1, 1677721600, true, EntityUpdates::validateStructure, EntityUpdates::deserialize); - register(162, "PlayAnimation", PlayAnimation.class, 6, 32768024, false, PlayAnimation::validateStructure, PlayAnimation::deserialize); - register(163, "ChangeVelocity", ChangeVelocity.class, 35, 35, false, ChangeVelocity::validateStructure, ChangeVelocity::deserialize); - register(164, "ApplyKnockback", ApplyKnockback.class, 38, 38, false, ApplyKnockback::validateStructure, ApplyKnockback::deserialize); register( - 165, "SpawnModelParticles", SpawnModelParticles.class, 5, 1677721600, false, SpawnModelParticles::validateStructure, SpawnModelParticles::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 155, + "PlaySoundEvent3D", + PlaySoundEvent3D.class, + 38, + 38, + false, + PlaySoundEvent3D::validateStructure, + PlaySoundEvent3D::deserialize ); - register(166, "MountMovement", MountMovement.class, 59, 59, false, MountMovement::validateStructure, MountMovement::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 156, + "PlaySoundEventEntity", + PlaySoundEventEntity.class, + 16, + 16, + false, + PlaySoundEventEntity::validateStructure, + PlaySoundEventEntity::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 157, + "UpdateSleepState", + UpdateSleepState.class, + 36, + 65536050, + false, + UpdateSleepState::validateStructure, + UpdateSleepState::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 158, + "SetPaused", + SetPaused.class, + 1, + 1, + false, + SetPaused::validateStructure, + SetPaused::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 159, + "ServerSetPaused", + ServerSetPaused.class, + 1, + 1, + false, + ServerSetPaused::validateStructure, + ServerSetPaused::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 160, + "SetEntitySeed", + SetEntitySeed.class, + 4, + 4, + false, + SetEntitySeed::validateStructure, + SetEntitySeed::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 161, + "EntityUpdates", + EntityUpdates.class, + 1, + 1677721600, + true, + EntityUpdates::validateStructure, + EntityUpdates::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 162, + "PlayAnimation", + PlayAnimation.class, + 6, + 32768024, + false, + PlayAnimation::validateStructure, + PlayAnimation::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 163, + "ChangeVelocity", + ChangeVelocity.class, + 35, + 35, + false, + ChangeVelocity::validateStructure, + ChangeVelocity::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 164, + "ApplyKnockback", + ApplyKnockback.class, + 38, + 38, + false, + ApplyKnockback::validateStructure, + ApplyKnockback::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 165, + "SpawnModelParticles", + SpawnModelParticles.class, + 5, + 1677721600, + false, + SpawnModelParticles::validateStructure, + SpawnModelParticles::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 166, + "MountMovement", + MountMovement.class, + 59, + 59, + false, + MountMovement::validateStructure, + MountMovement::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 170, "UpdatePlayerInventory", UpdatePlayerInventory.class, @@ -727,9 +1848,33 @@ public final class PacketRegistry { UpdatePlayerInventory::validateStructure, UpdatePlayerInventory::deserialize ); - register(171, "SetCreativeItem", SetCreativeItem.class, 9, 16384019, false, SetCreativeItem::validateStructure, SetCreativeItem::deserialize); - register(172, "DropCreativeItem", DropCreativeItem.class, 0, 16384010, false, DropCreativeItem::validateStructure, DropCreativeItem::deserialize); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 171, + "SetCreativeItem", + SetCreativeItem.class, + 9, + 16384019, + false, + SetCreativeItem::validateStructure, + SetCreativeItem::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 172, + "DropCreativeItem", + DropCreativeItem.class, + 0, + 16384010, + false, + DropCreativeItem::validateStructure, + DropCreativeItem::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 173, "SmartGiveCreativeItem", SmartGiveCreativeItem.class, @@ -739,11 +1884,57 @@ public final class PacketRegistry { SmartGiveCreativeItem::validateStructure, SmartGiveCreativeItem::deserialize ); - register(174, "DropItemStack", DropItemStack.class, 12, 12, false, DropItemStack::validateStructure, DropItemStack::deserialize); - register(175, "MoveItemStack", MoveItemStack.class, 20, 20, false, MoveItemStack::validateStructure, MoveItemStack::deserialize); - register(176, "SmartMoveItemStack", SmartMoveItemStack.class, 13, 13, false, SmartMoveItemStack::validateStructure, SmartMoveItemStack::deserialize); - register(177, "SetActiveSlot", SetActiveSlot.class, 8, 8, false, SetActiveSlot::validateStructure, SetActiveSlot::deserialize); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 174, + "DropItemStack", + DropItemStack.class, + 12, + 12, + false, + DropItemStack::validateStructure, + DropItemStack::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 175, + "MoveItemStack", + MoveItemStack.class, + 20, + 20, + false, + MoveItemStack::validateStructure, + MoveItemStack::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 176, + "SmartMoveItemStack", + SmartMoveItemStack.class, + 13, + 13, + false, + SmartMoveItemStack::validateStructure, + SmartMoveItemStack::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 177, + "SetActiveSlot", + SetActiveSlot.class, + 8, + 8, + false, + SetActiveSlot::validateStructure, + SetActiveSlot::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 178, "SwitchHotbarBlockSet", SwitchHotbarBlockSet.class, @@ -753,25 +1944,225 @@ public final class PacketRegistry { SwitchHotbarBlockSet::validateStructure, SwitchHotbarBlockSet::deserialize ); - register(179, "InventoryAction", InventoryAction.class, 6, 6, false, InventoryAction::validateStructure, InventoryAction::deserialize); - register(200, "OpenWindow", OpenWindow.class, 6, 1677721600, true, OpenWindow::validateStructure, OpenWindow::deserialize); - register(201, "UpdateWindow", UpdateWindow.class, 5, 1677721600, true, UpdateWindow::validateStructure, UpdateWindow::deserialize); - register(202, "CloseWindow", CloseWindow.class, 4, 4, false, CloseWindow::validateStructure, CloseWindow::deserialize); - register(203, "SendWindowAction", SendWindowAction.class, 4, 32768027, false, SendWindowAction::validateStructure, SendWindowAction::deserialize); - register(204, "ClientOpenWindow", ClientOpenWindow.class, 1, 1, false, ClientOpenWindow::validateStructure, ClientOpenWindow::deserialize); - register(210, "ServerMessage", ServerMessage.class, 2, 1677721600, false, ServerMessage::validateStructure, ServerMessage::deserialize); - register(211, "ChatMessage", ChatMessage.class, 1, 16384006, false, ChatMessage::validateStructure, ChatMessage::deserialize); - register(212, "Notification", Notification.class, 2, 1677721600, false, Notification::validateStructure, Notification::deserialize); - register(213, "KillFeedMessage", KillFeedMessage.class, 1, 1677721600, false, KillFeedMessage::validateStructure, KillFeedMessage::deserialize); - register(214, "ShowEventTitle", ShowEventTitle.class, 14, 1677721600, false, ShowEventTitle::validateStructure, ShowEventTitle::deserialize); - register(215, "HideEventTitle", HideEventTitle.class, 4, 4, false, HideEventTitle::validateStructure, HideEventTitle::deserialize); - register(216, "SetPage", SetPage.class, 2, 2, false, SetPage::validateStructure, SetPage::deserialize); - register(217, "CustomHud", CustomHud.class, 2, 1677721600, true, CustomHud::validateStructure, CustomHud::deserialize); - register(218, "CustomPage", CustomPage.class, 4, 1677721600, true, CustomPage::validateStructure, CustomPage::deserialize); - register(219, "CustomPageEvent", CustomPageEvent.class, 2, 16384007, false, CustomPageEvent::validateStructure, CustomPageEvent::deserialize); - register(222, "EditorBlocksChange", EditorBlocksChange.class, 30, 139264048, true, EditorBlocksChange::validateStructure, EditorBlocksChange::deserialize); - register(223, "ServerInfo", ServerInfo.class, 5, 32768023, false, ServerInfo::validateStructure, ServerInfo::deserialize); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 179, + "InventoryAction", + InventoryAction.class, + 6, + 6, + false, + InventoryAction::validateStructure, + InventoryAction::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 200, + "OpenWindow", + OpenWindow.class, + 6, + 1677721600, + true, + OpenWindow::validateStructure, + OpenWindow::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 201, + "UpdateWindow", + UpdateWindow.class, + 5, + 1677721600, + true, + UpdateWindow::validateStructure, + UpdateWindow::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 202, + "CloseWindow", + CloseWindow.class, + 4, + 4, + false, + CloseWindow::validateStructure, + CloseWindow::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 203, + "SendWindowAction", + SendWindowAction.class, + 4, + 32768027, + false, + SendWindowAction::validateStructure, + SendWindowAction::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 204, + "ClientOpenWindow", + ClientOpenWindow.class, + 1, + 1, + false, + ClientOpenWindow::validateStructure, + ClientOpenWindow::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 210, + "ServerMessage", + ServerMessage.class, + 2, + 1677721600, + false, + ServerMessage::validateStructure, + ServerMessage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 211, + "ChatMessage", + ChatMessage.class, + 1, + 16384006, + false, + ChatMessage::validateStructure, + ChatMessage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 212, + "Notification", + Notification.class, + 2, + 1677721600, + false, + Notification::validateStructure, + Notification::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 213, + "KillFeedMessage", + KillFeedMessage.class, + 1, + 1677721600, + false, + KillFeedMessage::validateStructure, + KillFeedMessage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 214, + "ShowEventTitle", + ShowEventTitle.class, + 14, + 1677721600, + false, + ShowEventTitle::validateStructure, + ShowEventTitle::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 215, + "HideEventTitle", + HideEventTitle.class, + 4, + 4, + false, + HideEventTitle::validateStructure, + HideEventTitle::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 216, + "SetPage", + SetPage.class, + 2, + 2, + false, + SetPage::validateStructure, + SetPage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 217, + "CustomHud", + CustomHud.class, + 2, + 1677721600, + true, + CustomHud::validateStructure, + CustomHud::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 218, + "CustomPage", + CustomPage.class, + 4, + 1677721600, + true, + CustomPage::validateStructure, + CustomPage::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 219, + "CustomPageEvent", + CustomPageEvent.class, + 2, + 16384007, + false, + CustomPageEvent::validateStructure, + CustomPageEvent::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 222, + "EditorBlocksChange", + EditorBlocksChange.class, + 30, + 139264048, + true, + EditorBlocksChange::validateStructure, + EditorBlocksChange::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 223, + "ServerInfo", + ServerInfo.class, + 5, + 32768023, + false, + ServerInfo::validateStructure, + ServerInfo::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 224, "AddToServerPlayerList", AddToServerPlayerList.class, @@ -782,6 +2173,8 @@ public final class PacketRegistry { AddToServerPlayerList::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 225, "RemoveFromServerPlayerList", RemoveFromServerPlayerList.class, @@ -792,6 +2185,8 @@ public final class PacketRegistry { RemoveFromServerPlayerList::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 226, "UpdateServerPlayerList", UpdateServerPlayerList.class, @@ -802,6 +2197,8 @@ public final class PacketRegistry { UpdateServerPlayerList::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 227, "UpdateServerPlayerListPing", UpdateServerPlayerListPing.class, @@ -812,10 +2209,32 @@ public final class PacketRegistry { UpdateServerPlayerListPing::deserialize ); register( - 228, "UpdateKnownRecipes", UpdateKnownRecipes.class, 1, 1677721600, false, UpdateKnownRecipes::validateStructure, UpdateKnownRecipes::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 228, + "UpdateKnownRecipes", + UpdateKnownRecipes.class, + 1, + 1677721600, + false, + UpdateKnownRecipes::validateStructure, + UpdateKnownRecipes::deserialize ); - register(229, "UpdatePortal", UpdatePortal.class, 6, 16384020, false, UpdatePortal::validateStructure, UpdatePortal::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 229, + "UpdatePortal", + UpdatePortal.class, + 6, + 16384020, + false, + UpdatePortal::validateStructure, + UpdatePortal::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 230, "UpdateVisibleHudComponents", UpdateVisibleHudComponents.class, @@ -826,6 +2245,8 @@ public final class PacketRegistry { UpdateVisibleHudComponents::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 231, "ResetUserInterfaceState", ResetUserInterfaceState.class, @@ -835,12 +2256,57 @@ public final class PacketRegistry { ResetUserInterfaceState::validateStructure, ResetUserInterfaceState::deserialize ); - register(232, "UpdateLanguage", UpdateLanguage.class, 1, 16384006, false, UpdateLanguage::validateStructure, UpdateLanguage::deserialize); - register(233, "WorldSavingStatus", WorldSavingStatus.class, 1, 1, false, WorldSavingStatus::validateStructure, WorldSavingStatus::deserialize); register( - 234, "OpenChatWithCommand", OpenChatWithCommand.class, 1, 16384006, false, OpenChatWithCommand::validateStructure, OpenChatWithCommand::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 232, + "UpdateLanguage", + UpdateLanguage.class, + 1, + 16384006, + false, + UpdateLanguage::validateStructure, + UpdateLanguage::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 233, + "WorldSavingStatus", + WorldSavingStatus.class, + 1, + 1, + false, + WorldSavingStatus::validateStructure, + WorldSavingStatus::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 234, + "OpenChatWithCommand", + OpenChatWithCommand.class, + 1, + 16384006, + false, + OpenChatWithCommand::validateStructure, + OpenChatWithCommand::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 235, + "UpdateAnchorUI", + UpdateAnchorUI.class, + 2, + 1677721600, + true, + UpdateAnchorUI::validateStructure, + UpdateAnchorUI::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 240, "UpdateWorldMapSettings", UpdateWorldMapSettings.class, @@ -850,12 +2316,45 @@ public final class PacketRegistry { UpdateWorldMapSettings::validateStructure, UpdateWorldMapSettings::deserialize ); - register(241, "UpdateWorldMap", UpdateWorldMap.class, 1, 1677721600, true, UpdateWorldMap::validateStructure, UpdateWorldMap::deserialize); - register(242, "ClearWorldMap", ClearWorldMap.class, 0, 0, false, ClearWorldMap::validateStructure, ClearWorldMap::deserialize); register( - 243, "UpdateWorldMapVisible", UpdateWorldMapVisible.class, 1, 1, false, UpdateWorldMapVisible::validateStructure, UpdateWorldMapVisible::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.WorldMap, + 241, + "UpdateWorldMap", + UpdateWorldMap.class, + 1, + 1677721600, + true, + UpdateWorldMap::validateStructure, + UpdateWorldMap::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.WorldMap, + 242, + "ClearWorldMap", + ClearWorldMap.class, + 0, + 0, + false, + ClearWorldMap::validateStructure, + ClearWorldMap::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 243, + "UpdateWorldMapVisible", + UpdateWorldMapVisible.class, + 1, + 1, + false, + UpdateWorldMapVisible::validateStructure, + UpdateWorldMapVisible::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 244, "TeleportToWorldMapMarker", TeleportToWorldMapMarker.class, @@ -866,6 +2365,8 @@ public final class PacketRegistry { TeleportToWorldMapMarker::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 245, "TeleportToWorldMapPosition", TeleportToWorldMapPosition.class, @@ -875,13 +2376,57 @@ public final class PacketRegistry { TeleportToWorldMapPosition::validateStructure, TeleportToWorldMapPosition::deserialize ); - register(246, "CreateUserMarker", CreateUserMarker.class, 13, 32768031, false, CreateUserMarker::validateStructure, CreateUserMarker::deserialize); - register(250, "RequestServerAccess", RequestServerAccess.class, 3, 3, false, RequestServerAccess::validateStructure, RequestServerAccess::deserialize); register( - 251, "UpdateServerAccess", UpdateServerAccess.class, 2, 1677721600, false, UpdateServerAccess::validateStructure, UpdateServerAccess::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 246, + "CreateUserMarker", + CreateUserMarker.class, + 13, + 32768031, + false, + CreateUserMarker::validateStructure, + CreateUserMarker::deserialize ); - register(252, "SetServerAccess", SetServerAccess.class, 2, 16384007, false, SetServerAccess::validateStructure, SetServerAccess::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 250, + "RequestServerAccess", + RequestServerAccess.class, + 3, + 3, + false, + RequestServerAccess::validateStructure, + RequestServerAccess::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 251, + "UpdateServerAccess", + UpdateServerAccess.class, + 2, + 1677721600, + false, + UpdateServerAccess::validateStructure, + UpdateServerAccess::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 252, + "SetServerAccess", + SetServerAccess.class, + 2, + 16384007, + false, + SetServerAccess::validateStructure, + SetServerAccess::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 260, "RequestMachinimaActorModel", RequestMachinimaActorModel.class, @@ -892,6 +2437,8 @@ public final class PacketRegistry { RequestMachinimaActorModel::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 261, "SetMachinimaActorModel", SetMachinimaActorModel.class, @@ -902,13 +2449,68 @@ public final class PacketRegistry { SetMachinimaActorModel::deserialize ); register( - 262, "UpdateMachinimaScene", UpdateMachinimaScene.class, 6, 36864033, true, UpdateMachinimaScene::validateStructure, UpdateMachinimaScene::deserialize + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 262, + "UpdateMachinimaScene", + UpdateMachinimaScene.class, + 6, + 36864033, + true, + UpdateMachinimaScene::validateStructure, + UpdateMachinimaScene::deserialize ); - register(280, "SetServerCamera", SetServerCamera.class, 157, 157, false, SetServerCamera::validateStructure, SetServerCamera::deserialize); - register(281, "CameraShakeEffect", CameraShakeEffect.class, 9, 9, false, CameraShakeEffect::validateStructure, CameraShakeEffect::deserialize); - register(282, "RequestFlyCameraMode", RequestFlyCameraMode.class, 1, 1, false, RequestFlyCameraMode::validateStructure, RequestFlyCameraMode::deserialize); - register(283, "SetFlyCameraMode", SetFlyCameraMode.class, 1, 1, false, SetFlyCameraMode::validateStructure, SetFlyCameraMode::deserialize); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 280, + "SetServerCamera", + SetServerCamera.class, + 157, + 157, + false, + SetServerCamera::validateStructure, + SetServerCamera::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 281, + "CameraShakeEffect", + CameraShakeEffect.class, + 9, + 9, + false, + CameraShakeEffect::validateStructure, + CameraShakeEffect::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 282, + "RequestFlyCameraMode", + RequestFlyCameraMode.class, + 1, + 1, + false, + RequestFlyCameraMode::validateStructure, + RequestFlyCameraMode::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 283, + "SetFlyCameraMode", + SetFlyCameraMode.class, + 1, + 1, + false, + SetFlyCameraMode::validateStructure, + SetFlyCameraMode::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, 290, "SyncInteractionChains", SyncInteractionChains.class, @@ -919,6 +2521,8 @@ public final class PacketRegistry { SyncInteractionChains::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 291, "CancelInteractionChain", CancelInteractionChain.class, @@ -928,15 +2532,81 @@ public final class PacketRegistry { CancelInteractionChain::validateStructure, CancelInteractionChain::deserialize ); - register(292, "PlayInteractionFor", PlayInteractionFor.class, 19, 16385065, false, PlayInteractionFor::validateStructure, PlayInteractionFor::deserialize); - register(293, "MountNPC", MountNPC.class, 16, 16, false, MountNPC::validateStructure, MountNPC::deserialize); - register(294, "DismountNPC", DismountNPC.class, 0, 0, false, DismountNPC::validateStructure, DismountNPC::deserialize); - register(300, "FailureReply", FailureReply.class, 5, 1677721600, false, FailureReply::validateStructure, FailureReply::deserialize); - register(301, "SuccessReply", SuccessReply.class, 5, 1677721600, false, SuccessReply::validateStructure, SuccessReply::deserialize); register( - 302, "AssetEditorInitialize", AssetEditorInitialize.class, 0, 0, false, AssetEditorInitialize::validateStructure, AssetEditorInitialize::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 292, + "PlayInteractionFor", + PlayInteractionFor.class, + 19, + 16385065, + false, + PlayInteractionFor::validateStructure, + PlayInteractionFor::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 293, + "MountNPC", + MountNPC.class, + 16, + 16, + false, + MountNPC::validateStructure, + MountNPC::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 294, + "DismountNPC", + DismountNPC.class, + 0, + 0, + false, + DismountNPC::validateStructure, + DismountNPC::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 300, + "FailureReply", + FailureReply.class, + 5, + 1677721600, + false, + FailureReply::validateStructure, + FailureReply::deserialize + ); + register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, + 301, + "SuccessReply", + SuccessReply.class, + 5, + 1677721600, + false, + SuccessReply::validateStructure, + SuccessReply::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 302, + "AssetEditorInitialize", + AssetEditorInitialize.class, + 0, + 0, + false, + AssetEditorInitialize::validateStructure, + AssetEditorInitialize::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 303, "AssetEditorAuthorization", AssetEditorAuthorization.class, @@ -947,6 +2617,8 @@ public final class PacketRegistry { AssetEditorAuthorization::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 304, "AssetEditorCapabilities", AssetEditorCapabilities.class, @@ -957,6 +2629,8 @@ public final class PacketRegistry { AssetEditorCapabilities::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 305, "AssetEditorSetupSchemas", AssetEditorSetupSchemas.class, @@ -967,6 +2641,8 @@ public final class PacketRegistry { AssetEditorSetupSchemas::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 306, "AssetEditorSetupAssetTypes", AssetEditorSetupAssetTypes.class, @@ -977,6 +2653,8 @@ public final class PacketRegistry { AssetEditorSetupAssetTypes::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 307, "AssetEditorCreateDirectory", AssetEditorCreateDirectory.class, @@ -987,6 +2665,8 @@ public final class PacketRegistry { AssetEditorCreateDirectory::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 308, "AssetEditorDeleteDirectory", AssetEditorDeleteDirectory.class, @@ -997,6 +2677,8 @@ public final class PacketRegistry { AssetEditorDeleteDirectory::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 309, "AssetEditorRenameDirectory", AssetEditorRenameDirectory.class, @@ -1007,6 +2689,8 @@ public final class PacketRegistry { AssetEditorRenameDirectory::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 310, "AssetEditorFetchAsset", AssetEditorFetchAsset.class, @@ -1017,6 +2701,8 @@ public final class PacketRegistry { AssetEditorFetchAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 311, "AssetEditorFetchJsonAssetWithParents", AssetEditorFetchJsonAssetWithParents.class, @@ -1027,6 +2713,8 @@ public final class PacketRegistry { AssetEditorFetchJsonAssetWithParents::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 312, "AssetEditorFetchAssetReply", AssetEditorFetchAssetReply.class, @@ -1037,6 +2725,8 @@ public final class PacketRegistry { AssetEditorFetchAssetReply::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 313, "AssetEditorFetchJsonAssetWithParentsReply", AssetEditorFetchJsonAssetWithParentsReply.class, @@ -1047,6 +2737,8 @@ public final class PacketRegistry { AssetEditorFetchJsonAssetWithParentsReply::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 314, "AssetEditorAssetPackSetup", AssetEditorAssetPackSetup.class, @@ -1057,6 +2749,8 @@ public final class PacketRegistry { AssetEditorAssetPackSetup::deserialize ); register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, 315, "AssetEditorUpdateAssetPack", AssetEditorUpdateAssetPack.class, @@ -1067,6 +2761,8 @@ public final class PacketRegistry { AssetEditorUpdateAssetPack::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 316, "AssetEditorCreateAssetPack", AssetEditorCreateAssetPack.class, @@ -1077,6 +2773,8 @@ public final class PacketRegistry { AssetEditorCreateAssetPack::deserialize ); register( + PacketRegistry.PacketDirection.Both, + NetworkChannel.Default, 317, "AssetEditorDeleteAssetPack", AssetEditorDeleteAssetPack.class, @@ -1087,16 +2785,8 @@ public final class PacketRegistry { AssetEditorDeleteAssetPack::deserialize ); register( - 318, - "AssetEditorEnableAssetPack", - AssetEditorEnableAssetPack.class, - 2, - 16384007, - false, - AssetEditorEnableAssetPack::validateStructure, - AssetEditorEnableAssetPack::deserialize - ); - register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 319, "AssetEditorAssetListSetup", AssetEditorAssetListSetup.class, @@ -1107,6 +2797,8 @@ public final class PacketRegistry { AssetEditorAssetListSetup::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 320, "AssetEditorAssetListUpdate", AssetEditorAssetListUpdate.class, @@ -1117,6 +2809,8 @@ public final class PacketRegistry { AssetEditorAssetListUpdate::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 321, "AssetEditorRequestChildrenList", AssetEditorRequestChildrenList.class, @@ -1127,6 +2821,8 @@ public final class PacketRegistry { AssetEditorRequestChildrenList::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 322, "AssetEditorRequestChildrenListReply", AssetEditorRequestChildrenListReply.class, @@ -1137,6 +2833,8 @@ public final class PacketRegistry { AssetEditorRequestChildrenListReply::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 323, "AssetEditorUpdateJsonAsset", AssetEditorUpdateJsonAsset.class, @@ -1147,6 +2845,8 @@ public final class PacketRegistry { AssetEditorUpdateJsonAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 324, "AssetEditorUpdateAsset", AssetEditorUpdateAsset.class, @@ -1157,6 +2857,8 @@ public final class PacketRegistry { AssetEditorUpdateAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 325, "AssetEditorJsonAssetUpdated", AssetEditorJsonAssetUpdated.class, @@ -1167,6 +2869,8 @@ public final class PacketRegistry { AssetEditorJsonAssetUpdated::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 326, "AssetEditorAssetUpdated", AssetEditorAssetUpdated.class, @@ -1177,6 +2881,8 @@ public final class PacketRegistry { AssetEditorAssetUpdated::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 327, "AssetEditorCreateAsset", AssetEditorCreateAsset.class, @@ -1187,6 +2893,8 @@ public final class PacketRegistry { AssetEditorCreateAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 328, "AssetEditorRenameAsset", AssetEditorRenameAsset.class, @@ -1197,6 +2905,8 @@ public final class PacketRegistry { AssetEditorRenameAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 329, "AssetEditorDeleteAsset", AssetEditorDeleteAsset.class, @@ -1207,6 +2917,8 @@ public final class PacketRegistry { AssetEditorDeleteAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 330, "AssetEditorDiscardChanges", AssetEditorDiscardChanges.class, @@ -1217,6 +2929,8 @@ public final class PacketRegistry { AssetEditorDiscardChanges::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 331, "AssetEditorFetchAutoCompleteData", AssetEditorFetchAutoCompleteData.class, @@ -1227,6 +2941,8 @@ public final class PacketRegistry { AssetEditorFetchAutoCompleteData::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 332, "AssetEditorFetchAutoCompleteDataReply", AssetEditorFetchAutoCompleteDataReply.class, @@ -1237,6 +2953,8 @@ public final class PacketRegistry { AssetEditorFetchAutoCompleteDataReply::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 333, "AssetEditorRequestDataset", AssetEditorRequestDataset.class, @@ -1247,6 +2965,8 @@ public final class PacketRegistry { AssetEditorRequestDataset::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 334, "AssetEditorRequestDatasetReply", AssetEditorRequestDatasetReply.class, @@ -1257,6 +2977,8 @@ public final class PacketRegistry { AssetEditorRequestDatasetReply::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 335, "AssetEditorActivateButton", AssetEditorActivateButton.class, @@ -1267,6 +2989,8 @@ public final class PacketRegistry { AssetEditorActivateButton::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 336, "AssetEditorSelectAsset", AssetEditorSelectAsset.class, @@ -1277,6 +3001,8 @@ public final class PacketRegistry { AssetEditorSelectAsset::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 337, "AssetEditorPopupNotification", AssetEditorPopupNotification.class, @@ -1287,6 +3013,8 @@ public final class PacketRegistry { AssetEditorPopupNotification::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 338, "AssetEditorFetchLastModifiedAssets", AssetEditorFetchLastModifiedAssets.class, @@ -1297,6 +3025,8 @@ public final class PacketRegistry { AssetEditorFetchLastModifiedAssets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 339, "AssetEditorLastModifiedAssets", AssetEditorLastModifiedAssets.class, @@ -1307,6 +3037,8 @@ public final class PacketRegistry { AssetEditorLastModifiedAssets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 340, "AssetEditorModifiedAssetsCount", AssetEditorModifiedAssetsCount.class, @@ -1317,6 +3049,8 @@ public final class PacketRegistry { AssetEditorModifiedAssetsCount::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 341, "AssetEditorSubscribeModifiedAssetsChanges", AssetEditorSubscribeModifiedAssetsChanges.class, @@ -1327,6 +3061,8 @@ public final class PacketRegistry { AssetEditorSubscribeModifiedAssetsChanges::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 342, "AssetEditorExportAssets", AssetEditorExportAssets.class, @@ -1337,6 +3073,8 @@ public final class PacketRegistry { AssetEditorExportAssets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 343, "AssetEditorExportAssetInitialize", AssetEditorExportAssetInitialize.class, @@ -1347,6 +3085,8 @@ public final class PacketRegistry { AssetEditorExportAssetInitialize::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 344, "AssetEditorExportAssetPart", AssetEditorExportAssetPart.class, @@ -1357,6 +3097,8 @@ public final class PacketRegistry { AssetEditorExportAssetPart::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 345, "AssetEditorExportAssetFinalize", AssetEditorExportAssetFinalize.class, @@ -1367,6 +3109,8 @@ public final class PacketRegistry { AssetEditorExportAssetFinalize::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 346, "AssetEditorExportDeleteAssets", AssetEditorExportDeleteAssets.class, @@ -1377,6 +3121,8 @@ public final class PacketRegistry { AssetEditorExportDeleteAssets::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 347, "AssetEditorExportComplete", AssetEditorExportComplete.class, @@ -1387,16 +3133,8 @@ public final class PacketRegistry { AssetEditorExportComplete::deserialize ); register( - 348, - "AssetEditorRebuildCaches", - AssetEditorRebuildCaches.class, - 5, - 5, - false, - AssetEditorRebuildCaches::validateStructure, - AssetEditorRebuildCaches::deserialize - ); - register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 349, "AssetEditorUndoChanges", AssetEditorUndoChanges.class, @@ -1407,6 +3145,8 @@ public final class PacketRegistry { AssetEditorUndoChanges::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 350, "AssetEditorRedoChanges", AssetEditorRedoChanges.class, @@ -1417,6 +3157,8 @@ public final class PacketRegistry { AssetEditorRedoChanges::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 351, "AssetEditorUndoRedoReply", AssetEditorUndoRedoReply.class, @@ -1427,6 +3169,8 @@ public final class PacketRegistry { AssetEditorUndoRedoReply::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 352, "AssetEditorSetGameTime", AssetEditorSetGameTime.class, @@ -1437,6 +3181,8 @@ public final class PacketRegistry { AssetEditorSetGameTime::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 353, "AssetEditorUpdateSecondsPerGameDay", AssetEditorUpdateSecondsPerGameDay.class, @@ -1447,6 +3193,8 @@ public final class PacketRegistry { AssetEditorUpdateSecondsPerGameDay::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 354, "AssetEditorUpdateWeatherPreviewLock", AssetEditorUpdateWeatherPreviewLock.class, @@ -1457,6 +3205,8 @@ public final class PacketRegistry { AssetEditorUpdateWeatherPreviewLock::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 355, "AssetEditorUpdateModelPreview", AssetEditorUpdateModelPreview.class, @@ -1466,11 +3216,33 @@ public final class PacketRegistry { AssetEditorUpdateModelPreview::validateStructure, AssetEditorUpdateModelPreview::deserialize ); - register(360, "UpdateSunSettings", UpdateSunSettings.class, 8, 8, false, UpdateSunSettings::validateStructure, UpdateSunSettings::deserialize); register( - 361, "UpdatePostFxSettings", UpdatePostFxSettings.class, 20, 20, false, UpdatePostFxSettings::validateStructure, UpdatePostFxSettings::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 360, + "UpdateSunSettings", + UpdateSunSettings.class, + 8, + 8, + false, + UpdateSunSettings::validateStructure, + UpdateSunSettings::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 361, + "UpdatePostFxSettings", + UpdatePostFxSettings.class, + 20, + 20, + false, + UpdatePostFxSettings::validateStructure, + UpdatePostFxSettings::deserialize + ); + register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 400, "BuilderToolArgUpdate", BuilderToolArgUpdate.class, @@ -1481,6 +3253,8 @@ public final class PacketRegistry { BuilderToolArgUpdate::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 401, "BuilderToolEntityAction", BuilderToolEntityAction.class, @@ -1491,6 +3265,8 @@ public final class PacketRegistry { BuilderToolEntityAction::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 402, "BuilderToolSetEntityTransform", BuilderToolSetEntityTransform.class, @@ -1501,6 +3277,8 @@ public final class PacketRegistry { BuilderToolSetEntityTransform::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 403, "BuilderToolExtrudeAction", BuilderToolExtrudeAction.class, @@ -1511,19 +3289,32 @@ public final class PacketRegistry { BuilderToolExtrudeAction::deserialize ); register( - 404, "BuilderToolStackArea", BuilderToolStackArea.class, 41, 41, false, BuilderToolStackArea::validateStructure, BuilderToolStackArea::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 404, + "BuilderToolStackArea", + BuilderToolStackArea.class, + 41, + 41, + false, + BuilderToolStackArea::validateStructure, + BuilderToolStackArea::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 405, "BuilderToolSelectionTransform", BuilderToolSelectionTransform.class, - 52, - 16384057, + 80, + 80, false, BuilderToolSelectionTransform::validateStructure, BuilderToolSelectionTransform::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 406, "BuilderToolRotateClipboard", BuilderToolRotateClipboard.class, @@ -1534,6 +3325,8 @@ public final class PacketRegistry { BuilderToolRotateClipboard::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 407, "BuilderToolPasteClipboard", BuilderToolPasteClipboard.class, @@ -1544,6 +3337,8 @@ public final class PacketRegistry { BuilderToolPasteClipboard::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 408, "BuilderToolSetTransformationModeState", BuilderToolSetTransformationModeState.class, @@ -1554,6 +3349,8 @@ public final class PacketRegistry { BuilderToolSetTransformationModeState::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 409, "BuilderToolSelectionUpdate", BuilderToolSelectionUpdate.class, @@ -1564,6 +3361,8 @@ public final class PacketRegistry { BuilderToolSelectionUpdate::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 410, "BuilderToolSelectionToolAskForClipboard", BuilderToolSelectionToolAskForClipboard.class, @@ -1574,6 +3373,8 @@ public final class PacketRegistry { BuilderToolSelectionToolAskForClipboard::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 411, "BuilderToolSelectionToolReplyWithClipboard", BuilderToolSelectionToolReplyWithClipboard.class, @@ -1584,6 +3385,8 @@ public final class PacketRegistry { BuilderToolSelectionToolReplyWithClipboard::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 412, "BuilderToolGeneralAction", BuilderToolGeneralAction.class, @@ -1594,6 +3397,8 @@ public final class PacketRegistry { BuilderToolGeneralAction::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 413, "BuilderToolOnUseInteraction", BuilderToolOnUseInteraction.class, @@ -1604,12 +3409,32 @@ public final class PacketRegistry { BuilderToolOnUseInteraction::deserialize ); register( - 414, "BuilderToolLineAction", BuilderToolLineAction.class, 24, 24, false, BuilderToolLineAction::validateStructure, BuilderToolLineAction::deserialize + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 414, + "BuilderToolLineAction", + BuilderToolLineAction.class, + 24, + 24, + false, + BuilderToolLineAction::validateStructure, + BuilderToolLineAction::deserialize ); register( - 415, "BuilderToolShowAnchor", BuilderToolShowAnchor.class, 12, 12, false, BuilderToolShowAnchor::validateStructure, BuilderToolShowAnchor::deserialize + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, + 415, + "BuilderToolShowAnchor", + BuilderToolShowAnchor.class, + 12, + 12, + false, + BuilderToolShowAnchor::validateStructure, + BuilderToolShowAnchor::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 416, "BuilderToolHideAnchors", BuilderToolHideAnchors.class, @@ -1619,8 +3444,21 @@ public final class PacketRegistry { BuilderToolHideAnchors::validateStructure, BuilderToolHideAnchors::deserialize ); - register(417, "PrefabUnselectPrefab", PrefabUnselectPrefab.class, 0, 0, false, PrefabUnselectPrefab::validateStructure, PrefabUnselectPrefab::deserialize); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, + 417, + "PrefabUnselectPrefab", + PrefabUnselectPrefab.class, + 0, + 0, + false, + PrefabUnselectPrefab::validateStructure, + PrefabUnselectPrefab::deserialize + ); + register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 418, "BuilderToolsSetSoundSet", BuilderToolsSetSoundSet.class, @@ -1631,6 +3469,8 @@ public final class PacketRegistry { BuilderToolsSetSoundSet::deserialize ); register( + PacketRegistry.PacketDirection.ToClient, + NetworkChannel.Default, 419, "BuilderToolLaserPointer", BuilderToolLaserPointer.class, @@ -1641,6 +3481,8 @@ public final class PacketRegistry { BuilderToolLaserPointer::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 420, "BuilderToolSetEntityScale", BuilderToolSetEntityScale.class, @@ -1651,6 +3493,8 @@ public final class PacketRegistry { BuilderToolSetEntityScale::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 421, "BuilderToolSetEntityPickupEnabled", BuilderToolSetEntityPickupEnabled.class, @@ -1661,6 +3505,8 @@ public final class PacketRegistry { BuilderToolSetEntityPickupEnabled::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 422, "BuilderToolSetEntityLight", BuilderToolSetEntityLight.class, @@ -1671,6 +3517,8 @@ public final class PacketRegistry { BuilderToolSetEntityLight::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 423, "BuilderToolSetNPCDebug", BuilderToolSetNPCDebug.class, @@ -1681,6 +3529,8 @@ public final class PacketRegistry { BuilderToolSetNPCDebug::deserialize ); register( + PacketRegistry.PacketDirection.ToServer, + NetworkChannel.Default, 425, "BuilderToolSetEntityCollision", BuilderToolSetEntityCollision.class, @@ -1692,9 +3542,16 @@ public final class PacketRegistry { ); } + public static enum PacketDirection { + ToServer, + ToClient, + Both; + } + public record PacketInfo( int id, @Nonnull String name, + @Nonnull NetworkChannel channel, @Nonnull Class type, int fixedBlockSize, int maxSize, diff --git a/src/com/hypixel/hytale/protocol/PlayerSkinUpdate.java b/src/com/hypixel/hytale/protocol/PlayerSkinUpdate.java new file mode 100644 index 00000000..ff5d9183 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/PlayerSkinUpdate.java @@ -0,0 +1,116 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class PlayerSkinUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 1; + public static final int FIXED_BLOCK_SIZE = 1; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 1; + public static final int MAX_SIZE = 327680184; + @Nullable + public PlayerSkin skin; + + public PlayerSkinUpdate() { + } + + public PlayerSkinUpdate(@Nullable PlayerSkin skin) { + this.skin = skin; + } + + public PlayerSkinUpdate(@Nonnull PlayerSkinUpdate other) { + this.skin = other.skin; + } + + @Nonnull + public static PlayerSkinUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + PlayerSkinUpdate obj = new PlayerSkinUpdate(); + byte nullBits = buf.getByte(offset); + int pos = offset + 1; + if ((nullBits & 1) != 0) { + obj.skin = PlayerSkin.deserialize(buf, pos); + pos += PlayerSkin.computeBytesConsumed(buf, pos); + } + + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + byte nullBits = buf.getByte(offset); + int pos = offset + 1; + if ((nullBits & 1) != 0) { + pos += PlayerSkin.computeBytesConsumed(buf, pos); + } + + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + byte nullBits = 0; + if (this.skin != null) { + nullBits = (byte)(nullBits | 1); + } + + buf.writeByte(nullBits); + if (this.skin != null) { + this.skin.serialize(buf); + } + + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + int size = 1; + if (this.skin != null) { + size += this.skin.computeSize(); + } + + return size; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 1) { + return ValidationResult.error("Buffer too small: expected at least 1 bytes"); + } else { + byte nullBits = buffer.getByte(offset); + int pos = offset + 1; + if ((nullBits & 1) != 0) { + ValidationResult skinResult = PlayerSkin.validateStructure(buffer, pos); + if (!skinResult.isValid()) { + return ValidationResult.error("Invalid Skin: " + skinResult.error()); + } + + pos += PlayerSkin.computeBytesConsumed(buffer, pos); + } + + return ValidationResult.OK; + } + } + + public PlayerSkinUpdate clone() { + PlayerSkinUpdate copy = new PlayerSkinUpdate(); + copy.skin = this.skin != null ? this.skin.clone() : null; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof PlayerSkinUpdate other ? Objects.equals(this.skin, other.skin) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.skin); + } +} diff --git a/src/com/hypixel/hytale/protocol/PredictionUpdate.java b/src/com/hypixel/hytale/protocol/PredictionUpdate.java new file mode 100644 index 00000000..9687a9d0 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/PredictionUpdate.java @@ -0,0 +1,76 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.PacketIO; +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import java.util.UUID; +import javax.annotation.Nonnull; + +public class PredictionUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 16; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 16; + public static final int MAX_SIZE = 16; + @Nonnull + public UUID predictionId = new UUID(0L, 0L); + + public PredictionUpdate() { + } + + public PredictionUpdate(@Nonnull UUID predictionId) { + this.predictionId = predictionId; + } + + public PredictionUpdate(@Nonnull PredictionUpdate other) { + this.predictionId = other.predictionId; + } + + @Nonnull + public static PredictionUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + PredictionUpdate obj = new PredictionUpdate(); + obj.predictionId = PacketIO.readUUID(buf, offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 16; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + PacketIO.writeUUID(buf, this.predictionId); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 16; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 16 ? ValidationResult.error("Buffer too small: expected at least 16 bytes") : ValidationResult.OK; + } + + public PredictionUpdate clone() { + PredictionUpdate copy = new PredictionUpdate(); + copy.predictionId = this.predictionId; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof PredictionUpdate other ? Objects.equals(this.predictionId, other.predictionId) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.predictionId); + } +} diff --git a/src/com/hypixel/hytale/protocol/PropUpdate.java b/src/com/hypixel/hytale/protocol/PropUpdate.java new file mode 100644 index 00000000..1892e9f7 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/PropUpdate.java @@ -0,0 +1,51 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import javax.annotation.Nonnull; + +public class PropUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 0; + + @Nonnull + public static PropUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + return new PropUpdate(); + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 0; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 0; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 0 ? ValidationResult.error("Buffer too small: expected at least 0 bytes") : ValidationResult.OK; + } + + public PropUpdate clone() { + return new PropUpdate(); + } + + @Override + public boolean equals(Object obj) { + return this == obj ? true : obj instanceof PropUpdate other; + } + + @Override + public int hashCode() { + return 0; + } +} diff --git a/src/com/hypixel/hytale/protocol/ProtocolSettings.java b/src/com/hypixel/hytale/protocol/ProtocolSettings.java index fa698d15..d535f3b1 100644 --- a/src/com/hypixel/hytale/protocol/ProtocolSettings.java +++ b/src/com/hypixel/hytale/protocol/ProtocolSettings.java @@ -1,11 +1,11 @@ package com.hypixel.hytale.protocol; public final class ProtocolSettings { - public static final int PROTOCOL_CRC = 672031543; + public static final int PROTOCOL_CRC = -1356075132; public static final int PROTOCOL_VERSION = 2; - public static final int PROTOCOL_BUILD_NUMBER = 12; - public static final int PACKET_COUNT = 270; - public static final int STRUCT_COUNT = 318; + public static final int PROTOCOL_BUILD_NUMBER = 20; + public static final int PACKET_COUNT = 268; + public static final int STRUCT_COUNT = 339; public static final int ENUM_COUNT = 137; public static final int MAX_PACKET_SIZE = 1677721600; @@ -13,6 +13,6 @@ public final class ProtocolSettings { } public static boolean validateCrc(int crc) { - return 672031543 == crc; + return -1356075132 == crc; } } diff --git a/src/com/hypixel/hytale/protocol/RepulsionUpdate.java b/src/com/hypixel/hytale/protocol/RepulsionUpdate.java new file mode 100644 index 00000000..fb01b04f --- /dev/null +++ b/src/com/hypixel/hytale/protocol/RepulsionUpdate.java @@ -0,0 +1,73 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class RepulsionUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 4; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 4; + public static final int MAX_SIZE = 4; + public int repulsionConfigIndex; + + public RepulsionUpdate() { + } + + public RepulsionUpdate(int repulsionConfigIndex) { + this.repulsionConfigIndex = repulsionConfigIndex; + } + + public RepulsionUpdate(@Nonnull RepulsionUpdate other) { + this.repulsionConfigIndex = other.repulsionConfigIndex; + } + + @Nonnull + public static RepulsionUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + RepulsionUpdate obj = new RepulsionUpdate(); + obj.repulsionConfigIndex = buf.getIntLE(offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 4; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + buf.writeIntLE(this.repulsionConfigIndex); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 4; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 4 ? ValidationResult.error("Buffer too small: expected at least 4 bytes") : ValidationResult.OK; + } + + public RepulsionUpdate clone() { + RepulsionUpdate copy = new RepulsionUpdate(); + copy.repulsionConfigIndex = this.repulsionConfigIndex; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof RepulsionUpdate other ? this.repulsionConfigIndex == other.repulsionConfigIndex : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.repulsionConfigIndex); + } +} diff --git a/src/com/hypixel/hytale/protocol/RespondToHitUpdate.java b/src/com/hypixel/hytale/protocol/RespondToHitUpdate.java new file mode 100644 index 00000000..23bbd078 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/RespondToHitUpdate.java @@ -0,0 +1,51 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import javax.annotation.Nonnull; + +public class RespondToHitUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 0; + + @Nonnull + public static RespondToHitUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + return new RespondToHitUpdate(); + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 0; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 0; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 0 ? ValidationResult.error("Buffer too small: expected at least 0 bytes") : ValidationResult.OK; + } + + public RespondToHitUpdate clone() { + return new RespondToHitUpdate(); + } + + @Override + public boolean equals(Object obj) { + return this == obj ? true : obj instanceof RespondToHitUpdate other; + } + + @Override + public int hashCode() { + return 0; + } +} diff --git a/src/com/hypixel/hytale/protocol/ToClientPacket.java b/src/com/hypixel/hytale/protocol/ToClientPacket.java new file mode 100644 index 00000000..f8d8d45a --- /dev/null +++ b/src/com/hypixel/hytale/protocol/ToClientPacket.java @@ -0,0 +1,4 @@ +package com.hypixel.hytale.protocol; + +public interface ToClientPacket extends Packet { +} diff --git a/src/com/hypixel/hytale/protocol/ToServerPacket.java b/src/com/hypixel/hytale/protocol/ToServerPacket.java new file mode 100644 index 00000000..7b552893 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/ToServerPacket.java @@ -0,0 +1,4 @@ +package com.hypixel.hytale.protocol; + +public interface ToServerPacket extends Packet { +} diff --git a/src/com/hypixel/hytale/protocol/TransformUpdate.java b/src/com/hypixel/hytale/protocol/TransformUpdate.java new file mode 100644 index 00000000..111907ed --- /dev/null +++ b/src/com/hypixel/hytale/protocol/TransformUpdate.java @@ -0,0 +1,74 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ValidationResult; +import io.netty.buffer.ByteBuf; +import java.util.Objects; +import javax.annotation.Nonnull; + +public class TransformUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 49; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 49; + public static final int MAX_SIZE = 49; + @Nonnull + public ModelTransform transform = new ModelTransform(); + + public TransformUpdate() { + } + + public TransformUpdate(@Nonnull ModelTransform transform) { + this.transform = transform; + } + + public TransformUpdate(@Nonnull TransformUpdate other) { + this.transform = other.transform; + } + + @Nonnull + public static TransformUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + TransformUpdate obj = new TransformUpdate(); + obj.transform = ModelTransform.deserialize(buf, offset + 0); + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + return 49; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + this.transform.serialize(buf); + return buf.writerIndex() - startPos; + } + + @Override + public int computeSize() { + return 49; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + return buffer.readableBytes() - offset < 49 ? ValidationResult.error("Buffer too small: expected at least 49 bytes") : ValidationResult.OK; + } + + public TransformUpdate clone() { + TransformUpdate copy = new TransformUpdate(); + copy.transform = this.transform.clone(); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof TransformUpdate other ? Objects.equals(this.transform, other.transform) : false; + } + } + + @Override + public int hashCode() { + return Objects.hash(this.transform); + } +} diff --git a/src/com/hypixel/hytale/protocol/UIComponentsUpdate.java b/src/com/hypixel/hytale/protocol/UIComponentsUpdate.java new file mode 100644 index 00000000..aa3a6077 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/UIComponentsUpdate.java @@ -0,0 +1,124 @@ +package com.hypixel.hytale.protocol; + +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import javax.annotation.Nonnull; + +public class UIComponentsUpdate extends ComponentUpdate { + public static final int NULLABLE_BIT_FIELD_SIZE = 0; + public static final int FIXED_BLOCK_SIZE = 0; + public static final int VARIABLE_FIELD_COUNT = 1; + public static final int VARIABLE_BLOCK_START = 0; + public static final int MAX_SIZE = 16384005; + @Nonnull + public int[] components = new int[0]; + + public UIComponentsUpdate() { + } + + public UIComponentsUpdate(@Nonnull int[] components) { + this.components = components; + } + + public UIComponentsUpdate(@Nonnull UIComponentsUpdate other) { + this.components = other.components; + } + + @Nonnull + public static UIComponentsUpdate deserialize(@Nonnull ByteBuf buf, int offset) { + UIComponentsUpdate obj = new UIComponentsUpdate(); + int pos = offset + 0; + int componentsCount = VarInt.peek(buf, pos); + if (componentsCount < 0) { + throw ProtocolException.negativeLength("Components", componentsCount); + } else if (componentsCount > 4096000) { + throw ProtocolException.arrayTooLong("Components", componentsCount, 4096000); + } else { + int componentsVarLen = VarInt.size(componentsCount); + if (pos + componentsVarLen + componentsCount * 4L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("Components", pos + componentsVarLen + componentsCount * 4, buf.readableBytes()); + } else { + pos += componentsVarLen; + obj.components = new int[componentsCount]; + + for (int i = 0; i < componentsCount; i++) { + obj.components[i] = buf.getIntLE(pos + i * 4); + } + + pos += componentsCount * 4; + return obj; + } + } + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + int pos = offset + 0; + int arrLen = VarInt.peek(buf, pos); + pos += VarInt.length(buf, pos) + arrLen * 4; + return pos - offset; + } + + @Override + public int serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + if (this.components.length > 4096000) { + throw ProtocolException.arrayTooLong("Components", this.components.length, 4096000); + } else { + VarInt.write(buf, this.components.length); + + for (int item : this.components) { + buf.writeIntLE(item); + } + + return buf.writerIndex() - startPos; + } + } + + @Override + public int computeSize() { + int size = 0; + return size + VarInt.size(this.components.length) + this.components.length * 4; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 0) { + return ValidationResult.error("Buffer too small: expected at least 0 bytes"); + } else { + int pos = offset + 0; + int componentsCount = VarInt.peek(buffer, pos); + if (componentsCount < 0) { + return ValidationResult.error("Invalid array count for Components"); + } else if (componentsCount > 4096000) { + return ValidationResult.error("Components exceeds max length 4096000"); + } else { + pos += VarInt.length(buffer, pos); + pos += componentsCount * 4; + return pos > buffer.writerIndex() ? ValidationResult.error("Buffer overflow reading Components") : ValidationResult.OK; + } + } + } + + public UIComponentsUpdate clone() { + UIComponentsUpdate copy = new UIComponentsUpdate(); + copy.components = Arrays.copyOf(this.components, this.components.length); + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return obj instanceof UIComponentsUpdate other ? Arrays.equals(this.components, other.components) : false; + } + } + + @Override + public int hashCode() { + int result = 1; + return 31 * result + Arrays.hashCode(this.components); + } +} diff --git a/src/com/hypixel/hytale/protocol/io/PacketIO.java b/src/com/hypixel/hytale/protocol/io/PacketIO.java index 9e45dda6..623553de 100644 --- a/src/com/hypixel/hytale/protocol/io/PacketIO.java +++ b/src/com/hypixel/hytale/protocol/io/PacketIO.java @@ -305,7 +305,7 @@ public final class PacketIO { if (id == null) { throw new ProtocolException("Unknown packet type: " + packetClass.getName()); } else { - PacketRegistry.PacketInfo info = PacketRegistry.getById(id); + PacketRegistry.PacketInfo info = PacketRegistry.getToClientPacketById(id); int lengthIndex = out.writerIndex(); out.writeIntLE(0); out.writeIntLE(id); @@ -351,7 +351,7 @@ public final class PacketIO { @Nonnull public static Packet readFramedPacket(@Nonnull ByteBuf in, int payloadLength, @Nonnull PacketStatsRecorder statsRecorder) { int packetId = in.readIntLE(); - PacketRegistry.PacketInfo info = PacketRegistry.getById(packetId); + PacketRegistry.PacketInfo info = PacketRegistry.getToServerPacketById(packetId); if (info == null) { in.skipBytes(payloadLength); throw new ProtocolException("Unknown packet ID: " + packetId); diff --git a/src/com/hypixel/hytale/protocol/io/netty/PacketDecoder.java b/src/com/hypixel/hytale/protocol/io/netty/PacketDecoder.java index 2f840bae..ad16d87d 100644 --- a/src/com/hypixel/hytale/protocol/io/netty/PacketDecoder.java +++ b/src/com/hypixel/hytale/protocol/io/netty/PacketDecoder.java @@ -1,5 +1,6 @@ package com.hypixel.hytale.protocol.io.netty; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.PacketRegistry; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.PacketStatsRecorder; @@ -80,30 +81,36 @@ public class PacketDecoder extends ByteToMessageDecoder { int payloadLength = in.readIntLE(); if (payloadLength >= 0 && payloadLength <= 1677721600) { int packetId = in.readIntLE(); - PacketRegistry.PacketInfo packetInfo = PacketRegistry.getById(packetId); + PacketRegistry.PacketInfo packetInfo = PacketRegistry.getToServerPacketById(packetId); if (packetInfo == null) { in.skipBytes(in.readableBytes()); ProtocolUtil.closeConnection(ctx.channel()); } else if (payloadLength > packetInfo.maxSize()) { in.skipBytes(in.readableBytes()); ProtocolUtil.closeConnection(ctx.channel()); - } else if (in.readableBytes() < payloadLength) { - in.resetReaderIndex(); } else { - PacketStatsRecorder statsRecorder = ctx.channel().attr(PacketStatsRecorder.CHANNEL_KEY).get(); - if (statsRecorder == null) { - statsRecorder = PacketStatsRecorder.NOOP; - } + NetworkChannel channelVal = ctx.channel().attr(ProtocolUtil.STREAM_CHANNEL_KEY).get(); + if (channelVal != null && channelVal != packetInfo.channel()) { + in.skipBytes(in.readableBytes()); + ProtocolUtil.closeConnection(ctx.channel()); + } else if (in.readableBytes() < payloadLength) { + in.resetReaderIndex(); + } else { + PacketStatsRecorder statsRecorder = ctx.channel().attr(PacketStatsRecorder.CHANNEL_KEY).get(); + if (statsRecorder == null) { + statsRecorder = PacketStatsRecorder.NOOP; + } - try { - out.add(PacketIO.readFramedPacketWithInfo(in, payloadLength, packetInfo, statsRecorder)); - this.lastPacketTimeNanos = System.nanoTime(); - } catch (ProtocolException var9) { - in.skipBytes(in.readableBytes()); - ProtocolUtil.closeConnection(ctx.channel()); - } catch (IndexOutOfBoundsException var10) { - in.skipBytes(in.readableBytes()); - ProtocolUtil.closeConnection(ctx.channel()); + try { + out.add(PacketIO.readFramedPacketWithInfo(in, payloadLength, packetInfo, statsRecorder)); + this.lastPacketTimeNanos = System.nanoTime(); + } catch (ProtocolException var10) { + in.skipBytes(in.readableBytes()); + ProtocolUtil.closeConnection(ctx.channel()); + } catch (IndexOutOfBoundsException var11) { + in.skipBytes(in.readableBytes()); + ProtocolUtil.closeConnection(ctx.channel()); + } } } } else { diff --git a/src/com/hypixel/hytale/protocol/io/netty/PacketEncoder.java b/src/com/hypixel/hytale/protocol/io/netty/PacketEncoder.java index 15129808..36ee862d 100644 --- a/src/com/hypixel/hytale/protocol/io/netty/PacketEncoder.java +++ b/src/com/hypixel/hytale/protocol/io/netty/PacketEncoder.java @@ -1,6 +1,7 @@ package com.hypixel.hytale.protocol.io.netty; import com.hypixel.hytale.protocol.CachedPacket; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.PacketStatsRecorder; @@ -20,11 +21,16 @@ public class PacketEncoder extends MessageToByteEncoder { packetClass = (Class)packet.getClass(); } - PacketStatsRecorder statsRecorder = ctx.channel().attr(PacketStatsRecorder.CHANNEL_KEY).get(); - if (statsRecorder == null) { - statsRecorder = PacketStatsRecorder.NOOP; - } + NetworkChannel channelAttr = ctx.channel().attr(ProtocolUtil.STREAM_CHANNEL_KEY).get(); + if (channelAttr != null && channelAttr != packet.getChannel()) { + throw new IllegalArgumentException("Packet channel " + packet.getChannel() + " does not match stream channel " + channelAttr); + } else { + PacketStatsRecorder statsRecorder = ctx.channel().attr(PacketStatsRecorder.CHANNEL_KEY).get(); + if (statsRecorder == null) { + statsRecorder = PacketStatsRecorder.NOOP; + } - PacketIO.writeFramedPacket(packet, packetClass, out, statsRecorder); + PacketIO.writeFramedPacket(packet, packetClass, out, statsRecorder); + } } } diff --git a/src/com/hypixel/hytale/protocol/io/netty/ProtocolUtil.java b/src/com/hypixel/hytale/protocol/io/netty/ProtocolUtil.java index 8d1db800..2c7a80c2 100644 --- a/src/com/hypixel/hytale/protocol/io/netty/ProtocolUtil.java +++ b/src/com/hypixel/hytale/protocol/io/netty/ProtocolUtil.java @@ -1,5 +1,6 @@ package com.hypixel.hytale.protocol.io.netty; +import com.hypixel.hytale.protocol.NetworkChannel; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -13,6 +14,7 @@ import java.time.Duration; import javax.annotation.Nonnull; public final class ProtocolUtil { + public static final AttributeKey STREAM_CHANNEL_KEY = AttributeKey.newInstance("STREAM_CHANNEL_ID"); public static final AttributeKey PACKET_TIMEOUT_KEY = AttributeKey.newInstance("PACKET_TIMEOUT"); public static final int APPLICATION_NO_ERROR = 0; public static final int APPLICATION_RATE_LIMITED = 1; diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorActivateButton.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorActivateButton.java index 2285387c..d170e778 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorActivateButton.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorActivateButton.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorActivateButton implements Packet { +public class AssetEditorActivateButton implements Packet, ToServerPacket { public static final int PACKET_ID = 335; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorActivateButton implements Packet { return 335; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorActivateButton() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListSetup.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListSetup.java index f65a3dba..1b128a50 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListSetup.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListSetup.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorAssetListSetup implements Packet { +public class AssetEditorAssetListSetup implements Packet, ToClientPacket { public static final int PACKET_ID = 319; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class AssetEditorAssetListSetup implements Packet { return 319; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorAssetListSetup() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListUpdate.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListUpdate.java index 33bb225a..ee19d5ae 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListUpdate.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetListUpdate.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorAssetListUpdate implements Packet { +public class AssetEditorAssetListUpdate implements Packet, ToClientPacket { public static final int PACKET_ID = 320; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -31,6 +33,11 @@ public class AssetEditorAssetListUpdate implements Packet { return 320; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorAssetListUpdate() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetPackSetup.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetPackSetup.java index 57ae324d..f0c64314 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetPackSetup.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetPackSetup.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -13,7 +15,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorAssetPackSetup implements Packet { +public class AssetEditorAssetPackSetup implements Packet, ToClientPacket { public static final int PACKET_ID = 314; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class AssetEditorAssetPackSetup implements Packet { return 314; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorAssetPackSetup() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetUpdated.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetUpdated.java index 1198f8e6..0dc79b40 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetUpdated.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAssetUpdated.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorAssetUpdated implements Packet { +public class AssetEditorAssetUpdated implements Packet, ToClientPacket { public static final int PACKET_ID = 326; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class AssetEditorAssetUpdated implements Packet { return 326; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorAssetUpdated() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAuthorization.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAuthorization.java index 8ce5f448..97b9c3e9 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAuthorization.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorAuthorization.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorAuthorization implements Packet { +public class AssetEditorAuthorization implements Packet, ToClientPacket { public static final int PACKET_ID = 303; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class AssetEditorAuthorization implements Packet { return 303; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorAuthorization() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCapabilities.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCapabilities.java index cea7bd59..fed1e2bc 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCapabilities.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCapabilities.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorCapabilities implements Packet { +public class AssetEditorCapabilities implements Packet, ToClientPacket { public static final int PACKET_ID = 304; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class AssetEditorCapabilities implements Packet { return 304; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorCapabilities() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAsset.java index 2f29509c..36f4a20f 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAsset.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorCreateAsset implements Packet { +public class AssetEditorCreateAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 327; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -34,6 +36,11 @@ public class AssetEditorCreateAsset implements Packet { return 327; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorCreateAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAssetPack.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAssetPack.java index 065c6fa5..48617296 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAssetPack.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateAssetPack.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorCreateAssetPack implements Packet { +public class AssetEditorCreateAssetPack implements Packet, ToServerPacket { public static final int PACKET_ID = 316; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorCreateAssetPack implements Packet { return 316; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorCreateAssetPack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateDirectory.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateDirectory.java index 81d8810c..6aa5c436 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateDirectory.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorCreateDirectory.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorCreateDirectory implements Packet { +public class AssetEditorCreateDirectory implements Packet, ToServerPacket { public static final int PACKET_ID = 307; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorCreateDirectory implements Packet { return 307; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorCreateDirectory() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAsset.java index 12e6cf90..3a3930fe 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAsset.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorDeleteAsset implements Packet { +public class AssetEditorDeleteAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 329; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorDeleteAsset implements Packet { return 329; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorDeleteAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAssetPack.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAssetPack.java index cf3c7069..1fa57061 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAssetPack.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteAssetPack.java @@ -1,6 +1,9 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorDeleteAssetPack implements Packet { +public class AssetEditorDeleteAssetPack implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 317; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +29,11 @@ public class AssetEditorDeleteAssetPack implements Packet { return 317; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorDeleteAssetPack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteDirectory.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteDirectory.java index 42154672..d15087f9 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteDirectory.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDeleteDirectory.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorDeleteDirectory implements Packet { +public class AssetEditorDeleteDirectory implements Packet, ToServerPacket { public static final int PACKET_ID = 308; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorDeleteDirectory implements Packet { return 308; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorDeleteDirectory() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDiscardChanges.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDiscardChanges.java index 94e49ac2..919db322 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDiscardChanges.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorDiscardChanges.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorDiscardChanges implements Packet { +public class AssetEditorDiscardChanges implements Packet, ToServerPacket { public static final int PACKET_ID = 330; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorDiscardChanges implements Packet { return 330; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorDiscardChanges() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorEnableAssetPack.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorEnableAssetPack.java deleted file mode 100644 index d1e6585c..00000000 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorEnableAssetPack.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.hypixel.hytale.protocol.packets.asseteditor; - -import com.hypixel.hytale.protocol.Packet; -import com.hypixel.hytale.protocol.io.PacketIO; -import com.hypixel.hytale.protocol.io.ProtocolException; -import com.hypixel.hytale.protocol.io.ValidationResult; -import com.hypixel.hytale.protocol.io.VarInt; -import io.netty.buffer.ByteBuf; -import java.util.Objects; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class AssetEditorEnableAssetPack implements Packet { - public static final int PACKET_ID = 318; - public static final boolean IS_COMPRESSED = false; - public static final int NULLABLE_BIT_FIELD_SIZE = 1; - public static final int FIXED_BLOCK_SIZE = 2; - public static final int VARIABLE_FIELD_COUNT = 1; - public static final int VARIABLE_BLOCK_START = 2; - public static final int MAX_SIZE = 16384007; - @Nullable - public String id; - public boolean enabled; - - @Override - public int getId() { - return 318; - } - - public AssetEditorEnableAssetPack() { - } - - public AssetEditorEnableAssetPack(@Nullable String id, boolean enabled) { - this.id = id; - this.enabled = enabled; - } - - public AssetEditorEnableAssetPack(@Nonnull AssetEditorEnableAssetPack other) { - this.id = other.id; - this.enabled = other.enabled; - } - - @Nonnull - public static AssetEditorEnableAssetPack deserialize(@Nonnull ByteBuf buf, int offset) { - AssetEditorEnableAssetPack obj = new AssetEditorEnableAssetPack(); - byte nullBits = buf.getByte(offset); - obj.enabled = buf.getByte(offset + 1) != 0; - int pos = offset + 2; - if ((nullBits & 1) != 0) { - int idLen = VarInt.peek(buf, pos); - if (idLen < 0) { - throw ProtocolException.negativeLength("Id", idLen); - } - - if (idLen > 4096000) { - throw ProtocolException.stringTooLong("Id", idLen, 4096000); - } - - int idVarLen = VarInt.length(buf, pos); - obj.id = PacketIO.readVarString(buf, pos, PacketIO.UTF8); - pos += idVarLen + idLen; - } - - return obj; - } - - public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { - byte nullBits = buf.getByte(offset); - int pos = offset + 2; - if ((nullBits & 1) != 0) { - int sl = VarInt.peek(buf, pos); - pos += VarInt.length(buf, pos) + sl; - } - - return pos - offset; - } - - @Override - public void serialize(@Nonnull ByteBuf buf) { - byte nullBits = 0; - if (this.id != null) { - nullBits = (byte)(nullBits | 1); - } - - buf.writeByte(nullBits); - buf.writeByte(this.enabled ? 1 : 0); - if (this.id != null) { - PacketIO.writeVarString(buf, this.id, 4096000); - } - } - - @Override - public int computeSize() { - int size = 2; - if (this.id != null) { - size += PacketIO.stringSize(this.id); - } - - return size; - } - - public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 2) { - return ValidationResult.error("Buffer too small: expected at least 2 bytes"); - } else { - byte nullBits = buffer.getByte(offset); - int pos = offset + 2; - if ((nullBits & 1) != 0) { - int idLen = VarInt.peek(buffer, pos); - if (idLen < 0) { - return ValidationResult.error("Invalid string length for Id"); - } - - if (idLen > 4096000) { - return ValidationResult.error("Id exceeds max length 4096000"); - } - - pos += VarInt.length(buffer, pos); - pos += idLen; - if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Id"); - } - } - - return ValidationResult.OK; - } - } - - public AssetEditorEnableAssetPack clone() { - AssetEditorEnableAssetPack copy = new AssetEditorEnableAssetPack(); - copy.id = this.id; - copy.enabled = this.enabled; - return copy; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else { - return !(obj instanceof AssetEditorEnableAssetPack other) ? false : Objects.equals(this.id, other.id) && this.enabled == other.enabled; - } - } - - @Override - public int hashCode() { - return Objects.hash(this.id, this.enabled); - } -} diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetFinalize.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetFinalize.java index ad8a7876..e1fee512 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetFinalize.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetFinalize.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class AssetEditorExportAssetFinalize implements Packet { +public class AssetEditorExportAssetFinalize implements Packet, ToClientPacket { public static final int PACKET_ID = 345; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class AssetEditorExportAssetFinalize implements Packet { return 345; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static AssetEditorExportAssetFinalize deserialize(@Nonnull ByteBuf buf, int offset) { return new AssetEditorExportAssetFinalize(); diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetInitialize.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetInitialize.java index 81394c57..809dbf40 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetInitialize.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetInitialize.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorExportAssetInitialize implements Packet { +public class AssetEditorExportAssetInitialize implements Packet, ToClientPacket { public static final int PACKET_ID = 343; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class AssetEditorExportAssetInitialize implements Packet { return 343; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorExportAssetInitialize() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetPart.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetPart.java index 9cf34b02..fcf9cbfa 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetPart.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssetPart.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorExportAssetPart implements Packet { +public class AssetEditorExportAssetPart implements Packet, ToClientPacket { public static final int PACKET_ID = 344; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorExportAssetPart implements Packet { return 344; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorExportAssetPart() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssets.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssets.java index 5cc961ad..d920088a 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportAssets.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorExportAssets implements Packet { +public class AssetEditorExportAssets implements Packet, ToServerPacket { public static final int PACKET_ID = 342; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorExportAssets implements Packet { return 342; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorExportAssets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportComplete.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportComplete.java index 514e49ec..eddb8431 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportComplete.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportComplete.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorExportComplete implements Packet { +public class AssetEditorExportComplete implements Packet, ToClientPacket { public static final int PACKET_ID = 347; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorExportComplete implements Packet { return 347; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorExportComplete() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportDeleteAssets.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportDeleteAssets.java index 8bac5c26..ca60537c 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportDeleteAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorExportDeleteAssets.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorExportDeleteAssets implements Packet { +public class AssetEditorExportDeleteAssets implements Packet, ToClientPacket { public static final int PACKET_ID = 346; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorExportDeleteAssets implements Packet { return 346; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorExportDeleteAssets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAsset.java index faf9a38a..5889a915 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAsset.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchAsset implements Packet { +public class AssetEditorFetchAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 310; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorFetchAsset implements Packet { return 310; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAssetReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAssetReply.java index d80d9441..35bfaae7 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAssetReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAssetReply.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchAssetReply implements Packet { +public class AssetEditorFetchAssetReply implements Packet, ToClientPacket { public static final int PACKET_ID = 312; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorFetchAssetReply implements Packet { return 312; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchAssetReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteData.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteData.java index 667664e7..de412387 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteData.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteData.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchAutoCompleteData implements Packet { +public class AssetEditorFetchAutoCompleteData implements Packet, ToServerPacket { public static final int PACKET_ID = 331; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class AssetEditorFetchAutoCompleteData implements Packet { return 331; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchAutoCompleteData() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteDataReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteDataReply.java index 4720cd65..95f27b4f 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteDataReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchAutoCompleteDataReply.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchAutoCompleteDataReply implements Packet { +public class AssetEditorFetchAutoCompleteDataReply implements Packet, ToClientPacket { public static final int PACKET_ID = 332; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class AssetEditorFetchAutoCompleteDataReply implements Packet { return 332; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchAutoCompleteDataReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParents.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParents.java index 349814fc..61a54f68 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParents.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParents.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchJsonAssetWithParents implements Packet { +public class AssetEditorFetchJsonAssetWithParents implements Packet, ToServerPacket { public static final int PACKET_ID = 311; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorFetchJsonAssetWithParents implements Packet { return 311; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchJsonAssetWithParents() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParentsReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParentsReply.java index 1d9fb157..3052b8c5 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParentsReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchJsonAssetWithParentsReply.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -13,7 +15,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorFetchJsonAssetWithParentsReply implements Packet { +public class AssetEditorFetchJsonAssetWithParentsReply implements Packet, ToClientPacket { public static final int PACKET_ID = 313; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class AssetEditorFetchJsonAssetWithParentsReply implements Packet { return 313; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorFetchJsonAssetWithParentsReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchLastModifiedAssets.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchLastModifiedAssets.java index e0b86b98..ac86a20c 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchLastModifiedAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorFetchLastModifiedAssets.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class AssetEditorFetchLastModifiedAssets implements Packet { +public class AssetEditorFetchLastModifiedAssets implements Packet, ToServerPacket { public static final int PACKET_ID = 338; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class AssetEditorFetchLastModifiedAssets implements Packet { return 338; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static AssetEditorFetchLastModifiedAssets deserialize(@Nonnull ByteBuf buf, int offset) { return new AssetEditorFetchLastModifiedAssets(); diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorInitialize.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorInitialize.java index 30884917..b3f99ac1 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorInitialize.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorInitialize.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class AssetEditorInitialize implements Packet { +public class AssetEditorInitialize implements Packet, ToServerPacket { public static final int PACKET_ID = 302; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class AssetEditorInitialize implements Packet { return 302; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static AssetEditorInitialize deserialize(@Nonnull ByteBuf buf, int offset) { return new AssetEditorInitialize(); diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorJsonAssetUpdated.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorJsonAssetUpdated.java index a654f9a8..a7b93808 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorJsonAssetUpdated.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorJsonAssetUpdated.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorJsonAssetUpdated implements Packet { +public class AssetEditorJsonAssetUpdated implements Packet, ToClientPacket { public static final int PACKET_ID = 325; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class AssetEditorJsonAssetUpdated implements Packet { return 325; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorJsonAssetUpdated() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorLastModifiedAssets.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorLastModifiedAssets.java index 32ca9aff..73c2fb8f 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorLastModifiedAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorLastModifiedAssets.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorLastModifiedAssets implements Packet { +public class AssetEditorLastModifiedAssets implements Packet, ToClientPacket { public static final int PACKET_ID = 339; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorLastModifiedAssets implements Packet { return 339; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorLastModifiedAssets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorModifiedAssetsCount.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorModifiedAssetsCount.java index 3a5738cd..56b21588 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorModifiedAssetsCount.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorModifiedAssetsCount.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorModifiedAssetsCount implements Packet { +public class AssetEditorModifiedAssetsCount implements Packet, ToClientPacket { public static final int PACKET_ID = 340; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class AssetEditorModifiedAssetsCount implements Packet { return 340; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorModifiedAssetsCount() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorPopupNotification.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorPopupNotification.java index f8a93c7c..df4d1840 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorPopupNotification.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorPopupNotification.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.asseteditor; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorPopupNotification implements Packet { +public class AssetEditorPopupNotification implements Packet, ToClientPacket { public static final int PACKET_ID = 337; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorPopupNotification implements Packet { return 337; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorPopupNotification() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRebuildCaches.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRebuildCaches.java index 60d2e72a..3f21bfc3 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRebuildCaches.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRebuildCaches.java @@ -1,14 +1,11 @@ package com.hypixel.hytale.protocol.packets.asseteditor; -import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorRebuildCaches implements Packet { - public static final int PACKET_ID = 348; - public static final boolean IS_COMPRESSED = false; +public class AssetEditorRebuildCaches { public static final int NULLABLE_BIT_FIELD_SIZE = 0; public static final int FIXED_BLOCK_SIZE = 5; public static final int VARIABLE_FIELD_COUNT = 0; @@ -20,11 +17,6 @@ public class AssetEditorRebuildCaches implements Packet { public boolean mapGeometry; public boolean itemIcons; - @Override - public int getId() { - return 348; - } - public AssetEditorRebuildCaches() { } @@ -59,7 +51,6 @@ public class AssetEditorRebuildCaches implements Packet { return 5; } - @Override public void serialize(@Nonnull ByteBuf buf) { buf.writeByte(this.blockTextures ? 1 : 0); buf.writeByte(this.models ? 1 : 0); @@ -68,7 +59,6 @@ public class AssetEditorRebuildCaches implements Packet { buf.writeByte(this.itemIcons ? 1 : 0); } - @Override public int computeSize() { return 5; } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRedoChanges.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRedoChanges.java index 03391a52..1578cd41 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRedoChanges.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRedoChanges.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRedoChanges implements Packet { +public class AssetEditorRedoChanges implements Packet, ToServerPacket { public static final int PACKET_ID = 350; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorRedoChanges implements Packet { return 350; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRedoChanges() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameAsset.java index 99c8016b..5d308b08 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameAsset.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRenameAsset implements Packet { +public class AssetEditorRenameAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 328; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorRenameAsset implements Packet { return 328; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRenameAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameDirectory.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameDirectory.java index 55c3ce02..e07c03a4 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameDirectory.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRenameDirectory.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRenameDirectory implements Packet { +public class AssetEditorRenameDirectory implements Packet, ToServerPacket { public static final int PACKET_ID = 309; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorRenameDirectory implements Packet { return 309; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRenameDirectory() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenList.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenList.java index 4db62797..e2d6e73c 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenList.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenList.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRequestChildrenList implements Packet { +public class AssetEditorRequestChildrenList implements Packet, ToServerPacket { public static final int PACKET_ID = 321; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -23,6 +25,11 @@ public class AssetEditorRequestChildrenList implements Packet { return 321; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRequestChildrenList() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenListReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenListReply.java index b6521baf..1d21db7c 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenListReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestChildrenListReply.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRequestChildrenListReply implements Packet { +public class AssetEditorRequestChildrenListReply implements Packet, ToClientPacket { public static final int PACKET_ID = 322; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class AssetEditorRequestChildrenListReply implements Packet { return 322; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRequestChildrenListReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDataset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDataset.java index 8e76eada..8dc77d61 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDataset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDataset.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRequestDataset implements Packet { +public class AssetEditorRequestDataset implements Packet, ToServerPacket { public static final int PACKET_ID = 333; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class AssetEditorRequestDataset implements Packet { return 333; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRequestDataset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDatasetReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDatasetReply.java index ee31b2f4..cfe9d75e 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDatasetReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorRequestDatasetReply.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorRequestDatasetReply implements Packet { +public class AssetEditorRequestDatasetReply implements Packet, ToClientPacket { public static final int PACKET_ID = 334; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class AssetEditorRequestDatasetReply implements Packet { return 334; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorRequestDatasetReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSelectAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSelectAsset.java index 13a7f8f7..9c1ac256 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSelectAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSelectAsset.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorSelectAsset implements Packet { +public class AssetEditorSelectAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 336; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -23,6 +25,11 @@ public class AssetEditorSelectAsset implements Packet { return 336; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorSelectAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetGameTime.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetGameTime.java index ce876948..5fd2a2a8 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetGameTime.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetGameTime.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.asseteditor; import com.hypixel.hytale.protocol.InstantData; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorSetGameTime implements Packet { +public class AssetEditorSetGameTime implements Packet, ToServerPacket { public static final int PACKET_ID = 352; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorSetGameTime implements Packet { return 352; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorSetGameTime() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupAssetTypes.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupAssetTypes.java index c3a45237..07a5d072 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupAssetTypes.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupAssetTypes.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorSetupAssetTypes implements Packet { +public class AssetEditorSetupAssetTypes implements Packet, ToClientPacket { public static final int PACKET_ID = 306; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorSetupAssetTypes implements Packet { return 306; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorSetupAssetTypes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupSchemas.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupSchemas.java index 6def1bda..f637cf99 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupSchemas.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSetupSchemas.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorSetupSchemas implements Packet { +public class AssetEditorSetupSchemas implements Packet, ToClientPacket { public static final int PACKET_ID = 305; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetEditorSetupSchemas implements Packet { return 305; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorSetupSchemas() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSubscribeModifiedAssetsChanges.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSubscribeModifiedAssetsChanges.java index 176f8b11..7e8d10b0 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSubscribeModifiedAssetsChanges.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorSubscribeModifiedAssetsChanges.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorSubscribeModifiedAssetsChanges implements Packet { +public class AssetEditorSubscribeModifiedAssetsChanges implements Packet, ToServerPacket { public static final int PACKET_ID = 341; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class AssetEditorSubscribeModifiedAssetsChanges implements Packet { return 341; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorSubscribeModifiedAssetsChanges() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoChanges.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoChanges.java index a35b8a24..09197daf 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoChanges.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoChanges.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUndoChanges implements Packet { +public class AssetEditorUndoChanges implements Packet, ToServerPacket { public static final int PACKET_ID = 349; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorUndoChanges implements Packet { return 349; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUndoChanges() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoRedoReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoRedoReply.java index 25bb0dcd..36347d5d 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoRedoReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUndoRedoReply.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUndoRedoReply implements Packet { +public class AssetEditorUndoRedoReply implements Packet, ToClientPacket { public static final int PACKET_ID = 351; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class AssetEditorUndoRedoReply implements Packet { return 351; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUndoRedoReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAsset.java index dd086960..89b37e8b 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAsset.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUpdateAsset implements Packet { +public class AssetEditorUpdateAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 324; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class AssetEditorUpdateAsset implements Packet { return 324; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAssetPack.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAssetPack.java index 256d0f80..d62e6128 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAssetPack.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateAssetPack.java @@ -1,6 +1,9 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUpdateAssetPack implements Packet { +public class AssetEditorUpdateAssetPack implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 315; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +31,11 @@ public class AssetEditorUpdateAssetPack implements Packet { return 315; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateAssetPack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateJsonAsset.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateJsonAsset.java index a612673f..d087aafe 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateJsonAsset.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateJsonAsset.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUpdateJsonAsset implements Packet { +public class AssetEditorUpdateJsonAsset implements Packet, ToServerPacket { public static final int PACKET_ID = 323; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class AssetEditorUpdateJsonAsset implements Packet { return 323; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateJsonAsset() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateModelPreview.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateModelPreview.java index 2a2e3880..9afce37c 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateModelPreview.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateModelPreview.java @@ -2,14 +2,16 @@ package com.hypixel.hytale.protocol.packets.asseteditor; import com.hypixel.hytale.protocol.BlockType; import com.hypixel.hytale.protocol.Model; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetEditorUpdateModelPreview implements Packet { +public class AssetEditorUpdateModelPreview implements Packet, ToClientPacket { public static final int PACKET_ID = 355; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -31,6 +33,11 @@ public class AssetEditorUpdateModelPreview implements Packet { return 355; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateModelPreview() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateSecondsPerGameDay.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateSecondsPerGameDay.java index 6eff03f6..712c89af 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateSecondsPerGameDay.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateSecondsPerGameDay.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorUpdateSecondsPerGameDay implements Packet { +public class AssetEditorUpdateSecondsPerGameDay implements Packet, ToClientPacket { public static final int PACKET_ID = 353; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class AssetEditorUpdateSecondsPerGameDay implements Packet { return 353; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateSecondsPerGameDay() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateWeatherPreviewLock.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateWeatherPreviewLock.java index e103ddaa..81113e8d 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateWeatherPreviewLock.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/AssetEditorUpdateWeatherPreviewLock.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.asseteditor; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetEditorUpdateWeatherPreviewLock implements Packet { +public class AssetEditorUpdateWeatherPreviewLock implements Packet, ToServerPacket { public static final int PACKET_ID = 354; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class AssetEditorUpdateWeatherPreviewLock implements Packet { return 354; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetEditorUpdateWeatherPreviewLock() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/FailureReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/FailureReply.java index 0c1d9a15..474b1e9e 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/FailureReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/FailureReply.java @@ -1,14 +1,17 @@ package com.hypixel.hytale.protocol.packets.asseteditor; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FailureReply implements Packet { +public class FailureReply implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 300; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +28,11 @@ public class FailureReply implements Packet { return 300; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public FailureReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/asseteditor/SuccessReply.java b/src/com/hypixel/hytale/protocol/packets/asseteditor/SuccessReply.java index 0eaf52ea..bd0e9334 100644 --- a/src/com/hypixel/hytale/protocol/packets/asseteditor/SuccessReply.java +++ b/src/com/hypixel/hytale/protocol/packets/asseteditor/SuccessReply.java @@ -1,14 +1,17 @@ package com.hypixel.hytale.protocol.packets.asseteditor; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SuccessReply implements Packet { +public class SuccessReply implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 301; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +28,11 @@ public class SuccessReply implements Packet { return 301; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SuccessReply() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/TrackOrUpdateObjective.java b/src/com/hypixel/hytale/protocol/packets/assets/TrackOrUpdateObjective.java index 2a037079..bd66420d 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/TrackOrUpdateObjective.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/TrackOrUpdateObjective.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Objective; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class TrackOrUpdateObjective implements Packet { +public class TrackOrUpdateObjective implements Packet, ToClientPacket { public static final int PACKET_ID = 69; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class TrackOrUpdateObjective implements Packet { return 69; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public TrackOrUpdateObjective() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UntrackObjective.java b/src/com/hypixel/hytale/protocol/packets/assets/UntrackObjective.java index b13cd66b..c5981c25 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UntrackObjective.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UntrackObjective.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; @@ -8,7 +10,7 @@ import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; -public class UntrackObjective implements Packet { +public class UntrackObjective implements Packet, ToClientPacket { public static final int PACKET_ID = 70; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +26,11 @@ public class UntrackObjective implements Packet { return 70; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UntrackObjective() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateAmbienceFX.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateAmbienceFX.java index 590e6c3f..8eff1826 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateAmbienceFX.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateAmbienceFX.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.AmbienceFX; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateAmbienceFX implements Packet { +public class UpdateAmbienceFX implements Packet, ToClientPacket { public static final int PACKET_ID = 62; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateAmbienceFX implements Packet { return 62; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateAmbienceFX() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateAudioCategories.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateAudioCategories.java index 36c3deba..3174f2ad 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateAudioCategories.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateAudioCategories.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.AudioCategory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateAudioCategories implements Packet { +public class UpdateAudioCategories implements Packet, ToClientPacket { public static final int PACKET_ID = 80; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateAudioCategories implements Packet { return 80; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateAudioCategories() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockBreakingDecals.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockBreakingDecals.java index b5fa7c60..a1ffe042 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockBreakingDecals.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockBreakingDecals.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockBreakingDecal; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockBreakingDecals implements Packet { +public class UpdateBlockBreakingDecals implements Packet, ToClientPacket { public static final int PACKET_ID = 45; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateBlockBreakingDecals implements Packet { return 45; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockBreakingDecals() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockGroups.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockGroups.java index e7931560..da0f71c8 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockGroups.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockGroups.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockGroup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockGroups implements Packet { +public class UpdateBlockGroups implements Packet, ToClientPacket { public static final int PACKET_ID = 78; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateBlockGroups implements Packet { return 78; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockGroups() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockHitboxes.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockHitboxes.java index 486339bc..293cb77a 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockHitboxes.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockHitboxes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.Hitbox; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockHitboxes implements Packet { +public class UpdateBlockHitboxes implements Packet, ToClientPacket { public static final int PACKET_ID = 41; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -34,6 +36,11 @@ public class UpdateBlockHitboxes implements Packet { return 41; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockHitboxes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockParticleSets.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockParticleSets.java index 9ff35d9c..93dfb887 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockParticleSets.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockParticleSets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockParticleSet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockParticleSets implements Packet { +public class UpdateBlockParticleSets implements Packet, ToClientPacket { public static final int PACKET_ID = 44; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateBlockParticleSets implements Packet { return 44; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockParticleSets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSets.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSets.java index b3381777..eeae520e 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSets.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockSet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockSets implements Packet { +public class UpdateBlockSets implements Packet, ToClientPacket { public static final int PACKET_ID = 46; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateBlockSets implements Packet { return 46; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockSets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSoundSets.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSoundSets.java index 500a6ec9..cd2626dd 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSoundSets.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockSoundSets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockSoundSet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockSoundSets implements Packet { +public class UpdateBlockSoundSets implements Packet, ToClientPacket { public static final int PACKET_ID = 42; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateBlockSoundSets implements Packet { return 42; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockSoundSets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockTypes.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockTypes.java index cec9596c..313e52ae 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockTypes.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateBlockTypes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.BlockType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockTypes implements Packet { +public class UpdateBlockTypes implements Packet, ToClientPacket { public static final int PACKET_ID = 40; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -37,6 +39,11 @@ public class UpdateBlockTypes implements Packet { return 40; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateBlockTypes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateCameraShake.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateCameraShake.java index ce620b83..e58d0e64 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateCameraShake.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateCameraShake.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.CameraShake; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateCameraShake implements Packet { +public class UpdateCameraShake implements Packet, ToClientPacket { public static final int PACKET_ID = 77; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class UpdateCameraShake implements Packet { return 77; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateCameraShake() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityEffects.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityEffects.java index 1b53e62f..ac3a9774 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityEffects.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityEffects.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.EntityEffect; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEntityEffects implements Packet { +public class UpdateEntityEffects implements Packet, ToClientPacket { public static final int PACKET_ID = 51; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateEntityEffects implements Packet { return 51; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEntityEffects() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityStatTypes.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityStatTypes.java index 72b948d1..03c95bb1 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityStatTypes.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityStatTypes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.EntityStatType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEntityStatTypes implements Packet { +public class UpdateEntityStatTypes implements Packet, ToClientPacket { public static final int PACKET_ID = 72; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateEntityStatTypes implements Packet { return 72; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEntityStatTypes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityUIComponents.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityUIComponents.java index 88d56343..1fefe3c4 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityUIComponents.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEntityUIComponents.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.EntityUIComponent; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEntityUIComponents implements Packet { +public class UpdateEntityUIComponents implements Packet, ToClientPacket { public static final int PACKET_ID = 73; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateEntityUIComponents implements Packet { return 73; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEntityUIComponents() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEnvironments.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEnvironments.java index a3f3c40e..63722fae 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEnvironments.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEnvironments.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.WorldEnvironment; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEnvironments implements Packet { +public class UpdateEnvironments implements Packet, ToClientPacket { public static final int PACKET_ID = 61; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -34,6 +36,11 @@ public class UpdateEnvironments implements Packet { return 61; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEnvironments() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEqualizerEffects.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEqualizerEffects.java index 880850bc..51b0e2d6 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateEqualizerEffects.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateEqualizerEffects.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.EqualizerEffect; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEqualizerEffects implements Packet { +public class UpdateEqualizerEffects implements Packet, ToClientPacket { public static final int PACKET_ID = 82; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateEqualizerEffects implements Packet { return 82; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEqualizerEffects() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFieldcraftCategories.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFieldcraftCategories.java index 116c2579..23a4497a 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFieldcraftCategories.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFieldcraftCategories.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemCategory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateFieldcraftCategories implements Packet { +public class UpdateFieldcraftCategories implements Packet, ToClientPacket { public static final int PACKET_ID = 58; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class UpdateFieldcraftCategories implements Packet { return 58; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateFieldcraftCategories() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluidFX.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluidFX.java index 8d7e56b1..70720883 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluidFX.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluidFX.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.FluidFX; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateFluidFX implements Packet { +public class UpdateFluidFX implements Packet, ToClientPacket { public static final int PACKET_ID = 63; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateFluidFX implements Packet { return 63; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateFluidFX() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluids.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluids.java index f1023995..64a2f8c4 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluids.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateFluids.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.Fluid; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateFluids implements Packet { +public class UpdateFluids implements Packet, ToClientPacket { public static final int PACKET_ID = 83; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateFluids implements Packet { return 83; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateFluids() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateHitboxCollisionConfig.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateHitboxCollisionConfig.java index b3c8d868..6c7044be 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateHitboxCollisionConfig.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateHitboxCollisionConfig.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.HitboxCollisionConfig; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateHitboxCollisionConfig implements Packet { +public class UpdateHitboxCollisionConfig implements Packet, ToClientPacket { public static final int PACKET_ID = 74; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateHitboxCollisionConfig implements Packet { return 74; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateHitboxCollisionConfig() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateInteractions.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateInteractions.java index 7d5df164..c7a53570 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateInteractions.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateInteractions.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.Interaction; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateInteractions implements Packet { +public class UpdateInteractions implements Packet, ToClientPacket { public static final int PACKET_ID = 66; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateInteractions implements Packet { return 66; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateInteractions() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemCategories.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemCategories.java index 944f46f4..1f034175 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemCategories.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemCategories.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemCategory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItemCategories implements Packet { +public class UpdateItemCategories implements Packet, ToClientPacket { public static final int PACKET_ID = 56; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class UpdateItemCategories implements Packet { return 56; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItemCategories() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemPlayerAnimations.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemPlayerAnimations.java index 296e0738..9b91d872 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemPlayerAnimations.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemPlayerAnimations.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemPlayerAnimations; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItemPlayerAnimations implements Packet { +public class UpdateItemPlayerAnimations implements Packet, ToClientPacket { public static final int PACKET_ID = 52; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateItemPlayerAnimations implements Packet { return 52; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItemPlayerAnimations() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemQualities.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemQualities.java index 194d5613..65dde823 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemQualities.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemQualities.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemQuality; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItemQualities implements Packet { +public class UpdateItemQualities implements Packet, ToClientPacket { public static final int PACKET_ID = 55; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateItemQualities implements Packet { return 55; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItemQualities() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemReticles.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemReticles.java index 3bf2c2fc..db638e17 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemReticles.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemReticles.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemReticleConfig; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItemReticles implements Packet { +public class UpdateItemReticles implements Packet, ToClientPacket { public static final int PACKET_ID = 57; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateItemReticles implements Packet { return 57; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItemReticles() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemSoundSets.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemSoundSets.java index ca2a0c36..6d85ae14 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemSoundSets.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItemSoundSets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemSoundSet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItemSoundSets implements Packet { +public class UpdateItemSoundSets implements Packet, ToClientPacket { public static final int PACKET_ID = 43; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateItemSoundSets implements Packet { return 43; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItemSoundSets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItems.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItems.java index e8cfae55..4c50ffc5 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateItems.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateItems.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ItemBase; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -16,7 +18,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateItems implements Packet { +public class UpdateItems implements Packet, ToClientPacket { public static final int PACKET_ID = 54; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -38,6 +40,11 @@ public class UpdateItems implements Packet { return 54; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateItems() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateModelvfxs.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateModelvfxs.java index ae366ae9..b3c18635 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateModelvfxs.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateModelvfxs.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.ModelVFX; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateModelvfxs implements Packet { +public class UpdateModelvfxs implements Packet, ToClientPacket { public static final int PACKET_ID = 53; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateModelvfxs implements Packet { return 53; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateModelvfxs() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateObjectiveTask.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateObjectiveTask.java index 6282a24e..eef4b7c2 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateObjectiveTask.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateObjectiveTask.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.ObjectiveTask; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; @@ -10,7 +12,7 @@ import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateObjectiveTask implements Packet { +public class UpdateObjectiveTask implements Packet, ToClientPacket { public static final int PACKET_ID = 71; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class UpdateObjectiveTask implements Packet { return 71; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateObjectiveTask() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSpawners.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSpawners.java index e944b678..9a908379 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSpawners.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSpawners.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ParticleSpawner; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -16,7 +18,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateParticleSpawners implements Packet { +public class UpdateParticleSpawners implements Packet, ToClientPacket { public static final int PACKET_ID = 50; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class UpdateParticleSpawners implements Packet { return 50; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateParticleSpawners() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSystems.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSystems.java index 2b755398..6f28645c 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSystems.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateParticleSystems.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ParticleSystem; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -16,7 +18,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateParticleSystems implements Packet { +public class UpdateParticleSystems implements Packet, ToClientPacket { public static final int PACKET_ID = 49; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class UpdateParticleSystems implements Packet { return 49; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateParticleSystems() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateProjectileConfigs.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateProjectileConfigs.java index 05ac4d0c..435a6a1b 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateProjectileConfigs.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateProjectileConfigs.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ProjectileConfig; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -16,7 +18,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateProjectileConfigs implements Packet { +public class UpdateProjectileConfigs implements Packet, ToClientPacket { public static final int PACKET_ID = 85; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class UpdateProjectileConfigs implements Packet { return 85; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateProjectileConfigs() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRecipes.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRecipes.java index fd274c2d..bd476d1c 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRecipes.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRecipes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.CraftingRecipe; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -16,7 +18,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateRecipes implements Packet { +public class UpdateRecipes implements Packet, ToClientPacket { public static final int PACKET_ID = 60; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class UpdateRecipes implements Packet { return 60; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateRecipes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRepulsionConfig.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRepulsionConfig.java index 2ca2b9ec..ab3a5075 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRepulsionConfig.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRepulsionConfig.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.RepulsionConfig; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateRepulsionConfig implements Packet { +public class UpdateRepulsionConfig implements Packet, ToClientPacket { public static final int PACKET_ID = 75; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateRepulsionConfig implements Packet { return 75; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateRepulsionConfig() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateResourceTypes.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateResourceTypes.java index bf740990..a98a8eda 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateResourceTypes.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateResourceTypes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ResourceType; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateResourceTypes implements Packet { +public class UpdateResourceTypes implements Packet, ToClientPacket { public static final int PACKET_ID = 59; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateResourceTypes implements Packet { return 59; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateResourceTypes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateReverbEffects.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateReverbEffects.java index 3e544b61..3515e545 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateReverbEffects.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateReverbEffects.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ReverbEffect; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateReverbEffects implements Packet { +public class UpdateReverbEffects implements Packet, ToClientPacket { public static final int PACKET_ID = 81; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateReverbEffects implements Packet { return 81; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateReverbEffects() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRootInteractions.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRootInteractions.java index 143cc2dc..8f51e798 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateRootInteractions.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateRootInteractions.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.RootInteraction; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateRootInteractions implements Packet { +public class UpdateRootInteractions implements Packet, ToClientPacket { public static final int PACKET_ID = 67; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateRootInteractions implements Packet { return 67; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateRootInteractions() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundEvents.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundEvents.java index dd7ac61b..2cc08c88 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundEvents.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundEvents.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SoundEvent; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateSoundEvents implements Packet { +public class UpdateSoundEvents implements Packet, ToClientPacket { public static final int PACKET_ID = 65; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateSoundEvents implements Packet { return 65; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateSoundEvents() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundSets.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundSets.java index 7aa63493..941eb103 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundSets.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateSoundSets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SoundSet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateSoundSets implements Packet { +public class UpdateSoundSets implements Packet, ToClientPacket { public static final int PACKET_ID = 79; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateSoundSets implements Packet { return 79; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateSoundSets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTagPatterns.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTagPatterns.java index f15f1236..b29d51cc 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTagPatterns.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTagPatterns.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.TagPattern; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateTagPatterns implements Packet { +public class UpdateTagPatterns implements Packet, ToClientPacket { public static final int PACKET_ID = 84; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateTagPatterns implements Packet { return 84; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateTagPatterns() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTrails.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTrails.java index f5e7e83f..48dc2f8d 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTrails.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTrails.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.Trail; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateTrails implements Packet { +public class UpdateTrails implements Packet, ToClientPacket { public static final int PACKET_ID = 48; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateTrails implements Packet { return 48; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateTrails() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTranslations.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTranslations.java index c2fa0adc..911cba01 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateTranslations.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateTranslations.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateTranslations implements Packet { +public class UpdateTranslations implements Packet, ToClientPacket { public static final int PACKET_ID = 64; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class UpdateTranslations implements Packet { return 64; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateTranslations() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateUnarmedInteractions.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateUnarmedInteractions.java index 337157ba..f096076c 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateUnarmedInteractions.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateUnarmedInteractions.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.InteractionType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateUnarmedInteractions implements Packet { +public class UpdateUnarmedInteractions implements Packet, ToClientPacket { public static final int PACKET_ID = 68; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class UpdateUnarmedInteractions implements Packet { return 68; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateUnarmedInteractions() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateViewBobbing.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateViewBobbing.java index 35879052..3e642ea9 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateViewBobbing.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateViewBobbing.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.assets; import com.hypixel.hytale.protocol.MovementType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.ViewBobbing; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -15,7 +17,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateViewBobbing implements Packet { +public class UpdateViewBobbing implements Packet, ToClientPacket { public static final int PACKET_ID = 76; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateViewBobbing implements Packet { return 76; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateViewBobbing() { } diff --git a/src/com/hypixel/hytale/protocol/packets/assets/UpdateWeathers.java b/src/com/hypixel/hytale/protocol/packets/assets/UpdateWeathers.java index 15c840a0..dd3cbbd3 100644 --- a/src/com/hypixel/hytale/protocol/packets/assets/UpdateWeathers.java +++ b/src/com/hypixel/hytale/protocol/packets/assets/UpdateWeathers.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.assets; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.Weather; import com.hypixel.hytale.protocol.io.ProtocolException; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateWeathers implements Packet { +public class UpdateWeathers implements Packet, ToClientPacket { public static final int PACKET_ID = 47; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateWeathers implements Packet { return 47; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateWeathers() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/AuthGrant.java b/src/com/hypixel/hytale/protocol/packets/auth/AuthGrant.java index 8b9228b2..caa34a8c 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/AuthGrant.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/AuthGrant.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AuthGrant implements Packet { +public class AuthGrant implements Packet, ToClientPacket { public static final int PACKET_ID = 11; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class AuthGrant implements Packet { return 11; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AuthGrant() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/AuthToken.java b/src/com/hypixel/hytale/protocol/packets/auth/AuthToken.java index 2aa925e8..d9d9ad1a 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/AuthToken.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/AuthToken.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AuthToken implements Packet { +public class AuthToken implements Packet, ToServerPacket { public static final int PACKET_ID = 12; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class AuthToken implements Packet { return 12; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AuthToken() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/ClientReferral.java b/src/com/hypixel/hytale/protocol/packets/auth/ClientReferral.java index 6d8dbe93..a9ec6a1f 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/ClientReferral.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/ClientReferral.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.auth; import com.hypixel.hytale.protocol.HostAddress; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ClientReferral implements Packet { +public class ClientReferral implements Packet, ToClientPacket { public static final int PACKET_ID = 18; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class ClientReferral implements Packet { return 18; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientReferral() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/ConnectAccept.java b/src/com/hypixel/hytale/protocol/packets/auth/ConnectAccept.java index 15bd0803..1f91d700 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/ConnectAccept.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/ConnectAccept.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ConnectAccept implements Packet { +public class ConnectAccept implements Packet, ToClientPacket { public static final int PACKET_ID = 14; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class ConnectAccept implements Packet { return 14; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ConnectAccept() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/PasswordAccepted.java b/src/com/hypixel/hytale/protocol/packets/auth/PasswordAccepted.java index e7acda8c..ee6e8341 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/PasswordAccepted.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/PasswordAccepted.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class PasswordAccepted implements Packet { +public class PasswordAccepted implements Packet, ToClientPacket { public static final int PACKET_ID = 16; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class PasswordAccepted implements Packet { return 16; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static PasswordAccepted deserialize(@Nonnull ByteBuf buf, int offset) { return new PasswordAccepted(); diff --git a/src/com/hypixel/hytale/protocol/packets/auth/PasswordRejected.java b/src/com/hypixel/hytale/protocol/packets/auth/PasswordRejected.java index 5708348f..86cb4856 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/PasswordRejected.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/PasswordRejected.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PasswordRejected implements Packet { +public class PasswordRejected implements Packet, ToClientPacket { public static final int PACKET_ID = 17; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class PasswordRejected implements Packet { return 17; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PasswordRejected() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/PasswordResponse.java b/src/com/hypixel/hytale/protocol/packets/auth/PasswordResponse.java index 571e89be..2b8b3ef0 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/PasswordResponse.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/PasswordResponse.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PasswordResponse implements Packet { +public class PasswordResponse implements Packet, ToServerPacket { public static final int PACKET_ID = 15; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class PasswordResponse implements Packet { return 15; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PasswordResponse() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/ServerAuthToken.java b/src/com/hypixel/hytale/protocol/packets/auth/ServerAuthToken.java index 46870392..4e5e5ae2 100644 --- a/src/com/hypixel/hytale/protocol/packets/auth/ServerAuthToken.java +++ b/src/com/hypixel/hytale/protocol/packets/auth/ServerAuthToken.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.auth; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ServerAuthToken implements Packet { +public class ServerAuthToken implements Packet, ToClientPacket { public static final int PACKET_ID = 13; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class ServerAuthToken implements Packet { return 13; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ServerAuthToken() { } diff --git a/src/com/hypixel/hytale/protocol/packets/auth/Status.java b/src/com/hypixel/hytale/protocol/packets/auth/Status.java deleted file mode 100644 index 96700e1d..00000000 --- a/src/com/hypixel/hytale/protocol/packets/auth/Status.java +++ /dev/null @@ -1,252 +0,0 @@ -package com.hypixel.hytale.protocol.packets.auth; - -import com.hypixel.hytale.protocol.Packet; -import com.hypixel.hytale.protocol.io.PacketIO; -import com.hypixel.hytale.protocol.io.ProtocolException; -import com.hypixel.hytale.protocol.io.ValidationResult; -import com.hypixel.hytale.protocol.io.VarInt; -import io.netty.buffer.ByteBuf; -import java.util.Objects; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public class Status implements Packet { - public static final int PACKET_ID = 10; - public static final boolean IS_COMPRESSED = false; - public static final int NULLABLE_BIT_FIELD_SIZE = 1; - public static final int FIXED_BLOCK_SIZE = 9; - public static final int VARIABLE_FIELD_COUNT = 2; - public static final int VARIABLE_BLOCK_START = 17; - public static final int MAX_SIZE = 2587; - @Nullable - public String name; - @Nullable - public String motd; - public int playerCount; - public int maxPlayers; - - @Override - public int getId() { - return 10; - } - - public Status() { - } - - public Status(@Nullable String name, @Nullable String motd, int playerCount, int maxPlayers) { - this.name = name; - this.motd = motd; - this.playerCount = playerCount; - this.maxPlayers = maxPlayers; - } - - public Status(@Nonnull Status other) { - this.name = other.name; - this.motd = other.motd; - this.playerCount = other.playerCount; - this.maxPlayers = other.maxPlayers; - } - - @Nonnull - public static Status deserialize(@Nonnull ByteBuf buf, int offset) { - Status obj = new Status(); - byte nullBits = buf.getByte(offset); - obj.playerCount = buf.getIntLE(offset + 1); - obj.maxPlayers = buf.getIntLE(offset + 5); - if ((nullBits & 1) != 0) { - int varPos0 = offset + 17 + buf.getIntLE(offset + 9); - int nameLen = VarInt.peek(buf, varPos0); - if (nameLen < 0) { - throw ProtocolException.negativeLength("Name", nameLen); - } - - if (nameLen > 128) { - throw ProtocolException.stringTooLong("Name", nameLen, 128); - } - - obj.name = PacketIO.readVarString(buf, varPos0, PacketIO.UTF8); - } - - if ((nullBits & 2) != 0) { - int varPos1 = offset + 17 + buf.getIntLE(offset + 13); - int motdLen = VarInt.peek(buf, varPos1); - if (motdLen < 0) { - throw ProtocolException.negativeLength("Motd", motdLen); - } - - if (motdLen > 512) { - throw ProtocolException.stringTooLong("Motd", motdLen, 512); - } - - obj.motd = PacketIO.readVarString(buf, varPos1, PacketIO.UTF8); - } - - return obj; - } - - public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { - byte nullBits = buf.getByte(offset); - int maxEnd = 17; - if ((nullBits & 1) != 0) { - int fieldOffset0 = buf.getIntLE(offset + 9); - int pos0 = offset + 17 + fieldOffset0; - int sl = VarInt.peek(buf, pos0); - pos0 += VarInt.length(buf, pos0) + sl; - if (pos0 - offset > maxEnd) { - maxEnd = pos0 - offset; - } - } - - if ((nullBits & 2) != 0) { - int fieldOffset1 = buf.getIntLE(offset + 13); - int pos1 = offset + 17 + fieldOffset1; - int sl = VarInt.peek(buf, pos1); - pos1 += VarInt.length(buf, pos1) + sl; - if (pos1 - offset > maxEnd) { - maxEnd = pos1 - offset; - } - } - - return maxEnd; - } - - @Override - public void serialize(@Nonnull ByteBuf buf) { - int startPos = buf.writerIndex(); - byte nullBits = 0; - if (this.name != null) { - nullBits = (byte)(nullBits | 1); - } - - if (this.motd != null) { - nullBits = (byte)(nullBits | 2); - } - - buf.writeByte(nullBits); - buf.writeIntLE(this.playerCount); - buf.writeIntLE(this.maxPlayers); - int nameOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int motdOffsetSlot = buf.writerIndex(); - buf.writeIntLE(0); - int varBlockStart = buf.writerIndex(); - if (this.name != null) { - buf.setIntLE(nameOffsetSlot, buf.writerIndex() - varBlockStart); - PacketIO.writeVarString(buf, this.name, 128); - } else { - buf.setIntLE(nameOffsetSlot, -1); - } - - if (this.motd != null) { - buf.setIntLE(motdOffsetSlot, buf.writerIndex() - varBlockStart); - PacketIO.writeVarString(buf, this.motd, 512); - } else { - buf.setIntLE(motdOffsetSlot, -1); - } - } - - @Override - public int computeSize() { - int size = 17; - if (this.name != null) { - size += PacketIO.stringSize(this.name); - } - - if (this.motd != null) { - size += PacketIO.stringSize(this.motd); - } - - return size; - } - - public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 17) { - return ValidationResult.error("Buffer too small: expected at least 17 bytes"); - } else { - byte nullBits = buffer.getByte(offset); - if ((nullBits & 1) != 0) { - int nameOffset = buffer.getIntLE(offset + 9); - if (nameOffset < 0) { - return ValidationResult.error("Invalid offset for Name"); - } - - int pos = offset + 17 + nameOffset; - if (pos >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Name"); - } - - int nameLen = VarInt.peek(buffer, pos); - if (nameLen < 0) { - return ValidationResult.error("Invalid string length for Name"); - } - - if (nameLen > 128) { - return ValidationResult.error("Name exceeds max length 128"); - } - - pos += VarInt.length(buffer, pos); - pos += nameLen; - if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Name"); - } - } - - if ((nullBits & 2) != 0) { - int motdOffset = buffer.getIntLE(offset + 13); - if (motdOffset < 0) { - return ValidationResult.error("Invalid offset for Motd"); - } - - int posx = offset + 17 + motdOffset; - if (posx >= buffer.writerIndex()) { - return ValidationResult.error("Offset out of bounds for Motd"); - } - - int motdLen = VarInt.peek(buffer, posx); - if (motdLen < 0) { - return ValidationResult.error("Invalid string length for Motd"); - } - - if (motdLen > 512) { - return ValidationResult.error("Motd exceeds max length 512"); - } - - posx += VarInt.length(buffer, posx); - posx += motdLen; - if (posx > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading Motd"); - } - } - - return ValidationResult.OK; - } - } - - public Status clone() { - Status copy = new Status(); - copy.name = this.name; - copy.motd = this.motd; - copy.playerCount = this.playerCount; - copy.maxPlayers = this.maxPlayers; - return copy; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else { - return !(obj instanceof Status other) - ? false - : Objects.equals(this.name, other.name) - && Objects.equals(this.motd, other.motd) - && this.playerCount == other.playerCount - && this.maxPlayers == other.maxPlayers; - } - } - - @Override - public int hashCode() { - return Objects.hash(this.name, this.motd, this.playerCount, this.maxPlayers); - } -} diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolArgUpdate.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolArgUpdate.java index 8626a2bd..c59ace76 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolArgUpdate.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolArgUpdate.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolArgUpdate implements Packet { +public class BuilderToolArgUpdate implements Packet, ToServerPacket { public static final int PACKET_ID = 400; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class BuilderToolArgUpdate implements Packet { return 400; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolArgUpdate() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolEntityAction.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolEntityAction.java index 6c228725..85cfc6f3 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolEntityAction.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolEntityAction.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolEntityAction implements Packet { +public class BuilderToolEntityAction implements Packet, ToServerPacket { public static final int PACKET_ID = 401; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class BuilderToolEntityAction implements Packet { return 401; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolEntityAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolExtrudeAction.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolExtrudeAction.java index 86ad924d..e144185f 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolExtrudeAction.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolExtrudeAction.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolExtrudeAction implements Packet { +public class BuilderToolExtrudeAction implements Packet, ToServerPacket { public static final int PACKET_ID = 403; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class BuilderToolExtrudeAction implements Packet { return 403; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolExtrudeAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolGeneralAction.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolGeneralAction.java index 28016872..b8391b95 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolGeneralAction.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolGeneralAction.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolGeneralAction implements Packet { +public class BuilderToolGeneralAction implements Packet, ToServerPacket { public static final int PACKET_ID = 412; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class BuilderToolGeneralAction implements Packet { return 412; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolGeneralAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolHideAnchors.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolHideAnchors.java index bd367b47..a5204230 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolHideAnchors.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolHideAnchors.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class BuilderToolHideAnchors implements Packet { +public class BuilderToolHideAnchors implements Packet, ToClientPacket { public static final int PACKET_ID = 416; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class BuilderToolHideAnchors implements Packet { return 416; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static BuilderToolHideAnchors deserialize(@Nonnull ByteBuf buf, int offset) { return new BuilderToolHideAnchors(); diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLaserPointer.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLaserPointer.java index e504f602..d9b16025 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLaserPointer.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLaserPointer.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolLaserPointer implements Packet { +public class BuilderToolLaserPointer implements Packet, ToClientPacket { public static final int PACKET_ID = 419; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -29,6 +31,11 @@ public class BuilderToolLaserPointer implements Packet { return 419; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolLaserPointer() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLineAction.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLineAction.java index a551534e..4469fb57 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLineAction.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolLineAction.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolLineAction implements Packet { +public class BuilderToolLineAction implements Packet, ToServerPacket { public static final int PACKET_ID = 414; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class BuilderToolLineAction implements Packet { return 414; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolLineAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolOnUseInteraction.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolOnUseInteraction.java index 65dca523..9262fdfa 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolOnUseInteraction.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolOnUseInteraction.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.buildertools; import com.hypixel.hytale.protocol.InteractionType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolOnUseInteraction implements Packet { +public class BuilderToolOnUseInteraction implements Packet, ToServerPacket { public static final int PACKET_ID = 413; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -40,6 +42,11 @@ public class BuilderToolOnUseInteraction implements Packet { return 413; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolOnUseInteraction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolPasteClipboard.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolPasteClipboard.java index c9f4c6c5..19e06cf8 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolPasteClipboard.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolPasteClipboard.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolPasteClipboard implements Packet { +public class BuilderToolPasteClipboard implements Packet, ToServerPacket { public static final int PACKET_ID = 407; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class BuilderToolPasteClipboard implements Packet { return 407; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolPasteClipboard() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolRotateClipboard.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolRotateClipboard.java index c818e40b..21027121 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolRotateClipboard.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolRotateClipboard.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolRotateClipboard implements Packet { +public class BuilderToolRotateClipboard implements Packet, ToServerPacket { public static final int PACKET_ID = 406; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class BuilderToolRotateClipboard implements Packet { return 406; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolRotateClipboard() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolAskForClipboard.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolAskForClipboard.java index f5e139db..411e5e42 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolAskForClipboard.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolAskForClipboard.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class BuilderToolSelectionToolAskForClipboard implements Packet { +public class BuilderToolSelectionToolAskForClipboard implements Packet, ToServerPacket { public static final int PACKET_ID = 410; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class BuilderToolSelectionToolAskForClipboard implements Packet { return 410; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static BuilderToolSelectionToolAskForClipboard deserialize(@Nonnull ByteBuf buf, int offset) { return new BuilderToolSelectionToolAskForClipboard(); diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolReplyWithClipboard.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolReplyWithClipboard.java index 571d4f45..8749a812 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolReplyWithClipboard.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionToolReplyWithClipboard.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -11,7 +13,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolSelectionToolReplyWithClipboard implements Packet { +public class BuilderToolSelectionToolReplyWithClipboard implements Packet, ToClientPacket { public static final int PACKET_ID = 411; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class BuilderToolSelectionToolReplyWithClipboard implements Packet { return 411; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSelectionToolReplyWithClipboard() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionTransform.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionTransform.java index 4df45c44..d9705638 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionTransform.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionTransform.java @@ -1,27 +1,29 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.math.Quatf; import com.hypixel.hytale.protocol.BlockPosition; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.Vector3f; -import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; -import com.hypixel.hytale.protocol.io.VarInt; import io.netty.buffer.ByteBuf; -import java.util.Arrays; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolSelectionTransform implements Packet { +public class BuilderToolSelectionTransform implements Packet, ToServerPacket { public static final int PACKET_ID = 405; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; - public static final int FIXED_BLOCK_SIZE = 52; - public static final int VARIABLE_FIELD_COUNT = 1; - public static final int VARIABLE_BLOCK_START = 52; - public static final int MAX_SIZE = 16384057; + public static final int FIXED_BLOCK_SIZE = 80; + public static final int VARIABLE_FIELD_COUNT = 0; + public static final int VARIABLE_BLOCK_START = 80; + public static final int MAX_SIZE = 80; @Nullable - public float[] transformationMatrix; + public Quatf rotation; + @Nullable + public BlockPosition translationOffset; @Nullable public BlockPosition initialSelectionMin; @Nullable @@ -39,11 +41,17 @@ public class BuilderToolSelectionTransform implements Packet { return 405; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSelectionTransform() { } public BuilderToolSelectionTransform( - @Nullable float[] transformationMatrix, + @Nullable Quatf rotation, + @Nullable BlockPosition translationOffset, @Nullable BlockPosition initialSelectionMin, @Nullable BlockPosition initialSelectionMax, @Nullable Vector3f initialRotationOrigin, @@ -52,7 +60,8 @@ public class BuilderToolSelectionTransform implements Packet { boolean isExitingTransformMode, @Nullable BlockPosition initialPastePointForClipboardPaste ) { - this.transformationMatrix = transformationMatrix; + this.rotation = rotation; + this.translationOffset = translationOffset; this.initialSelectionMin = initialSelectionMin; this.initialSelectionMax = initialSelectionMax; this.initialRotationOrigin = initialRotationOrigin; @@ -63,7 +72,8 @@ public class BuilderToolSelectionTransform implements Packet { } public BuilderToolSelectionTransform(@Nonnull BuilderToolSelectionTransform other) { - this.transformationMatrix = other.transformationMatrix; + this.rotation = other.rotation; + this.translationOffset = other.translationOffset; this.initialSelectionMin = other.initialSelectionMin; this.initialSelectionMax = other.initialSelectionMax; this.initialRotationOrigin = other.initialRotationOrigin; @@ -78,90 +88,79 @@ public class BuilderToolSelectionTransform implements Packet { BuilderToolSelectionTransform obj = new BuilderToolSelectionTransform(); byte nullBits = buf.getByte(offset); if ((nullBits & 1) != 0) { - obj.initialSelectionMin = BlockPosition.deserialize(buf, offset + 1); + obj.rotation = Quatf.deserialize(buf, offset + 1); } if ((nullBits & 2) != 0) { - obj.initialSelectionMax = BlockPosition.deserialize(buf, offset + 13); + obj.translationOffset = BlockPosition.deserialize(buf, offset + 17); } if ((nullBits & 4) != 0) { - obj.initialRotationOrigin = Vector3f.deserialize(buf, offset + 25); + obj.initialSelectionMin = BlockPosition.deserialize(buf, offset + 29); } - obj.cutOriginal = buf.getByte(offset + 37) != 0; - obj.applyTransformationToSelectionMinMax = buf.getByte(offset + 38) != 0; - obj.isExitingTransformMode = buf.getByte(offset + 39) != 0; if ((nullBits & 8) != 0) { - obj.initialPastePointForClipboardPaste = BlockPosition.deserialize(buf, offset + 40); + obj.initialSelectionMax = BlockPosition.deserialize(buf, offset + 41); } - int pos = offset + 52; if ((nullBits & 16) != 0) { - int transformationMatrixCount = VarInt.peek(buf, pos); - if (transformationMatrixCount < 0) { - throw ProtocolException.negativeLength("TransformationMatrix", transformationMatrixCount); - } + obj.initialRotationOrigin = Vector3f.deserialize(buf, offset + 53); + } - if (transformationMatrixCount > 4096000) { - throw ProtocolException.arrayTooLong("TransformationMatrix", transformationMatrixCount, 4096000); - } - - int transformationMatrixVarLen = VarInt.size(transformationMatrixCount); - if (pos + transformationMatrixVarLen + transformationMatrixCount * 4L > buf.readableBytes()) { - throw ProtocolException.bufferTooSmall( - "TransformationMatrix", pos + transformationMatrixVarLen + transformationMatrixCount * 4, buf.readableBytes() - ); - } - - pos += transformationMatrixVarLen; - obj.transformationMatrix = new float[transformationMatrixCount]; - - for (int i = 0; i < transformationMatrixCount; i++) { - obj.transformationMatrix[i] = buf.getFloatLE(pos + i * 4); - } - - pos += transformationMatrixCount * 4; + obj.cutOriginal = buf.getByte(offset + 65) != 0; + obj.applyTransformationToSelectionMinMax = buf.getByte(offset + 66) != 0; + obj.isExitingTransformMode = buf.getByte(offset + 67) != 0; + if ((nullBits & 32) != 0) { + obj.initialPastePointForClipboardPaste = BlockPosition.deserialize(buf, offset + 68); } return obj; } public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { - byte nullBits = buf.getByte(offset); - int pos = offset + 52; - if ((nullBits & 16) != 0) { - int arrLen = VarInt.peek(buf, pos); - pos += VarInt.length(buf, pos) + arrLen * 4; - } - - return pos - offset; + return 80; } @Override public void serialize(@Nonnull ByteBuf buf) { byte nullBits = 0; - if (this.initialSelectionMin != null) { + if (this.rotation != null) { nullBits = (byte)(nullBits | 1); } - if (this.initialSelectionMax != null) { + if (this.translationOffset != null) { nullBits = (byte)(nullBits | 2); } - if (this.initialRotationOrigin != null) { + if (this.initialSelectionMin != null) { nullBits = (byte)(nullBits | 4); } - if (this.initialPastePointForClipboardPaste != null) { + if (this.initialSelectionMax != null) { nullBits = (byte)(nullBits | 8); } - if (this.transformationMatrix != null) { + if (this.initialRotationOrigin != null) { nullBits = (byte)(nullBits | 16); } + if (this.initialPastePointForClipboardPaste != null) { + nullBits = (byte)(nullBits | 32); + } + buf.writeByte(nullBits); + if (this.rotation != null) { + this.rotation.serialize(buf); + } else { + buf.writeZero(16); + } + + if (this.translationOffset != null) { + this.translationOffset.serialize(buf); + } else { + buf.writeZero(12); + } + if (this.initialSelectionMin != null) { this.initialSelectionMin.serialize(buf); } else { @@ -188,60 +187,21 @@ public class BuilderToolSelectionTransform implements Packet { } else { buf.writeZero(12); } - - if (this.transformationMatrix != null) { - if (this.transformationMatrix.length > 4096000) { - throw ProtocolException.arrayTooLong("TransformationMatrix", this.transformationMatrix.length, 4096000); - } - - VarInt.write(buf, this.transformationMatrix.length); - - for (float item : this.transformationMatrix) { - buf.writeFloatLE(item); - } - } } @Override public int computeSize() { - int size = 52; - if (this.transformationMatrix != null) { - size += VarInt.size(this.transformationMatrix.length) + this.transformationMatrix.length * 4; - } - - return size; + return 80; } public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { - if (buffer.readableBytes() - offset < 52) { - return ValidationResult.error("Buffer too small: expected at least 52 bytes"); - } else { - byte nullBits = buffer.getByte(offset); - int pos = offset + 52; - if ((nullBits & 16) != 0) { - int transformationMatrixCount = VarInt.peek(buffer, pos); - if (transformationMatrixCount < 0) { - return ValidationResult.error("Invalid array count for TransformationMatrix"); - } - - if (transformationMatrixCount > 4096000) { - return ValidationResult.error("TransformationMatrix exceeds max length 4096000"); - } - - pos += VarInt.length(buffer, pos); - pos += transformationMatrixCount * 4; - if (pos > buffer.writerIndex()) { - return ValidationResult.error("Buffer overflow reading TransformationMatrix"); - } - } - - return ValidationResult.OK; - } + return buffer.readableBytes() - offset < 80 ? ValidationResult.error("Buffer too small: expected at least 80 bytes") : ValidationResult.OK; } public BuilderToolSelectionTransform clone() { BuilderToolSelectionTransform copy = new BuilderToolSelectionTransform(); - copy.transformationMatrix = this.transformationMatrix != null ? Arrays.copyOf(this.transformationMatrix, this.transformationMatrix.length) : null; + copy.rotation = this.rotation; + copy.translationOffset = this.translationOffset != null ? this.translationOffset.clone() : null; copy.initialSelectionMin = this.initialSelectionMin != null ? this.initialSelectionMin.clone() : null; copy.initialSelectionMax = this.initialSelectionMax != null ? this.initialSelectionMax.clone() : null; copy.initialRotationOrigin = this.initialRotationOrigin != null ? this.initialRotationOrigin.clone() : null; @@ -259,7 +219,8 @@ public class BuilderToolSelectionTransform implements Packet { } else { return !(obj instanceof BuilderToolSelectionTransform other) ? false - : Arrays.equals(this.transformationMatrix, other.transformationMatrix) + : Objects.equals(this.rotation, other.rotation) + && Objects.equals(this.translationOffset, other.translationOffset) && Objects.equals(this.initialSelectionMin, other.initialSelectionMin) && Objects.equals(this.initialSelectionMax, other.initialSelectionMax) && Objects.equals(this.initialRotationOrigin, other.initialRotationOrigin) @@ -272,14 +233,16 @@ public class BuilderToolSelectionTransform implements Packet { @Override public int hashCode() { - int result = 1; - result = 31 * result + Arrays.hashCode(this.transformationMatrix); - result = 31 * result + Objects.hashCode(this.initialSelectionMin); - result = 31 * result + Objects.hashCode(this.initialSelectionMax); - result = 31 * result + Objects.hashCode(this.initialRotationOrigin); - result = 31 * result + Boolean.hashCode(this.cutOriginal); - result = 31 * result + Boolean.hashCode(this.applyTransformationToSelectionMinMax); - result = 31 * result + Boolean.hashCode(this.isExitingTransformMode); - return 31 * result + Objects.hashCode(this.initialPastePointForClipboardPaste); + return Objects.hash( + this.rotation, + this.translationOffset, + this.initialSelectionMin, + this.initialSelectionMax, + this.initialRotationOrigin, + this.cutOriginal, + this.applyTransformationToSelectionMinMax, + this.isExitingTransformMode, + this.initialPastePointForClipboardPaste + ); } } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionUpdate.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionUpdate.java index c3b10d64..387210fd 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionUpdate.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSelectionUpdate.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolSelectionUpdate implements Packet { +public class BuilderToolSelectionUpdate implements Packet, ToServerPacket { public static final int PACKET_ID = 409; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class BuilderToolSelectionUpdate implements Packet { return 409; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSelectionUpdate() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityCollision.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityCollision.java index e09e6ecd..dafa9d82 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityCollision.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityCollision.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolSetEntityCollision implements Packet { +public class BuilderToolSetEntityCollision implements Packet, ToServerPacket { public static final int PACKET_ID = 425; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class BuilderToolSetEntityCollision implements Packet { return 425; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetEntityCollision() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityLight.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityLight.java index 92f1f444..abed5843 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityLight.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityLight.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.buildertools; import com.hypixel.hytale.protocol.ColorLight; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolSetEntityLight implements Packet { +public class BuilderToolSetEntityLight implements Packet, ToServerPacket { public static final int PACKET_ID = 422; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class BuilderToolSetEntityLight implements Packet { return 422; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetEntityLight() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityPickupEnabled.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityPickupEnabled.java index a46d96b8..8138f39d 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityPickupEnabled.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityPickupEnabled.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolSetEntityPickupEnabled implements Packet { +public class BuilderToolSetEntityPickupEnabled implements Packet, ToServerPacket { public static final int PACKET_ID = 421; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class BuilderToolSetEntityPickupEnabled implements Packet { return 421; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetEntityPickupEnabled() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityScale.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityScale.java index bd322545..b0239001 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityScale.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityScale.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolSetEntityScale implements Packet { +public class BuilderToolSetEntityScale implements Packet, ToServerPacket { public static final int PACKET_ID = 420; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class BuilderToolSetEntityScale implements Packet { return 420; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetEntityScale() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityTransform.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityTransform.java index 0bd7e009..c3774a58 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityTransform.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetEntityTransform.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.buildertools; import com.hypixel.hytale.protocol.ModelTransform; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolSetEntityTransform implements Packet { +public class BuilderToolSetEntityTransform implements Packet, ToServerPacket { public static final int PACKET_ID = 402; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class BuilderToolSetEntityTransform implements Packet { return 402; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetEntityTransform() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetNPCDebug.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetNPCDebug.java index f12ddcc9..b0000b28 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetNPCDebug.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetNPCDebug.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolSetNPCDebug implements Packet { +public class BuilderToolSetNPCDebug implements Packet, ToServerPacket { public static final int PACKET_ID = 423; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class BuilderToolSetNPCDebug implements Packet { return 423; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetNPCDebug() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetTransformationModeState.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetTransformationModeState.java index b4265a10..eebc9038 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetTransformationModeState.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolSetTransformationModeState.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolSetTransformationModeState implements Packet { +public class BuilderToolSetTransformationModeState implements Packet, ToServerPacket { public static final int PACKET_ID = 408; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class BuilderToolSetTransformationModeState implements Packet { return 408; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolSetTransformationModeState() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolShowAnchor.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolShowAnchor.java index ea027aea..876413c1 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolShowAnchor.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolShowAnchor.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolShowAnchor implements Packet { +public class BuilderToolShowAnchor implements Packet, ToClientPacket { public static final int PACKET_ID = 415; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class BuilderToolShowAnchor implements Packet { return 415; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolShowAnchor() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolStackArea.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolStackArea.java index e4ca72bb..3d1ac5f6 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolStackArea.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolStackArea.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.buildertools; import com.hypixel.hytale.protocol.BlockPosition; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BuilderToolStackArea implements Packet { +public class BuilderToolStackArea implements Packet, ToServerPacket { public static final int PACKET_ID = 404; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class BuilderToolStackArea implements Packet { return 404; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolStackArea() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolsSetSoundSet.java b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolsSetSoundSet.java index ebf515b2..b87ea4d6 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolsSetSoundSet.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/BuilderToolsSetSoundSet.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class BuilderToolsSetSoundSet implements Packet { +public class BuilderToolsSetSoundSet implements Packet, ToClientPacket { public static final int PACKET_ID = 418; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class BuilderToolsSetSoundSet implements Packet { return 418; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public BuilderToolsSetSoundSet() { } diff --git a/src/com/hypixel/hytale/protocol/packets/buildertools/PrefabUnselectPrefab.java b/src/com/hypixel/hytale/protocol/packets/buildertools/PrefabUnselectPrefab.java index c1393462..b5656ff2 100644 --- a/src/com/hypixel/hytale/protocol/packets/buildertools/PrefabUnselectPrefab.java +++ b/src/com/hypixel/hytale/protocol/packets/buildertools/PrefabUnselectPrefab.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.buildertools; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class PrefabUnselectPrefab implements Packet { +public class PrefabUnselectPrefab implements Packet, ToServerPacket { public static final int PACKET_ID = 417; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class PrefabUnselectPrefab implements Packet { return 417; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static PrefabUnselectPrefab deserialize(@Nonnull ByteBuf buf, int offset) { return new PrefabUnselectPrefab(); diff --git a/src/com/hypixel/hytale/protocol/packets/camera/CameraShakeEffect.java b/src/com/hypixel/hytale/protocol/packets/camera/CameraShakeEffect.java index 8199620e..1342cb2b 100644 --- a/src/com/hypixel/hytale/protocol/packets/camera/CameraShakeEffect.java +++ b/src/com/hypixel/hytale/protocol/packets/camera/CameraShakeEffect.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.camera; import com.hypixel.hytale.protocol.AccumulationMode; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class CameraShakeEffect implements Packet { +public class CameraShakeEffect implements Packet, ToClientPacket { public static final int PACKET_ID = 281; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class CameraShakeEffect implements Packet { return 281; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CameraShakeEffect() { } diff --git a/src/com/hypixel/hytale/protocol/packets/camera/RequestFlyCameraMode.java b/src/com/hypixel/hytale/protocol/packets/camera/RequestFlyCameraMode.java index 968428e8..910b82c3 100644 --- a/src/com/hypixel/hytale/protocol/packets/camera/RequestFlyCameraMode.java +++ b/src/com/hypixel/hytale/protocol/packets/camera/RequestFlyCameraMode.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.camera; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class RequestFlyCameraMode implements Packet { +public class RequestFlyCameraMode implements Packet, ToServerPacket { public static final int PACKET_ID = 282; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class RequestFlyCameraMode implements Packet { return 282; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RequestFlyCameraMode() { } diff --git a/src/com/hypixel/hytale/protocol/packets/camera/SetFlyCameraMode.java b/src/com/hypixel/hytale/protocol/packets/camera/SetFlyCameraMode.java index 7ee7f4cf..625c6408 100644 --- a/src/com/hypixel/hytale/protocol/packets/camera/SetFlyCameraMode.java +++ b/src/com/hypixel/hytale/protocol/packets/camera/SetFlyCameraMode.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.camera; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetFlyCameraMode implements Packet { +public class SetFlyCameraMode implements Packet, ToClientPacket { public static final int PACKET_ID = 283; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetFlyCameraMode implements Packet { return 283; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetFlyCameraMode() { } diff --git a/src/com/hypixel/hytale/protocol/packets/camera/SetServerCamera.java b/src/com/hypixel/hytale/protocol/packets/camera/SetServerCamera.java index 19109ac8..92950eb2 100644 --- a/src/com/hypixel/hytale/protocol/packets/camera/SetServerCamera.java +++ b/src/com/hypixel/hytale/protocol/packets/camera/SetServerCamera.java @@ -1,15 +1,17 @@ package com.hypixel.hytale.protocol.packets.camera; import com.hypixel.hytale.protocol.ClientCameraView; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.ServerCameraSettings; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetServerCamera implements Packet { +public class SetServerCamera implements Packet, ToClientPacket { public static final int PACKET_ID = 280; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class SetServerCamera implements Packet { return 280; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetServerCamera() { } diff --git a/src/com/hypixel/hytale/protocol/packets/connection/Connect.java b/src/com/hypixel/hytale/protocol/packets/connection/Connect.java index c561beb9..276f6898 100644 --- a/src/com/hypixel/hytale/protocol/packets/connection/Connect.java +++ b/src/com/hypixel/hytale/protocol/packets/connection/Connect.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.connection; import com.hypixel.hytale.protocol.HostAddress; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -13,7 +15,7 @@ import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Connect implements Packet { +public class Connect implements Packet, ToServerPacket { public static final int PACKET_ID = 0; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -45,6 +47,11 @@ public class Connect implements Packet { return 0; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public Connect() { } diff --git a/src/com/hypixel/hytale/protocol/packets/connection/Disconnect.java b/src/com/hypixel/hytale/protocol/packets/connection/Disconnect.java index ae099cdc..3b6c0afb 100644 --- a/src/com/hypixel/hytale/protocol/packets/connection/Disconnect.java +++ b/src/com/hypixel/hytale/protocol/packets/connection/Disconnect.java @@ -1,6 +1,9 @@ package com.hypixel.hytale.protocol.packets.connection; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Disconnect implements Packet { +public class Disconnect implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 1; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +31,11 @@ public class Disconnect implements Packet { return 1; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public Disconnect() { } diff --git a/src/com/hypixel/hytale/protocol/packets/connection/Ping.java b/src/com/hypixel/hytale/protocol/packets/connection/Ping.java index 30dc2bb2..505dc750 100644 --- a/src/com/hypixel/hytale/protocol/packets/connection/Ping.java +++ b/src/com/hypixel/hytale/protocol/packets/connection/Ping.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.connection; import com.hypixel.hytale.protocol.InstantData; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Ping implements Packet { +public class Ping implements Packet, ToClientPacket { public static final int PACKET_ID = 2; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class Ping implements Packet { return 2; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public Ping() { } diff --git a/src/com/hypixel/hytale/protocol/packets/connection/Pong.java b/src/com/hypixel/hytale/protocol/packets/connection/Pong.java index 5c4d0346..45d7882c 100644 --- a/src/com/hypixel/hytale/protocol/packets/connection/Pong.java +++ b/src/com/hypixel/hytale/protocol/packets/connection/Pong.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.connection; import com.hypixel.hytale.protocol.InstantData; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Pong implements Packet { +public class Pong implements Packet, ToServerPacket { public static final int PACKET_ID = 3; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class Pong implements Packet { return 3; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public Pong() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/ApplyKnockback.java b/src/com/hypixel/hytale/protocol/packets/entities/ApplyKnockback.java index fdc5a863..0527c651 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/ApplyKnockback.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/ApplyKnockback.java @@ -1,15 +1,17 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.ChangeVelocityType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ApplyKnockback implements Packet { +public class ApplyKnockback implements Packet, ToClientPacket { public static final int PACKET_ID = 164; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class ApplyKnockback implements Packet { return 164; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ApplyKnockback() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/ChangeVelocity.java b/src/com/hypixel/hytale/protocol/packets/entities/ChangeVelocity.java index cc0f2153..c315653c 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/ChangeVelocity.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/ChangeVelocity.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.ChangeVelocityType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.VelocityConfig; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; @@ -9,7 +11,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ChangeVelocity implements Packet { +public class ChangeVelocity implements Packet, ToClientPacket { public static final int PACKET_ID = 163; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class ChangeVelocity implements Packet { return 163; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ChangeVelocity() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/EntityUpdates.java b/src/com/hypixel/hytale/protocol/packets/entities/EntityUpdates.java index 40052435..1d9d42cc 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/EntityUpdates.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/EntityUpdates.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.EntityUpdate; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class EntityUpdates implements Packet { +public class EntityUpdates implements Packet, ToClientPacket { public static final int PACKET_ID = 161; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class EntityUpdates implements Packet { return 161; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public EntityUpdates() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/MountMovement.java b/src/com/hypixel/hytale/protocol/packets/entities/MountMovement.java index 40d1179f..3a2ce771 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/MountMovement.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/MountMovement.java @@ -2,15 +2,17 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.Direction; import com.hypixel.hytale.protocol.MovementStates; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class MountMovement implements Packet { +public class MountMovement implements Packet, ToServerPacket { public static final int PACKET_ID = 166; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class MountMovement implements Packet { return 166; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public MountMovement() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/PlayAnimation.java b/src/com/hypixel/hytale/protocol/packets/entities/PlayAnimation.java index 48cbe7a6..ed23390c 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/PlayAnimation.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/PlayAnimation.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.AnimationSlot; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PlayAnimation implements Packet { +public class PlayAnimation implements Packet, ToClientPacket { public static final int PACKET_ID = 162; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class PlayAnimation implements Packet { return 162; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlayAnimation() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/SetEntitySeed.java b/src/com/hypixel/hytale/protocol/packets/entities/SetEntitySeed.java index db75f198..02b93b96 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/SetEntitySeed.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/SetEntitySeed.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.entities; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetEntitySeed implements Packet { +public class SetEntitySeed implements Packet, ToClientPacket { public static final int PACKET_ID = 160; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetEntitySeed implements Packet { return 160; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetEntitySeed() { } diff --git a/src/com/hypixel/hytale/protocol/packets/entities/SpawnModelParticles.java b/src/com/hypixel/hytale/protocol/packets/entities/SpawnModelParticles.java index 5a3bb048..5e60745c 100644 --- a/src/com/hypixel/hytale/protocol/packets/entities/SpawnModelParticles.java +++ b/src/com/hypixel/hytale/protocol/packets/entities/SpawnModelParticles.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.entities; import com.hypixel.hytale.protocol.ModelParticle; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SpawnModelParticles implements Packet { +public class SpawnModelParticles implements Packet, ToClientPacket { public static final int PACKET_ID = 165; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class SpawnModelParticles implements Packet { return 165; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SpawnModelParticles() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interaction/CancelInteractionChain.java b/src/com/hypixel/hytale/protocol/packets/interaction/CancelInteractionChain.java index c5ab78e4..e1755121 100644 --- a/src/com/hypixel/hytale/protocol/packets/interaction/CancelInteractionChain.java +++ b/src/com/hypixel/hytale/protocol/packets/interaction/CancelInteractionChain.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.interaction; import com.hypixel.hytale.protocol.ForkedChainId; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class CancelInteractionChain implements Packet { +public class CancelInteractionChain implements Packet, ToClientPacket { public static final int PACKET_ID = 291; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class CancelInteractionChain implements Packet { return 291; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CancelInteractionChain() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interaction/DismountNPC.java b/src/com/hypixel/hytale/protocol/packets/interaction/DismountNPC.java index eafb20d2..ebc5c5ed 100644 --- a/src/com/hypixel/hytale/protocol/packets/interaction/DismountNPC.java +++ b/src/com/hypixel/hytale/protocol/packets/interaction/DismountNPC.java @@ -1,11 +1,14 @@ package com.hypixel.hytale.protocol.packets.interaction; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class DismountNPC implements Packet { +public class DismountNPC implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 294; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +22,11 @@ public class DismountNPC implements Packet { return 294; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static DismountNPC deserialize(@Nonnull ByteBuf buf, int offset) { return new DismountNPC(); diff --git a/src/com/hypixel/hytale/protocol/packets/interaction/MountNPC.java b/src/com/hypixel/hytale/protocol/packets/interaction/MountNPC.java index 004b4e2e..9e0f9cd7 100644 --- a/src/com/hypixel/hytale/protocol/packets/interaction/MountNPC.java +++ b/src/com/hypixel/hytale/protocol/packets/interaction/MountNPC.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.interaction; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class MountNPC implements Packet { +public class MountNPC implements Packet, ToClientPacket { public static final int PACKET_ID = 293; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +26,11 @@ public class MountNPC implements Packet { return 293; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public MountNPC() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interaction/PlayInteractionFor.java b/src/com/hypixel/hytale/protocol/packets/interaction/PlayInteractionFor.java index d2b56767..43bd467e 100644 --- a/src/com/hypixel/hytale/protocol/packets/interaction/PlayInteractionFor.java +++ b/src/com/hypixel/hytale/protocol/packets/interaction/PlayInteractionFor.java @@ -2,7 +2,9 @@ package com.hypixel.hytale.protocol.packets.interaction; import com.hypixel.hytale.protocol.ForkedChainId; import com.hypixel.hytale.protocol.InteractionType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PlayInteractionFor implements Packet { +public class PlayInteractionFor implements Packet, ToClientPacket { public static final int PACKET_ID = 292; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -37,6 +39,11 @@ public class PlayInteractionFor implements Packet { return 292; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlayInteractionFor() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interaction/SyncInteractionChains.java b/src/com/hypixel/hytale/protocol/packets/interaction/SyncInteractionChains.java index 67b632f9..55fe6b04 100644 --- a/src/com/hypixel/hytale/protocol/packets/interaction/SyncInteractionChains.java +++ b/src/com/hypixel/hytale/protocol/packets/interaction/SyncInteractionChains.java @@ -1,6 +1,9 @@ package com.hypixel.hytale.protocol.packets.interaction; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -8,7 +11,7 @@ import io.netty.buffer.ByteBuf; import java.util.Arrays; import javax.annotation.Nonnull; -public class SyncInteractionChains implements Packet { +public class SyncInteractionChains implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 290; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +27,11 @@ public class SyncInteractionChains implements Packet { return 290; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SyncInteractionChains() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/AddToServerPlayerList.java b/src/com/hypixel/hytale/protocol/packets/interface_/AddToServerPlayerList.java index c4fae670..a9dd955c 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/AddToServerPlayerList.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/AddToServerPlayerList.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AddToServerPlayerList implements Packet { +public class AddToServerPlayerList implements Packet, ToClientPacket { public static final int PACKET_ID = 224; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AddToServerPlayerList implements Packet { return 224; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AddToServerPlayerList() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/ChatMessage.java b/src/com/hypixel/hytale/protocol/packets/interface_/ChatMessage.java index 909bf120..be1142bd 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/ChatMessage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/ChatMessage.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ChatMessage implements Packet { +public class ChatMessage implements Packet, ToServerPacket { public static final int PACKET_ID = 211; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class ChatMessage implements Packet { return 211; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ChatMessage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/CustomHud.java b/src/com/hypixel/hytale/protocol/packets/interface_/CustomHud.java index dca66ddb..1543da81 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/CustomHud.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/CustomHud.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class CustomHud implements Packet { +public class CustomHud implements Packet, ToClientPacket { public static final int PACKET_ID = 217; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class CustomHud implements Packet { return 217; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CustomHud() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/CustomPage.java b/src/com/hypixel/hytale/protocol/packets/interface_/CustomPage.java index a237093f..c64e1af4 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/CustomPage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/CustomPage.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class CustomPage implements Packet { +public class CustomPage implements Packet, ToClientPacket { public static final int PACKET_ID = 218; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -35,6 +37,11 @@ public class CustomPage implements Packet { return 218; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CustomPage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/CustomPageEvent.java b/src/com/hypixel/hytale/protocol/packets/interface_/CustomPageEvent.java index 2496534c..4ac2ee99 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/CustomPageEvent.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/CustomPageEvent.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class CustomPageEvent implements Packet { +public class CustomPageEvent implements Packet, ToServerPacket { public static final int PACKET_ID = 219; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class CustomPageEvent implements Packet { return 219; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CustomPageEvent() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/EditorBlocksChange.java b/src/com/hypixel/hytale/protocol/packets/interface_/EditorBlocksChange.java index a94f38fd..780e99d0 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/EditorBlocksChange.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/EditorBlocksChange.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class EditorBlocksChange implements Packet { +public class EditorBlocksChange implements Packet, ToClientPacket { public static final int PACKET_ID = 222; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class EditorBlocksChange implements Packet { return 222; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public EditorBlocksChange() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/HideEventTitle.java b/src/com/hypixel/hytale/protocol/packets/interface_/HideEventTitle.java index 79105a7d..38e3b433 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/HideEventTitle.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/HideEventTitle.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class HideEventTitle implements Packet { +public class HideEventTitle implements Packet, ToClientPacket { public static final int PACKET_ID = 215; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class HideEventTitle implements Packet { return 215; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public HideEventTitle() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/KillFeedMessage.java b/src/com/hypixel/hytale/protocol/packets/interface_/KillFeedMessage.java index 2a7ca9cf..ab17bfca 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/KillFeedMessage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/KillFeedMessage.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.interface_; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class KillFeedMessage implements Packet { +public class KillFeedMessage implements Packet, ToClientPacket { public static final int PACKET_ID = 213; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -31,6 +33,11 @@ public class KillFeedMessage implements Packet { return 213; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public KillFeedMessage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/Notification.java b/src/com/hypixel/hytale/protocol/packets/interface_/Notification.java index c9e24457..1359298a 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/Notification.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/Notification.java @@ -2,7 +2,9 @@ package com.hypixel.hytale.protocol.packets.interface_; import com.hypixel.hytale.protocol.FormattedMessage; import com.hypixel.hytale.protocol.ItemWithAllMetadata; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class Notification implements Packet { +public class Notification implements Packet, ToClientPacket { public static final int PACKET_ID = 212; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class Notification implements Packet { return 212; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public Notification() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/OpenChatWithCommand.java b/src/com/hypixel/hytale/protocol/packets/interface_/OpenChatWithCommand.java index 33f6bc9c..66148885 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/OpenChatWithCommand.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/OpenChatWithCommand.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class OpenChatWithCommand implements Packet { +public class OpenChatWithCommand implements Packet, ToClientPacket { public static final int PACKET_ID = 234; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class OpenChatWithCommand implements Packet { return 234; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public OpenChatWithCommand() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/RemoveFromServerPlayerList.java b/src/com/hypixel/hytale/protocol/packets/interface_/RemoveFromServerPlayerList.java index 3102b740..227b9b09 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/RemoveFromServerPlayerList.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/RemoveFromServerPlayerList.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class RemoveFromServerPlayerList implements Packet { +public class RemoveFromServerPlayerList implements Packet, ToClientPacket { public static final int PACKET_ID = 225; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class RemoveFromServerPlayerList implements Packet { return 225; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RemoveFromServerPlayerList() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/ResetUserInterfaceState.java b/src/com/hypixel/hytale/protocol/packets/interface_/ResetUserInterfaceState.java index 88d8d417..b91ce2b9 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/ResetUserInterfaceState.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/ResetUserInterfaceState.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class ResetUserInterfaceState implements Packet { +public class ResetUserInterfaceState implements Packet, ToClientPacket { public static final int PACKET_ID = 231; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class ResetUserInterfaceState implements Packet { return 231; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static ResetUserInterfaceState deserialize(@Nonnull ByteBuf buf, int offset) { return new ResetUserInterfaceState(); diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/ServerInfo.java b/src/com/hypixel/hytale/protocol/packets/interface_/ServerInfo.java index ae18da2e..c68f2f24 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/ServerInfo.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/ServerInfo.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ServerInfo implements Packet { +public class ServerInfo implements Packet, ToClientPacket { public static final int PACKET_ID = 223; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class ServerInfo implements Packet { return 223; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ServerInfo() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/ServerMessage.java b/src/com/hypixel/hytale/protocol/packets/interface_/ServerMessage.java index 356444c0..42d52abc 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/ServerMessage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/ServerMessage.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.interface_; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ServerMessage implements Packet { +public class ServerMessage implements Packet, ToClientPacket { public static final int PACKET_ID = 210; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class ServerMessage implements Packet { return 210; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ServerMessage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/SetPage.java b/src/com/hypixel/hytale/protocol/packets/interface_/SetPage.java index 6733b84b..61cdc273 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/SetPage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/SetPage.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetPage implements Packet { +public class SetPage implements Packet, ToClientPacket { public static final int PACKET_ID = 216; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class SetPage implements Packet { return 216; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetPage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/ShowEventTitle.java b/src/com/hypixel/hytale/protocol/packets/interface_/ShowEventTitle.java index 74f3b920..354a5986 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/ShowEventTitle.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/ShowEventTitle.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.interface_; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ShowEventTitle implements Packet { +public class ShowEventTitle implements Packet, ToClientPacket { public static final int PACKET_ID = 214; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -35,6 +37,11 @@ public class ShowEventTitle implements Packet { return 214; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ShowEventTitle() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateAnchorUI.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateAnchorUI.java new file mode 100644 index 00000000..b94fbdb7 --- /dev/null +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateAnchorUI.java @@ -0,0 +1,401 @@ +package com.hypixel.hytale.protocol.packets.interface_; + +import com.hypixel.hytale.protocol.NetworkChannel; +import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.io.PacketIO; +import com.hypixel.hytale.protocol.io.ProtocolException; +import com.hypixel.hytale.protocol.io.ValidationResult; +import com.hypixel.hytale.protocol.io.VarInt; +import io.netty.buffer.ByteBuf; +import java.util.Arrays; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class UpdateAnchorUI implements Packet, ToClientPacket { + public static final int PACKET_ID = 235; + public static final boolean IS_COMPRESSED = true; + public static final int NULLABLE_BIT_FIELD_SIZE = 1; + public static final int FIXED_BLOCK_SIZE = 2; + public static final int VARIABLE_FIELD_COUNT = 3; + public static final int VARIABLE_BLOCK_START = 14; + public static final int MAX_SIZE = 1677721600; + @Nullable + public String anchorId; + public boolean clear; + @Nullable + public CustomUICommand[] commands; + @Nullable + public CustomUIEventBinding[] eventBindings; + + @Override + public int getId() { + return 235; + } + + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + + public UpdateAnchorUI() { + } + + public UpdateAnchorUI(@Nullable String anchorId, boolean clear, @Nullable CustomUICommand[] commands, @Nullable CustomUIEventBinding[] eventBindings) { + this.anchorId = anchorId; + this.clear = clear; + this.commands = commands; + this.eventBindings = eventBindings; + } + + public UpdateAnchorUI(@Nonnull UpdateAnchorUI other) { + this.anchorId = other.anchorId; + this.clear = other.clear; + this.commands = other.commands; + this.eventBindings = other.eventBindings; + } + + @Nonnull + public static UpdateAnchorUI deserialize(@Nonnull ByteBuf buf, int offset) { + UpdateAnchorUI obj = new UpdateAnchorUI(); + byte nullBits = buf.getByte(offset); + obj.clear = buf.getByte(offset + 1) != 0; + if ((nullBits & 1) != 0) { + int varPos0 = offset + 14 + buf.getIntLE(offset + 2); + int anchorIdLen = VarInt.peek(buf, varPos0); + if (anchorIdLen < 0) { + throw ProtocolException.negativeLength("AnchorId", anchorIdLen); + } + + if (anchorIdLen > 4096000) { + throw ProtocolException.stringTooLong("AnchorId", anchorIdLen, 4096000); + } + + obj.anchorId = PacketIO.readVarString(buf, varPos0, PacketIO.UTF8); + } + + if ((nullBits & 2) != 0) { + int varPos1 = offset + 14 + buf.getIntLE(offset + 6); + int commandsCount = VarInt.peek(buf, varPos1); + if (commandsCount < 0) { + throw ProtocolException.negativeLength("Commands", commandsCount); + } + + if (commandsCount > 4096000) { + throw ProtocolException.arrayTooLong("Commands", commandsCount, 4096000); + } + + int varIntLen = VarInt.length(buf, varPos1); + if (varPos1 + varIntLen + commandsCount * 2L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("Commands", varPos1 + varIntLen + commandsCount * 2, buf.readableBytes()); + } + + obj.commands = new CustomUICommand[commandsCount]; + int elemPos = varPos1 + varIntLen; + + for (int i = 0; i < commandsCount; i++) { + obj.commands[i] = CustomUICommand.deserialize(buf, elemPos); + elemPos += CustomUICommand.computeBytesConsumed(buf, elemPos); + } + } + + if ((nullBits & 4) != 0) { + int varPos2 = offset + 14 + buf.getIntLE(offset + 10); + int eventBindingsCount = VarInt.peek(buf, varPos2); + if (eventBindingsCount < 0) { + throw ProtocolException.negativeLength("EventBindings", eventBindingsCount); + } + + if (eventBindingsCount > 4096000) { + throw ProtocolException.arrayTooLong("EventBindings", eventBindingsCount, 4096000); + } + + int varIntLen = VarInt.length(buf, varPos2); + if (varPos2 + varIntLen + eventBindingsCount * 3L > buf.readableBytes()) { + throw ProtocolException.bufferTooSmall("EventBindings", varPos2 + varIntLen + eventBindingsCount * 3, buf.readableBytes()); + } + + obj.eventBindings = new CustomUIEventBinding[eventBindingsCount]; + int elemPos = varPos2 + varIntLen; + + for (int i = 0; i < eventBindingsCount; i++) { + obj.eventBindings[i] = CustomUIEventBinding.deserialize(buf, elemPos); + elemPos += CustomUIEventBinding.computeBytesConsumed(buf, elemPos); + } + } + + return obj; + } + + public static int computeBytesConsumed(@Nonnull ByteBuf buf, int offset) { + byte nullBits = buf.getByte(offset); + int maxEnd = 14; + if ((nullBits & 1) != 0) { + int fieldOffset0 = buf.getIntLE(offset + 2); + int pos0 = offset + 14 + fieldOffset0; + int sl = VarInt.peek(buf, pos0); + pos0 += VarInt.length(buf, pos0) + sl; + if (pos0 - offset > maxEnd) { + maxEnd = pos0 - offset; + } + } + + if ((nullBits & 2) != 0) { + int fieldOffset1 = buf.getIntLE(offset + 6); + int pos1 = offset + 14 + fieldOffset1; + int arrLen = VarInt.peek(buf, pos1); + pos1 += VarInt.length(buf, pos1); + + for (int i = 0; i < arrLen; i++) { + pos1 += CustomUICommand.computeBytesConsumed(buf, pos1); + } + + if (pos1 - offset > maxEnd) { + maxEnd = pos1 - offset; + } + } + + if ((nullBits & 4) != 0) { + int fieldOffset2 = buf.getIntLE(offset + 10); + int pos2 = offset + 14 + fieldOffset2; + int arrLen = VarInt.peek(buf, pos2); + pos2 += VarInt.length(buf, pos2); + + for (int i = 0; i < arrLen; i++) { + pos2 += CustomUIEventBinding.computeBytesConsumed(buf, pos2); + } + + if (pos2 - offset > maxEnd) { + maxEnd = pos2 - offset; + } + } + + return maxEnd; + } + + @Override + public void serialize(@Nonnull ByteBuf buf) { + int startPos = buf.writerIndex(); + byte nullBits = 0; + if (this.anchorId != null) { + nullBits = (byte)(nullBits | 1); + } + + if (this.commands != null) { + nullBits = (byte)(nullBits | 2); + } + + if (this.eventBindings != null) { + nullBits = (byte)(nullBits | 4); + } + + buf.writeByte(nullBits); + buf.writeByte(this.clear ? 1 : 0); + int anchorIdOffsetSlot = buf.writerIndex(); + buf.writeIntLE(0); + int commandsOffsetSlot = buf.writerIndex(); + buf.writeIntLE(0); + int eventBindingsOffsetSlot = buf.writerIndex(); + buf.writeIntLE(0); + int varBlockStart = buf.writerIndex(); + if (this.anchorId != null) { + buf.setIntLE(anchorIdOffsetSlot, buf.writerIndex() - varBlockStart); + PacketIO.writeVarString(buf, this.anchorId, 4096000); + } else { + buf.setIntLE(anchorIdOffsetSlot, -1); + } + + if (this.commands != null) { + buf.setIntLE(commandsOffsetSlot, buf.writerIndex() - varBlockStart); + if (this.commands.length > 4096000) { + throw ProtocolException.arrayTooLong("Commands", this.commands.length, 4096000); + } + + VarInt.write(buf, this.commands.length); + + for (CustomUICommand item : this.commands) { + item.serialize(buf); + } + } else { + buf.setIntLE(commandsOffsetSlot, -1); + } + + if (this.eventBindings != null) { + buf.setIntLE(eventBindingsOffsetSlot, buf.writerIndex() - varBlockStart); + if (this.eventBindings.length > 4096000) { + throw ProtocolException.arrayTooLong("EventBindings", this.eventBindings.length, 4096000); + } + + VarInt.write(buf, this.eventBindings.length); + + for (CustomUIEventBinding item : this.eventBindings) { + item.serialize(buf); + } + } else { + buf.setIntLE(eventBindingsOffsetSlot, -1); + } + } + + @Override + public int computeSize() { + int size = 14; + if (this.anchorId != null) { + size += PacketIO.stringSize(this.anchorId); + } + + if (this.commands != null) { + int commandsSize = 0; + + for (CustomUICommand elem : this.commands) { + commandsSize += elem.computeSize(); + } + + size += VarInt.size(this.commands.length) + commandsSize; + } + + if (this.eventBindings != null) { + int eventBindingsSize = 0; + + for (CustomUIEventBinding elem : this.eventBindings) { + eventBindingsSize += elem.computeSize(); + } + + size += VarInt.size(this.eventBindings.length) + eventBindingsSize; + } + + return size; + } + + public static ValidationResult validateStructure(@Nonnull ByteBuf buffer, int offset) { + if (buffer.readableBytes() - offset < 14) { + return ValidationResult.error("Buffer too small: expected at least 14 bytes"); + } else { + byte nullBits = buffer.getByte(offset); + if ((nullBits & 1) != 0) { + int anchorIdOffset = buffer.getIntLE(offset + 2); + if (anchorIdOffset < 0) { + return ValidationResult.error("Invalid offset for AnchorId"); + } + + int pos = offset + 14 + anchorIdOffset; + if (pos >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for AnchorId"); + } + + int anchorIdLen = VarInt.peek(buffer, pos); + if (anchorIdLen < 0) { + return ValidationResult.error("Invalid string length for AnchorId"); + } + + if (anchorIdLen > 4096000) { + return ValidationResult.error("AnchorId exceeds max length 4096000"); + } + + pos += VarInt.length(buffer, pos); + pos += anchorIdLen; + if (pos > buffer.writerIndex()) { + return ValidationResult.error("Buffer overflow reading AnchorId"); + } + } + + if ((nullBits & 2) != 0) { + int commandsOffset = buffer.getIntLE(offset + 6); + if (commandsOffset < 0) { + return ValidationResult.error("Invalid offset for Commands"); + } + + int posx = offset + 14 + commandsOffset; + if (posx >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for Commands"); + } + + int commandsCount = VarInt.peek(buffer, posx); + if (commandsCount < 0) { + return ValidationResult.error("Invalid array count for Commands"); + } + + if (commandsCount > 4096000) { + return ValidationResult.error("Commands exceeds max length 4096000"); + } + + posx += VarInt.length(buffer, posx); + + for (int i = 0; i < commandsCount; i++) { + ValidationResult structResult = CustomUICommand.validateStructure(buffer, posx); + if (!structResult.isValid()) { + return ValidationResult.error("Invalid CustomUICommand in Commands[" + i + "]: " + structResult.error()); + } + + posx += CustomUICommand.computeBytesConsumed(buffer, posx); + } + } + + if ((nullBits & 4) != 0) { + int eventBindingsOffset = buffer.getIntLE(offset + 10); + if (eventBindingsOffset < 0) { + return ValidationResult.error("Invalid offset for EventBindings"); + } + + int posxx = offset + 14 + eventBindingsOffset; + if (posxx >= buffer.writerIndex()) { + return ValidationResult.error("Offset out of bounds for EventBindings"); + } + + int eventBindingsCount = VarInt.peek(buffer, posxx); + if (eventBindingsCount < 0) { + return ValidationResult.error("Invalid array count for EventBindings"); + } + + if (eventBindingsCount > 4096000) { + return ValidationResult.error("EventBindings exceeds max length 4096000"); + } + + posxx += VarInt.length(buffer, posxx); + + for (int i = 0; i < eventBindingsCount; i++) { + ValidationResult structResult = CustomUIEventBinding.validateStructure(buffer, posxx); + if (!structResult.isValid()) { + return ValidationResult.error("Invalid CustomUIEventBinding in EventBindings[" + i + "]: " + structResult.error()); + } + + posxx += CustomUIEventBinding.computeBytesConsumed(buffer, posxx); + } + } + + return ValidationResult.OK; + } + } + + public UpdateAnchorUI clone() { + UpdateAnchorUI copy = new UpdateAnchorUI(); + copy.anchorId = this.anchorId; + copy.clear = this.clear; + copy.commands = this.commands != null ? Arrays.stream(this.commands).map(e -> e.clone()).toArray(CustomUICommand[]::new) : null; + copy.eventBindings = this.eventBindings != null ? Arrays.stream(this.eventBindings).map(e -> e.clone()).toArray(CustomUIEventBinding[]::new) : null; + return copy; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else { + return !(obj instanceof UpdateAnchorUI other) + ? false + : Objects.equals(this.anchorId, other.anchorId) + && this.clear == other.clear + && Arrays.equals((Object[])this.commands, (Object[])other.commands) + && Arrays.equals((Object[])this.eventBindings, (Object[])other.eventBindings); + } + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + Objects.hashCode(this.anchorId); + result = 31 * result + Boolean.hashCode(this.clear); + result = 31 * result + Arrays.hashCode((Object[])this.commands); + return 31 * result + Arrays.hashCode((Object[])this.eventBindings); + } +} diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateKnownRecipes.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateKnownRecipes.java index b3305b27..0ae498c5 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateKnownRecipes.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateKnownRecipes.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.interface_; import com.hypixel.hytale.protocol.CraftingRecipe; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateKnownRecipes implements Packet { +public class UpdateKnownRecipes implements Packet, ToClientPacket { public static final int PACKET_ID = 228; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class UpdateKnownRecipes implements Packet { return 228; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateKnownRecipes() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateLanguage.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateLanguage.java index c707172e..58a905e4 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateLanguage.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateLanguage.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateLanguage implements Packet { +public class UpdateLanguage implements Packet, ToServerPacket { public static final int PACKET_ID = 232; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class UpdateLanguage implements Packet { return 232; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateLanguage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdatePortal.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdatePortal.java index d475e6e8..0fd42908 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdatePortal.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdatePortal.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdatePortal implements Packet { +public class UpdatePortal implements Packet, ToClientPacket { public static final int PACKET_ID = 229; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class UpdatePortal implements Packet { return 229; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdatePortal() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerList.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerList.java index da0362da..3e2ae715 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerList.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerList.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateServerPlayerList implements Packet { +public class UpdateServerPlayerList implements Packet, ToClientPacket { public static final int PACKET_ID = 226; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class UpdateServerPlayerList implements Packet { return 226; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateServerPlayerList() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerListPing.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerListPing.java index 91906fa4..59e9b3e9 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerListPing.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateServerPlayerListPing.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateServerPlayerListPing implements Packet { +public class UpdateServerPlayerListPing implements Packet, ToClientPacket { public static final int PACKET_ID = 227; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class UpdateServerPlayerListPing implements Packet { return 227; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateServerPlayerListPing() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateVisibleHudComponents.java b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateVisibleHudComponents.java index 501821e8..3b8c3a14 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/UpdateVisibleHudComponents.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/UpdateVisibleHudComponents.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateVisibleHudComponents implements Packet { +public class UpdateVisibleHudComponents implements Packet, ToClientPacket { public static final int PACKET_ID = 230; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class UpdateVisibleHudComponents implements Packet { return 230; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateVisibleHudComponents() { } diff --git a/src/com/hypixel/hytale/protocol/packets/interface_/WorldSavingStatus.java b/src/com/hypixel/hytale/protocol/packets/interface_/WorldSavingStatus.java index 259058db..fe435b00 100644 --- a/src/com/hypixel/hytale/protocol/packets/interface_/WorldSavingStatus.java +++ b/src/com/hypixel/hytale/protocol/packets/interface_/WorldSavingStatus.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.interface_; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class WorldSavingStatus implements Packet { +public class WorldSavingStatus implements Packet, ToClientPacket { public static final int PACKET_ID = 233; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class WorldSavingStatus implements Packet { return 233; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public WorldSavingStatus() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/DropCreativeItem.java b/src/com/hypixel/hytale/protocol/packets/inventory/DropCreativeItem.java index cc356ca6..b517b4ca 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/DropCreativeItem.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/DropCreativeItem.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.inventory; import com.hypixel.hytale.protocol.ItemQuantity; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class DropCreativeItem implements Packet { +public class DropCreativeItem implements Packet, ToServerPacket { public static final int PACKET_ID = 172; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class DropCreativeItem implements Packet { return 172; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public DropCreativeItem() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/DropItemStack.java b/src/com/hypixel/hytale/protocol/packets/inventory/DropItemStack.java index dcb5a143..c2a07333 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/DropItemStack.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/DropItemStack.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.inventory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class DropItemStack implements Packet { +public class DropItemStack implements Packet, ToServerPacket { public static final int PACKET_ID = 174; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class DropItemStack implements Packet { return 174; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public DropItemStack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/InventoryAction.java b/src/com/hypixel/hytale/protocol/packets/inventory/InventoryAction.java index c95b668f..8bc329ed 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/InventoryAction.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/InventoryAction.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.inventory; import com.hypixel.hytale.protocol.InventoryActionType; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class InventoryAction implements Packet { +public class InventoryAction implements Packet, ToServerPacket { public static final int PACKET_ID = 179; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class InventoryAction implements Packet { return 179; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public InventoryAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/MoveItemStack.java b/src/com/hypixel/hytale/protocol/packets/inventory/MoveItemStack.java index 468418f9..ef1cd823 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/MoveItemStack.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/MoveItemStack.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.inventory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class MoveItemStack implements Packet { +public class MoveItemStack implements Packet, ToServerPacket { public static final int PACKET_ID = 175; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class MoveItemStack implements Packet { return 175; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public MoveItemStack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/SetActiveSlot.java b/src/com/hypixel/hytale/protocol/packets/inventory/SetActiveSlot.java index e78fa438..14966a60 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/SetActiveSlot.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/SetActiveSlot.java @@ -1,12 +1,15 @@ package com.hypixel.hytale.protocol.packets.inventory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetActiveSlot implements Packet { +public class SetActiveSlot implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 177; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +25,11 @@ public class SetActiveSlot implements Packet { return 177; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetActiveSlot() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/SetCreativeItem.java b/src/com/hypixel/hytale/protocol/packets/inventory/SetCreativeItem.java index 214a850b..a5dc16c0 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/SetCreativeItem.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/SetCreativeItem.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.inventory; import com.hypixel.hytale.protocol.ItemQuantity; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetCreativeItem implements Packet { +public class SetCreativeItem implements Packet, ToServerPacket { public static final int PACKET_ID = 171; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class SetCreativeItem implements Packet { return 171; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetCreativeItem() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/SmartGiveCreativeItem.java b/src/com/hypixel/hytale/protocol/packets/inventory/SmartGiveCreativeItem.java index b3e95844..b39d230b 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/SmartGiveCreativeItem.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/SmartGiveCreativeItem.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.inventory; import com.hypixel.hytale.protocol.ItemQuantity; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SmartMoveType; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SmartGiveCreativeItem implements Packet { +public class SmartGiveCreativeItem implements Packet, ToServerPacket { public static final int PACKET_ID = 173; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class SmartGiveCreativeItem implements Packet { return 173; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SmartGiveCreativeItem() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/SmartMoveItemStack.java b/src/com/hypixel/hytale/protocol/packets/inventory/SmartMoveItemStack.java index b20b10ef..061343bb 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/SmartMoveItemStack.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/SmartMoveItemStack.java @@ -1,13 +1,16 @@ package com.hypixel.hytale.protocol.packets.inventory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SmartMoveType; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SmartMoveItemStack implements Packet { +public class SmartMoveItemStack implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 176; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +29,11 @@ public class SmartMoveItemStack implements Packet { return 176; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SmartMoveItemStack() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/SwitchHotbarBlockSet.java b/src/com/hypixel/hytale/protocol/packets/inventory/SwitchHotbarBlockSet.java index ef36b9db..6b21c13d 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/SwitchHotbarBlockSet.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/SwitchHotbarBlockSet.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.inventory; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SwitchHotbarBlockSet implements Packet { +public class SwitchHotbarBlockSet implements Packet, ToServerPacket { public static final int PACKET_ID = 178; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class SwitchHotbarBlockSet implements Packet { return 178; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SwitchHotbarBlockSet() { } diff --git a/src/com/hypixel/hytale/protocol/packets/inventory/UpdatePlayerInventory.java b/src/com/hypixel/hytale/protocol/packets/inventory/UpdatePlayerInventory.java index c7fa33a2..72744306 100644 --- a/src/com/hypixel/hytale/protocol/packets/inventory/UpdatePlayerInventory.java +++ b/src/com/hypixel/hytale/protocol/packets/inventory/UpdatePlayerInventory.java @@ -1,15 +1,17 @@ package com.hypixel.hytale.protocol.packets.inventory; import com.hypixel.hytale.protocol.InventorySection; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SortType; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdatePlayerInventory implements Packet { +public class UpdatePlayerInventory implements Packet, ToClientPacket { public static final int PACKET_ID = 170; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -39,6 +41,11 @@ public class UpdatePlayerInventory implements Packet { return 170; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdatePlayerInventory() { } diff --git a/src/com/hypixel/hytale/protocol/packets/machinima/RequestMachinimaActorModel.java b/src/com/hypixel/hytale/protocol/packets/machinima/RequestMachinimaActorModel.java index 2214eb01..b419c1cc 100644 --- a/src/com/hypixel/hytale/protocol/packets/machinima/RequestMachinimaActorModel.java +++ b/src/com/hypixel/hytale/protocol/packets/machinima/RequestMachinimaActorModel.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.machinima; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class RequestMachinimaActorModel implements Packet { +public class RequestMachinimaActorModel implements Packet, ToServerPacket { public static final int PACKET_ID = 260; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class RequestMachinimaActorModel implements Packet { return 260; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RequestMachinimaActorModel() { } diff --git a/src/com/hypixel/hytale/protocol/packets/machinima/SetMachinimaActorModel.java b/src/com/hypixel/hytale/protocol/packets/machinima/SetMachinimaActorModel.java index 6c768a49..5528242c 100644 --- a/src/com/hypixel/hytale/protocol/packets/machinima/SetMachinimaActorModel.java +++ b/src/com/hypixel/hytale/protocol/packets/machinima/SetMachinimaActorModel.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.machinima; import com.hypixel.hytale.protocol.Model; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetMachinimaActorModel implements Packet { +public class SetMachinimaActorModel implements Packet, ToClientPacket { public static final int PACKET_ID = 261; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -31,6 +33,11 @@ public class SetMachinimaActorModel implements Packet { return 261; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetMachinimaActorModel() { } diff --git a/src/com/hypixel/hytale/protocol/packets/machinima/UpdateMachinimaScene.java b/src/com/hypixel/hytale/protocol/packets/machinima/UpdateMachinimaScene.java index 989ab812..1fc62db0 100644 --- a/src/com/hypixel/hytale/protocol/packets/machinima/UpdateMachinimaScene.java +++ b/src/com/hypixel/hytale/protocol/packets/machinima/UpdateMachinimaScene.java @@ -1,6 +1,9 @@ package com.hypixel.hytale.protocol.packets.machinima; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateMachinimaScene implements Packet { +public class UpdateMachinimaScene implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 262; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -34,6 +37,11 @@ public class UpdateMachinimaScene implements Packet { return 262; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateMachinimaScene() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/ClearDebugShapes.java b/src/com/hypixel/hytale/protocol/packets/player/ClearDebugShapes.java index dbec88ff..befeeefb 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ClearDebugShapes.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ClearDebugShapes.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class ClearDebugShapes implements Packet { +public class ClearDebugShapes implements Packet, ToClientPacket { public static final int PACKET_ID = 115; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class ClearDebugShapes implements Packet { return 115; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static ClearDebugShapes deserialize(@Nonnull ByteBuf buf, int offset) { return new ClearDebugShapes(); diff --git a/src/com/hypixel/hytale/protocol/packets/player/ClientMovement.java b/src/com/hypixel/hytale/protocol/packets/player/ClientMovement.java index 6757ef56..d37ec277 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ClientMovement.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ClientMovement.java @@ -3,9 +3,11 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.Direction; import com.hypixel.hytale.protocol.HalfFloatPosition; import com.hypixel.hytale.protocol.MovementStates; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; import com.hypixel.hytale.protocol.TeleportAck; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.Vector3d; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -14,7 +16,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ClientMovement implements Packet { +public class ClientMovement implements Packet, ToServerPacket { public static final int PACKET_ID = 108; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 2; @@ -47,6 +49,11 @@ public class ClientMovement implements Packet { return 108; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientMovement() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/ClientPlaceBlock.java b/src/com/hypixel/hytale/protocol/packets/player/ClientPlaceBlock.java index 44995446..b7ad0c92 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ClientPlaceBlock.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ClientPlaceBlock.java @@ -2,14 +2,16 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.BlockPosition; import com.hypixel.hytale.protocol.BlockRotation; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ClientPlaceBlock implements Packet { +public class ClientPlaceBlock implements Packet, ToServerPacket { public static final int PACKET_ID = 117; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class ClientPlaceBlock implements Packet { return 117; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientPlaceBlock() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/ClientReady.java b/src/com/hypixel/hytale/protocol/packets/player/ClientReady.java index f68c938f..e500b3c7 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ClientReady.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ClientReady.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ClientReady implements Packet { +public class ClientReady implements Packet, ToServerPacket { public static final int PACKET_ID = 105; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class ClientReady implements Packet { return 105; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientReady() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/ClientTeleport.java b/src/com/hypixel/hytale/protocol/packets/player/ClientTeleport.java index 105377b4..665c5bc5 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ClientTeleport.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ClientTeleport.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.ModelTransform; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ClientTeleport implements Packet { +public class ClientTeleport implements Packet, ToClientPacket { public static final int PACKET_ID = 109; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class ClientTeleport implements Packet { return 109; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientTeleport() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/DamageInfo.java b/src/com/hypixel/hytale/protocol/packets/player/DamageInfo.java index 3ccd7039..4871198e 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/DamageInfo.java +++ b/src/com/hypixel/hytale/protocol/packets/player/DamageInfo.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.DamageCause; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.Vector3d; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; @@ -9,7 +11,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class DamageInfo implements Packet { +public class DamageInfo implements Packet, ToClientPacket { public static final int PACKET_ID = 112; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class DamageInfo implements Packet { return 112; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public DamageInfo() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/DisplayDebug.java b/src/com/hypixel/hytale/protocol/packets/player/DisplayDebug.java index e589a2eb..a965a819 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/DisplayDebug.java +++ b/src/com/hypixel/hytale/protocol/packets/player/DisplayDebug.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.DebugShape; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.Vector3f; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class DisplayDebug implements Packet { +public class DisplayDebug implements Packet, ToClientPacket { public static final int PACKET_ID = 114; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -37,6 +39,11 @@ public class DisplayDebug implements Packet { return 114; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public DisplayDebug() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/JoinWorld.java b/src/com/hypixel/hytale/protocol/packets/player/JoinWorld.java index 126d5e36..6ffd9f97 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/JoinWorld.java +++ b/src/com/hypixel/hytale/protocol/packets/player/JoinWorld.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; @@ -8,7 +10,7 @@ import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; -public class JoinWorld implements Packet { +public class JoinWorld implements Packet, ToClientPacket { public static final int PACKET_ID = 104; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class JoinWorld implements Packet { return 104; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public JoinWorld() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/LoadHotbar.java b/src/com/hypixel/hytale/protocol/packets/player/LoadHotbar.java index 22440789..e9f1fa10 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/LoadHotbar.java +++ b/src/com/hypixel/hytale/protocol/packets/player/LoadHotbar.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class LoadHotbar implements Packet { +public class LoadHotbar implements Packet, ToServerPacket { public static final int PACKET_ID = 106; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class LoadHotbar implements Packet { return 106; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public LoadHotbar() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/MouseInteraction.java b/src/com/hypixel/hytale/protocol/packets/player/MouseInteraction.java index 494452d9..d77b5deb 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/MouseInteraction.java +++ b/src/com/hypixel/hytale/protocol/packets/player/MouseInteraction.java @@ -2,7 +2,9 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.MouseButtonEvent; import com.hypixel.hytale.protocol.MouseMotionEvent; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.Vector2f; import com.hypixel.hytale.protocol.WorldInteraction; import com.hypixel.hytale.protocol.io.PacketIO; @@ -14,7 +16,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class MouseInteraction implements Packet { +public class MouseInteraction implements Packet, ToServerPacket { public static final int PACKET_ID = 111; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -40,6 +42,11 @@ public class MouseInteraction implements Packet { return 111; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public MouseInteraction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/RemoveMapMarker.java b/src/com/hypixel/hytale/protocol/packets/player/RemoveMapMarker.java index 7111984b..bb02fc0e 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/RemoveMapMarker.java +++ b/src/com/hypixel/hytale/protocol/packets/player/RemoveMapMarker.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class RemoveMapMarker implements Packet { +public class RemoveMapMarker implements Packet, ToServerPacket { public static final int PACKET_ID = 119; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class RemoveMapMarker implements Packet { return 119; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RemoveMapMarker() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/ReticleEvent.java b/src/com/hypixel/hytale/protocol/packets/player/ReticleEvent.java index 1864e3db..e35e4d10 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/ReticleEvent.java +++ b/src/com/hypixel/hytale/protocol/packets/player/ReticleEvent.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ReticleEvent implements Packet { +public class ReticleEvent implements Packet, ToClientPacket { public static final int PACKET_ID = 113; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class ReticleEvent implements Packet { return 113; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ReticleEvent() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SaveHotbar.java b/src/com/hypixel/hytale/protocol/packets/player/SaveHotbar.java index cec3b579..696ca2e7 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SaveHotbar.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SaveHotbar.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SaveHotbar implements Packet { +public class SaveHotbar implements Packet, ToServerPacket { public static final int PACKET_ID = 107; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SaveHotbar implements Packet { return 107; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SaveHotbar() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SetBlockPlacementOverride.java b/src/com/hypixel/hytale/protocol/packets/player/SetBlockPlacementOverride.java index 13712666..051a7713 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SetBlockPlacementOverride.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SetBlockPlacementOverride.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetBlockPlacementOverride implements Packet { +public class SetBlockPlacementOverride implements Packet, ToClientPacket { public static final int PACKET_ID = 103; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetBlockPlacementOverride implements Packet { return 103; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetBlockPlacementOverride() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SetClientId.java b/src/com/hypixel/hytale/protocol/packets/player/SetClientId.java index eca8b0be..444268f1 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SetClientId.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SetClientId.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetClientId implements Packet { +public class SetClientId implements Packet, ToClientPacket { public static final int PACKET_ID = 100; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetClientId implements Packet { return 100; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetClientId() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SetGameMode.java b/src/com/hypixel/hytale/protocol/packets/player/SetGameMode.java index 9f86db93..6c23fd98 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SetGameMode.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SetGameMode.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.GameMode; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetGameMode implements Packet { +public class SetGameMode implements Packet, ToClientPacket { public static final int PACKET_ID = 101; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class SetGameMode implements Packet { return 101; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetGameMode() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SetMovementStates.java b/src/com/hypixel/hytale/protocol/packets/player/SetMovementStates.java index c4de0af3..2a518d39 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SetMovementStates.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SetMovementStates.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SavedMovementStates; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetMovementStates implements Packet { +public class SetMovementStates implements Packet, ToClientPacket { public static final int PACKET_ID = 102; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class SetMovementStates implements Packet { return 102; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetMovementStates() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/SyncPlayerPreferences.java b/src/com/hypixel/hytale/protocol/packets/player/SyncPlayerPreferences.java index 88fffd16..2d3097d6 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/SyncPlayerPreferences.java +++ b/src/com/hypixel/hytale/protocol/packets/player/SyncPlayerPreferences.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.PickupLocation; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SyncPlayerPreferences implements Packet { +public class SyncPlayerPreferences implements Packet, ToServerPacket { public static final int PACKET_ID = 116; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -38,6 +40,11 @@ public class SyncPlayerPreferences implements Packet { return 116; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SyncPlayerPreferences() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/UpdateMemoriesFeatureStatus.java b/src/com/hypixel/hytale/protocol/packets/player/UpdateMemoriesFeatureStatus.java index f9931582..45b7d9d5 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/UpdateMemoriesFeatureStatus.java +++ b/src/com/hypixel/hytale/protocol/packets/player/UpdateMemoriesFeatureStatus.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.player; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateMemoriesFeatureStatus implements Packet { +public class UpdateMemoriesFeatureStatus implements Packet, ToClientPacket { public static final int PACKET_ID = 118; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class UpdateMemoriesFeatureStatus implements Packet { return 118; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateMemoriesFeatureStatus() { } diff --git a/src/com/hypixel/hytale/protocol/packets/player/UpdateMovementSettings.java b/src/com/hypixel/hytale/protocol/packets/player/UpdateMovementSettings.java index 591d1bc4..c4e2eed5 100644 --- a/src/com/hypixel/hytale/protocol/packets/player/UpdateMovementSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/player/UpdateMovementSettings.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.player; import com.hypixel.hytale.protocol.MovementSettings; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateMovementSettings implements Packet { +public class UpdateMovementSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 110; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class UpdateMovementSettings implements Packet { return 110; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateMovementSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/serveraccess/RequestServerAccess.java b/src/com/hypixel/hytale/protocol/packets/serveraccess/RequestServerAccess.java index 75858234..716fb279 100644 --- a/src/com/hypixel/hytale/protocol/packets/serveraccess/RequestServerAccess.java +++ b/src/com/hypixel/hytale/protocol/packets/serveraccess/RequestServerAccess.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.serveraccess; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class RequestServerAccess implements Packet { +public class RequestServerAccess implements Packet, ToClientPacket { public static final int PACKET_ID = 250; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class RequestServerAccess implements Packet { return 250; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RequestServerAccess() { } diff --git a/src/com/hypixel/hytale/protocol/packets/serveraccess/SetServerAccess.java b/src/com/hypixel/hytale/protocol/packets/serveraccess/SetServerAccess.java index c3195cee..8f89996e 100644 --- a/src/com/hypixel/hytale/protocol/packets/serveraccess/SetServerAccess.java +++ b/src/com/hypixel/hytale/protocol/packets/serveraccess/SetServerAccess.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.serveraccess; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetServerAccess implements Packet { +public class SetServerAccess implements Packet, ToServerPacket { public static final int PACKET_ID = 252; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class SetServerAccess implements Packet { return 252; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetServerAccess() { } diff --git a/src/com/hypixel/hytale/protocol/packets/serveraccess/UpdateServerAccess.java b/src/com/hypixel/hytale/protocol/packets/serveraccess/UpdateServerAccess.java index 8be67ebd..cf78dfa3 100644 --- a/src/com/hypixel/hytale/protocol/packets/serveraccess/UpdateServerAccess.java +++ b/src/com/hypixel/hytale/protocol/packets/serveraccess/UpdateServerAccess.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.serveraccess; import com.hypixel.hytale.protocol.HostAddress; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateServerAccess implements Packet { +public class UpdateServerAccess implements Packet, ToServerPacket { public static final int PACKET_ID = 251; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class UpdateServerAccess implements Packet { return 251; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateServerAccess() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/AssetFinalize.java b/src/com/hypixel/hytale/protocol/packets/setup/AssetFinalize.java index b7ab6fca..acbe37d7 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/AssetFinalize.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/AssetFinalize.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class AssetFinalize implements Packet { +public class AssetFinalize implements Packet, ToClientPacket { public static final int PACKET_ID = 26; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class AssetFinalize implements Packet { return 26; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static AssetFinalize deserialize(@Nonnull ByteBuf buf, int offset) { return new AssetFinalize(); diff --git a/src/com/hypixel/hytale/protocol/packets/setup/AssetInitialize.java b/src/com/hypixel/hytale/protocol/packets/setup/AssetInitialize.java index 9fe4b2e1..9c25d68e 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/AssetInitialize.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/AssetInitialize.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.setup; import com.hypixel.hytale.protocol.Asset; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class AssetInitialize implements Packet { +public class AssetInitialize implements Packet, ToClientPacket { public static final int PACKET_ID = 24; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +26,11 @@ public class AssetInitialize implements Packet { return 24; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetInitialize() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/AssetPart.java b/src/com/hypixel/hytale/protocol/packets/setup/AssetPart.java index a523baf6..5e790fc7 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/AssetPart.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/AssetPart.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class AssetPart implements Packet { +public class AssetPart implements Packet, ToClientPacket { public static final int PACKET_ID = 25; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class AssetPart implements Packet { return 25; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public AssetPart() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/PlayerOptions.java b/src/com/hypixel/hytale/protocol/packets/setup/PlayerOptions.java index 0329d831..1d0757ee 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/PlayerOptions.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/PlayerOptions.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.PlayerSkin; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PlayerOptions implements Packet { +public class PlayerOptions implements Packet, ToServerPacket { public static final int PACKET_ID = 33; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class PlayerOptions implements Packet { return 33; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlayerOptions() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/RemoveAssets.java b/src/com/hypixel/hytale/protocol/packets/setup/RemoveAssets.java index 29319ac8..b7ea3c02 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/RemoveAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/RemoveAssets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.setup; import com.hypixel.hytale.protocol.Asset; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class RemoveAssets implements Packet { +public class RemoveAssets implements Packet, ToClientPacket { public static final int PACKET_ID = 27; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class RemoveAssets implements Packet { return 27; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RemoveAssets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/RequestAssets.java b/src/com/hypixel/hytale/protocol/packets/setup/RequestAssets.java index 2f92d5cf..0571b32f 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/RequestAssets.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/RequestAssets.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.setup; import com.hypixel.hytale.protocol.Asset; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class RequestAssets implements Packet { +public class RequestAssets implements Packet, ToServerPacket { public static final int PACKET_ID = 23; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class RequestAssets implements Packet { return 23; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public RequestAssets() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/RequestCommonAssetsRebuild.java b/src/com/hypixel/hytale/protocol/packets/setup/RequestCommonAssetsRebuild.java index 1cf30bdb..cfb10ee5 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/RequestCommonAssetsRebuild.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/RequestCommonAssetsRebuild.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class RequestCommonAssetsRebuild implements Packet { +public class RequestCommonAssetsRebuild implements Packet, ToClientPacket { public static final int PACKET_ID = 28; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class RequestCommonAssetsRebuild implements Packet { return 28; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static RequestCommonAssetsRebuild deserialize(@Nonnull ByteBuf buf, int offset) { return new RequestCommonAssetsRebuild(); diff --git a/src/com/hypixel/hytale/protocol/packets/setup/ServerTags.java b/src/com/hypixel/hytale/protocol/packets/setup/ServerTags.java index cd119617..1d02d785 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/ServerTags.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/ServerTags.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -13,7 +15,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class ServerTags implements Packet { +public class ServerTags implements Packet, ToClientPacket { public static final int PACKET_ID = 34; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -29,6 +31,11 @@ public class ServerTags implements Packet { return 34; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ServerTags() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/SetTimeDilation.java b/src/com/hypixel/hytale/protocol/packets/setup/SetTimeDilation.java index 01f7b9bd..010947cd 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/SetTimeDilation.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/SetTimeDilation.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetTimeDilation implements Packet { +public class SetTimeDilation implements Packet, ToClientPacket { public static final int PACKET_ID = 30; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetTimeDilation implements Packet { return 30; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetTimeDilation() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/SetUpdateRate.java b/src/com/hypixel/hytale/protocol/packets/setup/SetUpdateRate.java index b50015fb..fb8c04fb 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/SetUpdateRate.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/SetUpdateRate.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetUpdateRate implements Packet { +public class SetUpdateRate implements Packet, ToClientPacket { public static final int PACKET_ID = 29; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetUpdateRate implements Packet { return 29; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetUpdateRate() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/UpdateFeatures.java b/src/com/hypixel/hytale/protocol/packets/setup/UpdateFeatures.java index 31a66e12..0a2bc09c 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/UpdateFeatures.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/UpdateFeatures.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -12,7 +14,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateFeatures implements Packet { +public class UpdateFeatures implements Packet, ToClientPacket { public static final int PACKET_ID = 31; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class UpdateFeatures implements Packet { return 31; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateFeatures() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/ViewRadius.java b/src/com/hypixel/hytale/protocol/packets/setup/ViewRadius.java index 2f576b00..6cc45fcc 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/ViewRadius.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/ViewRadius.java @@ -1,12 +1,15 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ViewRadius implements Packet { +public class ViewRadius implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 32; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +24,11 @@ public class ViewRadius implements Packet { return 32; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ViewRadius() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadFinished.java b/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadFinished.java index 4b66c09d..924279b9 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadFinished.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadFinished.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.setup; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class WorldLoadFinished implements Packet { +public class WorldLoadFinished implements Packet, ToClientPacket { public static final int PACKET_ID = 22; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class WorldLoadFinished implements Packet { return 22; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static WorldLoadFinished deserialize(@Nonnull ByteBuf buf, int offset) { return new WorldLoadFinished(); diff --git a/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadProgress.java b/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadProgress.java index 84e94c5d..7b84287b 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadProgress.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/WorldLoadProgress.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.setup; import com.hypixel.hytale.protocol.FormattedMessage; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class WorldLoadProgress implements Packet { +public class WorldLoadProgress implements Packet, ToClientPacket { public static final int PACKET_ID = 21; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class WorldLoadProgress implements Packet { return 21; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public WorldLoadProgress() { } diff --git a/src/com/hypixel/hytale/protocol/packets/setup/WorldSettings.java b/src/com/hypixel/hytale/protocol/packets/setup/WorldSettings.java index e830d2f4..4b10c81c 100644 --- a/src/com/hypixel/hytale/protocol/packets/setup/WorldSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/setup/WorldSettings.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.setup; import com.hypixel.hytale.protocol.Asset; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class WorldSettings implements Packet { +public class WorldSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 20; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class WorldSettings implements Packet { return 20; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public WorldSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/window/ClientOpenWindow.java b/src/com/hypixel/hytale/protocol/packets/window/ClientOpenWindow.java index e8f0aa0c..6c04aa6c 100644 --- a/src/com/hypixel/hytale/protocol/packets/window/ClientOpenWindow.java +++ b/src/com/hypixel/hytale/protocol/packets/window/ClientOpenWindow.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.window; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ClientOpenWindow implements Packet { +public class ClientOpenWindow implements Packet, ToServerPacket { public static final int PACKET_ID = 204; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class ClientOpenWindow implements Packet { return 204; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ClientOpenWindow() { } diff --git a/src/com/hypixel/hytale/protocol/packets/window/CloseWindow.java b/src/com/hypixel/hytale/protocol/packets/window/CloseWindow.java index f9664a5c..9ac27cc4 100644 --- a/src/com/hypixel/hytale/protocol/packets/window/CloseWindow.java +++ b/src/com/hypixel/hytale/protocol/packets/window/CloseWindow.java @@ -1,12 +1,15 @@ package com.hypixel.hytale.protocol.packets.window; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class CloseWindow implements Packet { +public class CloseWindow implements Packet, ToServerPacket, ToClientPacket { public static final int PACKET_ID = 202; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +24,11 @@ public class CloseWindow implements Packet { return 202; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CloseWindow() { } diff --git a/src/com/hypixel/hytale/protocol/packets/window/OpenWindow.java b/src/com/hypixel/hytale/protocol/packets/window/OpenWindow.java index 72cb6834..bde3e616 100644 --- a/src/com/hypixel/hytale/protocol/packets/window/OpenWindow.java +++ b/src/com/hypixel/hytale/protocol/packets/window/OpenWindow.java @@ -2,7 +2,9 @@ package com.hypixel.hytale.protocol.packets.window; import com.hypixel.hytale.protocol.ExtraResources; import com.hypixel.hytale.protocol.InventorySection; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class OpenWindow implements Packet { +public class OpenWindow implements Packet, ToClientPacket { public static final int PACKET_ID = 200; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -35,6 +37,11 @@ public class OpenWindow implements Packet { return 200; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public OpenWindow() { } diff --git a/src/com/hypixel/hytale/protocol/packets/window/SendWindowAction.java b/src/com/hypixel/hytale/protocol/packets/window/SendWindowAction.java index beb244db..428f6fd5 100644 --- a/src/com/hypixel/hytale/protocol/packets/window/SendWindowAction.java +++ b/src/com/hypixel/hytale/protocol/packets/window/SendWindowAction.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.window; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SendWindowAction implements Packet { +public class SendWindowAction implements Packet, ToServerPacket { public static final int PACKET_ID = 203; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -23,6 +25,11 @@ public class SendWindowAction implements Packet { return 203; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SendWindowAction() { } diff --git a/src/com/hypixel/hytale/protocol/packets/window/UpdateWindow.java b/src/com/hypixel/hytale/protocol/packets/window/UpdateWindow.java index 78f666b3..16dd4dcf 100644 --- a/src/com/hypixel/hytale/protocol/packets/window/UpdateWindow.java +++ b/src/com/hypixel/hytale/protocol/packets/window/UpdateWindow.java @@ -2,7 +2,9 @@ package com.hypixel.hytale.protocol.packets.window; import com.hypixel.hytale.protocol.ExtraResources; import com.hypixel.hytale.protocol.InventorySection; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -12,7 +14,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateWindow implements Packet { +public class UpdateWindow implements Packet, ToClientPacket { public static final int PACKET_ID = 201; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -33,6 +35,11 @@ public class UpdateWindow implements Packet { return 201; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateWindow() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ClearEditorTimeOverride.java b/src/com/hypixel/hytale/protocol/packets/world/ClearEditorTimeOverride.java index 98ed3adc..177c43e3 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ClearEditorTimeOverride.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ClearEditorTimeOverride.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class ClearEditorTimeOverride implements Packet { +public class ClearEditorTimeOverride implements Packet, ToClientPacket { public static final int PACKET_ID = 148; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class ClearEditorTimeOverride implements Packet { return 148; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + @Nonnull public static ClearEditorTimeOverride deserialize(@Nonnull ByteBuf buf, int offset) { return new ClearEditorTimeOverride(); diff --git a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent2D.java b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent2D.java index 87c97336..444f5c07 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent2D.java +++ b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent2D.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SoundCategory; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class PlaySoundEvent2D implements Packet { +public class PlaySoundEvent2D implements Packet, ToClientPacket { public static final int PACKET_ID = 154; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class PlaySoundEvent2D implements Packet { return 154; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlaySoundEvent2D() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent3D.java b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent3D.java index 1c233eaf..60615cbb 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent3D.java +++ b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEvent3D.java @@ -1,15 +1,17 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; import com.hypixel.hytale.protocol.SoundCategory; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class PlaySoundEvent3D implements Packet { +public class PlaySoundEvent3D implements Packet, ToClientPacket { public static final int PACKET_ID = 155; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class PlaySoundEvent3D implements Packet { return 155; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlaySoundEvent3D() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEventEntity.java b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEventEntity.java index 6d8d3b9f..0e235265 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEventEntity.java +++ b/src/com/hypixel/hytale/protocol/packets/world/PlaySoundEventEntity.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class PlaySoundEventEntity implements Packet { +public class PlaySoundEventEntity implements Packet, ToClientPacket { public static final int PACKET_ID = 156; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +26,11 @@ public class PlaySoundEventEntity implements Packet { return 156; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public PlaySoundEventEntity() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlock.java b/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlock.java index 7189861f..c14cbaf1 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlock.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlock.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ServerSetBlock implements Packet { +public class ServerSetBlock implements Packet, ToClientPacket { public static final int PACKET_ID = 140; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -26,6 +28,11 @@ public class ServerSetBlock implements Packet { return 140; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public ServerSetBlock() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlocks.java b/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlocks.java index 8a27087d..aec276e8 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlocks.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ServerSetBlocks.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -8,7 +10,7 @@ import io.netty.buffer.ByteBuf; import java.util.Arrays; import javax.annotation.Nonnull; -public class ServerSetBlocks implements Packet { +public class ServerSetBlocks implements Packet, ToClientPacket { public static final int PACKET_ID = 141; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -27,6 +29,11 @@ public class ServerSetBlocks implements Packet { return 141; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public ServerSetBlocks() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluid.java b/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluid.java index 71add375..7b98b76d 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluid.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluid.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ServerSetFluid implements Packet { +public class ServerSetFluid implements Packet, ToClientPacket { public static final int PACKET_ID = 142; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class ServerSetFluid implements Packet { return 142; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public ServerSetFluid() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluids.java b/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluids.java index f9d070da..1fb83c95 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluids.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ServerSetFluids.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -8,7 +10,7 @@ import io.netty.buffer.ByteBuf; import java.util.Arrays; import javax.annotation.Nonnull; -public class ServerSetFluids implements Packet { +public class ServerSetFluids implements Packet, ToClientPacket { public static final int PACKET_ID = 143; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -27,6 +29,11 @@ public class ServerSetFluids implements Packet { return 143; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public ServerSetFluids() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/ServerSetPaused.java b/src/com/hypixel/hytale/protocol/packets/world/ServerSetPaused.java index a6a8fb52..7d9de493 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/ServerSetPaused.java +++ b/src/com/hypixel/hytale/protocol/packets/world/ServerSetPaused.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class ServerSetPaused implements Packet { +public class ServerSetPaused implements Packet, ToClientPacket { public static final int PACKET_ID = 159; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class ServerSetPaused implements Packet { return 159; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public ServerSetPaused() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetChunk.java b/src/com/hypixel/hytale/protocol/packets/world/SetChunk.java index 68275918..3ed1b81d 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetChunk.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetChunk.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetChunk implements Packet { +public class SetChunk implements Packet, ToClientPacket { public static final int PACKET_ID = 131; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -32,6 +34,11 @@ public class SetChunk implements Packet { return 131; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public SetChunk() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetChunkEnvironments.java b/src/com/hypixel/hytale/protocol/packets/world/SetChunkEnvironments.java index e8e4365a..a65c7085 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetChunkEnvironments.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetChunkEnvironments.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetChunkEnvironments implements Packet { +public class SetChunkEnvironments implements Packet, ToClientPacket { public static final int PACKET_ID = 134; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class SetChunkEnvironments implements Packet { return 134; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public SetChunkEnvironments() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetChunkHeightmap.java b/src/com/hypixel/hytale/protocol/packets/world/SetChunkHeightmap.java index e83f20b7..7a3ca9ae 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetChunkHeightmap.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetChunkHeightmap.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetChunkHeightmap implements Packet { +public class SetChunkHeightmap implements Packet, ToClientPacket { public static final int PACKET_ID = 132; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class SetChunkHeightmap implements Packet { return 132; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public SetChunkHeightmap() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetChunkTintmap.java b/src/com/hypixel/hytale/protocol/packets/world/SetChunkTintmap.java index 920fef13..9a8526c6 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetChunkTintmap.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetChunkTintmap.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetChunkTintmap implements Packet { +public class SetChunkTintmap implements Packet, ToClientPacket { public static final int PACKET_ID = 133; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class SetChunkTintmap implements Packet { return 133; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public SetChunkTintmap() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetFluids.java b/src/com/hypixel/hytale/protocol/packets/world/SetFluids.java index 4d7b3472..70127003 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetFluids.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetFluids.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -9,7 +11,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SetFluids implements Packet { +public class SetFluids implements Packet, ToClientPacket { public static final int PACKET_ID = 136; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class SetFluids implements Packet { return 136; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public SetFluids() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SetPaused.java b/src/com/hypixel/hytale/protocol/packets/world/SetPaused.java index 5eeef8cd..27abb5bd 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SetPaused.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SetPaused.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class SetPaused implements Packet { +public class SetPaused implements Packet, ToServerPacket { public static final int PACKET_ID = 158; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class SetPaused implements Packet { return 158; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SetPaused() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SpawnBlockParticleSystem.java b/src/com/hypixel/hytale/protocol/packets/world/SpawnBlockParticleSystem.java index 622393f9..bf65fa2c 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SpawnBlockParticleSystem.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SpawnBlockParticleSystem.java @@ -1,15 +1,17 @@ package com.hypixel.hytale.protocol.packets.world; import com.hypixel.hytale.protocol.BlockParticleEvent; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SpawnBlockParticleSystem implements Packet { +public class SpawnBlockParticleSystem implements Packet, ToClientPacket { public static final int PACKET_ID = 153; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -28,6 +30,11 @@ public class SpawnBlockParticleSystem implements Packet { return 153; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SpawnBlockParticleSystem() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/SpawnParticleSystem.java b/src/com/hypixel/hytale/protocol/packets/world/SpawnParticleSystem.java index e870116d..d26f85bc 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/SpawnParticleSystem.java +++ b/src/com/hypixel/hytale/protocol/packets/world/SpawnParticleSystem.java @@ -2,8 +2,10 @@ package com.hypixel.hytale.protocol.packets.world; import com.hypixel.hytale.protocol.Color; import com.hypixel.hytale.protocol.Direction; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -13,7 +15,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class SpawnParticleSystem implements Packet { +public class SpawnParticleSystem implements Packet, ToClientPacket { public static final int PACKET_ID = 152; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -36,6 +38,11 @@ public class SpawnParticleSystem implements Packet { return 152; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public SpawnParticleSystem() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UnloadChunk.java b/src/com/hypixel/hytale/protocol/packets/world/UnloadChunk.java index aefff6de..11f6d266 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UnloadChunk.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UnloadChunk.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UnloadChunk implements Packet { +public class UnloadChunk implements Packet, ToClientPacket { public static final int PACKET_ID = 135; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class UnloadChunk implements Packet { return 135; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public UnloadChunk() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateBlockDamage.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateBlockDamage.java index a58cefea..8630af8d 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateBlockDamage.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateBlockDamage.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.world; import com.hypixel.hytale.protocol.BlockPosition; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateBlockDamage implements Packet { +public class UpdateBlockDamage implements Packet, ToClientPacket { public static final int PACKET_ID = 144; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class UpdateBlockDamage implements Packet { return 144; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Chunks; + } + public UpdateBlockDamage() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorTimeOverride.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorTimeOverride.java index 36cd54e7..1fd64083 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorTimeOverride.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorTimeOverride.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.world; import com.hypixel.hytale.protocol.InstantData; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateEditorTimeOverride implements Packet { +public class UpdateEditorTimeOverride implements Packet, ToClientPacket { public static final int PACKET_ID = 147; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -25,6 +27,11 @@ public class UpdateEditorTimeOverride implements Packet { return 147; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEditorTimeOverride() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorWeatherOverride.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorWeatherOverride.java index 407dcfdf..4d3e43d7 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorWeatherOverride.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateEditorWeatherOverride.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateEditorWeatherOverride implements Packet { +public class UpdateEditorWeatherOverride implements Packet, ToClientPacket { public static final int PACKET_ID = 150; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class UpdateEditorWeatherOverride implements Packet { return 150; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEditorWeatherOverride() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateEnvironmentMusic.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateEnvironmentMusic.java index 67fc6180..4d386d4a 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateEnvironmentMusic.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateEnvironmentMusic.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateEnvironmentMusic implements Packet { +public class UpdateEnvironmentMusic implements Packet, ToClientPacket { public static final int PACKET_ID = 151; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class UpdateEnvironmentMusic implements Packet { return 151; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateEnvironmentMusic() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdatePostFxSettings.java b/src/com/hypixel/hytale/protocol/packets/world/UpdatePostFxSettings.java index 4259333d..dde35163 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdatePostFxSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdatePostFxSettings.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdatePostFxSettings implements Packet { +public class UpdatePostFxSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 361; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -25,6 +27,11 @@ public class UpdatePostFxSettings implements Packet { return 361; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdatePostFxSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateSleepState.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateSleepState.java index 40a554e8..9062d23b 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateSleepState.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateSleepState.java @@ -1,13 +1,15 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateSleepState implements Packet { +public class UpdateSleepState implements Packet, ToClientPacket { public static final int PACKET_ID = 157; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -27,6 +29,11 @@ public class UpdateSleepState implements Packet { return 157; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateSleepState() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateSunSettings.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateSunSettings.java index 45892241..420e9786 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateSunSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateSunSettings.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateSunSettings implements Packet { +public class UpdateSunSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 360; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class UpdateSunSettings implements Packet { return 360; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateSunSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateTime.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateTime.java index e3311fe9..1e919737 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateTime.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateTime.java @@ -1,14 +1,16 @@ package com.hypixel.hytale.protocol.packets.world; import com.hypixel.hytale.protocol.InstantData; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateTime implements Packet { +public class UpdateTime implements Packet, ToClientPacket { public static final int PACKET_ID = 146; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -24,6 +26,11 @@ public class UpdateTime implements Packet { return 146; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateTime() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateTimeSettings.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateTimeSettings.java index 3dc6b57e..bc27d309 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateTimeSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateTimeSettings.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateTimeSettings implements Packet { +public class UpdateTimeSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 145; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -24,6 +26,11 @@ public class UpdateTimeSettings implements Packet { return 145; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateTimeSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/world/UpdateWeather.java b/src/com/hypixel/hytale/protocol/packets/world/UpdateWeather.java index 5e83a193..6d5113d3 100644 --- a/src/com/hypixel/hytale/protocol/packets/world/UpdateWeather.java +++ b/src/com/hypixel/hytale/protocol/packets/world/UpdateWeather.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.world; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateWeather implements Packet { +public class UpdateWeather implements Packet, ToClientPacket { public static final int PACKET_ID = 149; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class UpdateWeather implements Packet { return 149; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateWeather() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/ClearWorldMap.java b/src/com/hypixel/hytale/protocol/packets/worldmap/ClearWorldMap.java index 0151a2e3..be17ce47 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/ClearWorldMap.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/ClearWorldMap.java @@ -1,11 +1,13 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -public class ClearWorldMap implements Packet { +public class ClearWorldMap implements Packet, ToClientPacket { public static final int PACKET_ID = 242; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -19,6 +21,11 @@ public class ClearWorldMap implements Packet { return 242; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.WorldMap; + } + @Nonnull public static ClearWorldMap deserialize(@Nonnull ByteBuf buf, int offset) { return new ClearWorldMap(); diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/CreateUserMarker.java b/src/com/hypixel/hytale/protocol/packets/worldmap/CreateUserMarker.java index cf1039a3..a27c1317 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/CreateUserMarker.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/CreateUserMarker.java @@ -1,7 +1,9 @@ package com.hypixel.hytale.protocol.packets.worldmap; import com.hypixel.hytale.protocol.Color; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -11,7 +13,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class CreateUserMarker implements Packet { +public class CreateUserMarker implements Packet, ToServerPacket { public static final int PACKET_ID = 246; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -34,6 +36,11 @@ public class CreateUserMarker implements Packet { return 246; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public CreateUserMarker() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapMarker.java b/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapMarker.java index e7d44ace..9192d9f6 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapMarker.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapMarker.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class TeleportToWorldMapMarker implements Packet { +public class TeleportToWorldMapMarker implements Packet, ToServerPacket { public static final int PACKET_ID = 244; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -26,6 +28,11 @@ public class TeleportToWorldMapMarker implements Packet { return 244; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public TeleportToWorldMapMarker() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapPosition.java b/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapPosition.java index 8490f9a9..3466bab2 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapPosition.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/TeleportToWorldMapPosition.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class TeleportToWorldMapPosition implements Packet { +public class TeleportToWorldMapPosition implements Packet, ToServerPacket { public static final int PACKET_ID = 245; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -22,6 +24,11 @@ public class TeleportToWorldMapPosition implements Packet { return 245; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public TeleportToWorldMapPosition() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMap.java b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMap.java index 207d7757..6874dedf 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMap.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMap.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.PacketIO; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; @@ -10,7 +12,7 @@ import java.util.Arrays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateWorldMap implements Packet { +public class UpdateWorldMap implements Packet, ToClientPacket { public static final int PACKET_ID = 241; public static final boolean IS_COMPRESSED = true; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -30,6 +32,11 @@ public class UpdateWorldMap implements Packet { return 241; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.WorldMap; + } + public UpdateWorldMap() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapSettings.java b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapSettings.java index 4a8eb0c2..7ad5b745 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapSettings.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapSettings.java @@ -1,6 +1,8 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.io.ProtocolException; import com.hypixel.hytale.protocol.io.ValidationResult; import com.hypixel.hytale.protocol.io.VarInt; @@ -12,7 +14,7 @@ import java.util.Map.Entry; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class UpdateWorldMapSettings implements Packet { +public class UpdateWorldMapSettings implements Packet, ToClientPacket { public static final int PACKET_ID = 240; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 1; @@ -38,6 +40,11 @@ public class UpdateWorldMapSettings implements Packet { return 240; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateWorldMapSettings() { } diff --git a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapVisible.java b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapVisible.java index 4d52dc60..6e916851 100644 --- a/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapVisible.java +++ b/src/com/hypixel/hytale/protocol/packets/worldmap/UpdateWorldMapVisible.java @@ -1,12 +1,14 @@ package com.hypixel.hytale.protocol.packets.worldmap; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.ValidationResult; import io.netty.buffer.ByteBuf; import java.util.Objects; import javax.annotation.Nonnull; -public class UpdateWorldMapVisible implements Packet { +public class UpdateWorldMapVisible implements Packet, ToServerPacket { public static final int PACKET_ID = 243; public static final boolean IS_COMPRESSED = false; public static final int NULLABLE_BIT_FIELD_SIZE = 0; @@ -21,6 +23,11 @@ public class UpdateWorldMapVisible implements Packet { return 243; } + @Override + public NetworkChannel getChannel() { + return NetworkChannel.Default; + } + public UpdateWorldMapVisible() { } diff --git a/src/com/hypixel/hytale/registry/Registry.java b/src/com/hypixel/hytale/registry/Registry.java index 862e2752..d5a05dfb 100644 --- a/src/com/hypixel/hytale/registry/Registry.java +++ b/src/com/hypixel/hytale/registry/Registry.java @@ -50,6 +50,16 @@ public abstract class Registry { this.enabled = false; } + public void shutdownAndCleanup(boolean shutdown) { + this.enabled = false; + + for (int i = this.registrations.size() - 1; i >= 0; i--) { + this.registrations.get(i).accept(shutdown); + } + + this.registrations.clear(); + } + public T register(@Nonnull T registration) { if (!this.enabled) { registration.unregister(); diff --git a/src/com/hypixel/hytale/server/core/Constants.java b/src/com/hypixel/hytale/server/core/Constants.java index ebfaaf66..9fe67f00 100644 --- a/src/com/hypixel/hytale/server/core/Constants.java +++ b/src/com/hypixel/hytale/server/core/Constants.java @@ -9,6 +9,7 @@ import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule; import com.hypixel.hytale.server.core.io.ServerManager; import com.hypixel.hytale.server.core.modules.LegacyModule; import com.hypixel.hytale.server.core.modules.accesscontrol.AccessControlModule; +import com.hypixel.hytale.server.core.modules.anchoraction.AnchorActionModule; import com.hypixel.hytale.server.core.modules.block.BlockModule; import com.hypixel.hytale.server.core.modules.blockhealth.BlockHealthModule; import com.hypixel.hytale.server.core.modules.blockset.BlockSetModule; @@ -70,6 +71,7 @@ public final class Constants { BlockHealthModule.MANIFEST, PrefabSpawnerModule.MANIFEST, TimeModule.MANIFEST, + AnchorActionModule.MANIFEST, InteractionModule.MANIFEST, EntityModule.MANIFEST, EntityStatsModule.MANIFEST, diff --git a/src/com/hypixel/hytale/server/core/HytaleServer.java b/src/com/hypixel/hytale/server/core/HytaleServer.java index 8693171e..2a60afc3 100644 --- a/src/com/hypixel/hytale/server/core/HytaleServer.java +++ b/src/com/hypixel/hytale/server/core/HytaleServer.java @@ -546,6 +546,12 @@ public class HytaleServer { } } + public void reportSingleplayerStatus(String message, double progress) { + if (Constants.SINGLEPLAYER) { + HytaleLoggerBackend.rawLog("-=|" + message + "|" + progress); + } + } + public void reportSaveProgress(@Nonnull World world, int saved, int total) { if (this.isShuttingDown()) { double progress = MathUtil.round((double)saved / total, 2) * 100.0; diff --git a/src/com/hypixel/hytale/server/core/HytaleServerConfig.java b/src/com/hypixel/hytale/server/core/HytaleServerConfig.java index eff958e9..83918038 100644 --- a/src/com/hypixel/hytale/server/core/HytaleServerConfig.java +++ b/src/com/hypixel/hytale/server/core/HytaleServerConfig.java @@ -5,18 +5,20 @@ import com.hypixel.hytale.codec.DocumentContainingCodec; import com.hypixel.hytale.codec.ExtraInfo; import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.builder.BuilderCodec; -import com.hypixel.hytale.codec.codecs.EnumCodec; import com.hypixel.hytale.codec.codecs.map.MapCodec; import com.hypixel.hytale.codec.codecs.map.ObjectMapCodec; import com.hypixel.hytale.codec.lookup.Priority; import com.hypixel.hytale.codec.util.RawJsonReader; import com.hypixel.hytale.common.plugin.PluginIdentifier; -import com.hypixel.hytale.common.semver.SemverRange; import com.hypixel.hytale.common.util.java.ManifestUtil; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.protocol.GameMode; import com.hypixel.hytale.server.core.auth.AuthCredentialStoreProvider; import com.hypixel.hytale.server.core.codec.ProtocolCodecs; +import com.hypixel.hytale.server.core.config.BackupConfig; +import com.hypixel.hytale.server.core.config.ModConfig; +import com.hypixel.hytale.server.core.config.RateLimitConfig; +import com.hypixel.hytale.server.core.config.UpdateConfig; import com.hypixel.hytale.server.core.universe.playerdata.DefaultPlayerStorageProvider; import com.hypixel.hytale.server.core.universe.playerdata.DiskPlayerStorageProvider; import com.hypixel.hytale.server.core.universe.playerdata.PlayerStorageProvider; @@ -60,7 +62,7 @@ public class HytaleServerConfig { .add() .append(new KeyedCodec<>("ConnectionTimeouts", HytaleServerConfig.TimeoutProfile.CODEC), (o, m) -> o.connectionTimeouts = m, o -> o.connectionTimeouts) .add() - .append(new KeyedCodec<>("RateLimit", HytaleServerConfig.RateLimitConfig.CODEC), (o, m) -> o.rateLimitConfig = m, o -> o.rateLimitConfig) + .append(new KeyedCodec<>("RateLimit", RateLimitConfig.CODEC), (o, m) -> o.rateLimitConfig = m, o -> o.rateLimitConfig) .add() .append(new KeyedCodec<>("Modules", new MapCodec<>(HytaleServerConfig.Module.CODEC, ConcurrentHashMap::new, false)), (o, m) -> { o.modules = m; @@ -74,10 +76,7 @@ public class HytaleServerConfig { .add() .append( new KeyedCodec<>( - "Plugins", - new ObjectMapCodec<>( - HytaleServerConfig.ModConfig.CODEC, Object2ObjectOpenHashMap::new, PluginIdentifier::toString, PluginIdentifier::fromString, false - ) + "Plugins", new ObjectMapCodec<>(ModConfig.CODEC, Object2ObjectOpenHashMap::new, PluginIdentifier::toString, PluginIdentifier::fromString, false) ), (o, i) -> o.legacyPluginConfig = i, o -> null @@ -86,8 +85,7 @@ public class HytaleServerConfig { .add() .append( new KeyedCodec<>( - "Mods", - new ObjectMapCodec<>(HytaleServerConfig.ModConfig.CODEC, ConcurrentHashMap::new, PluginIdentifier::toString, PluginIdentifier::fromString, false) + "Mods", new ObjectMapCodec<>(ModConfig.CODEC, ConcurrentHashMap::new, PluginIdentifier::toString, PluginIdentifier::fromString, false) ), (o, i) -> o.modConfig = i, o -> o.modConfig @@ -106,18 +104,21 @@ public class HytaleServerConfig { .add() .append(new KeyedCodec<>("AuthCredentialStore", Codec.BSON_DOCUMENT), (o, value) -> o.authCredentialStoreConfig = value, o -> o.authCredentialStoreConfig) .add() - .append(new KeyedCodec<>("Update", HytaleServerConfig.UpdateConfig.CODEC), (o, value) -> o.updateConfig = value, o -> o.updateConfig) + .append(new KeyedCodec<>("Update", UpdateConfig.CODEC), (o, value) -> o.updateConfig = value, o -> o.updateConfig) .add() .append(new KeyedCodec<>("SkipModValidationForVersion", Codec.STRING), (o, v) -> o.skipModValidationForVersion = v, o -> o.skipModValidationForVersion) .add() + .append(new KeyedCodec<>("Backup", BackupConfig.CODEC), (o, value) -> o.backupConfig = value, o -> o.backupConfig) + .add() .afterDecode((config, extraInfo) -> { config.defaults.hytaleServerConfig = config; config.connectionTimeouts.setHytaleServerConfig(config); - config.rateLimitConfig.hytaleServerConfig = config; - config.updateConfig.hytaleServerConfig = config; + config.rateLimitConfig.setHytaleServerConfig(config); + config.updateConfig.setHytaleServerConfig(config); + config.backupConfig.setHytaleServerConfig(config); config.modules.values().forEach(m -> m.setHytaleServerConfig(config)); if (config.legacyPluginConfig != null && !config.legacyPluginConfig.isEmpty()) { - for (Entry entry : config.legacyPluginConfig.entrySet()) { + for (Entry entry : config.legacyPluginConfig.entrySet()) { config.modConfig.putIfAbsent(entry.getKey(), entry.getValue()); } @@ -146,15 +147,15 @@ public class HytaleServerConfig { @Nonnull private HytaleServerConfig.TimeoutProfile connectionTimeouts = new HytaleServerConfig.TimeoutProfile(this); @Nonnull - private HytaleServerConfig.RateLimitConfig rateLimitConfig = new HytaleServerConfig.RateLimitConfig(this); + private RateLimitConfig rateLimitConfig = new RateLimitConfig(this); @Nonnull private Map modules = new ConcurrentHashMap<>(); @Nonnull private Map logLevels = Collections.emptyMap(); @Nullable - private transient Map legacyPluginConfig; + private transient Map legacyPluginConfig; @Nonnull - private Map modConfig = new ConcurrentHashMap<>(); + private Map modConfig = new ConcurrentHashMap<>(); @Nullable private Boolean defaultModsEnabled; @Nonnull @@ -169,10 +170,16 @@ public class HytaleServerConfig { private transient AuthCredentialStoreProvider authCredentialStoreProvider = null; private boolean displayTmpTagsInStrings; @Nonnull - private HytaleServerConfig.UpdateConfig updateConfig = new HytaleServerConfig.UpdateConfig(this); + private UpdateConfig updateConfig = new UpdateConfig(this); + @Nonnull + private BackupConfig backupConfig = new BackupConfig(this); @Nullable private String skipModValidationForVersion; + public static void setBoot(@Nonnull HytaleServerConfig serverConfig, @Nonnull PluginIdentifier identifier, boolean enabled) { + serverConfig.modConfig.computeIfAbsent(identifier, id -> new ModConfig()).setEnabled(enabled); + } + public String getServerName() { return this.serverName; } @@ -247,11 +254,11 @@ public class HytaleServerConfig { } @Nonnull - public HytaleServerConfig.RateLimitConfig getRateLimitConfig() { + public RateLimitConfig getRateLimitConfig() { return this.rateLimitConfig; } - public void setRateLimitConfig(@Nonnull HytaleServerConfig.RateLimitConfig rateLimitConfig) { + public void setRateLimitConfig(@Nonnull RateLimitConfig rateLimitConfig) { this.rateLimitConfig = rateLimitConfig; this.markChanged(); } @@ -282,11 +289,11 @@ public class HytaleServerConfig { } @Nonnull - public Map getModConfig() { + public Map getModConfig() { return this.modConfig; } - public void setModConfig(@Nonnull Map modConfig) { + public void setModConfig(@Nonnull Map modConfig) { this.modConfig = modConfig; this.markChanged(); } @@ -327,15 +334,25 @@ public class HytaleServerConfig { } @Nonnull - public HytaleServerConfig.UpdateConfig getUpdateConfig() { + public UpdateConfig getUpdateConfig() { return this.updateConfig; } - public void setUpdateConfig(@Nonnull HytaleServerConfig.UpdateConfig updateConfig) { + public void setUpdateConfig(@Nonnull UpdateConfig updateConfig) { this.updateConfig = updateConfig; this.markChanged(); } + @Nonnull + public BackupConfig getBackupConfig() { + return this.backupConfig; + } + + public void setBackupConfig(@Nonnull BackupConfig backupConfig) { + this.backupConfig = backupConfig; + this.markChanged(); + } + public boolean shouldSkipModValidation() { return this.skipModValidationForVersion != null && this.skipModValidationForVersion.equals(ManifestUtil.getImplementationRevisionId()); } @@ -442,47 +459,6 @@ public class HytaleServerConfig { } } - public static class ModConfig { - public static final BuilderCodec CODEC = BuilderCodec.builder( - HytaleServerConfig.ModConfig.class, HytaleServerConfig.ModConfig::new - ) - .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (modConfig, enabled) -> modConfig.enabled = enabled, modConfig -> modConfig.enabled) - .add() - .append( - new KeyedCodec<>("RequiredVersion", SemverRange.CODEC), - (modConfig, semverRange) -> modConfig.requiredVersion = semverRange, - modConfig -> modConfig.requiredVersion - ) - .add() - .build(); - @Nullable - private Boolean enabled; - @Nullable - private SemverRange requiredVersion; - - @Nullable - public Boolean getEnabled() { - return this.enabled; - } - - public void setEnabled(Boolean enabled) { - this.enabled = enabled; - } - - @Nullable - public SemverRange getRequiredVersion() { - return this.requiredVersion; - } - - public void setRequiredVersion(SemverRange requiredVersion) { - this.requiredVersion = requiredVersion; - } - - public static void setBoot(HytaleServerConfig serverConfig, PluginIdentifier identifier, boolean enabled) { - serverConfig.getModConfig().computeIfAbsent(identifier, id -> new HytaleServerConfig.ModConfig()).enabled = enabled; - } - } - public static class Module { @Nonnull protected static BuilderCodec.Builder BUILDER_CODEC_BUILDER = BuilderCodec.builder( @@ -581,62 +557,6 @@ public class HytaleServerConfig { } } - public static class RateLimitConfig { - public static final int DEFAULT_PACKETS_PER_SECOND = 2000; - public static final int DEFAULT_BURST_CAPACITY = 500; - public static final Codec CODEC = BuilderCodec.builder( - HytaleServerConfig.RateLimitConfig.class, HytaleServerConfig.RateLimitConfig::new - ) - .addField(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (o, b) -> o.enabled = b, o -> o.enabled) - .addField(new KeyedCodec<>("PacketsPerSecond", Codec.INTEGER), (o, i) -> o.packetsPerSecond = i, o -> o.packetsPerSecond) - .addField(new KeyedCodec<>("BurstCapacity", Codec.INTEGER), (o, i) -> o.burstCapacity = i, o -> o.burstCapacity) - .build(); - private Boolean enabled; - private Integer packetsPerSecond; - private Integer burstCapacity; - transient HytaleServerConfig hytaleServerConfig; - - public RateLimitConfig() { - } - - public RateLimitConfig(HytaleServerConfig hytaleServerConfig) { - this.hytaleServerConfig = hytaleServerConfig; - } - - public boolean isEnabled() { - return this.enabled != null ? this.enabled : true; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public int getPacketsPerSecond() { - return this.packetsPerSecond != null ? this.packetsPerSecond : 2000; - } - - public void setPacketsPerSecond(int packetsPerSecond) { - this.packetsPerSecond = packetsPerSecond; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public int getBurstCapacity() { - return this.burstCapacity != null ? this.burstCapacity : 500; - } - - public void setBurstCapacity(int burstCapacity) { - this.burstCapacity = burstCapacity; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - } - public static class TimeoutProfile { private static final HytaleServerConfig.TimeoutProfile SINGLEPLAYER_DEFAULTS = new HytaleServerConfig.TimeoutProfile( Duration.ofSeconds(30L), @@ -838,136 +758,4 @@ public class HytaleServerConfig { this.hytaleServerConfig = hytaleServerConfig; } } - - public static class UpdateConfig { - public static final int DEFAULT_CHECK_INTERVAL_SECONDS = 3600; - public static final Codec CODEC = BuilderCodec.builder( - HytaleServerConfig.UpdateConfig.class, HytaleServerConfig.UpdateConfig::new - ) - .addField(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (o, b) -> o.enabled = b, o -> o.enabled) - .addField(new KeyedCodec<>("CheckIntervalSeconds", Codec.INTEGER), (o, i) -> o.checkIntervalSeconds = i, o -> o.checkIntervalSeconds) - .addField(new KeyedCodec<>("NotifyPlayersOnAvailable", Codec.BOOLEAN), (o, b) -> o.notifyPlayersOnAvailable = b, o -> o.notifyPlayersOnAvailable) - .addField(new KeyedCodec<>("Patchline", Codec.STRING), (o, s) -> o.patchline = s, o -> o.patchline) - .addField(new KeyedCodec<>("RunBackupBeforeUpdate", Codec.BOOLEAN), (o, b) -> o.runBackupBeforeUpdate = b, o -> o.runBackupBeforeUpdate) - .addField(new KeyedCodec<>("BackupConfigBeforeUpdate", Codec.BOOLEAN), (o, b) -> o.backupConfigBeforeUpdate = b, o -> o.backupConfigBeforeUpdate) - .addField( - new KeyedCodec<>("AutoApplyMode", new EnumCodec<>(HytaleServerConfig.UpdateConfig.AutoApplyMode.class)), - (o, m) -> o.autoApplyMode = m, - o -> o.autoApplyMode - ) - .addField(new KeyedCodec<>("AutoApplyDelayMinutes", Codec.INTEGER), (o, i) -> o.autoApplyDelayMinutes = i, o -> o.autoApplyDelayMinutes) - .build(); - private Boolean enabled; - private Integer checkIntervalSeconds; - private Boolean notifyPlayersOnAvailable; - private String patchline; - private Boolean runBackupBeforeUpdate; - private Boolean backupConfigBeforeUpdate; - private HytaleServerConfig.UpdateConfig.AutoApplyMode autoApplyMode; - private Integer autoApplyDelayMinutes; - transient HytaleServerConfig hytaleServerConfig; - - public UpdateConfig() { - } - - public UpdateConfig(HytaleServerConfig hytaleServerConfig) { - this.hytaleServerConfig = hytaleServerConfig; - } - - public boolean isEnabled() { - return this.enabled != null ? this.enabled : true; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public int getCheckIntervalSeconds() { - return this.checkIntervalSeconds != null ? this.checkIntervalSeconds : 3600; - } - - public void setCheckIntervalSeconds(int checkIntervalSeconds) { - this.checkIntervalSeconds = checkIntervalSeconds; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public boolean isNotifyPlayersOnAvailable() { - return this.notifyPlayersOnAvailable != null ? this.notifyPlayersOnAvailable : true; - } - - public void setNotifyPlayersOnAvailable(boolean notifyPlayersOnAvailable) { - this.notifyPlayersOnAvailable = notifyPlayersOnAvailable; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - @Nullable - public String getPatchline() { - return this.patchline; - } - - public void setPatchline(@Nullable String patchline) { - this.patchline = patchline; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public boolean isRunBackupBeforeUpdate() { - return this.runBackupBeforeUpdate != null ? this.runBackupBeforeUpdate : true; - } - - public void setRunBackupBeforeUpdate(boolean runBackupBeforeUpdate) { - this.runBackupBeforeUpdate = runBackupBeforeUpdate; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public boolean isBackupConfigBeforeUpdate() { - return this.backupConfigBeforeUpdate != null ? this.backupConfigBeforeUpdate : true; - } - - public void setBackupConfigBeforeUpdate(boolean backupConfigBeforeUpdate) { - this.backupConfigBeforeUpdate = backupConfigBeforeUpdate; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - @Nonnull - public HytaleServerConfig.UpdateConfig.AutoApplyMode getAutoApplyMode() { - return this.autoApplyMode != null ? this.autoApplyMode : HytaleServerConfig.UpdateConfig.AutoApplyMode.DISABLED; - } - - public void setAutoApplyMode(@Nonnull HytaleServerConfig.UpdateConfig.AutoApplyMode autoApplyMode) { - this.autoApplyMode = autoApplyMode; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public int getAutoApplyDelayMinutes() { - return this.autoApplyDelayMinutes != null ? this.autoApplyDelayMinutes : 30; - } - - public void setAutoApplyDelayMinutes(int autoApplyDelayMinutes) { - this.autoApplyDelayMinutes = autoApplyDelayMinutes; - if (this.hytaleServerConfig != null) { - this.hytaleServerConfig.markChanged(); - } - } - - public static enum AutoApplyMode { - DISABLED, - WHEN_EMPTY, - SCHEDULED; - } - } } diff --git a/src/com/hypixel/hytale/server/core/asset/AssetModule.java b/src/com/hypixel/hytale/server/core/asset/AssetModule.java index 4ea7e851..1af4a947 100644 --- a/src/com/hypixel/hytale/server/core/asset/AssetModule.java +++ b/src/com/hypixel/hytale/server/core/asset/AssetModule.java @@ -28,6 +28,7 @@ import com.hypixel.hytale.server.core.asset.type.gameplay.respawn.HomeOrSpawnPoi import com.hypixel.hytale.server.core.asset.type.gameplay.respawn.RespawnController; import com.hypixel.hytale.server.core.asset.type.gameplay.respawn.WorldSpawnPoint; import com.hypixel.hytale.server.core.asset.type.item.DroplistCommand; +import com.hypixel.hytale.server.core.config.ModConfig; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.event.events.BootEvent; import com.hypixel.hytale.server.core.event.events.player.AddPlayerToWorldEvent; @@ -42,6 +43,7 @@ import com.hypixel.hytale.server.core.universe.world.worldgen.provider.IWorldGen import com.hypixel.hytale.server.core.universe.world.worldmap.IWorldMap; import com.hypixel.hytale.server.core.universe.world.worldmap.provider.IWorldMapProvider; import com.hypixel.hytale.sneakythrow.SneakyThrow; +import it.unimi.dsi.fastutil.objects.ObjectBooleanPair; import java.awt.Color; import java.io.BufferedReader; import java.io.FileReader; @@ -69,7 +71,7 @@ public class AssetModule extends JavaPlugin { private AssetMonitor assetMonitor; @Nonnull private final List assetPacks = new CopyOnWriteArrayList<>(); - private final List pendingAssetPacks = new ArrayList<>(); + private final List> pendingAssetPacks = new ArrayList<>(); private boolean hasSetup = false; private boolean hasLoaded = false; private final List> pendingAssetStores = new CopyOnWriteArrayList<>(); @@ -101,7 +103,21 @@ public class AssetModule extends JavaPlugin { } this.hasSetup = true; - this.assetPacks.addAll(this.pendingAssetPacks); + + for (ObjectBooleanPair p : this.pendingAssetPacks) { + if (this.getAssetPack(p.left().getName()) != null) { + if (!p.rightBoolean()) { + throw new IllegalStateException("Asset pack with name '" + p.left().getName() + "' already exists"); + } + + this.getLogger() + .at(Level.WARNING) + .log("Asset pack with name '%s' already exists, skipping registration from path: %s", p.left().getName(), p.left().getRoot()); + } else { + this.assetPacks.add(p.left()); + } + } + this.pendingAssetPacks.clear(); this.loadPacksFromDirectory(PluginManager.MODS_PATH); @@ -347,7 +363,7 @@ public class AssetModule extends JavaPlugin { PluginIdentifier packIdentifier = new PluginIdentifier(manifest); HytaleServerConfig serverConfig = HytaleServer.get().getConfig(); - HytaleServerConfig.ModConfig modConfig = serverConfig.getModConfig().get(packIdentifier); + ModConfig modConfig = serverConfig.getModConfig().get(packIdentifier); boolean enabled; if (modConfig != null && modConfig.getEnabled() != null) { enabled = modConfig.getEnabled(); @@ -357,14 +373,14 @@ public class AssetModule extends JavaPlugin { String packId = packIdentifier.toString(); if (enabled) { - this.registerPack(packId, packPath, manifest); + this.registerPack(packId, packPath, manifest, false); this.getLogger().at(Level.INFO).log("Loaded pack: %s from %s", packId, packPath.getFileName()); } else { this.getLogger().at(Level.INFO).log("Skipped disabled pack: %s", packId); } } - public void registerPack(@Nonnull String name, @Nonnull Path path, @Nonnull PluginManifest manifest) { + public void registerPack(@Nonnull String name, @Nonnull Path path, @Nonnull PluginManifest manifest, boolean ignoreIfExists) { Path absolutePath = path.toAbsolutePath().normalize(); Path packLocation = absolutePath; FileSystem fileSystem = null; @@ -377,14 +393,20 @@ public class AssetModule extends JavaPlugin { fileSystem = FileSystems.newFileSystem(absolutePath, (ClassLoader)null); absolutePath = fileSystem.getPath("").toAbsolutePath().normalize(); isImmutable = true; - } catch (IOException var13) { - throw SneakyThrow.sneakyThrow(var13); + } catch (IOException var14) { + throw SneakyThrow.sneakyThrow(var14); } } AssetPack pack = new AssetPack(packLocation, name, absolutePath, fileSystem, isImmutable, manifest); if (!this.hasSetup) { - this.pendingAssetPacks.add(pack); + this.pendingAssetPacks.add(ObjectBooleanPair.of(pack, ignoreIfExists)); + } else if (this.getAssetPack(name) != null) { + if (ignoreIfExists) { + this.getLogger().at(Level.WARNING).log("Asset pack with name '%s' already exists, skipping registration from path: %s", name, path); + } else { + throw new IllegalStateException("Asset pack with name '" + name + "' already exists"); + } } else { this.assetPacks.add(pack); AssetRegistry.ASSET_LOCK.writeLock().lock(); diff --git a/src/com/hypixel/hytale/server/core/asset/AssetRegistryLoader.java b/src/com/hypixel/hytale/server/core/asset/AssetRegistryLoader.java index eacff09a..21836d2e 100644 --- a/src/com/hypixel/hytale/server/core/asset/AssetRegistryLoader.java +++ b/src/com/hypixel/hytale/server/core/asset/AssetRegistryLoader.java @@ -19,7 +19,7 @@ import com.hypixel.hytale.codec.schema.SchemaContext; import com.hypixel.hytale.codec.schema.config.Schema; import com.hypixel.hytale.common.util.FormatUtil; import com.hypixel.hytale.logger.HytaleLogger; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.Constants; import com.hypixel.hytale.server.core.HytaleServer; import com.hypixel.hytale.server.core.Options; @@ -328,8 +328,8 @@ public class AssetRegistryLoader { } public static void sendAssets(@Nonnull PacketHandler packetHandler) { - Consumer packetConsumer = packetHandler::write; - Consumer singlePacketConsumer = packetHandler::write; + Consumer packetConsumer = packetHandler::write; + Consumer singlePacketConsumer = packetHandler::write; HytaleAssetStore.SETUP_PACKET_CONSUMERS.add(singlePacketConsumer); try { diff --git a/src/com/hypixel/hytale/server/core/asset/HytaleAssetStore.java b/src/com/hypixel/hytale/server/core/asset/HytaleAssetStore.java index 189f11c6..66028787 100644 --- a/src/com/hypixel/hytale/server/core/asset/HytaleAssetStore.java +++ b/src/com/hypixel/hytale/server/core/asset/HytaleAssetStore.java @@ -11,7 +11,7 @@ import com.hypixel.hytale.common.util.PathUtil; import com.hypixel.hytale.event.EventBus; import com.hypixel.hytale.event.IEventDispatcher; import com.hypixel.hytale.protocol.ItemWithAllMetadata; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.interface_.NotificationStyle; import com.hypixel.hytale.server.core.HytaleServer; import com.hypixel.hytale.server.core.Message; @@ -42,11 +42,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; public class HytaleAssetStore, M extends AssetMap> extends AssetStore { - public static final Queue> SETUP_PACKET_CONSUMERS = new ConcurrentLinkedQueue<>(); + public static final Queue> SETUP_PACKET_CONSUMERS = new ConcurrentLinkedQueue<>(); protected final AssetPacketGenerator packetGenerator; protected final Function notificationItemFunction; @Nullable - protected SoftReference cachedInitPackets; + protected SoftReference cachedInitPackets; public HytaleAssetStore(@Nonnull HytaleAssetStore.Builder builder) { super(builder); @@ -90,19 +90,19 @@ public class HytaleAssetStore, M extends Ass Universe universe = Universe.get(); if (universe.getPlayerCount() != 0 || !SETUP_PACKET_CONSUMERS.isEmpty()) { if (toBeRemoved != null && !toBeRemoved.isEmpty()) { - Packet packet = this.packetGenerator.generateRemovePacket(this.assetMap, toBeRemoved, query); + ToClientPacket packet = this.packetGenerator.generateRemovePacket(this.assetMap, toBeRemoved, query); universe.broadcastPacketNoCache(packet); - for (Consumer c : SETUP_PACKET_CONSUMERS) { + for (Consumer c : SETUP_PACKET_CONSUMERS) { c.accept(packet); } } if (toBeUpdated != null && !toBeUpdated.isEmpty()) { - Packet packet = this.packetGenerator.generateUpdatePacket(this.assetMap, toBeUpdated, query); + ToClientPacket packet = this.packetGenerator.generateUpdatePacket(this.assetMap, toBeUpdated, query); universe.broadcastPacketNoCache(packet); - for (Consumer c : SETUP_PACKET_CONSUMERS) { + for (Consumer c : SETUP_PACKET_CONSUMERS) { c.accept(packet); } } @@ -110,15 +110,15 @@ public class HytaleAssetStore, M extends Ass } } - public void sendAssets(@Nonnull Consumer packetConsumer) { + public void sendAssets(@Nonnull Consumer packetConsumer) { if (this.packetGenerator != null) { - Packet[] packets = this.cachedInitPackets == null ? null : this.cachedInitPackets.get(); + ToClientPacket[] packets = this.cachedInitPackets == null ? null : this.cachedInitPackets.get(); if (packets != null) { packetConsumer.accept(packets); } else { Map map = this.assetMap.getAssetMap(); - Packet packet = this.packetGenerator.generateInitPacket(this.assetMap, map); - this.cachedInitPackets = new SoftReference<>(packets = new Packet[]{packet}); + ToClientPacket packet = this.packetGenerator.generateInitPacket(this.assetMap, map); + this.cachedInitPackets = new SoftReference<>(packets = new ToClientPacket[]{packet}); packetConsumer.accept(packets); } } diff --git a/src/com/hypixel/hytale/server/core/asset/common/CommonAssetModule.java b/src/com/hypixel/hytale/server/core/asset/common/CommonAssetModule.java index 36ca343f..7261563e 100644 --- a/src/com/hypixel/hytale/server/core/asset/common/CommonAssetModule.java +++ b/src/com/hypixel/hytale/server/core/asset/common/CommonAssetModule.java @@ -13,7 +13,7 @@ import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.logger.sentry.SkipSentryException; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.protocol.Asset; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.interface_.Notification; import com.hypixel.hytale.protocol.packets.interface_.NotificationStyle; import com.hypixel.hytale.protocol.packets.setup.AssetFinalize; @@ -483,7 +483,7 @@ public class CommonAssetModule extends JavaPlugin { CommonAsset thisAsset = toSend.get(i); byte[] allBytes = thisAsset.getBlob().join(); byte[][] parts = ArrayUtil.split(allBytes, 2621440); - Packet[] packets = new Packet[2 + parts.length]; + ToClientPacket[] packets = new ToClientPacket[2 + parts.length]; packets[0] = new AssetInitialize(thisAsset.toPacket(), allBytes.length); for (int partIndex = 0; partIndex < parts.length; partIndex++) { @@ -505,7 +505,7 @@ public class CommonAssetModule extends JavaPlugin { CommonAsset thisAsset = toSend.get(i); byte[] allBytes = thisAsset.getBlob().join(); byte[][] parts = ArrayUtil.split(allBytes, 2621440); - Packet[] packets = new Packet[2 + parts.length * 2]; + ToClientPacket[] packets = new ToClientPacket[2 + parts.length * 2]; packets[0] = new AssetInitialize(thisAsset.toPacket(), allBytes.length); for (int partIndex = 0; partIndex < parts.length; partIndex++) { @@ -532,7 +532,7 @@ public class CommonAssetModule extends JavaPlugin { this.getLogger().at(Level.WARNING).log("Failed to send asset: %s, %s", asset.getName(), asset.getHash()); } else { byte[][] parts = ArrayUtil.split(allBytes, 2621440); - Packet[] packets = new Packet[2 + (forceRebuild ? 1 : 0) + parts.length]; + ToClientPacket[] packets = new ToClientPacket[2 + (forceRebuild ? 1 : 0) + parts.length]; packets[0] = new AssetInitialize(asset.toPacket(), allBytes.length); for (int i = 0; i < parts.length; i++) { @@ -558,7 +558,7 @@ public class CommonAssetModule extends JavaPlugin { Message message = Message.translation("server.general.assetstore.removedAssets").param("class", "Common").color("#FF3874"); int packetCountThreshold = 5; int packetsCount = 1 + (forceRebuild ? 1 : 0) + (assets.size() < 5 ? assets.size() : 1); - Packet[] packets = new Packet[packetsCount]; + ToClientPacket[] packets = new ToClientPacket[packetsCount]; int i = 0; for (CommonAssetRegistry.PackAsset asset : assets) { diff --git a/src/com/hypixel/hytale/server/core/asset/packet/AssetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/packet/AssetPacketGenerator.java index d0c01fbf..ca9d195f 100644 --- a/src/com/hypixel/hytale/server/core/asset/packet/AssetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/packet/AssetPacketGenerator.java @@ -3,17 +3,17 @@ package com.hypixel.hytale.server.core.asset.packet; import com.hypixel.hytale.assetstore.AssetMap; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.JsonAssetWithMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; public abstract class AssetPacketGenerator, M extends AssetMap> { - public abstract Packet generateInitPacket(M var1, Map var2); + public abstract ToClientPacket generateInitPacket(M var1, Map var2); - public abstract Packet generateUpdatePacket(M var1, Map var2, @Nonnull AssetUpdateQuery var3); + public abstract ToClientPacket generateUpdatePacket(M var1, Map var2, @Nonnull AssetUpdateQuery var3); @Nullable - public abstract Packet generateRemovePacket(M var1, Set var2, @Nonnull AssetUpdateQuery var3); + public abstract ToClientPacket generateRemovePacket(M var1, Set var2, @Nonnull AssetUpdateQuery var3); } diff --git a/src/com/hypixel/hytale/server/core/asset/packet/DefaultAssetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/packet/DefaultAssetPacketGenerator.java index fc9284f9..51a7805e 100644 --- a/src/com/hypixel/hytale/server/core/asset/packet/DefaultAssetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/packet/DefaultAssetPacketGenerator.java @@ -2,26 +2,26 @@ package com.hypixel.hytale.server.core.asset.packet; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; import com.hypixel.hytale.assetstore.map.JsonAssetWithMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; public abstract class DefaultAssetPacketGenerator>> extends SimpleAssetPacketGenerator> { - public abstract Packet generateInitPacket(DefaultAssetMap var1, Map var2); + public abstract ToClientPacket generateInitPacket(DefaultAssetMap var1, Map var2); - public abstract Packet generateUpdatePacket(Map var1); + public abstract ToClientPacket generateUpdatePacket(Map var1); @Nullable - public abstract Packet generateRemovePacket(Set var1); + public abstract ToClientPacket generateRemovePacket(Set var1); - public final Packet generateUpdatePacket(DefaultAssetMap assetMap, Map loadedAssets) { + public final ToClientPacket generateUpdatePacket(DefaultAssetMap assetMap, Map loadedAssets) { return this.generateUpdatePacket(loadedAssets); } @Nullable - public final Packet generateRemovePacket(DefaultAssetMap assetMap, Set removed) { + public final ToClientPacket generateRemovePacket(DefaultAssetMap assetMap, Set removed) { return this.generateRemovePacket(removed); } } diff --git a/src/com/hypixel/hytale/server/core/asset/packet/SimpleAssetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/packet/SimpleAssetPacketGenerator.java index fae7f1a6..beaf35b3 100644 --- a/src/com/hypixel/hytale/server/core/asset/packet/SimpleAssetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/packet/SimpleAssetPacketGenerator.java @@ -3,7 +3,7 @@ package com.hypixel.hytale.server.core.asset.packet; import com.hypixel.hytale.assetstore.AssetMap; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.JsonAssetWithMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; @@ -11,20 +11,20 @@ import javax.annotation.Nullable; public abstract class SimpleAssetPacketGenerator, M extends AssetMap> extends AssetPacketGenerator { @Override - public abstract Packet generateInitPacket(M var1, Map var2); + public abstract ToClientPacket generateInitPacket(M var1, Map var2); @Override - public Packet generateUpdatePacket(M assetMap, Map loadedAssets, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateUpdatePacket(M assetMap, Map loadedAssets, @Nonnull AssetUpdateQuery query) { return this.generateUpdatePacket(assetMap, loadedAssets); } @Override - public Packet generateRemovePacket(M assetMap, Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket(M assetMap, Set removed, @Nonnull AssetUpdateQuery query) { return this.generateRemovePacket(assetMap, removed); } - protected abstract Packet generateUpdatePacket(M var1, Map var2); + protected abstract ToClientPacket generateUpdatePacket(M var1, Map var2); @Nullable - protected abstract Packet generateRemovePacket(M var1, Set var2); + protected abstract ToClientPacket generateRemovePacket(M var1, Set var2); } diff --git a/src/com/hypixel/hytale/server/core/asset/type/ambiencefx/AmbienceFXPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/ambiencefx/AmbienceFXPacketGenerator.java index f690eeb5..f1f45c9d 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/ambiencefx/AmbienceFXPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/ambiencefx/AmbienceFXPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.ambiencefx; import com.hypixel.hytale.assetstore.map.IndexedAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateAmbienceFX; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class AmbienceFXPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map assets) { UpdateAmbienceFX packet = new UpdateAmbienceFX(); packet.type = UpdateType.Init; packet.ambienceFX = new Object2ObjectOpenHashMap<>(); @@ -34,7 +34,7 @@ public class AmbienceFXPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateAmbienceFX packet = new UpdateAmbienceFX(); packet.type = UpdateType.AddOrUpdate; packet.ambienceFX = new Object2ObjectOpenHashMap<>(); @@ -54,7 +54,7 @@ public class AmbienceFXPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedAssetMap assetMap, @Nonnull Set removed) { UpdateAmbienceFX packet = new UpdateAmbienceFX(); packet.type = UpdateType.Remove; packet.ambienceFX = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/audiocategory/AudioCategoryPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/audiocategory/AudioCategoryPacketGenerator.java index 9422f9c0..11aa8805 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/audiocategory/AudioCategoryPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/audiocategory/AudioCategoryPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.audiocategory; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateAudioCategories; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class AudioCategoryPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateAudioCategories packet = new UpdateAudioCategories(); packet.type = UpdateType.Init; packet.categories = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,9 @@ public class AudioCategoryPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateAudioCategories packet = new UpdateAudioCategories(); packet.type = UpdateType.AddOrUpdate; packet.categories = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +56,7 @@ public class AudioCategoryPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateAudioCategories packet = new UpdateAudioCategories(); packet.type = UpdateType.Remove; packet.categories = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blockbreakingdecal/BlockBreakingDecalPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blockbreakingdecal/BlockBreakingDecalPacketGenerator.java index 77171d79..85d7ea29 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blockbreakingdecal/BlockBreakingDecalPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blockbreakingdecal/BlockBreakingDecalPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.blockbreakingdecal; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockBreakingDecals; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -17,7 +17,7 @@ import javax.annotation.Nullable; public class BlockBreakingDecalPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { UpdateBlockBreakingDecals packet = new UpdateBlockBreakingDecals(); packet.type = UpdateType.Init; packet.blockBreakingDecals = assetMap.getAssetMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toPacket())); @@ -26,7 +26,7 @@ public class BlockBreakingDecalPacketGenerator extends DefaultAssetPacketGenerat @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateBlockBreakingDecals packet = new UpdateBlockBreakingDecals(); packet.type = UpdateType.AddOrUpdate; packet.blockBreakingDecals = loadedAssets.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toPacket())); @@ -35,7 +35,7 @@ public class BlockBreakingDecalPacketGenerator extends DefaultAssetPacketGenerat @Nullable @Override - public Packet generateRemovePacket(@Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateBlockBreakingDecals packet = new UpdateBlockBreakingDecals(); packet.type = UpdateType.Remove; packet.blockBreakingDecals = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blockhitbox/BlockBoundingBoxesPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blockhitbox/BlockBoundingBoxesPacketGenerator.java index 71af9b7b..c61c5195 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blockhitbox/BlockBoundingBoxesPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blockhitbox/BlockBoundingBoxesPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.asset.type.blockhitbox; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; import com.hypixel.hytale.protocol.Hitbox; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockHitboxes; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -15,7 +15,9 @@ import javax.annotation.Nonnull; public class BlockBoundingBoxesPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets + ) { UpdateBlockHitboxes packet = new UpdateBlockHitboxes(); packet.type = UpdateType.Init; Map hitboxes = new Int2ObjectOpenHashMap<>(); @@ -36,7 +38,7 @@ public class BlockBoundingBoxesPacketGenerator } @Nonnull - public Packet generateUpdatePacket( + public ToClientPacket generateUpdatePacket( @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets ) { UpdateBlockHitboxes packet = new UpdateBlockHitboxes(); @@ -59,7 +61,7 @@ public class BlockBoundingBoxesPacketGenerator } @Nonnull - public Packet generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateBlockHitboxes packet = new UpdateBlockHitboxes(); packet.type = UpdateType.Remove; Map hitboxes = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blockparticle/BlockParticleSetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blockparticle/BlockParticleSetPacketGenerator.java index 9dfb9257..a67b0090 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blockparticle/BlockParticleSetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blockparticle/BlockParticleSetPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.blockparticle; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockParticleSets; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class BlockParticleSetPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateBlockParticleSets packet = new UpdateBlockParticleSets(); packet.type = UpdateType.Init; packet.blockParticleSets = new Object2ObjectOpenHashMap<>(); @@ -29,7 +29,7 @@ public class BlockParticleSetPacketGenerator extends DefaultAssetPacketGenerator @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateBlockParticleSets packet = new UpdateBlockParticleSets(); packet.type = UpdateType.AddOrUpdate; packet.blockParticleSets = new Object2ObjectOpenHashMap<>(); @@ -43,7 +43,7 @@ public class BlockParticleSetPacketGenerator extends DefaultAssetPacketGenerator @Nonnull @Override - public Packet generateRemovePacket(@Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateBlockParticleSets packet = new UpdateBlockParticleSets(); packet.type = UpdateType.Remove; packet.blockParticleSets = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blockset/BlockSetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blockset/BlockSetPacketGenerator.java index 78c8d675..dd11a4d8 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blockset/BlockSetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blockset/BlockSetPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.asset.type.blockset; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockSets; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -17,7 +17,7 @@ import javax.annotation.Nullable; public class BlockSetPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, Map assets) { UpdateBlockSets packet = new UpdateBlockSets(); packet.type = UpdateType.Init; packet.blockSets = assetMap.getAssetMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toPacket())); @@ -25,7 +25,7 @@ public class BlockSetPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateBlockSets packet = new UpdateBlockSets(); @@ -35,7 +35,9 @@ public class BlockSetPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket( + IndexedLookupTableAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query + ) { UpdateBlockSets packet = new UpdateBlockSets(); packet.type = UpdateType.Remove; packet.blockSets = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blocksound/BlockSoundSetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blocksound/BlockSoundSetPacketGenerator.java index 552b4d80..7c54d35d 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blocksound/BlockSoundSetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blocksound/BlockSoundSetPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.blocksound; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockSoundSets; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class BlockSoundSetPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateBlockSoundSets packet = new UpdateBlockSoundSets(); packet.type = UpdateType.Init; packet.blockSoundSets = new Int2ObjectOpenHashMap<>(); @@ -34,7 +34,9 @@ public class BlockSoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateBlockSoundSets packet = new UpdateBlockSoundSets(); packet.type = UpdateType.AddOrUpdate; packet.blockSoundSets = new Int2ObjectOpenHashMap<>(); @@ -54,7 +56,7 @@ public class BlockSoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateBlockSoundSets packet = new UpdateBlockSoundSets(); packet.type = UpdateType.Remove; packet.blockSoundSets = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blocktick/config/RandomTickProcedure.java b/src/com/hypixel/hytale/server/core/asset/type/blocktick/config/RandomTickProcedure.java new file mode 100644 index 00000000..06411d56 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/asset/type/blocktick/config/RandomTickProcedure.java @@ -0,0 +1,14 @@ +package com.hypixel.hytale.server.core.asset.type.blocktick.config; + +import com.hypixel.hytale.codec.lookup.CodecMapCodec; +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; +import com.hypixel.hytale.server.core.universe.world.chunk.section.BlockSection; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; + +public interface RandomTickProcedure { + CodecMapCodec CODEC = new CodecMapCodec<>("Type"); + + void onRandomTick(Store var1, CommandBuffer var2, BlockSection var3, int var4, int var5, int var6, int var7, BlockType var8); +} diff --git a/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockGroupPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockGroupPacketGenerator.java index c23805ae..6b40a91f 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockGroupPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockGroupPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.blocktype; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockGroups; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -17,7 +17,7 @@ import javax.annotation.Nullable; public class BlockGroupPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { UpdateBlockGroups packet = new UpdateBlockGroups(); packet.type = UpdateType.Init; packet.groups = assetMap.getAssetMap().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toPacket())); @@ -26,7 +26,7 @@ public class BlockGroupPacketGenerator extends DefaultAssetPacketGenerator loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateBlockGroups packet = new UpdateBlockGroups(); packet.type = UpdateType.AddOrUpdate; packet.groups = loadedAssets.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().toPacket())); @@ -35,7 +35,7 @@ public class BlockGroupPacketGenerator extends DefaultAssetPacketGenerator removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateBlockGroups packet = new UpdateBlockGroups(); packet.type = UpdateType.Remove; packet.groups = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockTypePacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockTypePacketGenerator.java index cfb86173..be416b1b 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockTypePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blocktype/BlockTypePacketGenerator.java @@ -3,7 +3,7 @@ package com.hypixel.hytale.server.core.asset.type.blocktype; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.BlockTypeAssetMap; import com.hypixel.hytale.protocol.CachedPacket; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateBlockTypes; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -16,7 +16,7 @@ import javax.annotation.Nonnull; public class BlockTypePacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull BlockTypeAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull BlockTypeAssetMap assetMap, @Nonnull Map assets) { UpdateBlockTypes packet = new UpdateBlockTypes(); packet.type = UpdateType.Init; Map blockTypes = new Int2ObjectOpenHashMap<>(); @@ -41,7 +41,7 @@ public class BlockTypePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateBlockTypes packet = new UpdateBlockTypes(); @@ -69,7 +69,9 @@ public class BlockTypePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket( + @Nonnull BlockTypeAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query + ) { UpdateBlockTypes packet = new UpdateBlockTypes(); packet.type = UpdateType.Remove; Map blockTypes = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/blocktype/config/BlockType.java b/src/com/hypixel/hytale/server/core/asset/type/blocktype/config/BlockType.java index 30c38a38..6cea1d0f 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/blocktype/config/BlockType.java +++ b/src/com/hypixel/hytale/server/core/asset/type/blocktype/config/BlockType.java @@ -52,6 +52,7 @@ import com.hypixel.hytale.server.core.asset.type.blockbreakingdecal.config.Block import com.hypixel.hytale.server.core.asset.type.blockhitbox.BlockBoundingBoxes; import com.hypixel.hytale.server.core.asset.type.blockparticle.config.BlockParticleSet; import com.hypixel.hytale.server.core.asset.type.blocksound.config.BlockSoundSet; +import com.hypixel.hytale.server.core.asset.type.blocktick.config.RandomTickProcedure; import com.hypixel.hytale.server.core.asset.type.blocktick.config.TickProcedure; import com.hypixel.hytale.server.core.asset.type.blocktype.config.bench.Bench; import com.hypixel.hytale.server.core.asset.type.blocktype.config.farming.FarmingData; @@ -246,6 +247,13 @@ public class BlockType implements JsonAssetWithMap blockType.tickProcedure = parent.tickProcedure ) .add() + .appendInherited( + new KeyedCodec<>("RandomTickProcedure", RandomTickProcedure.CODEC), + (blockType, v) -> blockType.randomTickProcedure = v, + blockType -> blockType.randomTickProcedure, + (blockType, parent) -> blockType.randomTickProcedure = parent.randomTickProcedure + ) + .add() .appendInherited( new KeyedCodec<>("ConnectedBlockRuleSet", ConnectedBlockRuleSet.CODEC), (blockType, connectedBlockRuleSet) -> blockType.connectedBlockRuleSet = connectedBlockRuleSet, @@ -847,6 +855,7 @@ public class BlockType implements JsonAssetWithMap { protected IntArg height = new IntArg(5, 1, 100); protected IntArg thickness = new IntArg(0, 0, 100); protected BoolArg capped = new BoolArg(false); - protected BrushShapeArg shape = new BrushShapeArg(BrushShape.Cube); + protected BrushShapeArg shape = new BrushShapeArg(BrushShape.Sphere); protected BrushOriginArg origin = new BrushOriginArg(BrushOrigin.Center); protected BoolArg originRotation = new BoolArg(false); protected BrushAxisArg rotationAxis = new BrushAxisArg(BrushAxis.None); diff --git a/src/com/hypixel/hytale/server/core/asset/type/entityeffect/EntityEffectPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/entityeffect/EntityEffectPacketGenerator.java index 87519c61..ee0bb887 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/entityeffect/EntityEffectPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/entityeffect/EntityEffectPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.entityeffect; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateEntityEffects; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class EntityEffectPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateEntityEffects packet = new UpdateEntityEffects(); packet.type = UpdateType.Init; packet.entityEffects = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,9 @@ public class EntityEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + protected ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateEntityEffects packet = new UpdateEntityEffects(); packet.type = UpdateType.AddOrUpdate; packet.entityEffects = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +56,7 @@ public class EntityEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + protected ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateEntityEffects packet = new UpdateEntityEffects(); packet.type = UpdateType.Remove; packet.entityEffects = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/environment/EnvironmentPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/environment/EnvironmentPacketGenerator.java index d591419f..6ad75e57 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/environment/EnvironmentPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/environment/EnvironmentPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.asset.type.environment; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateEnvironments; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class EnvironmentPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { Map assetsFromMap = assetMap.getAssetMap(); if (assets.size() != assetsFromMap.size()) { throw new UnsupportedOperationException("Environments can not handle partial init packets!!!"); @@ -41,7 +41,7 @@ public class EnvironmentPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateEnvironments packet = new UpdateEnvironments(); @@ -64,7 +64,7 @@ public class EnvironmentPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { UpdateEnvironments packet = new UpdateEnvironments(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/equalizereffect/EqualizerEffectPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/equalizereffect/EqualizerEffectPacketGenerator.java index dc9aad6f..60f9d36f 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/equalizereffect/EqualizerEffectPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/equalizereffect/EqualizerEffectPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.equalizereffect; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateEqualizerEffects; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class EqualizerEffectPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateEqualizerEffects packet = new UpdateEqualizerEffects(); packet.type = UpdateType.Init; packet.effects = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,9 @@ public class EqualizerEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateEqualizerEffects packet = new UpdateEqualizerEffects(); packet.type = UpdateType.AddOrUpdate; packet.effects = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +56,7 @@ public class EqualizerEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateEqualizerEffects packet = new UpdateEqualizerEffects(); packet.type = UpdateType.Remove; packet.effects = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/fluid/FireFluidTicker.java b/src/com/hypixel/hytale/server/core/asset/type/fluid/FireFluidTicker.java index 2346b328..b9f4046a 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/fluid/FireFluidTicker.java +++ b/src/com/hypixel/hytale/server/core/asset/type/fluid/FireFluidTicker.java @@ -110,7 +110,7 @@ public class FireFluidTicker extends FluidTicker { int blockX = worldX + x; int blockY = worldY + y; int blockZ = worldZ + z; - if (blockY >= 0 && blockY < 256) { + if (blockY >= 0 && blockY < 320) { boolean isDifferentSection = !ChunkUtil.isSameChunkSection(worldX, worldY, worldZ, blockX, blockY, blockZ); FluidSection otherFluidSection = isDifferentSection ? accessor.getFluidSectionByBlock(blockX, blockY, blockZ) : fluidSection; BlockSection otherBlockSection = isDifferentSection ? accessor.getBlockSectionByBlock(blockX, blockY, blockZ) : blockSection; diff --git a/src/com/hypixel/hytale/server/core/asset/type/fluid/FluidTypePacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/fluid/FluidTypePacketGenerator.java index 76447b32..34893e80 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/fluid/FluidTypePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/fluid/FluidTypePacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.asset.type.fluid; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateFluids; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class FluidTypePacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateFluids packet = new UpdateFluids(); packet.type = UpdateType.Init; HashMap fluidTypes = new HashMap<>(); @@ -34,7 +34,7 @@ public class FluidTypePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateFluids packet = new UpdateFluids(); @@ -56,7 +56,7 @@ public class FluidTypePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { UpdateFluids packet = new UpdateFluids(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/fluidfx/FluidFXPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/fluidfx/FluidFXPacketGenerator.java index 013f17b8..94944a7e 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/fluidfx/FluidFXPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/fluidfx/FluidFXPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.fluidfx; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateFluidFX; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class FluidFXPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateFluidFX packet = new UpdateFluidFX(); packet.type = UpdateType.Init; packet.fluidFX = new Int2ObjectOpenHashMap<>(); @@ -34,7 +34,7 @@ public class FluidFXPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateFluidFX packet = new UpdateFluidFX(); packet.type = UpdateType.AddOrUpdate; packet.fluidFX = new Int2ObjectOpenHashMap<>(); @@ -54,7 +54,7 @@ public class FluidFXPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateFluidFX packet = new UpdateFluidFX(); packet.type = UpdateType.Remove; packet.fluidFX = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/item/FieldcraftCategoryPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/item/FieldcraftCategoryPacketGenerator.java index 624ba0de..0aef093d 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/item/FieldcraftCategoryPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/item/FieldcraftCategoryPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.asset.type.item; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; import com.hypixel.hytale.protocol.ItemCategory; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateFieldcraftCategories; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class FieldcraftCategoryPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { Map assetsFromMap = assetMap.getAssetMap(); if (assets.size() != assetsFromMap.size()) { throw new UnsupportedOperationException("Item categories can not handle partial init packets!!!"); @@ -35,7 +35,7 @@ public class FieldcraftCategoryPacketGenerator extends DefaultAssetPacketGenerat @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map assets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map assets) { UpdateFieldcraftCategories packet = new UpdateFieldcraftCategories(); packet.type = UpdateType.AddOrUpdate; ItemCategory[] arr = new ItemCategory[assets.size()]; @@ -50,7 +50,7 @@ public class FieldcraftCategoryPacketGenerator extends DefaultAssetPacketGenerat } @Override - public Packet generateRemovePacket(Set removed) { + public ToClientPacket generateRemovePacket(Set removed) { throw new IllegalArgumentException("We don't support removing item categories at this time!"); } } diff --git a/src/com/hypixel/hytale/server/core/asset/type/item/ItemCategoryPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/item/ItemCategoryPacketGenerator.java index 55c5fe5e..b91dc5b6 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/item/ItemCategoryPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/item/ItemCategoryPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.item; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateItemCategories; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; public class ItemCategoryPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { Map assetsFromMap = assetMap.getAssetMap(); if (assets.size() != assetsFromMap.size()) { throw new UnsupportedOperationException("Item categories can not handle partial init packets!!!"); @@ -34,7 +34,7 @@ public class ItemCategoryPacketGenerator extends DefaultAssetPacketGenerator assets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map assets) { UpdateItemCategories packet = new UpdateItemCategories(); packet.type = UpdateType.AddOrUpdate; com.hypixel.hytale.protocol.ItemCategory[] arr = new com.hypixel.hytale.protocol.ItemCategory[assets.size()]; @@ -50,7 +50,7 @@ public class ItemCategoryPacketGenerator extends DefaultAssetPacketGenerator removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateItemCategories packet = new UpdateItemCategories(); packet.type = UpdateType.Remove; com.hypixel.hytale.protocol.ItemCategory[] arr = new com.hypixel.hytale.protocol.ItemCategory[removed.size()]; diff --git a/src/com/hypixel/hytale/server/core/asset/type/item/ResourceTypePacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/item/ResourceTypePacketGenerator.java index 38e04222..73c6f515 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/item/ResourceTypePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/item/ResourceTypePacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.item; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateResourceTypes; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class ResourceTypePacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, @Nonnull Map assets) { Map assetsFromMap = assetMap.getAssetMap(); if (assets.size() != assetsFromMap.size()) { throw new UnsupportedOperationException("Resource types can not handle partial init packets!!!"); @@ -34,7 +34,7 @@ public class ResourceTypePacketGenerator extends DefaultAssetPacketGenerator loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateResourceTypes packet = new UpdateResourceTypes(); packet.type = UpdateType.AddOrUpdate; packet.resourceTypes = new Object2ObjectOpenHashMap<>(); @@ -48,7 +48,7 @@ public class ResourceTypePacketGenerator extends DefaultAssetPacketGenerator removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateResourceTypes packet = new UpdateResourceTypes(); packet.type = UpdateType.Remove; packet.resourceTypes = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/item/config/CraftingRecipe.java b/src/com/hypixel/hytale/server/core/asset/type/item/config/CraftingRecipe.java index a4231d60..170c42e2 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/item/config/CraftingRecipe.java +++ b/src/com/hypixel/hytale/server/core/asset/type/item/config/CraftingRecipe.java @@ -65,8 +65,12 @@ public class CraftingRecipe implements JsonAssetWithMap benchRequirement.type = benchType, benchRequirement -> benchRequirement.type ) + .addValidator(Validators.nonNull()) .add() - .append(new KeyedCodec<>("Id", Codec.STRING), (benchRequirement, s) -> benchRequirement.id = s, benchRequirement -> benchRequirement.id) + .append( + new KeyedCodec<>("Id", Codec.STRING), (benchRequirement, s) -> benchRequirement.id = s, benchRequirement -> benchRequirement.id + ) + .addValidator(Validators.nonNull()) .add() .append( new KeyedCodec<>("Categories", Codec.STRING_ARRAY), diff --git a/src/com/hypixel/hytale/server/core/asset/type/item/config/Item.java b/src/com/hypixel/hytale/server/core/asset/type/item/config/Item.java index 12892a86..4df97969 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/item/config/Item.java +++ b/src/com/hypixel/hytale/server/core/asset/type/item/config/Item.java @@ -381,6 +381,14 @@ public class Item implements JsonAssetWithMap item.durabilityLossOnHit = parent.durabilityLossOnHit ) .add() + .appendInherited( + new KeyedCodec<>("DurabilityLossOnDeath", Codec.BOOLEAN), + (item, s) -> item.durabilityLossOnDeath = s, + item -> item.durabilityLossOnDeath, + (item, parent) -> item.durabilityLossOnDeath = parent.durabilityLossOnDeath + ) + .documentation("Whether this item should loose durability on death, if so configured in DeathConfig.") + .add() .appendInherited( new KeyedCodec<>("BlockType", new ContainedAssetCodec<>(BlockType.class, BlockType.CODEC, ContainedAssetCodec.Mode.INHERIT_ID_AND_PARENT)), (item, s) -> item.hasBlockType = true, @@ -542,6 +550,7 @@ public class Item implements JsonAssetWithMap cachedPacket; public static AssetStore> getAssetStore() { @@ -990,6 +999,10 @@ public class Item implements JsonAssetWithMap { @Nonnull @Override - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateItemPlayerAnimations packet = new UpdateItemPlayerAnimations(); packet.type = UpdateType.Init; packet.itemPlayerAnimations = new Object2ObjectOpenHashMap<>(assets.size()); @@ -28,7 +28,7 @@ public class ItemPlayerAnimationsPacketGenerator extends DefaultAssetPacketGener @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateItemPlayerAnimations packet = new UpdateItemPlayerAnimations(); packet.type = UpdateType.AddOrUpdate; packet.itemPlayerAnimations = new Object2ObjectOpenHashMap<>(loadedAssets.size()); @@ -42,7 +42,7 @@ public class ItemPlayerAnimationsPacketGenerator extends DefaultAssetPacketGener @Nonnull @Override - public Packet generateRemovePacket(@Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateItemPlayerAnimations packet = new UpdateItemPlayerAnimations(); packet.type = UpdateType.Remove; packet.itemPlayerAnimations = new Object2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/itemsound/ItemSoundSetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/itemsound/ItemSoundSetPacketGenerator.java index 47ade803..2694f752 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/itemsound/ItemSoundSetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/itemsound/ItemSoundSetPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.itemsound; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateItemSoundSets; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class ItemSoundSetPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateItemSoundSets packet = new UpdateItemSoundSets(); packet.type = UpdateType.Init; packet.itemSoundSets = new Int2ObjectOpenHashMap<>(); @@ -34,7 +34,9 @@ public class ItemSoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateItemSoundSets packet = new UpdateItemSoundSets(); packet.type = UpdateType.AddOrUpdate; packet.itemSoundSets = new Int2ObjectOpenHashMap<>(); @@ -54,7 +56,7 @@ public class ItemSoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateItemSoundSets packet = new UpdateItemSoundSets(); packet.type = UpdateType.Remove; packet.itemSoundSets = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/model/config/Model.java b/src/com/hypixel/hytale/server/core/asset/type/model/config/Model.java index ce216c2d..97ffa983 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/model/config/Model.java +++ b/src/com/hypixel/hytale/server/core/asset/type/model/config/Model.java @@ -40,12 +40,18 @@ public class Model implements NetworkSerializable animationSetMap; private final CameraSettings camera; private final ColorLight light; @@ -69,6 +75,8 @@ public class Model implements NetworkSerializable animationSetMap, CameraSettings camera, ColorLight light, @@ -90,6 +98,8 @@ public class Model implements NetworkSerializable map = new Object2ObjectOpenHashMap<>(this.animationSetMap.size()); @@ -241,8 +265,12 @@ public class Model implements NetworkSerializable getAnimationSetMap() { return this.animationSetMap != null ? this.animationSetMap : Collections.emptyMap(); } @@ -350,7 +396,13 @@ public class Model implements NetworkSerializableappend( new KeyedCodec<>("CursedItems", Codec.STRING_ARRAY), (portalType, o) -> portalType.cursedItems = o == null ? Collections.emptySet() : Set.of(o), @@ -65,7 +60,6 @@ public class PortalType implements JsonAssetWithMap cursedItems = Collections.emptySet(); public static AssetStore> getAssetStore() { @@ -96,11 +90,6 @@ public class PortalType implements JsonAssetWithMap getCursedItems() { return this.cursedItems; } diff --git a/src/com/hypixel/hytale/server/core/asset/type/reverbeffect/ReverbEffectPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/reverbeffect/ReverbEffectPacketGenerator.java index 188ae96e..62124de5 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/reverbeffect/ReverbEffectPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/reverbeffect/ReverbEffectPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.reverbeffect; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateReverbEffects; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class ReverbEffectPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateReverbEffects packet = new UpdateReverbEffects(); packet.type = UpdateType.Init; packet.effects = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,9 @@ public class ReverbEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateReverbEffects packet = new UpdateReverbEffects(); packet.type = UpdateType.AddOrUpdate; packet.effects = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +56,7 @@ public class ReverbEffectPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateReverbEffects packet = new UpdateReverbEffects(); packet.type = UpdateType.Remove; packet.effects = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/soundevent/SoundEventPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/soundevent/SoundEventPacketGenerator.java index c79227a6..8a1258aa 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/soundevent/SoundEventPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/soundevent/SoundEventPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.soundevent; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateSoundEvents; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class SoundEventPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateSoundEvents packet = new UpdateSoundEvents(); packet.type = UpdateType.Init; packet.soundEvents = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,7 @@ public class SoundEventPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateSoundEvents packet = new UpdateSoundEvents(); packet.type = UpdateType.AddOrUpdate; packet.soundEvents = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +54,7 @@ public class SoundEventPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateSoundEvents packet = new UpdateSoundEvents(); packet.type = UpdateType.Remove; packet.soundEvents = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/soundset/SoundSetPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/soundset/SoundSetPacketGenerator.java index eae4c5a4..5df45032 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/soundset/SoundSetPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/soundset/SoundSetPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.soundset; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateSoundSets; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class SoundSetPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateSoundSets packet = new UpdateSoundSets(); packet.type = UpdateType.Init; packet.soundSets = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,7 @@ public class SoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateSoundSets packet = new UpdateSoundSets(); packet.type = UpdateType.AddOrUpdate; packet.soundSets = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +54,7 @@ public class SoundSetPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateSoundSets packet = new UpdateSoundSets(); packet.type = UpdateType.Remove; packet.soundSets = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/tagpattern/TagPatternPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/tagpattern/TagPatternPacketGenerator.java index 4054cfe4..a48a2f79 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/tagpattern/TagPatternPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/tagpattern/TagPatternPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.tagpattern; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateTagPatterns; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class TagPatternPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateTagPatterns packet = new UpdateTagPatterns(); packet.type = UpdateType.Init; packet.patterns = new Int2ObjectOpenHashMap<>(assets.size()); @@ -34,7 +34,7 @@ public class TagPatternPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateTagPatterns packet = new UpdateTagPatterns(); packet.type = UpdateType.AddOrUpdate; packet.patterns = new Int2ObjectOpenHashMap<>(loadedAssets.size()); @@ -54,7 +54,7 @@ public class TagPatternPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateTagPatterns packet = new UpdateTagPatterns(); packet.type = UpdateType.Remove; packet.patterns = new Int2ObjectOpenHashMap<>(removed.size()); diff --git a/src/com/hypixel/hytale/server/core/asset/type/trail/TrailPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/trail/TrailPacketGenerator.java index 16974858..7fe3e5b6 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/trail/TrailPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/trail/TrailPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.trail; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateTrails; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class TrailPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateTrails packet = new UpdateTrails(); packet.type = UpdateType.Init; packet.trails = new Object2ObjectOpenHashMap<>(); @@ -29,7 +29,7 @@ public class TrailPacketGenerator extends DefaultAssetPacketGenerator loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateTrails packet = new UpdateTrails(); packet.type = UpdateType.AddOrUpdate; packet.trails = new Object2ObjectOpenHashMap<>(); @@ -43,7 +43,7 @@ public class TrailPacketGenerator extends DefaultAssetPacketGenerator removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateTrails packet = new UpdateTrails(); packet.type = UpdateType.Remove; packet.trails = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/asset/type/weather/WeatherPacketGenerator.java b/src/com/hypixel/hytale/server/core/asset/type/weather/WeatherPacketGenerator.java index 4d024ce9..7a033420 100644 --- a/src/com/hypixel/hytale/server/core/asset/type/weather/WeatherPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/asset/type/weather/WeatherPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.asset.type.weather; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateWeathers; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class WeatherPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateWeathers packet = new UpdateWeathers(); packet.type = UpdateType.Init; packet.weathers = new Int2ObjectOpenHashMap<>(); @@ -34,7 +34,7 @@ public class WeatherPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets) { UpdateWeathers packet = new UpdateWeathers(); packet.type = UpdateType.AddOrUpdate; packet.weathers = new Int2ObjectOpenHashMap<>(); @@ -54,7 +54,7 @@ public class WeatherPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateWeathers packet = new UpdateWeathers(); packet.type = UpdateType.Remove; packet.weathers = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/command/commands/debug/AssetsCommand.java b/src/com/hypixel/hytale/server/core/command/commands/debug/AssetsCommand.java index a233c18f..6570e091 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/debug/AssetsCommand.java +++ b/src/com/hypixel/hytale/server/core/command/commands/debug/AssetsCommand.java @@ -40,7 +40,10 @@ public class AssetsCommand extends AbstractCommandCollection { } context.sendMessage( - Message.raw("Longest asset name for " + e.getKey().getSimpleName() + ": " + longestName + " (" + longestName.length() + " characters)") + Message.translation("server.commands.assets.longest.result") + .param("type", e.getKey().getSimpleName()) + .param("assetName", longestName) + .param("length", longestName.length()) ); } } diff --git a/src/com/hypixel/hytale/server/core/command/commands/debug/stresstest/Bot.java b/src/com/hypixel/hytale/server/core/command/commands/debug/stresstest/Bot.java index c30cd1ff..5c7a7a5f 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/debug/stresstest/Bot.java +++ b/src/com/hypixel/hytale/server/core/command/commands/debug/stresstest/Bot.java @@ -5,7 +5,6 @@ import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; import com.hypixel.hytale.protocol.Asset; import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.Direction; import com.hypixel.hytale.protocol.EntityUpdate; import com.hypixel.hytale.protocol.InstantData; @@ -14,6 +13,7 @@ import com.hypixel.hytale.protocol.MovementStates; import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; import com.hypixel.hytale.protocol.TeleportAck; +import com.hypixel.hytale.protocol.TransformUpdate; import com.hypixel.hytale.protocol.io.netty.PacketDecoder; import com.hypixel.hytale.protocol.io.netty.PacketEncoder; import com.hypixel.hytale.protocol.packets.connection.ClientType; @@ -170,7 +170,7 @@ public class Bot extends SimpleChannelInboundHandler { @Override public void channelActive(@Nonnull ChannelHandlerContext ctx) { UUID uuid = UUID.nameUUIDFromBytes(("BOT|" + this.name).getBytes(StandardCharsets.UTF_8)); - ctx.writeAndFlush(new Connect(672031543, 12, "bot", ClientType.Game, uuid, this.name, null, "en", null, null)); + ctx.writeAndFlush(new Connect(-1356075132, 20, "bot", ClientType.Game, uuid, this.name, null, "en", null, null)); this.logger.at(Level.INFO).log("Connected!"); } @@ -239,8 +239,8 @@ public class Bot extends SimpleChannelInboundHandler { } for (ComponentUpdate update : entry.updates) { - if (update.type == ComponentUpdateType.Transform) { - this.updateModelTransform(update.transform); + if (update instanceof TransformUpdate transformUpdate) { + this.updateModelTransform(transformUpdate.transform); break; } } diff --git a/src/com/hypixel/hytale/server/core/command/commands/player/camera/CameraDemo.java b/src/com/hypixel/hytale/server/core/command/commands/player/camera/CameraDemo.java index fe98bd03..973a7a31 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/player/camera/CameraDemo.java +++ b/src/com/hypixel/hytale/server/core/command/commands/player/camera/CameraDemo.java @@ -51,7 +51,7 @@ public class CameraDemo { public void deactivate() { if (this.isActive) { - this.eventRegistry.shutdown(); + this.eventRegistry.shutdownAndCleanup(false); Universe.get().getPlayers().forEach(p -> { CameraManager cameraManager = p.getComponent(CameraManager.getComponentType()); if (cameraManager != null) { diff --git a/src/com/hypixel/hytale/server/core/command/commands/server/auth/AuthStatusCommand.java b/src/com/hypixel/hytale/server/core/command/commands/server/auth/AuthStatusCommand.java index 73217f4a..72f1212f 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/server/auth/AuthStatusCommand.java +++ b/src/com/hypixel/hytale/server/core/command/commands/server/auth/AuthStatusCommand.java @@ -73,7 +73,7 @@ public class AuthStatusCommand extends CommandBase { Message sessionTokenStatus = authManager.hasSessionToken() ? MESSAGE_STATUS_TOKEN_PRESENT : MESSAGE_STATUS_TOKEN_MISSING; Message identityTokenStatus = authManager.hasIdentityToken() ? MESSAGE_STATUS_TOKEN_PRESENT : MESSAGE_STATUS_TOKEN_MISSING; - String expiryStatus = ""; + Message expiryStatus = Message.empty(); Instant expiry = authManager.getTokenExpiry(); if (expiry != null) { long secondsRemaining = expiry.getEpochSecond() - Instant.now().getEpochSecond(); @@ -81,18 +81,23 @@ public class AuthStatusCommand extends CommandBase { long hours = secondsRemaining / 3600L; long minutes = secondsRemaining % 3600L / 60L; long seconds = secondsRemaining % 60L; - expiryStatus = String.format("%02d:%02d:%02d remaining", hours, minutes, seconds); + expiryStatus = Message.translation("server.commands.auth.status.remaining") + .param("hours", String.format("%02d", hours)) + .param("minutes", String.format("%02d", minutes)) + .param("seconds", String.format("%02d", seconds)); } else { - expiryStatus = "EXPIRED"; + expiryStatus = Message.translation("server.commands.auth.status.expired"); } } - String certificateStatus; + Message certificateStatus; if (authManager.getServerCertificate() != null) { String fingerprint = authManager.getServerCertificateFingerprint(); - certificateStatus = fingerprint != null ? fingerprint.substring(0, 16) + "..." : "Unknown"; + certificateStatus = fingerprint != null + ? Message.raw(fingerprint.substring(0, 16) + "...") + : Message.translation("server.commands.auth.status.certificate.unknown"); } else { - certificateStatus = "Not loaded"; + certificateStatus = Message.translation("server.commands.auth.status.certificate.notLoaded"); } context.sendMessage( diff --git a/src/com/hypixel/hytale/server/core/command/commands/utility/BackupCommand.java b/src/com/hypixel/hytale/server/core/command/commands/utility/BackupCommand.java index 6c45f64d..1db9286c 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/utility/BackupCommand.java +++ b/src/com/hypixel/hytale/server/core/command/commands/utility/BackupCommand.java @@ -2,7 +2,6 @@ package com.hypixel.hytale.server.core.command.commands.utility; import com.hypixel.hytale.server.core.HytaleServer; import com.hypixel.hytale.server.core.Message; -import com.hypixel.hytale.server.core.Options; import com.hypixel.hytale.server.core.command.system.CommandContext; import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand; import com.hypixel.hytale.server.core.universe.Universe; @@ -29,7 +28,7 @@ public class BackupCommand extends AbstractAsyncCommand { if (!HytaleServer.get().isBooted()) { context.sendMessage(MESSAGE_COMMANDS_ERRORS_WAIT_FOR_BOOT); return CompletableFuture.completedFuture(null); - } else if (!Options.getOptionSet().has(Options.BACKUP_DIRECTORY)) { + } else if (HytaleServer.get().getConfig().getBackupConfig().getDirectory() == null) { context.sendMessage(MESSAGE_COMMANDS_BACKUP_NOT_CONFIGURED); return CompletableFuture.completedFuture(null); } else { diff --git a/src/com/hypixel/hytale/server/core/command/commands/utility/UIGalleryCommand.java b/src/com/hypixel/hytale/server/core/command/commands/utility/UIGalleryCommand.java new file mode 100644 index 00000000..f1efb4a3 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/command/commands/utility/UIGalleryCommand.java @@ -0,0 +1,49 @@ +package com.hypixel.hytale.server.core.command.commands.utility; + +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.protocol.GameMode; +import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.command.system.CommandContext; +import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand; +import com.hypixel.hytale.server.core.command.system.pages.UIGalleryPage; +import com.hypixel.hytale.server.core.entity.entities.Player; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.util.concurrent.CompletableFuture; +import javax.annotation.Nonnull; + +public class UIGalleryCommand extends AbstractAsyncCommand { + @Nonnull + private static final Message MESSAGE_PLAYER_NOT_IN_WORLD = Message.translation("server.commands.errors.playerNotInWorld"); + + public UIGalleryCommand() { + super("ui-gallery", "server.commands.uigallery.desc"); + this.setPermissionGroup(GameMode.Creative); + } + + @Nonnull + @Override + protected CompletableFuture executeAsync(@Nonnull CommandContext context) { + if (!context.isPlayer()) { + return CompletableFuture.completedFuture(null); + } else { + Ref playerRef = context.senderAsPlayerRef(); + if (playerRef != null && playerRef.isValid()) { + Store store = playerRef.getStore(); + World world = store.getExternalData().getWorld(); + return CompletableFuture.runAsync(() -> { + Player playerComponent = store.getComponent(playerRef, Player.getComponentType()); + PlayerRef playerRefComponent = store.getComponent(playerRef, PlayerRef.getComponentType()); + if (playerComponent != null && playerRefComponent != null) { + playerComponent.getPageManager().openCustomPage(playerRef, store, new UIGalleryPage(playerRefComponent)); + } + }, world); + } else { + context.sendMessage(MESSAGE_PLAYER_NOT_IN_WORLD); + return CompletableFuture.completedFuture(null); + } + } + } +} diff --git a/src/com/hypixel/hytale/server/core/command/commands/utility/net/NetworkCommand.java b/src/com/hypixel/hytale/server/core/command/commands/utility/net/NetworkCommand.java index bc0cd27e..8a003f08 100644 --- a/src/com/hypixel/hytale/server/core/command/commands/utility/net/NetworkCommand.java +++ b/src/com/hypixel/hytale/server/core/command/commands/utility/net/NetworkCommand.java @@ -2,6 +2,7 @@ package com.hypixel.hytale.server.core.command.commands.utility.net; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.command.system.CommandContext; import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg; @@ -10,12 +11,17 @@ import com.hypixel.hytale.server.core.command.system.basecommands.AbstractComman import com.hypixel.hytale.server.core.command.system.basecommands.AbstractTargetPlayerCommand; import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase; import com.hypixel.hytale.server.core.entity.knockback.KnockbackSystems; +import com.hypixel.hytale.server.core.io.PacketHandler; import com.hypixel.hytale.server.core.io.netty.LatencySimulationHandler; import com.hypixel.hytale.server.core.modules.entity.player.KnockbackPredictionSystems; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import io.netty.channel.Channel; +import io.netty.handler.codec.quic.QuicStreamChannel; +import io.netty.handler.codec.quic.QuicStreamPriority; +import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -25,6 +31,7 @@ public class NetworkCommand extends AbstractCommandCollection { super("network", "server.commands.network.desc"); this.addAliases("net"); this.addSubCommand(new NetworkCommand.LatencySimulationCommand()); + this.addSubCommand(new NetworkCommand.StreamPriorityCommand()); this.addSubCommand(new NetworkCommand.ServerKnockbackCommand()); this.addSubCommand(new NetworkCommand.DebugKnockbackCommand()); } @@ -114,4 +121,173 @@ public class NetworkCommand extends AbstractCommandCollection { ); } } + + public static class StreamPriorityCommand extends AbstractCommandCollection { + private static final Map> PRESETS = Map.of( + "default", + PacketHandler.DEFAULT_STREAM_PRIORITIES, + "equal", + priority(0, 0, 0), + "tiered", + priority(0, 1, 2), + "maplow", + priority(0, 0, 1), + "datalow", + priority(0, 1, 1), + "chunkshi", + priority(1, 0, 2), + "maphi", + priority(1, 2, 0) + ); + + public StreamPriorityCommand() { + super("streampriority", "server.commands.network.streamPriority.desc"); + this.addAliases("sp"); + this.addSubCommand(new NetworkCommand.StreamPriorityCommand.Set()); + this.addSubCommand(new NetworkCommand.StreamPriorityCommand.Preset()); + this.addSubCommand(new NetworkCommand.StreamPriorityCommand.Reset()); + } + + private static void applyPriorities(@Nonnull PlayerRef playerRef, @Nonnull Map priorities) { + PacketHandler handler = playerRef.getPacketHandler(); + + for (Entry entry : priorities.entrySet()) { + if (handler.getChannel(entry.getKey()) instanceof QuicStreamChannel quicStreamChannel) { + quicStreamChannel.updatePriority(entry.getValue()); + } + } + } + + private static String formatPriorities(@Nonnull Map priorities) { + StringBuilder sb = new StringBuilder(); + + for (NetworkChannel channel : NetworkChannel.VALUES) { + QuicStreamPriority priority = priorities.get(channel); + if (priority != null) { + if (!sb.isEmpty()) { + sb.append(", "); + } + + sb.append(channel.name()).append('=').append(priority.urgency()); + } + } + + return sb.toString(); + } + + private static Map priority(int defaultUrgency, int chunksUrgency, int worldMapUrgency) { + return Map.of( + NetworkChannel.Default, + new QuicStreamPriority(defaultUrgency, true), + NetworkChannel.Chunks, + new QuicStreamPriority(chunksUrgency, true), + NetworkChannel.WorldMap, + new QuicStreamPriority(worldMapUrgency, true) + ); + } + + static class Preset extends AbstractTargetPlayerCommand { + @Nonnull + private final RequiredArg presetArg = this.withRequiredArg( + "preset", "server.commands.network.streamPriority.preset.name.desc", ArgTypes.STRING + ); + + Preset() { + super("preset", "server.commands.network.streamPriority.preset.desc"); + } + + @Override + protected void execute( + @Nonnull CommandContext context, + @Nullable Ref sourceRef, + @Nonnull Ref ref, + @Nonnull PlayerRef playerRef, + @Nonnull World world, + @Nonnull Store store + ) { + String name = this.presetArg.get(context).toLowerCase(); + Map priorities = NetworkCommand.StreamPriorityCommand.PRESETS.get(name); + if (priorities == null) { + context.sendMessage( + Message.translation("server.commands.network.streamPriority.preset.unknown") + .param("name", name) + .param("presets", String.join(", ", NetworkCommand.StreamPriorityCommand.PRESETS.keySet())) + ); + } else { + NetworkCommand.StreamPriorityCommand.applyPriorities(playerRef, priorities); + context.sendMessage( + Message.translation("server.commands.network.streamPriority.preset.success") + .param("name", name) + .param("priorities", NetworkCommand.StreamPriorityCommand.formatPriorities(priorities)) + ); + } + } + } + + static class Reset extends AbstractTargetPlayerCommand { + Reset() { + super("reset", "server.commands.network.streamPriority.reset.desc"); + } + + @Override + protected void execute( + @Nonnull CommandContext context, + @Nullable Ref sourceRef, + @Nonnull Ref ref, + @Nonnull PlayerRef playerRef, + @Nonnull World world, + @Nonnull Store store + ) { + NetworkCommand.StreamPriorityCommand.applyPriorities(playerRef, PacketHandler.DEFAULT_STREAM_PRIORITIES); + context.sendMessage( + Message.translation("server.commands.network.streamPriority.reset.success") + .param("priorities", NetworkCommand.StreamPriorityCommand.formatPriorities(PacketHandler.DEFAULT_STREAM_PRIORITIES)) + ); + } + } + + static class Set extends AbstractTargetPlayerCommand { + @Nonnull + private final RequiredArg channelArg = this.withRequiredArg( + "channel", + "server.commands.network.streamPriority.set.channel.desc", + ArgTypes.forEnum("server.commands.network.streamPriority.channel", NetworkChannel.class) + ); + @Nonnull + private final RequiredArg priorityArg = this.withRequiredArg( + "priority", "server.commands.network.streamPriority.set.priority.desc", ArgTypes.INTEGER + ); + + Set() { + super("set", "server.commands.network.streamPriority.set.desc"); + } + + @Override + protected void execute( + @Nonnull CommandContext context, + @Nullable Ref sourceRef, + @Nonnull Ref ref, + @Nonnull PlayerRef playerRef, + @Nonnull World world, + @Nonnull Store store + ) { + NetworkChannel networkChannel = this.channelArg.get(context); + int priority = this.priorityArg.get(context); + if (priority >= 0 && priority <= 255) { + if (playerRef.getPacketHandler().getChannel(networkChannel) instanceof QuicStreamChannel quicStreamChannel) { + quicStreamChannel.updatePriority(new QuicStreamPriority(priority, true)); + context.sendMessage( + Message.translation("server.commands.network.streamPriority.set.success") + .param("channel", networkChannel.name()) + .param("priority", priority) + ); + } else { + context.sendMessage(Message.translation("server.commands.network.streamPriority.set.notQuic").param("channel", networkChannel.name())); + } + } else { + context.sendMessage(Message.translation("server.commands.network.streamPriority.set.invalidPriority")); + } + } + } + } } diff --git a/src/com/hypixel/hytale/server/core/command/system/CommandManager.java b/src/com/hypixel/hytale/server/core/command/system/CommandManager.java index de8e480a..f8198931 100644 --- a/src/com/hypixel/hytale/server/core/command/system/CommandManager.java +++ b/src/com/hypixel/hytale/server/core/command/system/CommandManager.java @@ -48,6 +48,7 @@ import com.hypixel.hytale.server.core.command.commands.utility.ConvertPrefabsCom import com.hypixel.hytale.server.core.command.commands.utility.EventTitleCommand; import com.hypixel.hytale.server.core.command.commands.utility.NotifyCommand; import com.hypixel.hytale.server.core.command.commands.utility.StashCommand; +import com.hypixel.hytale.server.core.command.commands.utility.UIGalleryCommand; import com.hypixel.hytale.server.core.command.commands.utility.ValidateCPBCommand; import com.hypixel.hytale.server.core.command.commands.utility.git.GitCommand; import com.hypixel.hytale.server.core.command.commands.utility.help.HelpCommand; @@ -159,6 +160,7 @@ public class CommandManager implements CommandOwner { this.registerSystemCommand(new SleepCommand()); this.registerSystemCommand(new NetworkCommand()); this.registerSystemCommand(new CommandsCommand()); + this.registerSystemCommand(new UIGalleryCommand()); this.registerSystemCommand(new GitCommand()); } diff --git a/src/com/hypixel/hytale/server/core/command/system/pages/CommandListPage.java b/src/com/hypixel/hytale/server/core/command/system/pages/CommandListPage.java index cb17c5e0..46b9b5cb 100644 --- a/src/com/hypixel/hytale/server/core/command/system/pages/CommandListPage.java +++ b/src/com/hypixel/hytale/server/core/command/system/pages/CommandListPage.java @@ -557,7 +557,7 @@ public class CommandListPage extends InteractiveCustomUIPage arg = requiredArgs.get(i); commandBuilder.append("#RequiredArgumentsList", "Pages/ParameterItem.ui"); commandBuilder.set("#RequiredArgumentsList[" + i + "] #ParamName.TextSpans", Message.raw(arg.getName())); - commandBuilder.set("#RequiredArgumentsList[" + i + "] #ParamTag.TextSpans", Message.raw("[Required]")); + commandBuilder.set("#RequiredArgumentsList[" + i + "] #ParamTag.TextSpans", Message.translation("server.customUI.commandListPage.required")); commandBuilder.set( "#RequiredArgumentsList[" + i + "] #ParamType.TextSpans", Message.translation("server.customUI.commandListPage.paramType").param("type", arg.getArgumentType().getName()) @@ -593,7 +593,9 @@ public class CommandListPage extends InteractiveCustomUIPage") ); - commandBuilder.set("#OptionalArgumentsList[" + optIndex + "] #ParamTag.TextSpans", Message.raw("[Optional]")); + commandBuilder.set( + "#OptionalArgumentsList[" + optIndex + "] #ParamTag.TextSpans", Message.translation("server.customUI.commandListPage.optional") + ); commandBuilder.set( "#OptionalArgumentsList[" + optIndex + "] #ParamType.TextSpans", Message.translation("server.customUI.commandListPage.paramType").param("type", optArg.getArgumentType().getName()) @@ -612,7 +614,9 @@ public class CommandListPage extends InteractiveCustomUIPage") ); - commandBuilder.set("#DefaultArgumentsList[" + defIndex + "] #ParamTag.TextSpans", Message.raw("[Default]")); + commandBuilder.set( + "#DefaultArgumentsList[" + defIndex + "] #ParamTag.TextSpans", Message.translation("server.customUI.commandListPage.default") + ); commandBuilder.set( "#DefaultArgumentsList[" + defIndex + "] #ParamType.TextSpans", Message.translation("server.customUI.commandListPage.paramTypeDefault") @@ -630,7 +634,7 @@ public class CommandListPage extends InteractiveCustomUIPage { + private static final Value CATEGORY_BUTTON_STYLE = Value.ref("Pages/UIGallery/CategoryButton.ui", "LabelStyle"); + private static final Value CATEGORY_BUTTON_SELECTED_STYLE = Value.ref("Pages/UIGallery/CategoryButton.ui", "SelectedLabelStyle"); + private UIGalleryPage.Category selectedCategory = UIGalleryPage.Category.BUTTONS; + private final IntSet expandedCodeBlocks = new IntOpenHashSet(); + + public UIGalleryPage(@Nonnull PlayerRef playerRef) { + super(playerRef, CustomPageLifetime.CanDismiss, UIGalleryPage.UIGalleryEventData.CODEC); + } + + @Override + public void build( + @Nonnull Ref ref, @Nonnull UICommandBuilder commandBuilder, @Nonnull UIEventBuilder eventBuilder, @Nonnull Store store + ) { + commandBuilder.append("Pages/UIGallery/UIGalleryPage.ui"); + this.buildCategoryList(commandBuilder, eventBuilder); + this.displayCategory(this.selectedCategory, commandBuilder, eventBuilder); + } + + public void handleDataEvent(@Nonnull Ref ref, @Nonnull Store store, @Nonnull UIGalleryPage.UIGalleryEventData data) { + UICommandBuilder commandBuilder = new UICommandBuilder(); + UIEventBuilder eventBuilder = new UIEventBuilder(); + if (data.category != null) { + UIGalleryPage.Category newCategory = UIGalleryPage.Category.fromId(data.category); + if (newCategory != this.selectedCategory) { + int oldIndex = this.selectedCategory.ordinal(); + commandBuilder.set("#CategoryList[" + oldIndex + "].Style", CATEGORY_BUTTON_STYLE); + int newIndex = newCategory.ordinal(); + commandBuilder.set("#CategoryList[" + newIndex + "].Style", CATEGORY_BUTTON_SELECTED_STYLE); + this.expandedCodeBlocks.clear(); + this.selectedCategory = newCategory; + this.displayCategory(this.selectedCategory, commandBuilder, eventBuilder); + } + + this.sendUpdate(commandBuilder, eventBuilder, false); + } else if (data.toggleCode != null) { + try { + int codeIndex = Integer.parseInt(data.toggleCode); + this.toggleCodeBlock(codeIndex, commandBuilder); + this.sendUpdate(commandBuilder, eventBuilder, false); + } catch (NumberFormatException var9) { + } + } + } + + private void buildCategoryList(@Nonnull UICommandBuilder commandBuilder, @Nonnull UIEventBuilder eventBuilder) { + commandBuilder.clear("#CategoryList"); + + for (int i = 0; i < UIGalleryPage.Category.values().length; i++) { + UIGalleryPage.Category category = UIGalleryPage.Category.values()[i]; + commandBuilder.append("#CategoryList", "Pages/UIGallery/CategoryButton.ui"); + commandBuilder.set("#CategoryList[" + i + "].TextSpans", Message.translation(category.getNameKey())); + if (category == this.selectedCategory) { + commandBuilder.set("#CategoryList[" + i + "].Style", CATEGORY_BUTTON_SELECTED_STYLE); + } + + eventBuilder.addEventBinding(CustomUIEventBindingType.Activating, "#CategoryList[" + i + "]", EventData.of("Category", category.getId())); + } + } + + private void displayCategory(@Nonnull UIGalleryPage.Category category, @Nonnull UICommandBuilder commandBuilder, @Nonnull UIEventBuilder eventBuilder) { + commandBuilder.set("#CategoryTitle.TextSpans", Message.translation(category.getNameKey())); + commandBuilder.set("#CategoryDescription.TextSpans", Message.translation(category.getDescriptionKey())); + commandBuilder.clear("#CategoryContent"); + commandBuilder.append("#CategoryContent", category.getContentPath()); + + for (int i = 0; i < category.getCodeBlockCount(); i++) { + String selector = "#CategoryContent #Code" + i + " #ToggleCode"; + eventBuilder.addEventBinding(CustomUIEventBindingType.Activating, selector, EventData.of("ToggleCode", String.valueOf(i))); + } + } + + private void toggleCodeBlock(int index, @Nonnull UICommandBuilder commandBuilder) { + String containerSelector = "#CategoryContent #Code" + index + " #CodeContainer"; + String buttonSelector = "#CategoryContent #Code" + index + " #ToggleCode"; + if (this.expandedCodeBlocks.contains(index)) { + this.expandedCodeBlocks.remove(index); + commandBuilder.set(containerSelector + ".Visible", false); + commandBuilder.set(buttonSelector + ".TextSpans", Message.raw("Show Code")); + } else { + this.expandedCodeBlocks.add(index); + commandBuilder.set(containerSelector + ".Visible", true); + commandBuilder.set(buttonSelector + ".TextSpans", Message.raw("Hide Code")); + } + } + + private static enum Category { + BUTTONS( + "buttons", + "server.customUI.uiGallery.category.buttons", + "server.customUI.uiGallery.category.buttons.desc", + "Pages/UIGallery/Categories/ButtonsContent.ui", + 7 + ), + INPUTS( + "inputs", + "server.customUI.uiGallery.category.inputs", + "server.customUI.uiGallery.category.inputs.desc", + "Pages/UIGallery/Categories/InputsContent.ui", + 4 + ), + SELECTION( + "selection", + "server.customUI.uiGallery.category.selection", + "server.customUI.uiGallery.category.selection.desc", + "Pages/UIGallery/Categories/SelectionContent.ui", + 4 + ), + CONTAINERS( + "containers", + "server.customUI.uiGallery.category.containers", + "server.customUI.uiGallery.category.containers.desc", + "Pages/UIGallery/Categories/ContainersContent.ui", + 7 + ), + TEXT("text", "server.customUI.uiGallery.category.text", "server.customUI.uiGallery.category.text.desc", "Pages/UIGallery/Categories/TextContent.ui", 3), + SLIDERS( + "sliders", + "server.customUI.uiGallery.category.sliders", + "server.customUI.uiGallery.category.sliders.desc", + "Pages/UIGallery/Categories/SlidersContent.ui", + 3 + ), + PROGRESS( + "progress", + "server.customUI.uiGallery.category.progress", + "server.customUI.uiGallery.category.progress.desc", + "Pages/UIGallery/Categories/ProgressContent.ui", + 3 + ), + SCROLLBARS( + "scrollbars", + "server.customUI.uiGallery.category.scrollbars", + "server.customUI.uiGallery.category.scrollbars.desc", + "Pages/UIGallery/Categories/ScrollbarsContent.ui", + 3 + ), + NAVIGATION( + "navigation", + "server.customUI.uiGallery.category.navigation", + "server.customUI.uiGallery.category.navigation.desc", + "Pages/UIGallery/Categories/NavigationContent.ui", + 2 + ), + TOOLTIPS( + "tooltips", + "server.customUI.uiGallery.category.tooltips", + "server.customUI.uiGallery.category.tooltips.desc", + "Pages/UIGallery/Categories/TooltipsContent.ui", + 2 + ); + + private final String id; + private final String nameKey; + private final String descriptionKey; + private final String contentPath; + private final int codeBlockCount; + + private Category(String id, String nameKey, String descriptionKey, String contentPath, int codeBlockCount) { + this.id = id; + this.nameKey = nameKey; + this.descriptionKey = descriptionKey; + this.contentPath = contentPath; + this.codeBlockCount = codeBlockCount; + } + + public String getId() { + return this.id; + } + + public String getNameKey() { + return this.nameKey; + } + + public String getDescriptionKey() { + return this.descriptionKey; + } + + public String getContentPath() { + return this.contentPath; + } + + public int getCodeBlockCount() { + return this.codeBlockCount; + } + + public static UIGalleryPage.Category fromId(String id) { + for (UIGalleryPage.Category category : values()) { + if (category.id.equals(id)) { + return category; + } + } + + return BUTTONS; + } + } + + public static class UIGalleryEventData { + static final String KEY_CATEGORY = "Category"; + static final String KEY_TOGGLE_CODE = "ToggleCode"; + public static final BuilderCodec CODEC = BuilderCodec.builder( + UIGalleryPage.UIGalleryEventData.class, UIGalleryPage.UIGalleryEventData::new + ) + .addField(new KeyedCodec<>("Category", Codec.STRING), (entry, s) -> entry.category = s, entry -> entry.category) + .addField(new KeyedCodec<>("ToggleCode", Codec.STRING), (entry, s) -> entry.toggleCode = s, entry -> entry.toggleCode) + .build(); + private String category; + private String toggleCode; + } +} diff --git a/src/com/hypixel/hytale/server/core/config/BackupConfig.java b/src/com/hypixel/hytale/server/core/config/BackupConfig.java new file mode 100644 index 00000000..cea5c53a --- /dev/null +++ b/src/com/hypixel/hytale/server/core/config/BackupConfig.java @@ -0,0 +1,172 @@ +package com.hypixel.hytale.server.core.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.codec.validation.Validators; +import com.hypixel.hytale.server.core.HytaleServerConfig; +import com.hypixel.hytale.server.core.Options; +import java.nio.file.Path; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import joptsimple.OptionSet; + +public class BackupConfig { + public static final int DEFAULT_FREQUENCY_MINUTES = 30; + public static final int DEFAULT_MAX_COUNT = 5; + public static final int DEFAULT_ARCHIVE_MAX_COUNT = 5; + @Nonnull + public static final Codec CODEC = BuilderCodec.builder(BackupConfig.class, BackupConfig::new) + .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (o, b) -> o.enabled = b, o -> o.enabled) + .documentation("Determines whether automatic backups are enabled. Can be overridden by the --backup CLI option.") + .add() + .append(new KeyedCodec<>("FrequencyMinutes", Codec.INTEGER), (o, i) -> o.frequencyMinutes = i, o -> o.frequencyMinutes) + .addValidator(Validators.greaterThan(0)) + .documentation("The backup frequency in minutes. Must be at least 1. Can be overridden by the --backup-frequency CLI option.") + .add() + .append(new KeyedCodec<>("Directory", Codec.STRING), (o, s) -> o.directory = s, o -> o.directory) + .addValidator(Validators.nonEmptyString()) + .documentation("The backup directory path. Can be overridden by the --backup-directory CLI option.") + .add() + .append(new KeyedCodec<>("MaxCount", Codec.INTEGER), (o, i) -> o.maxCount = i, o -> o.maxCount) + .addValidator(Validators.greaterThan(0)) + .documentation("The maximum number of recent backups to retain. Must be at least 1. Can be overridden by the --backup-max-count CLI option.") + .add() + .append(new KeyedCodec<>("ArchiveMaxCount", Codec.INTEGER), (o, i) -> o.archiveMaxCount = i, o -> o.archiveMaxCount) + .addValidator(Validators.greaterThan(0)) + .documentation("The maximum number of archived backups to retain. Must be at least 1. Can be overridden by the --backup-archive-max-count CLI option.") + .add() + .build(); + @Nullable + private Boolean enabled; + @Nullable + private Integer frequencyMinutes; + @Nullable + private String directory; + @Nullable + private Integer maxCount; + @Nullable + private Integer archiveMaxCount; + @Nullable + transient HytaleServerConfig hytaleServerConfig; + + public BackupConfig() { + } + + public BackupConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public void setHytaleServerConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public boolean isEnabled() { + if (Options.getOptionSet().has(Options.BACKUP)) { + return true; + } else { + return this.enabled != null ? this.enabled : false; + } + } + + @Nullable + public Boolean getEnabledConfig() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getFrequencyMinutes() { + OptionSet optionSet = Options.getOptionSet(); + if (optionSet.has(Options.BACKUP_FREQUENCY_MINUTES)) { + return Math.max(optionSet.valueOf(Options.BACKUP_FREQUENCY_MINUTES), 1); + } else { + return this.frequencyMinutes != null ? Math.max(this.frequencyMinutes, 1) : 30; + } + } + + @Nullable + public Integer getFrequencyMinutesConfig() { + return this.frequencyMinutes; + } + + public void setFrequencyMinutes(int frequencyMinutes) { + this.frequencyMinutes = frequencyMinutes; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + @Nullable + public Path getDirectory() { + OptionSet optionSet = Options.getOptionSet(); + if (optionSet.has(Options.BACKUP_DIRECTORY)) { + return optionSet.valueOf(Options.BACKUP_DIRECTORY); + } else { + return this.directory != null ? Path.of(this.directory) : null; + } + } + + @Nullable + public String getDirectoryConfig() { + return this.directory; + } + + public void setDirectory(@Nullable String directory) { + this.directory = directory; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getMaxCount() { + OptionSet optionSet = Options.getOptionSet(); + if (optionSet.has(Options.BACKUP_MAX_COUNT)) { + return optionSet.valueOf(Options.BACKUP_MAX_COUNT); + } else { + return this.maxCount != null ? this.maxCount : 5; + } + } + + @Nullable + public Integer getMaxCountConfig() { + return this.maxCount; + } + + public void setMaxCount(int maxCount) { + this.maxCount = maxCount; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getArchiveMaxCount() { + OptionSet optionSet = Options.getOptionSet(); + if (optionSet.has(Options.BACKUP_ARCHIVE_MAX_COUNT)) { + return optionSet.valueOf(Options.BACKUP_ARCHIVE_MAX_COUNT); + } else { + return this.archiveMaxCount != null ? this.archiveMaxCount : 5; + } + } + + @Nullable + public Integer getArchiveMaxCountConfig() { + return this.archiveMaxCount; + } + + public void setArchiveMaxCount(int archiveMaxCount) { + this.archiveMaxCount = archiveMaxCount; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public boolean isConfigured() { + return this.isEnabled() && this.getDirectory() != null; + } +} diff --git a/src/com/hypixel/hytale/server/core/config/ModConfig.java b/src/com/hypixel/hytale/server/core/config/ModConfig.java new file mode 100644 index 00000000..1728bab4 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/config/ModConfig.java @@ -0,0 +1,46 @@ +package com.hypixel.hytale.server.core.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.common.semver.SemverRange; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ModConfig { + @Nonnull + public static final BuilderCodec CODEC = BuilderCodec.builder(ModConfig.class, ModConfig::new) + .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (modConfig, enabled) -> modConfig.enabled = enabled, modConfig -> modConfig.enabled) + .documentation("Determines whether the mod/plugin is enabled.") + .add() + .append( + new KeyedCodec<>("RequiredVersion", SemverRange.CODEC), + (modConfig, semverRange) -> modConfig.requiredVersion = semverRange, + modConfig -> modConfig.requiredVersion + ) + .documentation("The required version range for the mod/plugin.") + .add() + .build(); + @Nullable + private Boolean enabled; + @Nullable + private SemverRange requiredVersion; + + @Nullable + public Boolean getEnabled() { + return this.enabled; + } + + public void setEnabled(@Nonnull Boolean enabled) { + this.enabled = enabled; + } + + @Nullable + public SemverRange getRequiredVersion() { + return this.requiredVersion; + } + + public void setRequiredVersion(@Nonnull SemverRange requiredVersion) { + this.requiredVersion = requiredVersion; + } +} diff --git a/src/com/hypixel/hytale/server/core/config/RateLimitConfig.java b/src/com/hypixel/hytale/server/core/config/RateLimitConfig.java new file mode 100644 index 00000000..d749f597 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/config/RateLimitConfig.java @@ -0,0 +1,74 @@ +package com.hypixel.hytale.server.core.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.server.core.HytaleServerConfig; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class RateLimitConfig { + public static final int DEFAULT_PACKETS_PER_SECOND = 2000; + public static final int DEFAULT_BURST_CAPACITY = 500; + @Nonnull + public static final Codec CODEC = BuilderCodec.builder(RateLimitConfig.class, RateLimitConfig::new) + .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (o, b) -> o.enabled = b, o -> o.enabled) + .documentation("Determines whether packet rate limiting is enabled.") + .add() + .append(new KeyedCodec<>("PacketsPerSecond", Codec.INTEGER), (o, i) -> o.packetsPerSecond = i, o -> o.packetsPerSecond) + .documentation("The number of packets allowed per second.") + .add() + .append(new KeyedCodec<>("BurstCapacity", Codec.INTEGER), (o, i) -> o.burstCapacity = i, o -> o.burstCapacity) + .documentation("The number of packets that can be sent in a burst before rate limiting is applied.") + .add() + .build(); + private Boolean enabled; + private Integer packetsPerSecond; + private Integer burstCapacity; + @Nullable + transient HytaleServerConfig hytaleServerConfig; + + public RateLimitConfig() { + } + + public RateLimitConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public void setHytaleServerConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public boolean isEnabled() { + return this.enabled != null ? this.enabled : true; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getPacketsPerSecond() { + return this.packetsPerSecond != null ? this.packetsPerSecond : 2000; + } + + public void setPacketsPerSecond(int packetsPerSecond) { + this.packetsPerSecond = packetsPerSecond; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getBurstCapacity() { + return this.burstCapacity != null ? this.burstCapacity : 500; + } + + public void setBurstCapacity(int burstCapacity) { + this.burstCapacity = burstCapacity; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } +} diff --git a/src/com/hypixel/hytale/server/core/config/UpdateConfig.java b/src/com/hypixel/hytale/server/core/config/UpdateConfig.java new file mode 100644 index 00000000..f1e55847 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/config/UpdateConfig.java @@ -0,0 +1,159 @@ +package com.hypixel.hytale.server.core.config; + +import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.codec.codecs.EnumCodec; +import com.hypixel.hytale.server.core.HytaleServerConfig; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class UpdateConfig { + public static final int DEFAULT_CHECK_INTERVAL_SECONDS = 3600; + @Nonnull + public static final Codec CODEC = BuilderCodec.builder(UpdateConfig.class, UpdateConfig::new) + .append(new KeyedCodec<>("Enabled", Codec.BOOLEAN), (o, b) -> o.enabled = b, o -> o.enabled) + .documentation("Determines whether to enable automatic update checks.") + .add() + .append(new KeyedCodec<>("CheckIntervalSeconds", Codec.INTEGER), (o, i) -> o.checkIntervalSeconds = i, o -> o.checkIntervalSeconds) + .documentation("The interval, in seconds, between automatic update checks.") + .add() + .append(new KeyedCodec<>("NotifyPlayersOnAvailable", Codec.BOOLEAN), (o, b) -> o.notifyPlayersOnAvailable = b, o -> o.notifyPlayersOnAvailable) + .documentation("Whether to notify players in-game when an update is available.") + .add() + .append(new KeyedCodec<>("Patchline", Codec.STRING), (o, s) -> o.patchline = s, o -> o.patchline) + .documentation("The patchline to check for updates on.") + .add() + .append(new KeyedCodec<>("RunBackupBeforeUpdate", Codec.BOOLEAN), (o, b) -> o.runBackupBeforeUpdate = b, o -> o.runBackupBeforeUpdate) + .documentation("Determines whether to run a backup before applying an update.") + .add() + .append(new KeyedCodec<>("BackupConfigBeforeUpdate", Codec.BOOLEAN), (o, b) -> o.backupConfigBeforeUpdate = b, o -> o.backupConfigBeforeUpdate) + .documentation("Determines whether to backup the server config before applying an update.") + .add() + .append( + new KeyedCodec<>("AutoApplyMode", new EnumCodec<>(UpdateConfig.AutoApplyMode.class)), (o, m) -> o.autoApplyMode = m, o -> o.autoApplyMode + ) + .documentation("The mode for automatically applying updates.") + .add() + .append(new KeyedCodec<>("AutoApplyDelayMinutes", Codec.INTEGER), (o, i) -> o.autoApplyDelayMinutes = i, o -> o.autoApplyDelayMinutes) + .documentation("The delay in minutes before auto-applying an update while using SCHEDULED mode.") + .add() + .build(); + private Boolean enabled; + private Integer checkIntervalSeconds; + private Boolean notifyPlayersOnAvailable; + private String patchline; + private Boolean runBackupBeforeUpdate; + private Boolean backupConfigBeforeUpdate; + private UpdateConfig.AutoApplyMode autoApplyMode; + private Integer autoApplyDelayMinutes; + @Nullable + transient HytaleServerConfig hytaleServerConfig; + + public UpdateConfig() { + } + + public UpdateConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public void setHytaleServerConfig(@Nonnull HytaleServerConfig hytaleServerConfig) { + this.hytaleServerConfig = hytaleServerConfig; + } + + public boolean isEnabled() { + return this.enabled != null ? this.enabled : true; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getCheckIntervalSeconds() { + return this.checkIntervalSeconds != null ? this.checkIntervalSeconds : 3600; + } + + public void setCheckIntervalSeconds(int checkIntervalSeconds) { + this.checkIntervalSeconds = checkIntervalSeconds; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public boolean isNotifyPlayersOnAvailable() { + return this.notifyPlayersOnAvailable != null ? this.notifyPlayersOnAvailable : true; + } + + public void setNotifyPlayersOnAvailable(boolean notifyPlayersOnAvailable) { + this.notifyPlayersOnAvailable = notifyPlayersOnAvailable; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + @Nullable + public String getPatchline() { + return this.patchline; + } + + public void setPatchline(@Nullable String patchline) { + this.patchline = patchline; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public boolean isRunBackupBeforeUpdate() { + return this.runBackupBeforeUpdate != null ? this.runBackupBeforeUpdate : true; + } + + public void setRunBackupBeforeUpdate(boolean runBackupBeforeUpdate) { + this.runBackupBeforeUpdate = runBackupBeforeUpdate; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public boolean isBackupConfigBeforeUpdate() { + return this.backupConfigBeforeUpdate != null ? this.backupConfigBeforeUpdate : true; + } + + public void setBackupConfigBeforeUpdate(boolean backupConfigBeforeUpdate) { + this.backupConfigBeforeUpdate = backupConfigBeforeUpdate; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + @Nonnull + public UpdateConfig.AutoApplyMode getAutoApplyMode() { + return this.autoApplyMode != null ? this.autoApplyMode : UpdateConfig.AutoApplyMode.DISABLED; + } + + public void setAutoApplyMode(@Nonnull UpdateConfig.AutoApplyMode autoApplyMode) { + this.autoApplyMode = autoApplyMode; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public int getAutoApplyDelayMinutes() { + return this.autoApplyDelayMinutes != null ? this.autoApplyDelayMinutes : 30; + } + + public void setAutoApplyDelayMinutes(int autoApplyDelayMinutes) { + this.autoApplyDelayMinutes = autoApplyDelayMinutes; + if (this.hytaleServerConfig != null) { + this.hytaleServerConfig.markChanged(); + } + } + + public static enum AutoApplyMode { + DISABLED, + WHEN_EMPTY, + SCHEDULED; + } +} diff --git a/src/com/hypixel/hytale/server/core/entity/entities/Player.java b/src/com/hypixel/hytale/server/core/entity/entities/Player.java index 434fb8be..c03d4e31 100644 --- a/src/com/hypixel/hytale/server/core/entity/entities/Player.java +++ b/src/com/hypixel/hytale/server/core/entity/entities/Player.java @@ -207,7 +207,7 @@ public class Player extends LivingEntity implements CommandSender, PermissionHol Store store = ref.getStore(); ChunkTracker tracker = store.getComponent(ref, ChunkTracker.getComponentType()); if (tracker != null) { - tracker.clear(); + tracker.unloadAll(this.playerRef); } this.playerRef.removeFromStore(); @@ -219,7 +219,7 @@ public class Player extends LivingEntity implements CommandSender, PermissionHol Store storex = ref.getStore(); ChunkTracker trackerx = storex.getComponent(ref, ChunkTracker.getComponentType()); if (trackerx != null) { - trackerx.clear(); + trackerx.unloadAll(this.playerRef); } this.playerRef.removeFromStore(); diff --git a/src/com/hypixel/hytale/server/core/entity/entities/player/pages/PageManager.java b/src/com/hypixel/hytale/server/core/entity/entities/player/pages/PageManager.java index 26889d10..482907eb 100644 --- a/src/com/hypixel/hytale/server/core/entity/entities/player/pages/PageManager.java +++ b/src/com/hypixel/hytale/server/core/entity/entities/player/pages/PageManager.java @@ -9,6 +9,7 @@ import com.hypixel.hytale.protocol.packets.interface_.SetPage; import com.hypixel.hytale.protocol.packets.window.OpenWindow; import com.hypixel.hytale.server.core.entity.entities.player.windows.Window; import com.hypixel.hytale.server.core.entity.entities.player.windows.WindowManager; +import com.hypixel.hytale.server.core.modules.anchoraction.AnchorActionModule; import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder; import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder; import com.hypixel.hytale.server.core.universe.PlayerRef; @@ -125,11 +126,15 @@ public class PageManager { this.customPage = null; break; case Data: - if (this.customPageRequiredAcknowledgments.get() != 0 || this.customPage == null) { + if (this.customPageRequiredAcknowledgments.get() != 0) { return; } - this.customPage.handleDataEvent(ref, store, event.data); + if (this.customPage != null) { + this.customPage.handleDataEvent(ref, store, event.data); + } else { + AnchorActionModule.get().tryHandle(this.playerRef, event.data); + } break; case Acknowledge: if (this.customPageRequiredAcknowledgments.decrementAndGet() < 0) { diff --git a/src/com/hypixel/hytale/server/core/entity/movement/MovementStatesSystems.java b/src/com/hypixel/hytale/server/core/entity/movement/MovementStatesSystems.java index 3538bda7..1fecec70 100644 --- a/src/com/hypixel/hytale/server/core/entity/movement/MovementStatesSystems.java +++ b/src/com/hypixel/hytale/server/core/entity/movement/MovementStatesSystems.java @@ -13,9 +13,8 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.MovementStates; +import com.hypixel.hytale.protocol.MovementStatesUpdate; import com.hypixel.hytale.protocol.SavedMovementStates; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.entity.entities.player.data.PlayerWorldData; @@ -168,8 +167,7 @@ public class MovementStatesSystems { @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, @Nonnull MovementStatesComponent movementStatesComponent ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.MovementStates; + MovementStatesUpdate update = new MovementStatesUpdate(); update.movementStates = movementStatesComponent.getMovementStates(); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { diff --git a/src/com/hypixel/hytale/server/core/entity/nameplate/NameplateSystems.java b/src/com/hypixel/hytale/server/core/entity/nameplate/NameplateSystems.java index 64310356..080837aa 100644 --- a/src/com/hypixel/hytale/server/core/entity/nameplate/NameplateSystems.java +++ b/src/com/hypixel/hytale/server/core/entity/nameplate/NameplateSystems.java @@ -9,8 +9,8 @@ import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.NameplateUpdate; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import java.util.Map; @@ -132,10 +132,7 @@ public class NameplateSystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull Nameplate nameplateComponent, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Nameplate; - update.nameplate = new com.hypixel.hytale.protocol.Nameplate(); - update.nameplate.text = nameplateComponent.getText(); + NameplateUpdate update = new NameplateUpdate(nameplateComponent.getText()); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/inventory/Inventory.java b/src/com/hypixel/hytale/server/core/inventory/Inventory.java index d53f9a22..ad406ecb 100644 --- a/src/com/hypixel/hytale/server/core/inventory/Inventory.java +++ b/src/com/hypixel/hytale/server/core/inventory/Inventory.java @@ -581,6 +581,10 @@ public class Inventory implements NetworkSerializable { return this.combinedBackpackStorageHotbar; } + public CombinedItemContainer getCombinedBackpackStorageHotbarFirst() { + return this.combinedHotbarStorageBackpack; + } + public CombinedItemContainer getCombinedArmorHotbarUtilityStorage() { return this.combinedArmorHotbarUtilityStorage; } diff --git a/src/com/hypixel/hytale/server/core/io/PacketHandler.java b/src/com/hypixel/hytale/server/core/io/PacketHandler.java index 7b9c0802..b6924ee4 100644 --- a/src/com/hypixel/hytale/server/core/io/PacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/PacketHandler.java @@ -10,7 +10,9 @@ import com.hypixel.hytale.metrics.MetricsRegistry; import com.hypixel.hytale.metrics.metric.HistoricMetric; import com.hypixel.hytale.metrics.metric.Metric; import com.hypixel.hytale.protocol.CachedPacket; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.NetworkChannel; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.PacketStatsRecorder; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.connection.Disconnect; @@ -31,6 +33,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.local.LocalAddress; import io.netty.channel.unix.DomainSocketAddress; import io.netty.handler.codec.quic.QuicStreamChannel; +import io.netty.handler.codec.quic.QuicStreamPriority; import io.netty.util.Attribute; import io.netty.util.AttributeKey; import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; @@ -43,6 +46,7 @@ import java.net.SocketAddress; import java.security.SecureRandom; import java.time.Duration; import java.time.Instant; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -56,10 +60,19 @@ import javax.annotation.Nullable; public abstract class PacketHandler implements IPacketReceiver { public static final int MAX_PACKET_ID = 512; + @Nonnull + public static final Map DEFAULT_STREAM_PRIORITIES = Map.of( + NetworkChannel.Default, + new QuicStreamPriority(0, true), + NetworkChannel.Chunks, + new QuicStreamPriority(0, true), + NetworkChannel.WorldMap, + new QuicStreamPriority(1, true) + ); private static final HytaleLogger LOGIN_TIMING_LOGGER = HytaleLogger.get("LoginTiming"); private static final AttributeKey LOGIN_START_ATTRIBUTE_KEY = AttributeKey.newInstance("LOGIN_START"); @Nonnull - protected final Channel channel; + protected final Channel[] channels = new Channel[NetworkChannel.COUNT]; @Nonnull protected final ProtocolVersion protocolVersion; @Nullable @@ -80,7 +93,7 @@ public abstract class PacketHandler implements IPacketReceiver { protected final PacketHandler.DisconnectReason disconnectReason = new PacketHandler.DisconnectReason(); public PacketHandler(@Nonnull Channel channel, @Nonnull ProtocolVersion protocolVersion) { - this.channel = channel; + this.channels[0] = channel; this.protocolVersion = protocolVersion; this.pingInfo = new PacketHandler.PingInfo[PongType.VALUES.length]; @@ -91,7 +104,7 @@ public abstract class PacketHandler implements IPacketReceiver { @Nonnull public Channel getChannel() { - return this.channel; + return this.channels[0]; } @Deprecated(forRemoval = true) @@ -129,11 +142,11 @@ public abstract class PacketHandler implements IPacketReceiver { protected void unregistered0(@Nullable PacketHandler newHandler) { } - public void handle(@Nonnull Packet packet) { + public void handle(@Nonnull ToServerPacket packet) { this.accept(packet); } - public abstract void accept(@Nonnull Packet var1); + public abstract void accept(@Nonnull ToServerPacket var1); public void logCloseMessage() { HytaleLogger.getLogger().at(Level.INFO).log("%s was closed.", this.getIdentifier()); @@ -149,64 +162,89 @@ public abstract class PacketHandler implements IPacketReceiver { public void tryFlush() { if (this.queuedPackets.getAndSet(0) > 0) { - this.channel.flush(); + for (Channel channel : this.channels) { + if (channel != null) { + channel.flush(); + } + } } } - public void write(@Nonnull Packet... packets) { - Packet[] cachedPackets = new Packet[packets.length]; - this.handleOutboundAndCachePackets(packets, cachedPackets); - if (this.queuePackets) { - this.channel.write(cachedPackets, this.channel.voidPromise()); - this.queuedPackets.getAndIncrement(); - } else { - this.channel.writeAndFlush(cachedPackets, this.channel.voidPromise()); + public void write(@Nonnull ToClientPacket... packets) { + if (packets.length != 0) { + ToClientPacket[] cachedPackets = new ToClientPacket[packets.length]; + this.handleOutboundAndCachePackets(packets, cachedPackets); + NetworkChannel networkChannel = packets[0].getChannel(); + + for (int i = 1; i < packets.length; i++) { + if (networkChannel != packets[i].getChannel()) { + throw new IllegalArgumentException("All packets must be sent on the same channel!"); + } + } + + Channel channel = this.channels[networkChannel.getValue()]; + if (this.queuePackets) { + channel.write(cachedPackets, channel.voidPromise()); + this.queuedPackets.getAndIncrement(); + } else { + channel.writeAndFlush(cachedPackets, channel.voidPromise()); + } } } - public void write(@Nonnull Packet[] packets, @Nonnull Packet finalPacket) { - Packet[] cachedPackets = new Packet[packets.length + 1]; + public void write(@Nonnull ToClientPacket[] packets, @Nonnull ToClientPacket finalPacket) { + ToClientPacket[] cachedPackets = new ToClientPacket[packets.length + 1]; this.handleOutboundAndCachePackets(packets, cachedPackets); cachedPackets[cachedPackets.length - 1] = this.handleOutboundAndCachePacket(finalPacket); + NetworkChannel networkChannel = finalPacket.getChannel(); + + for (int i = 0; i < packets.length; i++) { + if (networkChannel != packets[i].getChannel()) { + throw new IllegalArgumentException("All packets must be sent on the same channel!"); + } + } + + Channel channel = this.channels[networkChannel.getValue()]; if (this.queuePackets) { - this.channel.write(cachedPackets, this.channel.voidPromise()); + channel.write(cachedPackets, channel.voidPromise()); this.queuedPackets.getAndIncrement(); } else { - this.channel.writeAndFlush(cachedPackets, this.channel.voidPromise()); + channel.writeAndFlush(cachedPackets, channel.voidPromise()); } } @Override - public void write(@Nonnull Packet packet) { + public void write(@Nonnull ToClientPacket packet) { this.writePacket(packet, true); } @Override - public void writeNoCache(@Nonnull Packet packet) { + public void writeNoCache(@Nonnull ToClientPacket packet) { this.writePacket(packet, false); } - public void writePacket(@Nonnull Packet packet, boolean cache) { + public void writePacket(@Nonnull ToClientPacket packet, boolean cache) { if (!PacketAdapters.__handleOutbound(this, packet)) { - Packet toSend; + ToClientPacket toSend; if (cache) { toSend = this.handleOutboundAndCachePacket(packet); } else { toSend = packet; } + Channel channel = this.channels[packet.getChannel().getValue()]; if (this.queuePackets) { - this.channel.write(toSend, this.channel.voidPromise()); + channel.write(toSend, channel.voidPromise()); this.queuedPackets.getAndIncrement(); } else { - this.channel.writeAndFlush(toSend, this.channel.voidPromise()); + channel.writeAndFlush(toSend, channel.voidPromise()); } } } - private void handleOutboundAndCachePackets(@Nonnull Packet[] packets, @Nonnull Packet[] cachedPackets) { + private void handleOutboundAndCachePackets(@Nonnull ToClientPacket[] packets, @Nonnull ToClientPacket[] cachedPackets) { for (int i = 0; i < packets.length; i++) { - Packet packet = packets[i]; + ToClientPacket packet = packets[i]; if (!PacketAdapters.__handleOutbound(this, packet)) { cachedPackets[i] = this.handleOutboundAndCachePacket(packet); } @@ -214,24 +252,26 @@ public abstract class PacketHandler implements IPacketReceiver { } @Nonnull - private Packet handleOutboundAndCachePacket(@Nonnull Packet packet) { - return (Packet)(packet instanceof CachedPacket ? packet : CachedPacket.cache(packet)); + private ToClientPacket handleOutboundAndCachePacket(@Nonnull ToClientPacket packet) { + return (ToClientPacket)(packet instanceof CachedPacket ? packet : CachedPacket.cache(packet)); } public void disconnect(@Nonnull String message) { this.disconnectReason.setServerDisconnectReason(message); String sni = this.getSniHostname(); - HytaleLogger.getLogger().at(Level.INFO).log("Disconnecting %s (SNI: %s) with the message: %s", NettyUtil.formatRemoteAddress(this.channel), sni, message); + HytaleLogger.getLogger() + .at(Level.INFO) + .log("Disconnecting %s (SNI: %s) with the message: %s", NettyUtil.formatRemoteAddress(this.getChannel()), sni, message); this.disconnect0(message); } protected void disconnect0(@Nonnull String message) { - this.channel.writeAndFlush(new Disconnect(message, DisconnectType.Disconnect)).addListener(ProtocolUtil.CLOSE_ON_COMPLETE); + this.getChannel().writeAndFlush(new Disconnect(message, DisconnectType.Disconnect)).addListener(ProtocolUtil.CLOSE_ON_COMPLETE); } @Nullable public PacketStatsRecorder getPacketStatsRecorder() { - return this.channel.attr(PacketStatsRecorder.CHANNEL_KEY).get(); + return this.getChannel().attr(PacketStatsRecorder.CHANNEL_KEY).get(); } @Nonnull @@ -277,23 +317,23 @@ public abstract class PacketHandler implements IPacketReceiver { } protected void initStage(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition) { - NettyUtil.TimeoutContext.init(this.channel, stage, this.getIdentifier()); + NettyUtil.TimeoutContext.init(this.getChannel(), stage, this.getIdentifier()); this.setStageTimeout(stage, timeout, condition); } protected void enterStage(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition) { - NettyUtil.TimeoutContext.update(this.channel, stage, this.getIdentifier()); + NettyUtil.TimeoutContext.update(this.getChannel(), stage, this.getIdentifier()); this.updatePacketTimeout(timeout); this.setStageTimeout(stage, timeout, condition); } protected void enterStage(@Nonnull String stage, @Nonnull Duration timeout) { - NettyUtil.TimeoutContext.update(this.channel, stage, this.getIdentifier()); + NettyUtil.TimeoutContext.update(this.getChannel(), stage, this.getIdentifier()); this.updatePacketTimeout(timeout); } protected void continueStage(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition) { - NettyUtil.TimeoutContext.update(this.channel, stage); + NettyUtil.TimeoutContext.update(this.getChannel(), stage); this.updatePacketTimeout(timeout); this.setStageTimeout(stage, timeout, condition); } @@ -304,15 +344,15 @@ public abstract class PacketHandler implements IPacketReceiver { } if (this instanceof AuthenticationPacketHandler || !(this instanceof PasswordPacketHandler) || this.auth != null) { - logConnectionTimings(this.channel, "Entering stage '" + stageId + "'", Level.FINEST); + logConnectionTimings(this.getChannel(), "Entering stage '" + stageId + "'", Level.FINEST); long timeoutMillis = timeout.toMillis(); - this.timeoutTask = this.channel + this.timeoutTask = this.getChannel() .eventLoop() .schedule( () -> { - if (this.channel.isOpen()) { + if (this.getChannel().isOpen()) { if (!meets.getAsBoolean()) { - NettyUtil.TimeoutContext context = this.channel.attr(NettyUtil.TimeoutContext.KEY).get(); + NettyUtil.TimeoutContext context = this.getChannel().attr(NettyUtil.TimeoutContext.KEY).get(); String duration = context != null ? FormatUtil.nanosToString(System.nanoTime() - context.connectionStartNs()) : "unknown"; HytaleLogger.getLogger() .at(Level.WARNING) @@ -328,7 +368,7 @@ public abstract class PacketHandler implements IPacketReceiver { } private void updatePacketTimeout(@Nonnull Duration timeout) { - this.channel.attr(ProtocolUtil.PACKET_TIMEOUT_KEY).set(timeout); + this.getChannel().attr(ProtocolUtil.PACKET_TIMEOUT_KEY).set(timeout); } protected void clearTimeout() { @@ -349,7 +389,7 @@ public abstract class PacketHandler implements IPacketReceiver { } public boolean stillActive() { - return this.channel.isActive(); + return this.getChannel().isActive(); } public int getQueuedPacketsCount() { @@ -358,10 +398,10 @@ public abstract class PacketHandler implements IPacketReceiver { public boolean isLocalConnection() { SocketAddress socketAddress; - if (this.channel instanceof QuicStreamChannel quicStreamChannel) { + if (this.getChannel() instanceof QuicStreamChannel quicStreamChannel) { socketAddress = quicStreamChannel.parent().remoteSocketAddress(); } else { - socketAddress = this.channel.remoteAddress(); + socketAddress = this.getChannel().remoteAddress(); } if (socketAddress instanceof InetSocketAddress) { @@ -374,10 +414,10 @@ public abstract class PacketHandler implements IPacketReceiver { public boolean isLANConnection() { SocketAddress socketAddress; - if (this.channel instanceof QuicStreamChannel quicStreamChannel) { + if (this.getChannel() instanceof QuicStreamChannel quicStreamChannel) { socketAddress = quicStreamChannel.parent().remoteSocketAddress(); } else { - socketAddress = this.channel.remoteAddress(); + socketAddress = this.getChannel().remoteAddress(); } if (socketAddress instanceof InetSocketAddress) { @@ -390,7 +430,7 @@ public abstract class PacketHandler implements IPacketReceiver { @Nullable public String getSniHostname() { - return this.channel instanceof QuicStreamChannel quicStreamChannel ? quicStreamChannel.parent().attr(QUICTransport.SNI_HOSTNAME_ATTR).get() : null; + return this.getChannel() instanceof QuicStreamChannel quicStreamChannel ? quicStreamChannel.parent().attr(QUICTransport.SNI_HOSTNAME_ATTR).get() : null; } @Nonnull @@ -413,6 +453,15 @@ public abstract class PacketHandler implements IPacketReceiver { return this.clientReadyForChunksFuture; } + @Nonnull + public Channel getChannel(@Nonnull NetworkChannel networkChannel) { + return this.channels[networkChannel.getValue()]; + } + + public void setChannel(@Nonnull NetworkChannel networkChannel, @Nonnull Channel channel) { + this.channels[networkChannel.getValue()] = channel; + } + public static void logConnectionTimings(@Nonnull Channel channel, @Nonnull String message, @Nonnull Level level) { Attribute loginStartAttribute = channel.attr(LOGIN_START_ATTRIBUTE_KEY); long now = System.nanoTime(); diff --git a/src/com/hypixel/hytale/server/core/io/PacketStatsRecorderImpl.java b/src/com/hypixel/hytale/server/core/io/PacketStatsRecorderImpl.java index 625005cc..0f8258c0 100644 --- a/src/com/hypixel/hytale/server/core/io/PacketStatsRecorderImpl.java +++ b/src/com/hypixel/hytale/server/core/io/PacketStatsRecorderImpl.java @@ -151,7 +151,7 @@ public class PacketStatsRecorderImpl implements PacketStatsRecorder { @Nullable @Override public String getName() { - PacketRegistry.PacketInfo info = PacketRegistry.getById(this.packetId); + PacketRegistry.PacketInfo info = PacketRegistry.all().get(this.packetId); return info != null ? info.name() : null; } diff --git a/src/com/hypixel/hytale/server/core/io/handlers/GenericPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/GenericPacketHandler.java index bbdedb3b..ca478b9e 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/GenericPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/GenericPacketHandler.java @@ -1,6 +1,6 @@ package com.hypixel.hytale.server.core.io.handlers; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.server.core.io.PacketHandler; import com.hypixel.hytale.server.core.io.ProtocolVersion; import io.netty.channel.Channel; @@ -10,13 +10,13 @@ import java.util.function.Consumer; import javax.annotation.Nonnull; public abstract class GenericPacketHandler extends PacketHandler { - private static final Consumer EMPTY_CONSUMER = packet -> {}; + private static final Consumer EMPTY_CONSUMER = packet -> {}; @Nonnull protected final List packetHandlers = new ObjectArrayList<>(); - private Consumer[] handlers = newHandlerArray(0); + private Consumer[] handlers = newHandlerArray(0); @Nonnull - public static Consumer[] newHandlerArray(int size) { + public static Consumer[] newHandlerArray(int size) { return new Consumer[size]; } @@ -28,9 +28,9 @@ public abstract class GenericPacketHandler extends PacketHandler { this.packetHandlers.add(subPacketHandler); } - public void registerHandler(int packetId, @Nonnull Consumer handler) { + public void registerHandler(int packetId, @Nonnull Consumer handler) { if (packetId >= this.handlers.length) { - Consumer[] newHandlers = newHandlerArray(packetId + 1); + Consumer[] newHandlers = newHandlerArray(packetId + 1); System.arraycopy(this.handlers, 0, newHandlers, 0, this.handlers.length); this.handlers = newHandlers; } @@ -45,9 +45,9 @@ public abstract class GenericPacketHandler extends PacketHandler { } @Override - public final void accept(@Nonnull Packet packet) { + public final void accept(@Nonnull ToServerPacket packet) { int packetId = packet.getId(); - Consumer handler = this.handlers.length > packetId ? this.handlers[packetId] : null; + Consumer handler = this.handlers.length > packetId ? this.handlers[packetId] : null; if (handler != null) { try { handler.accept(packet); diff --git a/src/com/hypixel/hytale/server/core/io/handlers/IPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/IPacketHandler.java index c8a6c3d1..4ab840b8 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/IPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/IPacketHandler.java @@ -1,12 +1,12 @@ package com.hypixel.hytale.server.core.io.handlers; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.server.core.universe.PlayerRef; import java.util.function.Consumer; import javax.annotation.Nonnull; public interface IPacketHandler { - void registerHandler(int var1, @Nonnull Consumer var2); + void registerHandler(int var1, @Nonnull Consumer var2); void registerNoOpHandlers(int... var1); diff --git a/src/com/hypixel/hytale/server/core/io/handlers/IWorldPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/IWorldPacketHandler.java new file mode 100644 index 00000000..72b8841b --- /dev/null +++ b/src/com/hypixel/hytale/server/core/io/handlers/IWorldPacketHandler.java @@ -0,0 +1,39 @@ +package com.hypixel.hytale.server.core.io.handlers; + +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.util.function.Predicate; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public interface IWorldPacketHandler { + void handle(@Nonnull T var1, @Nonnull PlayerRef var2, @Nonnull Ref var3, @Nonnull World var4, @Nonnull Store var5); + + static void registerHandler(@Nonnull IPacketHandler packetHandler, int packetId, @Nonnull IWorldPacketHandler handler) { + registerHandler(packetHandler, packetId, handler, null); + } + + static void registerHandler( + @Nonnull IPacketHandler packetHandler, int packetId, @Nonnull IWorldPacketHandler handler, @Nullable Predicate precondition + ) { + packetHandler.registerHandler(packetId, packet -> { + PlayerRef playerRef = packetHandler.getPlayerRef(); + Ref ref = playerRef.getReference(); + if (ref != null && ref.isValid()) { + if (precondition == null || precondition.test(playerRef)) { + Store store = ref.getStore(); + World world = store.getExternalData().getWorld(); + world.execute(() -> { + if (ref.isValid()) { + handler.handle((T)packet, playerRef, ref, world, store); + } + }); + } + } + }); + } +} diff --git a/src/com/hypixel/hytale/server/core/io/handlers/InitialPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/InitialPacketHandler.java index 94b1c492..5df409a0 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/InitialPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/InitialPacketHandler.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.io.handlers; import com.hypixel.hytale.common.util.java.ManifestUtil; import com.hypixel.hytale.logger.HytaleLogger; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.auth.ConnectAccept; import com.hypixel.hytale.protocol.packets.connection.ClientType; @@ -40,18 +40,18 @@ public class InitialPacketHandler extends PacketHandler { @Nonnull @Override public String getIdentifier() { - return "{Initial(" + NettyUtil.formatRemoteAddress(this.channel) + ")}"; + return "{Initial(" + NettyUtil.formatRemoteAddress(this.getChannel()) + ")}"; } @Override public void registered0(PacketHandler oldHandler) { HytaleServerConfig.TimeoutProfile timeouts = HytaleServer.get().getConfig().getConnectionTimeouts(); this.initStage("initial", timeouts.getInitial(), () -> !this.registered); - PacketHandler.logConnectionTimings(this.channel, "Registered", Level.FINE); + PacketHandler.logConnectionTimings(this.getChannel(), "Registered", Level.FINE); } @Override - public void accept(@Nonnull Packet packet) { + public void accept(@Nonnull ToServerPacket packet) { if (packet.getId() == 0) { this.handle((Connect)packet); } else if (packet.getId() == 1) { @@ -66,18 +66,18 @@ public class InitialPacketHandler extends PacketHandler { if (this.receivedConnect) { super.disconnect(message); } else { - HytaleLogger.getLogger().at(Level.INFO).log("Silently disconnecting %s because no Connect packet!", NettyUtil.formatRemoteAddress(this.channel)); - ProtocolUtil.closeConnection(this.channel); + HytaleLogger.getLogger().at(Level.INFO).log("Silently disconnecting %s because no Connect packet!", NettyUtil.formatRemoteAddress(this.getChannel())); + ProtocolUtil.closeConnection(this.getChannel()); } } public void handle(@Nonnull Connect packet) { this.receivedConnect = true; this.clearTimeout(); - PacketHandler.logConnectionTimings(this.channel, "Connect", Level.FINE); - if (packet.protocolCrc != 672031543) { + PacketHandler.logConnectionTimings(this.getChannel(), "Connect", Level.FINE); + if (packet.protocolCrc != -1356075132) { int clientBuild = packet.protocolBuildNumber; - int serverBuild = 12; + int serverBuild = 20; int errorCode; if (clientBuild < serverBuild) { errorCode = 5; @@ -86,7 +86,7 @@ public class InitialPacketHandler extends PacketHandler { } String serverVersion = ManifestUtil.getImplementationVersion(); - ProtocolUtil.closeApplicationConnection(this.channel, errorCode, serverVersion != null ? serverVersion : "unknown"); + ProtocolUtil.closeApplicationConnection(this.getChannel(), errorCode, serverVersion != null ? serverVersion : "unknown"); } else if (HytaleServer.get().isShuttingDown()) { this.disconnect("Server is shutting down!"); } else if (!HytaleServer.get().isBooted()) { @@ -98,9 +98,11 @@ public class InitialPacketHandler extends PacketHandler { language = "en-US"; } - boolean isTcpConnection = !(this.channel instanceof QuicStreamChannel); + boolean isTcpConnection = !(this.getChannel() instanceof QuicStreamChannel); if (isTcpConnection) { - HytaleLogger.getLogger().at(Level.INFO).log("TCP connection from %s - only insecure auth supported", NettyUtil.formatRemoteAddress(this.channel)); + HytaleLogger.getLogger() + .at(Level.INFO) + .log("TCP connection from %s - only insecure auth supported", NettyUtil.formatRemoteAddress(this.getChannel())); } if (packet.uuid == null) { @@ -135,7 +137,7 @@ public class InitialPacketHandler extends PacketHandler { if (isTcpConnection) { HytaleLogger.getLogger() .at(Level.WARNING) - .log("Rejecting authenticated connection from %s - TCP only supports insecure auth", NettyUtil.formatRemoteAddress(this.channel)); + .log("Rejecting authenticated connection from %s - TCP only supports insecure auth", NettyUtil.formatRemoteAddress(this.getChannel())); this.disconnect("TCP connections only support insecure authentication. Use QUIC for authenticated connections."); return; } @@ -148,11 +150,11 @@ public class InitialPacketHandler extends PacketHandler { HytaleLogger.getLogger() .at(Level.INFO) - .log("Starting authenticated flow for %s (%s) from %s", packet.username, packet.uuid, NettyUtil.formatRemoteAddress(this.channel)); + .log("Starting authenticated flow for %s (%s) from %s", packet.username, packet.uuid, NettyUtil.formatRemoteAddress(this.getChannel())); NettyUtil.setChannelHandler( - this.channel, + this.getChannel(), new AuthenticationPacketHandler( - this.channel, + this.getChannel(), protocolVersion, language, supplier, @@ -170,7 +172,7 @@ public class InitialPacketHandler extends PacketHandler { .at(Level.WARNING) .log( "Rejecting development connection from %s - server requires authentication (auth-mode=%s)", - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), authMode ); this.disconnect("This server requires authentication!"); @@ -181,7 +183,7 @@ public class InitialPacketHandler extends PacketHandler { if (!Constants.SINGLEPLAYER) { HytaleLogger.getLogger() .at(Level.WARNING) - .log("Rejecting connection from %s - offline mode is only valid in singleplayer", NettyUtil.formatRemoteAddress(this.channel)); + .log("Rejecting connection from %s - offline mode is only valid in singleplayer", NettyUtil.formatRemoteAddress(this.getChannel())); this.disconnect("Offline mode is only available in singleplayer."); return; } @@ -202,16 +204,16 @@ public class InitialPacketHandler extends PacketHandler { HytaleLogger.getLogger() .at(Level.INFO) - .log("Starting development flow for %s (%s) from %s", packet.username, packet.uuid, NettyUtil.formatRemoteAddress(this.channel)); + .log("Starting development flow for %s (%s) from %s", packet.username, packet.uuid, NettyUtil.formatRemoteAddress(this.getChannel())); byte[] passwordChallenge = this.generatePasswordChallengeIfNeeded(packet.uuid); this.write(new ConnectAccept(passwordChallenge)); PasswordPacketHandler.SetupHandlerSupplier setupSupplier = isEditorClient && EDITOR_PACKET_HANDLER_SUPPLIER != null ? (ch, pv, lang, auth) -> EDITOR_PACKET_HANDLER_SUPPLIER.create(ch, pv, lang, auth) : SetupPacketHandler::new; NettyUtil.setChannelHandler( - this.channel, + this.getChannel(), new PasswordPacketHandler( - this.channel, + this.getChannel(), protocolVersion, language, packet.uuid, @@ -250,7 +252,7 @@ public class InitialPacketHandler extends PacketHandler { public void handle(@Nonnull Disconnect packet) { this.disconnectReason.setClientDisconnectType(packet.type); - HytaleLogger.getLogger().at(Level.WARNING).log("Disconnecting %s - Sent disconnect packet???", NettyUtil.formatRemoteAddress(this.channel)); - ProtocolUtil.closeApplicationConnection(this.channel); + HytaleLogger.getLogger().at(Level.WARNING).log("Disconnecting %s - Sent disconnect packet???", NettyUtil.formatRemoteAddress(this.getChannel())); + ProtocolUtil.closeApplicationConnection(this.getChannel()); } } diff --git a/src/com/hypixel/hytale/server/core/io/handlers/SetupPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/SetupPacketHandler.java index 10c4d4fc..1d67535f 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/SetupPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/SetupPacketHandler.java @@ -7,7 +7,7 @@ import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.protocol.Asset; import com.hypixel.hytale.protocol.HostAddress; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.auth.ClientReferral; import com.hypixel.hytale.protocol.packets.connection.Disconnect; @@ -91,7 +91,7 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { @Override public String getIdentifier() { return "{Setup(" - + NettyUtil.formatRemoteAddress(this.channel) + + NettyUtil.formatRemoteAddress(this.getChannel()) + "), " + this.username + ", " @@ -132,7 +132,7 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { if (otherPlayer != null) { HytaleLogger.getLogger().at(Level.INFO).log("Found match of player %s on %s", this.uuid, otherPlayer.getUsername()); Channel otherPlayerChannel = otherPlayer.getPacketHandler().getChannel(); - if (!NettyUtil.isFromSameOrigin(otherPlayerChannel, this.channel)) { + if (!NettyUtil.isFromSameOrigin(otherPlayerChannel, this.getChannel())) { this.disconnect("You are already logged in on that account!"); otherPlayer.sendMessage(Message.translation("server.io.setuppackethandler.otherLoginAttempt")); return; @@ -154,7 +154,7 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { } } - PacketHandler.logConnectionTimings(this.channel, "Load Player Config", Level.FINE); + PacketHandler.logConnectionTimings(this.getChannel(), "Load Player Config", Level.FINE); WorldSettings worldSettings = new WorldSettings(); worldSettings.worldHeight = 320; Asset[] requiredAssets = CommonAssetModule.get().getRequiredAssets(); @@ -169,7 +169,7 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { } @Override - public void accept(@Nonnull Packet packet) { + public void accept(@Nonnull ToServerPacket packet) { switch (packet.getId()) { case 1: this.handle((Disconnect)packet); @@ -215,9 +215,14 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { HytaleLogger.getLogger() .at(Level.INFO) .log( - "%s - %s at %s left with reason: %s - %s", this.uuid, this.username, NettyUtil.formatRemoteAddress(this.channel), packet.type.name(), packet.reason + "%s - %s at %s left with reason: %s - %s", + this.uuid, + this.username, + NettyUtil.formatRemoteAddress(this.getChannel()), + packet.type.name(), + packet.reason ); - ProtocolUtil.closeApplicationConnection(this.channel); + ProtocolUtil.closeApplicationConnection(this.getChannel()); if (packet.type == DisconnectType.Crash && Constants.SINGLEPLAYER && (Universe.get().getPlayerCount() == 0 || SingleplayerModule.isOwner(this.auth, this.uuid))) { @@ -230,25 +235,25 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { throw new IllegalArgumentException("Received duplicate RequestAssets!"); } else { this.receivedRequest = true; - PacketHandler.logConnectionTimings(this.channel, "Request Assets", Level.FINE); + PacketHandler.logConnectionTimings(this.getChannel(), "Request Assets", Level.FINE); CompletableFuture future = CompletableFutureUtil._catch( HytaleServer.get() .getEventBus() .dispatchForAsync(SendCommonAssetsEvent.class) .dispatch(new SendCommonAssetsEvent(this, packet.assets)) .thenAccept(event -> { - if (this.channel.isActive()) { - PacketHandler.logConnectionTimings(this.channel, "Send Common Assets", Level.FINE); + if (this.getChannel().isActive()) { + PacketHandler.logConnectionTimings(this.getChannel(), "Send Common Assets", Level.FINE); this.assets.sent(event.getRequestedAssets()); AssetRegistryLoader.sendAssets(this); I18nModule.get().sendTranslations(this, this.language); - PacketHandler.logConnectionTimings(this.channel, "Send Config Assets", Level.FINE); + PacketHandler.logConnectionTimings(this.getChannel(), "Send Config Assets", Level.FINE); this.write(new WorldLoadProgress(Message.translation("client.general.worldLoad.loadingWorld").getFormattedMessage(), 0, 0)); this.write(new WorldLoadFinished()); } }) .exceptionally(throwable -> { - if (!this.channel.isActive()) { + if (!this.getChannel().isActive()) { return null; } else { this.disconnect("An exception occurred while trying to login!"); @@ -269,8 +274,8 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { if (!this.receivedRequest) { throw new IllegalArgumentException("Hasn't received RequestAssets yet!"); } else { - PacketHandler.logConnectionTimings(this.channel, "Player Options", Level.FINE); - if (this.channel.isActive()) { + PacketHandler.logConnectionTimings(this.getChannel(), "Player Options", Level.FINE); + if (this.getChannel().isActive()) { if (packet.skin != null) { try { CosmeticsModule.get().validateSkin(packet.skin); @@ -284,15 +289,17 @@ public class SetupPacketHandler extends GenericConnectionPacketHandler { CompletableFuture future = CompletableFutureUtil._catch( Universe.get() - .addPlayer(this.channel, this.language, this.protocolVersion, this.uuid, this.username, this.auth, this.clientViewRadiusChunks, packet.skin) + .addPlayer( + this.getChannel(), this.language, this.protocolVersion, this.uuid, this.username, this.auth, this.clientViewRadiusChunks, packet.skin + ) .thenAccept(player -> { - if (this.channel.isActive()) { - PacketHandler.logConnectionTimings(this.channel, "Add To Universe", Level.FINE); + if (this.getChannel().isActive()) { + PacketHandler.logConnectionTimings(this.getChannel(), "Add To Universe", Level.FINE); this.clearTimeout(); } }) .exceptionally(throwable -> { - if (!this.channel.isActive()) { + if (!this.getChannel().isActive()) { return null; } else { this.disconnect("An exception occurred when adding to the universe!"); diff --git a/src/com/hypixel/hytale/server/core/io/handlers/game/GamePacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/game/GamePacketHandler.java index a4823354..6656d802 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/game/GamePacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/game/GamePacketHandler.java @@ -13,7 +13,7 @@ import com.hypixel.hytale.math.vector.Vector3i; import com.hypixel.hytale.protocol.BlockRotation; import com.hypixel.hytale.protocol.GameMode; import com.hypixel.hytale.protocol.HostAddress; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.camera.RequestFlyCameraMode; import com.hypixel.hytale.protocol.packets.camera.SetFlyCameraMode; @@ -74,6 +74,7 @@ import com.hypixel.hytale.server.core.io.ProtocolVersion; import com.hypixel.hytale.server.core.io.ServerManager; import com.hypixel.hytale.server.core.io.handlers.GenericPacketHandler; import com.hypixel.hytale.server.core.io.handlers.IPacketHandler; +import com.hypixel.hytale.server.core.io.handlers.IWorldPacketHandler; import com.hypixel.hytale.server.core.io.handlers.SubPacketHandler; import com.hypixel.hytale.server.core.io.netty.NettyUtil; import com.hypixel.hytale.server.core.modules.entity.EntityModule; @@ -152,7 +153,7 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa @Override public String getIdentifier() { return "{Playing(" - + NettyUtil.formatRemoteAddress(this.channel) + + NettyUtil.formatRemoteAddress(this.getChannel()) + "), " + (this.playerRef != null ? this.playerRef.getUuid() + ", " + this.playerRef.getUsername() : "null player") + "}"; @@ -171,50 +172,38 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa this.registerHandler(211, p -> this.handle((ChatMessage)p)); this.registerHandler(23, p -> this.handle((RequestAssets)p)); this.registerHandler(219, p -> this.handle((CustomPageEvent)p)); - this.registerWorldHandler(32, this::handleViewRadius); - this.registerWorldHandler(232, this::handleUpdateLanguage); - this.registerWorldHandler(111, this::handleMouseInteraction); + IWorldPacketHandler.registerHandler(this, 32, this::handleViewRadius); + IWorldPacketHandler.registerHandler(this, 232, this::handleUpdateLanguage); + IWorldPacketHandler.registerHandler(this, 111, this::handleMouseInteraction); this.registerHandler(251, p -> this.handle((UpdateServerAccess)p)); this.registerHandler(252, p -> this.handle((SetServerAccess)p)); - this.registerWorldHandler(204, this::handleClientOpenWindow); - this.registerWorldHandler(203, this::handleSendWindowAction); - this.registerWorldHandler(202, this::handleCloseWindow); + IWorldPacketHandler.registerHandler(this, 204, this::handleClientOpenWindow); + IWorldPacketHandler.registerHandler(this, 203, this::handleSendWindowAction); + IWorldPacketHandler.registerHandler(this, 202, this::handleCloseWindow); this.registerHandler(260, p -> this.handle((RequestMachinimaActorModel)p)); - this.registerWorldHandler(262, this::handleUpdateMachinimaScene); + IWorldPacketHandler.registerHandler(this, 262, this::handleUpdateMachinimaScene); this.registerHandler(105, p -> this.handle((ClientReady)p)); - this.registerWorldHandler(166, this::handleMountMovement); - this.registerWorldHandler(116, this::handleSyncPlayerPreferences); - this.registerWorldHandler(117, this::handleClientPlaceBlock); - this.registerWorldHandler(119, this::handleRemoveMapMarker); - this.registerWorldHandler(243, this::handleUpdateWorldMapVisible); - this.registerWorldHandler(244, this::handleTeleportToWorldMapMarker); - this.registerWorldHandler(245, this::handleTeleportToWorldMapPosition); - this.registerWorldHandler(246, this::handleCreateUserMarker); + IWorldPacketHandler.registerHandler(this, 166, this::handleMountMovement); + IWorldPacketHandler.registerHandler(this, 116, this::handleSyncPlayerPreferences); + IWorldPacketHandler.registerHandler(this, 117, this::handleClientPlaceBlock); + IWorldPacketHandler.registerHandler(this, 119, this::handleRemoveMapMarker); + IWorldPacketHandler.registerHandler(this, 243, this::handleUpdateWorldMapVisible); + IWorldPacketHandler.registerHandler(this, 244, this::handleTeleportToWorldMapMarker); + IWorldPacketHandler.registerHandler(this, 245, this::handleTeleportToWorldMapPosition); + IWorldPacketHandler.registerHandler(this, 246, this::handleCreateUserMarker); this.registerHandler(290, p -> this.handle((SyncInteractionChains)p)); - this.registerWorldHandler(158, this::handleSetPaused); - this.registerWorldHandler(282, this::handleRequestFlyCameraMode); + IWorldPacketHandler.registerHandler(this, 158, this::handleSetPaused); + IWorldPacketHandler.registerHandler(this, 282, this::handleRequestFlyCameraMode); this.packetHandlers.forEach(SubPacketHandler::registerHandlers); } - private void registerWorldHandler(int packetId, @Nonnull GamePacketHandler.WorldPacketHandler handler) { - this.registerHandler(packetId, packet -> { - Ref ref = this.playerRef.getReference(); - if (ref != null) { - Store store = ref.getStore(); - World world = store.getExternalData().getWorld(); - world.execute(() -> { - if (ref.isValid()) { - handler.consumer((T)packet, ref, world, store); - } - }); - } - }); - } - @Override public void closed(ChannelHandlerContext ctx) { super.closed(ctx); - Universe.get().removePlayer(this.playerRef); + NetworkChannel streamChannel = ctx.channel().attr(ProtocolUtil.STREAM_CHANNEL_KEY).get(); + if (streamChannel == null || streamChannel == NetworkChannel.Default) { + Universe.get().removePlayer(this.playerRef); + } } @Override @@ -226,7 +215,7 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa .log( "Disconnecting %s at %s (SNI: %s) with the message: %s", this.playerRef.getUsername(), - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), this.getSniHostname(), message ); @@ -245,19 +234,21 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa "%s - %s at %s left with reason: %s - %s", this.playerRef.getUuid(), this.playerRef.getUsername(), - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), packet.type.name(), packet.reason ); - ProtocolUtil.closeApplicationConnection(this.channel); + ProtocolUtil.closeApplicationConnection(this.getChannel()); } - public void handleMouseInteraction(@Nonnull MouseInteraction packet, Ref ref, World world, Store store) { + public void handleMouseInteraction( + @Nonnull MouseInteraction packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; - InteractionModule.get().doMouseInteraction(ref, store, packet, playerComponent, this.playerRef); + InteractionModule.get().doMouseInteraction(ref, store, packet, playerComponent, playerRef); } public void handle(@Nonnull ClientMovement packet) { @@ -415,19 +406,23 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa Store store = ref.getStore(); World world = store.getExternalData().getWorld(); world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (ref.isValid()) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); - assert playerComponent != null; + assert playerComponent != null; - PageManager pageManager = playerComponent.getPageManager(); - pageManager.handleEvent(ref, store, packet); + PageManager pageManager = playerComponent.getPageManager(); + pageManager.handleEvent(ref, store, packet); + } }); } else { this.playerRef.getPacketHandler().writeNoCache(new SetPage(Page.None, true)); } } - public void handleViewRadius(@Nonnull ViewRadius packet, Ref ref, World world, Store store) { + public void handleViewRadius( + @Nonnull ViewRadius packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -441,12 +436,16 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa entityViewerComponent.viewRadiusBlocks = playerComponent.getViewRadius() * 32; } - public void handleUpdateLanguage(@Nonnull UpdateLanguage packet, Ref ref, World world, Store store) { - this.playerRef.setLanguage(packet.language); + public void handleUpdateLanguage( + @Nonnull UpdateLanguage packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { + playerRef.setLanguage(packet.language); I18nModule.get().sendTranslations(this, packet.language); } - protected void handleClientOpenWindow(@Nonnull ClientOpenWindow packet, Ref ref, World world, Store store) { + protected void handleClientOpenWindow( + @Nonnull ClientOpenWindow packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Supplier supplier = Window.CLIENT_REQUESTABLE_WINDOW_TYPES.get(packet.type); if (supplier == null) { throw new RuntimeException("Unable to process ClientOpenWindow packet. Window type is not supported!"); @@ -462,7 +461,9 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa } } - public void handleSendWindowAction(@Nonnull SendWindowAction packet, Ref ref, World world, Store store) { + public void handleSendWindowAction( + @Nonnull SendWindowAction packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -477,7 +478,13 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa } } - public void handleSyncPlayerPreferences(@Nonnull SyncPlayerPreferences packet, Ref ref, World world, Store store) { + public void handleSyncPlayerPreferences( + @Nonnull SyncPlayerPreferences packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { ComponentType componentType = EntityModule.get().getPlayerSettingsComponentType(); store.putComponent( ref, @@ -499,7 +506,9 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa store.getComponent(ref, Player.getComponentType()).invalidateEquipmentNetwork(); } - public void handleClientPlaceBlock(@Nonnull ClientPlaceBlock packet, Ref ref, World world, Store store) { + public void handleClientPlaceBlock( + @Nonnull ClientPlaceBlock packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -563,11 +572,15 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa } } - public void handleRemoveMapMarker(@Nonnull RemoveMapMarker packet, Ref ref, World world, Store store) { - world.getWorldMapManager().handleUserRemoveMarker(this.playerRef, packet); + public void handleRemoveMapMarker( + @Nonnull RemoveMapMarker packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { + world.getWorldMapManager().handleUserRemoveMarker(playerRef, packet); } - public void handleCloseWindow(@Nonnull CloseWindow packet, Ref ref, World world, Store store) { + public void handleCloseWindow( + @Nonnull CloseWindow packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -614,7 +627,13 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa this.writeNoCache(new SetMachinimaActorModel(Model.createUnitScaleModel(modelAsset).toPacket(), packet.sceneName, packet.actorName)); } - public void handleUpdateMachinimaScene(@Nonnull UpdateMachinimaScene packet, Ref ref, World world, Store store) { + public void handleUpdateMachinimaScene( + @Nonnull UpdateMachinimaScene packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { } public void handle(@Nonnull ClientReady packet) { @@ -635,16 +654,24 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa Store store = ref.getStore(); World world = store.getExternalData().getWorld(); world.execute(() -> { - Player playerComponent = store.getComponent(ref, Player.getComponentType()); + if (ref.isValid()) { + Player playerComponent = store.getComponent(ref, Player.getComponentType()); - assert playerComponent != null; + assert playerComponent != null; - playerComponent.handleClientReady(false); + playerComponent.handleClientReady(false); + } }); } } - public void handleUpdateWorldMapVisible(@Nonnull UpdateWorldMapVisible packet, Ref ref, World world, Store store) { + public void handleUpdateWorldMapVisible( + @Nonnull UpdateWorldMapVisible packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -652,7 +679,13 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa playerComponent.getWorldMapTracker().setClientHasWorldMapVisible(packet.visible); } - public void handleTeleportToWorldMapMarker(@Nonnull TeleportToWorldMapMarker packet, Ref ref, World world, Store store) { + public void handleTeleportToWorldMapMarker( + @Nonnull TeleportToWorldMapMarker packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -673,12 +706,18 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa } Teleport teleportComponent = Teleport.createForPlayer(transform); - world.getEntityStore().getStore().addComponent(this.playerRef.getReference(), Teleport.getComponentType(), teleportComponent); + world.getEntityStore().getStore().addComponent(playerRef.getReference(), Teleport.getComponentType(), teleportComponent); } } } - public void handleTeleportToWorldMapPosition(@Nonnull TeleportToWorldMapPosition packet, Ref ref, World world, Store store) { + public void handleTeleportToWorldMapPosition( + @Nonnull TeleportToWorldMapPosition packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -694,21 +733,25 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa Vector3d position = new Vector3d(packet.x, blockChunkComponent.getHeight(packet.x, packet.y) + 2, packet.y); Teleport teleportComponent = Teleport.createForPlayer(null, position, new Vector3f(0.0F, 0.0F, 0.0F)); - world.getEntityStore().getStore().addComponent(this.playerRef.getReference(), Teleport.getComponentType(), teleportComponent); + world.getEntityStore().getStore().addComponent(playerRef.getReference(), Teleport.getComponentType(), teleportComponent); }, world); } } - public void handleCreateUserMarker(@Nonnull CreateUserMarker packet, Ref ref, World world, Store store) { + public void handleCreateUserMarker( + @Nonnull CreateUserMarker packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { WorldMapManager worldMapManager = world.getWorldMapManager(); - worldMapManager.handleUserCreateMarker(this.playerRef, packet); + worldMapManager.handleUserCreateMarker(playerRef, packet); } public void handle(@Nonnull SyncInteractionChains packet) { Collections.addAll(this.interactionPacketQueue, packet.updates); } - public void handleMountMovement(@Nonnull MountMovement packet, Ref ref, World world, Store store) { + public void handleMountMovement( + @Nonnull MountMovement packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -729,13 +772,21 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa } } - public void handleSetPaused(@Nonnull SetPaused packet, Ref ref, World world, Store store) { + public void handleSetPaused( + @Nonnull SetPaused packet, @Nonnull PlayerRef playerRef, @Nonnull Ref ref, @Nonnull World world, @Nonnull Store store + ) { if (world.getPlayerCount() == 1 && Constants.SINGLEPLAYER) { world.setPaused(packet.paused); } } - public void handleRequestFlyCameraMode(@Nonnull RequestFlyCameraMode packet, Ref ref, World world, Store store) { + public void handleRequestFlyCameraMode( + @Nonnull RequestFlyCameraMode packet, + @Nonnull PlayerRef playerRef, + @Nonnull Ref ref, + @Nonnull World world, + @Nonnull Store store + ) { Player playerComponent = store.getComponent(ref, Player.getComponentType()); assert playerComponent != null; @@ -743,16 +794,12 @@ public class GamePacketHandler extends GenericPacketHandler implements IPacketHa if (playerComponent.hasPermission("hytale.camera.flycam")) { this.writeNoCache(new SetFlyCameraMode(packet.entering)); if (packet.entering) { - this.playerRef.sendMessage(Message.translation("server.general.flyCamera.enabled")); + playerRef.sendMessage(Message.translation("server.general.flyCamera.enabled")); } else { - this.playerRef.sendMessage(Message.translation("server.general.flyCamera.disabled")); + playerRef.sendMessage(Message.translation("server.general.flyCamera.disabled")); } } else { - this.playerRef.sendMessage(Message.translation("server.general.flyCamera.noPermission")); + playerRef.sendMessage(Message.translation("server.general.flyCamera.noPermission")); } } - - private interface WorldPacketHandler { - void consumer(T var1, Ref var2, World var3, Store var4); - } } diff --git a/src/com/hypixel/hytale/server/core/io/handlers/login/AuthenticationPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/login/AuthenticationPacketHandler.java index aa08c7a5..56a9bcf2 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/login/AuthenticationPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/login/AuthenticationPacketHandler.java @@ -36,7 +36,7 @@ public class AuthenticationPacketHandler extends HandshakeHandler { @Nonnull @Override public String getIdentifier() { - return "{Authenticating(" + NettyUtil.formatRemoteAddress(this.channel) + "), authHandlerSupplier=" + this.authHandlerSupplier + "}"; + return "{Authenticating(" + NettyUtil.formatRemoteAddress(this.getChannel()) + "), authHandlerSupplier=" + this.authHandlerSupplier + "}"; } @Override @@ -51,11 +51,11 @@ public class AuthenticationPacketHandler extends HandshakeHandler { @Override protected void onAuthenticated(byte[] passwordChallenge) { - PacketHandler.logConnectionTimings(this.channel, "Authenticated", Level.FINE); + PacketHandler.logConnectionTimings(this.getChannel(), "Authenticated", Level.FINE); NettyUtil.setChannelHandler( - this.channel, + this.getChannel(), new PasswordPacketHandler( - this.channel, + this.getChannel(), this.protocolVersion, this.language, this.auth.getUuid(), diff --git a/src/com/hypixel/hytale/server/core/io/handlers/login/HandshakeHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/login/HandshakeHandler.java index aaa1368a..c9e366fb 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/login/HandshakeHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/login/HandshakeHandler.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.io.handlers.login; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.protocol.HostAddress; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.auth.AuthGrant; import com.hypixel.hytale.protocol.packets.auth.AuthToken; @@ -90,7 +90,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { } @Override - public void accept(@Nonnull Packet packet) { + public void accept(@Nonnull ToServerPacket packet) { switch (packet.getId()) { case 1: this.handle((Disconnect)packet); @@ -109,7 +109,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { this.enterStage("auth", timeouts.getAuth()); JWTValidator.IdentityTokenClaims identityClaims = getJwtValidator().validateIdentityToken(this.identityToken); if (identityClaims == null) { - LOGGER.at(Level.WARNING).log("Identity token validation failed for %s from %s", this.username, NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Identity token validation failed for %s from %s", this.username, NettyUtil.formatRemoteAddress(this.getChannel())); this.disconnect("Invalid or expired identity token"); } else { UUID tokenUuid = identityClaims.getSubjectAsUUID(); @@ -120,7 +120,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { .log( "Identity token missing required scope for %s from %s (clientType: %s, required: %s, actual: %s)", this.username, - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), this.clientType, requiredScope, identityClaims.scope @@ -133,7 +133,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { this.username, this.playerUuid, identityClaims.scope, - NettyUtil.formatRemoteAddress(this.channel) + NettyUtil.formatRemoteAddress(this.getChannel()) ); this.continueStage("auth:grant", timeouts.getAuthGrant(), () -> this.authState != HandshakeHandler.AuthState.REQUESTING_AUTH_GRANT); this.requestAuthGrant(); @@ -143,7 +143,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { .log( "Identity token UUID mismatch for %s from %s (expected: %s, got: %s)", this.username, - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), this.playerUuid, tokenUuid ); @@ -155,21 +155,21 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { private void requestAuthGrant() { String serverSessionToken = ServerAuthManager.getInstance().getSessionToken(); if (serverSessionToken != null && !serverSessionToken.isEmpty()) { + Channel channel = this.getChannel(); getSessionServiceClient() .requestAuthorizationGrantAsync(this.identityToken, AuthConfig.getServerAudience(), serverSessionToken) .thenAccept( authGrant -> { - if (this.channel.isActive()) { + if (channel.isActive()) { if (authGrant == null) { - this.channel.eventLoop().execute(() -> this.disconnect("Failed to obtain authorization grant from session service")); + channel.eventLoop().execute(() -> this.disconnect("Failed to obtain authorization grant from session service")); } else { String serverIdentityToken = ServerAuthManager.getInstance().getIdentityToken(); if (serverIdentityToken != null && !serverIdentityToken.isEmpty()) { - this.channel - .eventLoop() + channel.eventLoop() .execute( () -> { - if (this.channel.isActive()) { + if (channel.isActive()) { if (this.authState != HandshakeHandler.AuthState.REQUESTING_AUTH_GRANT) { LOGGER.at(Level.WARNING).log("State changed during auth grant request, current state: %s", this.authState); } else { @@ -177,7 +177,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { LOGGER.at(Level.INFO) .log( "Sending AuthGrant to %s (with server identity: %s)", - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(channel), !serverIdentityToken.isEmpty() ); this.write(new AuthGrant(authGrant, serverIdentityToken)); @@ -192,7 +192,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { ); } else { LOGGER.at(Level.SEVERE).log("Server identity token not available - cannot complete mutual authentication"); - this.channel.eventLoop().execute(() -> this.disconnect("Server authentication unavailable - please try again later")); + channel.eventLoop().execute(() -> this.disconnect("Server authentication unavailable - please try again later")); } } } @@ -200,7 +200,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { ) .exceptionally(ex -> { LOGGER.at(Level.WARNING).withCause(ex).log("Error requesting auth grant"); - this.channel.eventLoop().execute(() -> this.disconnect("Authentication error: " + ex.getMessage())); + channel.eventLoop().execute(() -> this.disconnect("Authentication error: " + ex.getMessage())); return null; }); } else { @@ -216,19 +216,20 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { "%s (%s) at %s left with reason: %s - %s", this.playerUuid, this.username, - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), packet.type.name(), packet.reason ); - ProtocolUtil.closeApplicationConnection(this.channel); + ProtocolUtil.closeApplicationConnection(this.getChannel()); } public void handle(@Nonnull AuthToken packet) { + Channel channel = this.getChannel(); if (this.authState != HandshakeHandler.AuthState.AWAITING_AUTH_TOKEN) { - LOGGER.at(Level.WARNING).log("Received unexpected AuthToken packet in state %s from %s", this.authState, NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Received unexpected AuthToken packet in state %s from %s", this.authState, NettyUtil.formatRemoteAddress(channel)); this.disconnect("Protocol error: unexpected AuthToken packet"); } else if (this.authTokenPacketReceived) { - LOGGER.at(Level.WARNING).log("Received duplicate AuthToken packet from %s", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Received duplicate AuthToken packet from %s", NettyUtil.formatRemoteAddress(channel)); this.disconnect("Protocol error: duplicate AuthToken packet"); } else { this.authTokenPacketReceived = true; @@ -237,31 +238,31 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { String accessToken = packet.accessToken; if (accessToken != null && !accessToken.isEmpty()) { String serverAuthGrant = packet.serverAuthorizationGrant; - X509Certificate clientCert = this.channel.attr(QUICTransport.CLIENT_CERTIFICATE_ATTR).get(); + X509Certificate clientCert = channel.attr(QUICTransport.CLIENT_CERTIFICATE_ATTR).get(); LOGGER.at(Level.INFO) .log( "Received AuthToken from %s, validating JWT (mTLS cert present: %s, server auth grant: %s)", - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(channel), clientCert != null, serverAuthGrant != null && !serverAuthGrant.isEmpty() ); JWTValidator.JWTClaims claims = getJwtValidator().validateToken(accessToken, clientCert); if (claims == null) { - LOGGER.at(Level.WARNING).log("JWT validation failed for %s", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("JWT validation failed for %s", NettyUtil.formatRemoteAddress(channel)); this.disconnect("Invalid access token"); } else { UUID tokenUuid = claims.getSubjectAsUUID(); String tokenUsername = claims.username; if (tokenUuid == null || !tokenUuid.equals(this.playerUuid)) { LOGGER.at(Level.WARNING) - .log("JWT UUID mismatch for %s (expected: %s, got: %s)", NettyUtil.formatRemoteAddress(this.channel), this.playerUuid, tokenUuid); + .log("JWT UUID mismatch for %s (expected: %s, got: %s)", NettyUtil.formatRemoteAddress(channel), this.playerUuid, tokenUuid); this.disconnect("Invalid token claims: UUID mismatch"); } else if (tokenUsername == null || tokenUsername.isEmpty()) { - LOGGER.at(Level.WARNING).log("JWT missing username for %s", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("JWT missing username for %s", NettyUtil.formatRemoteAddress(channel)); this.disconnect("Invalid token claims: missing username"); } else if (!tokenUsername.equals(this.username)) { LOGGER.at(Level.WARNING) - .log("JWT username mismatch for %s (expected: %s, got: %s)", NettyUtil.formatRemoteAddress(this.channel), this.username, tokenUsername); + .log("JWT username mismatch for %s (expected: %s, got: %s)", NettyUtil.formatRemoteAddress(channel), this.username, tokenUsername); this.disconnect("Invalid token claims: username mismatch"); } else { this.authenticatedUsername = tokenUsername; @@ -279,7 +280,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { } } } else { - LOGGER.at(Level.WARNING).log("Received AuthToken packet with empty access token from %s", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Received AuthToken packet with empty access token from %s", NettyUtil.formatRemoteAddress(channel)); this.disconnect("Invalid access token"); } } @@ -308,16 +309,16 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { } else { LOGGER.at(Level.FINE) .log("Using session token (first 20 chars): %s...", serverSessionToken.length() > 20 ? serverSessionToken.substring(0, 20) : serverSessionToken); + Channel channel = this.getChannel(); getSessionServiceClient() .exchangeAuthGrantForTokenAsync(serverAuthGrant, serverCertFingerprint, serverSessionToken) .thenAccept( serverAccessToken -> { - if (this.channel.isActive()) { - this.channel - .eventLoop() + if (channel.isActive()) { + channel.eventLoop() .execute( () -> { - if (this.channel.isActive()) { + if (channel.isActive()) { if (this.authState != HandshakeHandler.AuthState.EXCHANGING_SERVER_TOKEN) { LOGGER.at(Level.WARNING).log("State changed during server token exchange, current state: %s", this.authState); } else if (serverAccessToken == null) { @@ -328,7 +329,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { LOGGER.at(Level.INFO) .log( "Sending ServerAuthToken to %s (with password challenge: %s)", - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(channel), passwordChallenge != null ); this.write(new ServerAuthToken(serverAccessToken, passwordChallenge)); @@ -342,7 +343,7 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { ) .exceptionally(ex -> { LOGGER.at(Level.WARNING).withCause(ex).log("Error exchanging server auth grant"); - this.channel.eventLoop().execute(() -> { + channel.eventLoop().execute(() -> { if (this.authState == HandshakeHandler.AuthState.EXCHANGING_SERVER_TOKEN) { this.disconnect("Server authentication failed - please try again later"); } @@ -384,7 +385,9 @@ public abstract class HandshakeHandler extends GenericConnectionPacketHandler { this.authState = HandshakeHandler.AuthState.AUTHENTICATED; this.clearTimeout(); LOGGER.at(Level.INFO) - .log("Mutual authentication complete for %s (%s) from %s", this.authenticatedUsername, this.playerUuid, NettyUtil.formatRemoteAddress(this.channel)); + .log( + "Mutual authentication complete for %s (%s) from %s", this.authenticatedUsername, this.playerUuid, NettyUtil.formatRemoteAddress(this.getChannel()) + ); this.onAuthenticated(passwordChallenge); } diff --git a/src/com/hypixel/hytale/server/core/io/handlers/login/PasswordPacketHandler.java b/src/com/hypixel/hytale/server/core/io/handlers/login/PasswordPacketHandler.java index bcde9561..f89a71b0 100644 --- a/src/com/hypixel/hytale/server/core/io/handlers/login/PasswordPacketHandler.java +++ b/src/com/hypixel/hytale/server/core/io/handlers/login/PasswordPacketHandler.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.io.handlers.login; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.protocol.HostAddress; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.auth.PasswordAccepted; import com.hypixel.hytale.protocol.packets.auth.PasswordRejected; @@ -60,7 +60,7 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { @Nonnull @Override public String getIdentifier() { - return "{Password(" + NettyUtil.formatRemoteAddress(this.channel) + "), " + this.username + "}"; + return "{Password(" + NettyUtil.formatRemoteAddress(this.getChannel()) + "), " + this.username + "}"; } @Override @@ -76,7 +76,7 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { } @Override - public void accept(@Nonnull Packet packet) { + public void accept(@Nonnull ToServerPacket packet) { switch (packet.getId()) { case 1: this.handle((Disconnect)packet); @@ -96,11 +96,11 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { "%s (%s) at %s left with reason: %s - %s", this.playerUuid, this.username, - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), packet.type.name(), packet.reason ); - ProtocolUtil.closeApplicationConnection(this.channel); + ProtocolUtil.closeApplicationConnection(this.getChannel()); } public void handle(@Nonnull PasswordResponse packet) { @@ -120,7 +120,7 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { .log( "Invalid password from %s (%s), %d attempts remaining", this.username, - NettyUtil.formatRemoteAddress(this.channel), + NettyUtil.formatRemoteAddress(this.getChannel()), this.attemptsRemaining ); if (this.attemptsRemaining <= 0) { @@ -141,11 +141,11 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { this.disconnect("Server configuration error"); } } else { - LOGGER.at(Level.WARNING).log("Received empty password hash from %s", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Received empty password hash from %s", NettyUtil.formatRemoteAddress(this.getChannel())); this.disconnect("Invalid password response"); } } else { - LOGGER.at(Level.WARNING).log("Received unexpected PasswordResponse from %s - no password required", NettyUtil.formatRemoteAddress(this.channel)); + LOGGER.at(Level.WARNING).log("Received unexpected PasswordResponse from %s - no password required", NettyUtil.formatRemoteAddress(this.getChannel())); this.disconnect("Protocol error: unexpected PasswordResponse"); } } @@ -167,7 +167,7 @@ public class PasswordPacketHandler extends GenericConnectionPacketHandler { } LOGGER.at(Level.INFO).log("Connection complete for %s (%s) (SNI: %s), transitioning to setup", this.username, this.playerUuid, this.getSniHostname()); - NettyUtil.setChannelHandler(this.channel, this.setupHandlerSupplier.create(this.channel, this.protocolVersion, this.language, this.auth)); + NettyUtil.setChannelHandler(this.getChannel(), this.setupHandlerSupplier.create(this.getChannel(), this.protocolVersion, this.language, this.auth)); } @Nullable diff --git a/src/com/hypixel/hytale/server/core/io/netty/HytaleChannelInitializer.java b/src/com/hypixel/hytale/server/core/io/netty/HytaleChannelInitializer.java index e07cd72e..03f4e20c 100644 --- a/src/com/hypixel/hytale/server/core/io/netty/HytaleChannelInitializer.java +++ b/src/com/hypixel/hytale/server/core/io/netty/HytaleChannelInitializer.java @@ -9,7 +9,7 @@ import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.connection.Disconnect; import com.hypixel.hytale.protocol.packets.connection.DisconnectType; import com.hypixel.hytale.server.core.HytaleServer; -import com.hypixel.hytale.server.core.HytaleServerConfig; +import com.hypixel.hytale.server.core.config.RateLimitConfig; import com.hypixel.hytale.server.core.io.PacketStatsRecorderImpl; import com.hypixel.hytale.server.core.io.handlers.InitialPacketHandler; import com.hypixel.hytale.server.core.io.transport.QUICTransport; @@ -61,18 +61,30 @@ public class HytaleChannelInitializer extends ChannelInitializer { .log("Received connection from %s to %s", NettyUtil.formatRemoteAddress(channel), NettyUtil.formatLocalAddress(channel)); } - PacketStatsRecorderImpl statsRecorder = new PacketStatsRecorderImpl(); - channel.attr(PacketStatsRecorder.CHANNEL_KEY).set(statsRecorder); - Duration initialTimeout = HytaleServer.get().getConfig().getConnectionTimeouts().getInitial(); - channel.attr(ProtocolUtil.PACKET_TIMEOUT_KEY).set(initialTimeout); - channel.pipeline().addLast("packetDecoder", new PacketDecoder()); - HytaleServerConfig.RateLimitConfig rateLimitConfig = HytaleServer.get().getConfig().getRateLimitConfig(); - if (rateLimitConfig.isEnabled()) { - channel.pipeline().addLast("rateLimit", new RateLimitHandler(rateLimitConfig.getBurstCapacity(), rateLimitConfig.getPacketsPerSecond())); + boolean canRead = true; + boolean canWrite = true; + if (channel instanceof QuicStreamChannel streamChannel) { + canRead = !streamChannel.isInputShutdown(); + canWrite = !streamChannel.isOutputShutdown(); + } + + PacketStatsRecorderImpl statsRecorder = new PacketStatsRecorderImpl(); + channel.attr(PacketStatsRecorder.CHANNEL_KEY).set(statsRecorder); + if (canRead) { + Duration initialTimeout = HytaleServer.get().getConfig().getConnectionTimeouts().getInitial(); + channel.attr(ProtocolUtil.PACKET_TIMEOUT_KEY).set(initialTimeout); + channel.pipeline().addLast("packetDecoder", new PacketDecoder()); + RateLimitConfig rateLimitConfig = HytaleServer.get().getConfig().getRateLimitConfig(); + if (rateLimitConfig.isEnabled()) { + channel.pipeline().addLast("rateLimit", new RateLimitHandler(rateLimitConfig.getBurstCapacity(), rateLimitConfig.getPacketsPerSecond())); + } + } + + if (canWrite) { + channel.pipeline().addLast("packetEncoder", new PacketEncoder()); + channel.pipeline().addLast("packetArrayEncoder", NettyUtil.PACKET_ARRAY_ENCODER_INSTANCE); } - channel.pipeline().addLast("packetEncoder", new PacketEncoder()); - channel.pipeline().addLast("packetArrayEncoder", NettyUtil.PACKET_ARRAY_ENCODER_INSTANCE); if (NettyUtil.PACKET_LOGGER.getLevel() != Level.OFF) { channel.pipeline().addLast("logger", NettyUtil.LOGGER); } diff --git a/src/com/hypixel/hytale/server/core/io/netty/NettyUtil.java b/src/com/hypixel/hytale/server/core/io/netty/NettyUtil.java index 8e526220..3833d28d 100644 --- a/src/com/hypixel/hytale/server/core/io/netty/NettyUtil.java +++ b/src/com/hypixel/hytale/server/core/io/netty/NettyUtil.java @@ -2,6 +2,8 @@ package com.hypixel.hytale.server.core.io.netty; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.logger.backend.HytaleLoggerBackend; +import com.hypixel.hytale.protocol.NetworkChannel; +import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.server.core.io.PacketHandler; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.Universe; @@ -27,6 +29,8 @@ import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.quic.QuicChannel; import io.netty.handler.codec.quic.QuicStreamChannel; +import io.netty.handler.codec.quic.QuicStreamPriority; +import io.netty.handler.codec.quic.QuicStreamType; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import io.netty.util.AttributeKey; @@ -37,6 +41,7 @@ import java.lang.reflect.Constructor; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Objects; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadFactory; import java.util.logging.Level; import javax.annotation.Nonnull; @@ -78,6 +83,33 @@ public class NettyUtil { packetHandler.registered(oldPlayerConnection); } + @Nonnull + public static CompletableFuture createStream( + @Nonnull QuicChannel conn, + @Nonnull QuicStreamType streamType, + @Nonnull NetworkChannel networkChannel, + @Nullable QuicStreamPriority priority, + @Nonnull PacketHandler packetHandler + ) { + CompletableFuture future = new CompletableFuture<>(); + conn.createStream(streamType, new HytaleChannelInitializer()).addListener(result -> { + if (!result.isSuccess()) { + future.completeExceptionally(result.cause()); + } else { + QuicStreamChannel channel = result.getNow(); + channel.attr(ProtocolUtil.STREAM_CHANNEL_KEY).set(networkChannel); + if (priority != null) { + channel.updatePriority(priority); + } + + setChannelHandler(channel, packetHandler); + packetHandler.setChannel(networkChannel, channel); + future.complete(null); + } + }); + return future; + } + @Nonnull public static EventLoopGroup getEventLoopGroup(String name) { return getEventLoopGroup(0, name); diff --git a/src/com/hypixel/hytale/server/core/io/netty/PlayerChannelHandler.java b/src/com/hypixel/hytale/server/core/io/netty/PlayerChannelHandler.java index 5f662f25..19ab586c 100644 --- a/src/com/hypixel/hytale/server/core/io/netty/PlayerChannelHandler.java +++ b/src/com/hypixel/hytale/server/core/io/netty/PlayerChannelHandler.java @@ -1,6 +1,6 @@ package com.hypixel.hytale.server.core.io.netty; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToServerPacket; import com.hypixel.hytale.server.core.io.PacketHandler; import com.hypixel.hytale.server.core.io.adapter.PacketAdapters; import io.netty.channel.ChannelHandlerContext; @@ -26,7 +26,7 @@ public class PlayerChannelHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (ctx.channel().isActive()) { - Packet packet = (Packet)msg; + ToServerPacket packet = (ToServerPacket)msg; if (!PacketAdapters.__handleInbound(this.handler, packet)) { this.handler.handle(packet); } diff --git a/src/com/hypixel/hytale/server/core/io/transport/QUICTransport.java b/src/com/hypixel/hytale/server/core/io/transport/QUICTransport.java index 25cf605b..40bb2b16 100644 --- a/src/com/hypixel/hytale/server/core/io/transport/QUICTransport.java +++ b/src/com/hypixel/hytale/server/core/io/transport/QUICTransport.java @@ -20,8 +20,9 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.DatagramChannel; import io.netty.channel.socket.SocketProtocolFamily; import io.netty.channel.socket.nio.NioChannelOption; -import io.netty.handler.codec.quic.InsecureQuicTokenHandler; +import io.netty.handler.codec.quic.QLogConfiguration; import io.netty.handler.codec.quic.QuicChannel; +import io.netty.handler.codec.quic.QuicChannelOption; import io.netty.handler.codec.quic.QuicCongestionControlAlgorithm; import io.netty.handler.codec.quic.QuicServerCodecBuilder; import io.netty.handler.codec.quic.QuicSslContext; @@ -155,7 +156,8 @@ public class QUICTransport implements Transport { Duration playTimeout = HytaleServer.get().getConfig().getConnectionTimeouts().getPlay(); ChannelHandler quicHandler = new QuicServerCodecBuilder() .sslContext(this.sslContext) - .tokenHandler(InsecureQuicTokenHandler.INSTANCE) + .tokenHandler(null) + .activeMigration(false) .maxIdleTimeout(playTimeout.toMillis(), TimeUnit.MILLISECONDS) .ackDelayExponent(3L) .initialMaxData(524288L) @@ -166,6 +168,7 @@ public class QUICTransport implements Transport { .initialMaxStreamsBidirectional(1L) .discoverPmtu(true) .congestionControlAlgorithm(QuicCongestionControlAlgorithm.BBR) + .option(QuicChannelOption.QLOG, System.getProperty("hytale.qlog") != null ? new QLogConfiguration(".", "hytale-server-quic-qlogs", "") : null) .handler( new ChannelInboundHandlerAdapter() { @Override diff --git a/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionHandler.java b/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionHandler.java new file mode 100644 index 00000000..fae329aa --- /dev/null +++ b/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionHandler.java @@ -0,0 +1,10 @@ +package com.hypixel.hytale.server.core.modules.anchoraction; + +import com.google.gson.JsonObject; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import javax.annotation.Nonnull; + +@FunctionalInterface +public interface AnchorActionHandler { + void handle(@Nonnull PlayerRef var1, @Nonnull JsonObject var2); +} diff --git a/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionModule.java b/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionModule.java new file mode 100644 index 00000000..3ff5dba5 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/modules/anchoraction/AnchorActionModule.java @@ -0,0 +1,83 @@ +package com.hypixel.hytale.server.core.modules.anchoraction; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.hypixel.hytale.common.plugin.PluginManifest; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.logger.HytaleLogger; +import com.hypixel.hytale.server.core.plugin.JavaPlugin; +import com.hypixel.hytale.server.core.plugin.JavaPluginInit; +import com.hypixel.hytale.server.core.universe.PlayerRef; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.Nonnull; + +public class AnchorActionModule extends JavaPlugin { + public static final PluginManifest MANIFEST = PluginManifest.corePlugin(AnchorActionModule.class).build(); + private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); + private static AnchorActionModule instance; + private final Map handlers = new ConcurrentHashMap<>(); + + public static AnchorActionModule get() { + return instance; + } + + public AnchorActionModule(@Nonnull JavaPluginInit init) { + super(init); + instance = this; + } + + public void register(@Nonnull String action, @Nonnull AnchorActionHandler handler) { + this.handlers.put(action, handler); + } + + public void register(@Nonnull String action, @Nonnull AnchorActionModule.WorldThreadAnchorActionHandler handler) { + this.register(action, (playerRef, data) -> { + Ref ref = playerRef.getReference(); + if (ref != null) { + Store store = ref.getStore(); + World world = store.getExternalData().getWorld(); + world.execute(() -> { + if (ref.isValid()) { + handler.handle(playerRef, ref, store, data); + } + }); + } + }); + } + + public void unregister(@Nonnull String action) { + this.handlers.remove(action); + } + + public boolean tryHandle(@Nonnull PlayerRef playerRef, @Nonnull String rawData) { + String action = null; + + try { + JsonObject data = JsonParser.parseString(rawData).getAsJsonObject(); + if (!data.has("action")) { + return false; + } else { + action = data.get("action").getAsString(); + AnchorActionHandler handler = this.handlers.get(action); + if (handler == null) { + return false; + } else { + handler.handle(playerRef, data); + return true; + } + } + } catch (Exception var6) { + LOGGER.atWarning().withCause(var6).log("Failed to handle anchor action '%s' for player %s", action, playerRef.getUuid()); + return false; + } + } + + @FunctionalInterface + public interface WorldThreadAnchorActionHandler { + void handle(@Nonnull PlayerRef var1, @Nonnull Ref var2, @Nonnull Store var3, @Nonnull JsonObject var4); + } +} diff --git a/src/com/hypixel/hytale/server/core/modules/block/BlockModule.java b/src/com/hypixel/hytale/server/core/modules/block/BlockModule.java index 6263c4bc..fc0fb4ff 100644 --- a/src/com/hypixel/hytale/server/core/modules/block/BlockModule.java +++ b/src/com/hypixel/hytale/server/core/modules/block/BlockModule.java @@ -5,6 +5,7 @@ import com.hypixel.hytale.common.plugin.PluginManifest; import com.hypixel.hytale.component.AddReason; import com.hypixel.hytale.component.CommandBuffer; import com.hypixel.hytale.component.Component; +import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.ComponentRegistryProxy; import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Holder; @@ -256,7 +257,13 @@ public class BlockModule extends JavaPlugin { public void markNeedsSaving() { if (this.chunkRef.isValid()) { - BlockComponentChunk blockComponentChunk = this.chunkRef.getStore().getComponent(this.chunkRef, BlockComponentChunk.getComponentType()); + this.markNeedsSaving(this.chunkRef.getStore()); + } + } + + public void markNeedsSaving(ComponentAccessor accessor) { + if (this.chunkRef.isValid()) { + BlockComponentChunk blockComponentChunk = accessor.getComponent(this.chunkRef, BlockComponentChunk.getComponentType()); if (blockComponentChunk != null) { blockComponentChunk.markNeedsSaving(); } diff --git a/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthChunk.java b/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthChunk.java index 2bd3b3e4..b1da8850 100644 --- a/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthChunk.java +++ b/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthChunk.java @@ -6,7 +6,7 @@ import com.hypixel.hytale.codec.builder.BuilderCodec; import com.hypixel.hytale.component.Component; import com.hypixel.hytale.math.vector.Vector3i; import com.hypixel.hytale.protocol.BlockPosition; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.UpdateBlockDamage; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; @@ -109,7 +109,7 @@ public class BlockHealthChunk implements Component { return this.blockHealthMap.getOrDefault(block, BlockHealth.NO_DAMAGE_INSTANCE).getHealth(); } - public void createBlockDamagePackets(@Nonnull List list) { + public void createBlockDamagePackets(@Nonnull List list) { for (Entry entry : this.blockHealthMap.entrySet()) { Vector3i block = entry.getKey(); BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ()); diff --git a/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthModule.java b/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthModule.java index 3cdfb61d..f0ff66da 100644 --- a/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthModule.java +++ b/src/com/hypixel/hytale/server/core/modules/blockhealth/BlockHealthModule.java @@ -19,7 +19,7 @@ import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.vector.Vector3i; import com.hypixel.hytale.protocol.BlockPosition; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.UpdateBlockDamage; import com.hypixel.hytale.server.core.asset.type.gameplay.WorldConfig; import com.hypixel.hytale.server.core.event.events.ecs.PlaceBlockEvent; @@ -106,7 +106,7 @@ public class BlockHealthModule extends JavaPlugin { Store store, CommandBuffer commandBuffer, PlayerRef player, - @Nonnull List results + @Nonnull List results ) { BlockHealthChunk blockHealthChunkComponent = archetypeChunk.getComponent(index, this.blockHealthCunkComponentType); diff --git a/src/com/hypixel/hytale/server/core/modules/debug/DebugUtils.java b/src/com/hypixel/hytale/server/core/modules/debug/DebugUtils.java index 71aca04e..070b83dc 100644 --- a/src/com/hypixel/hytale/server/core/modules/debug/DebugUtils.java +++ b/src/com/hypixel/hytale/server/core/modules/debug/DebugUtils.java @@ -169,6 +169,29 @@ public class DebugUtils { } } + public static void addDisc( + @Nonnull World world, + @Nonnull Matrix4d matrix, + double outerRadius, + double innerRadius, + @Nonnull Vector3f color, + float opacity, + int segmentCount, + float time, + boolean fade + ) { + float[] shapeParams = new float[]{ + (float)outerRadius, segmentCount, (float)innerRadius, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F + }; + add(world, DebugShape.Disc, matrix, color, opacity, time, fade, shapeParams); + } + + public static void addDisc( + @Nonnull World world, @Nonnull Matrix4d matrix, double outerRadius, double innerRadius, @Nonnull Vector3f color, float opacity, float time, boolean fade + ) { + addDisc(world, matrix, outerRadius, innerRadius, color, opacity, 32, time, fade); + } + public static void addDisc(@Nonnull World world, @Nonnull Vector3d center, double radius, @Nonnull Vector3f color, float time, boolean fade) { addDisc(world, center.x, center.y, center.z, radius, 0.0, color, 0.8F, time, fade); } @@ -214,10 +237,7 @@ public class DebugUtils { Matrix4d matrix = new Matrix4d(); matrix.identity(); matrix.translate(x, y, z); - float[] shapeParams = new float[]{ - (float)outerRadius, segmentCount, (float)innerRadius, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F - }; - add(world, DebugShape.Disc, matrix, color, opacity, time, fade, shapeParams); + addDisc(world, matrix, outerRadius, innerRadius, color, opacity, segmentCount, time, fade); } public static void addSector( diff --git a/src/com/hypixel/hytale/server/core/modules/entity/BlockEntitySystems.java b/src/com/hypixel/hytale/server/core/modules/entity/BlockEntitySystems.java index 3412ca97..b9e3cd39 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/BlockEntitySystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/BlockEntitySystems.java @@ -16,8 +16,7 @@ import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.shape.Box; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.BlockUpdate; import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.entity.entities.BlockEntity; import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox; @@ -136,15 +135,12 @@ public class BlockEntitySystems { private static void queueUpdatesFor( Ref ref, @Nonnull BlockEntity entity, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, float entityScale ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Block; String key = entity.getBlockTypeKey(); int index = BlockType.getAssetMap().getIndex(key); if (index == Integer.MIN_VALUE) { throw new IllegalArgumentException("Unknown key! " + key); } else { - update.blockId = index; - update.entityScale = entityScale; + BlockUpdate update = new BlockUpdate(index, entityScale); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/EntityModule.java b/src/com/hypixel/hytale/server/core/modules/entity/EntityModule.java index 15e7a76b..3273d7bd 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/EntityModule.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/EntityModule.java @@ -529,7 +529,7 @@ public class EntityModule extends JavaPlugin { entityStoreRegistry.registerSystem(new ModelSystems.PlayerConnect()); entityStoreRegistry.registerSystem(new ModelSystems.ModelChange()); entityStoreRegistry.registerSystem(new ModelSystems.UpdateBoundingBox()); - entityStoreRegistry.registerSystem(new ModelSystems.UpdateCrouchingBoundingBox()); + entityStoreRegistry.registerSystem(new ModelSystems.UpdateMovementStateBoundingBox()); entityStoreRegistry.registerSystem(new ModelSystems.PlayerUpdateMovementManager()); entityStoreRegistry.registerSystem(new ModelSystems.AnimationEntityTrackerUpdate()); entityStoreRegistry.registerSystem(new EntitySystems.NewSpawnEntityTrackerUpdate()); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/damage/DamageSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/damage/DamageSystems.java index 4333bc44..dc2c63bd 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/damage/DamageSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/damage/DamageSystems.java @@ -28,8 +28,6 @@ import com.hypixel.hytale.math.vector.Vector4d; import com.hypixel.hytale.protocol.AnimationSlot; import com.hypixel.hytale.protocol.BlockMaterial; import com.hypixel.hytale.protocol.CombatTextUpdate; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.InteractionType; import com.hypixel.hytale.protocol.MovementStates; import com.hypixel.hytale.protocol.SoundCategory; @@ -843,12 +841,7 @@ public class DamageSystems { private static void queueUpdateFor( @Nonnull Ref ref, float damageAmount, @Nullable Float hitAngleDeg, @Nonnull EntityTrackerSystems.EntityViewer viewer ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.CombatText; - CombatTextUpdate combatTextUpdate = new CombatTextUpdate(); - combatTextUpdate.hitAngleDeg = hitAngleDeg == null ? 0.0F : hitAngleDeg; - combatTextUpdate.text = Integer.toString((int)Math.floor(damageAmount)); - update.combatTextUpdate = combatTextUpdate; + CombatTextUpdate update = new CombatTextUpdate(hitAngleDeg == null ? 0.0F : hitAngleDeg, Integer.toString((int)Math.floor(damageAmount))); viewer.queueUpdate(ref, update); } } diff --git a/src/com/hypixel/hytale/server/core/modules/entity/damage/DeathSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/damage/DeathSystems.java index eb603221..be7388ac 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/damage/DeathSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/damage/DeathSystems.java @@ -260,7 +260,7 @@ public class DeathSystems { for (short i = 0; i < combinedItemContainer.getCapacity(); i++) { ItemStack itemStack = combinedItemContainer.getItemStack(i); - if (!ItemStack.isEmpty(itemStack) && !itemStack.isBroken()) { + if (!ItemStack.isEmpty(itemStack) && !itemStack.isBroken() && itemStack.getItem().getDurabilityLossOnDeath()) { double durabilityLoss = itemStack.getMaxDurability() * durabilityLossRatio; ItemStack updatedItemStack = itemStack.withIncreasedDurability(-durabilityLoss); ItemStackSlotTransaction transaction = combinedItemContainer.replaceItemStackInSlot(i, itemStack, updatedItemStack); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionConfigPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionConfigPacketGenerator.java index 69867a00..016f76e5 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionConfigPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionConfigPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.entity.hitboxcollision; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateHitboxCollisionConfig; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -16,7 +16,7 @@ import javax.annotation.Nonnull; public class HitboxCollisionConfigPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket( + public ToClientPacket generateInitPacket( @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets ) { Int2ObjectMap hitboxCollisionConfigs = new Int2ObjectOpenHashMap<>(); @@ -29,7 +29,7 @@ public class HitboxCollisionConfigPacketGenerator } @Nonnull - public Packet generateUpdatePacket( + public ToClientPacket generateUpdatePacket( @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query @@ -44,7 +44,7 @@ public class HitboxCollisionConfigPacketGenerator } @Nonnull - public Packet generateRemovePacket( + public ToClientPacket generateRemovePacket( @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap hitboxCollisionConfigs = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionSystems.java index 9280a52f..0b0ad7c1 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/hitboxcollision/HitboxCollisionSystems.java @@ -13,8 +13,8 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.HitboxCollisionUpdate; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; import com.hypixel.hytale.server.core.universe.world.World; @@ -130,9 +130,7 @@ public class HitboxCollisionSystems { private static void queueUpdatesFor( Ref ref, @Nonnull HitboxCollision hitboxCollision, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.HitboxCollision; - update.hitboxCollisionConfigIndex = hitboxCollision.getHitboxCollisionConfigIndex(); + HitboxCollisionUpdate update = new HitboxCollisionUpdate(hitboxCollision.getHitboxCollisionConfigIndex()); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/item/ItemSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/item/ItemSystems.java index 96d48e26..c8083ba5 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/item/ItemSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/item/ItemSystems.java @@ -14,8 +14,7 @@ import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.shape.Box; import com.hypixel.hytale.protocol.ColorLight; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.ItemUpdate; import com.hypixel.hytale.server.core.inventory.ItemStack; import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox; import com.hypixel.hytale.server.core.modules.entity.component.DynamicLight; @@ -123,11 +122,8 @@ public class ItemSystems { float entityScale, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Item; ItemStack itemStack = item.getItemStack(); - update.item = itemStack != null ? itemStack.toPacket() : null; - update.entityScale = entityScale; + ItemUpdate update = new ItemUpdate(itemStack != null ? itemStack.toPacket() : null, entityScale); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/player/ChunkTracker.java b/src/com/hypixel/hytale/server/core/modules/entity/player/ChunkTracker.java index dca842a0..34275dd3 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/player/ChunkTracker.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/player/ChunkTracker.java @@ -15,7 +15,8 @@ import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.metrics.MetricsRegistry; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.NetworkChannel; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.UnloadChunk; import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.entity.entities.Player; @@ -141,7 +142,7 @@ public class ChunkTracker implements Component { float dt, @Nonnull CommandBuffer commandBuffer ) { - if (this.readyForChunks) { + if (this.readyForChunks && playerRefComponent.getPacketHandler().getChannel(NetworkChannel.Chunks).isWritable()) { this.transformComponent = transformComponent; int chunkViewRadius = this.chunkViewRadius = playerComponent.getViewRadius(); Vector3d position = transformComponent.getPosition(); @@ -526,7 +527,7 @@ public class ChunkTracker implements Component { Ref chunkRef = chunkComponentStore.getChunkReference(chunkIndex); if (chunkRef != null) { Store chunkStore = chunkComponentStore.getStore(); - ObjectArrayList packets = new ObjectArrayList<>(); + ObjectArrayList packets = new ObjectArrayList<>(); chunkStore.fetch(Collections.singletonList(chunkRef), ChunkStore.UNLOAD_PACKETS_DATA_QUERY_SYSTEM_TYPE, playerRef, packets); for (int i = 0; i < packets.size(); i++) { @@ -617,14 +618,14 @@ public class ChunkTracker implements Component { private CompletableFuture _loadChunkAsync( long chunkIndex, @Nonnull PlayerRef playerRefComponent, @Nonnull Ref chunkRef, @Nonnull ChunkStore chunkComponentStore ) { - List packets = new ObjectArrayList<>(); + List packets = new ObjectArrayList<>(); chunkComponentStore.getStore().fetch(Collections.singletonList(chunkRef), ChunkStore.LOAD_PACKETS_DATA_QUERY_SYSTEM_TYPE, playerRefComponent, packets); - ObjectArrayList> futurePackets = new ObjectArrayList<>(); + ObjectArrayList> futurePackets = new ObjectArrayList<>(); chunkComponentStore.getStore() .fetch(Collections.singletonList(chunkRef), ChunkStore.LOAD_FUTURE_PACKETS_DATA_QUERY_SYSTEM_TYPE, playerRefComponent, futurePackets); return CompletableFuture.allOf(futurePackets.toArray(CompletableFuture[]::new)).thenAcceptAsync(o -> { - for (CompletableFuture futurePacket : futurePackets) { - Packet packet = futurePacket.join(); + for (CompletableFuture futurePacket : futurePackets) { + ToClientPacket packet = futurePacket.join(); if (packet != null) { packets.add(packet); } diff --git a/src/com/hypixel/hytale/server/core/modules/entity/player/PlayerSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/player/PlayerSystems.java index 655d65fa..90cc7cc4 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/player/PlayerSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/player/PlayerSystems.java @@ -26,11 +26,21 @@ import com.hypixel.hytale.math.vector.Transform; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.EntityEffectsUpdate; +import com.hypixel.hytale.protocol.EntityStatsUpdate; import com.hypixel.hytale.protocol.EntityUpdate; -import com.hypixel.hytale.protocol.Equipment; +import com.hypixel.hytale.protocol.EquipmentUpdate; +import com.hypixel.hytale.protocol.IntangibleUpdate; +import com.hypixel.hytale.protocol.InteractableUpdate; +import com.hypixel.hytale.protocol.InvulnerableUpdate; import com.hypixel.hytale.protocol.ItemArmorSlot; import com.hypixel.hytale.protocol.ModelTransform; +import com.hypixel.hytale.protocol.ModelUpdate; +import com.hypixel.hytale.protocol.NameplateUpdate; +import com.hypixel.hytale.protocol.PlayerSkinUpdate; +import com.hypixel.hytale.protocol.PredictionUpdate; +import com.hypixel.hytale.protocol.RespondToHitUpdate; +import com.hypixel.hytale.protocol.TransformUpdate; import com.hypixel.hytale.protocol.packets.buildertools.BuilderToolsSetSoundSet; import com.hypixel.hytale.protocol.packets.entities.EntityUpdates; import com.hypixel.hytale.protocol.packets.inventory.SetActiveSlot; @@ -574,49 +584,33 @@ public class PlayerSystems { ObjectArrayList list = new ObjectArrayList<>(); Archetype viewerArchetype = store.getArchetype(viewerRef); if (viewerArchetype.contains(Interactable.getComponentType())) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Interactable; - list.add(update); + list.add(new InteractableUpdate()); } if (viewerArchetype.contains(Intangible.getComponentType())) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Intangible; - list.add(update); + list.add(new IntangibleUpdate()); } if (viewerArchetype.contains(Invulnerable.getComponentType())) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Invulnerable; - list.add(update); + list.add(new InvulnerableUpdate()); } if (viewerArchetype.contains(RespondToHit.getComponentType())) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.RespondToHit; - list.add(update); + list.add(new RespondToHitUpdate()); } Nameplate nameplateComponent = store.getComponent(viewerRef, Nameplate.getComponentType()); if (nameplateComponent != null) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Nameplate; - update.nameplate = new com.hypixel.hytale.protocol.Nameplate(); - update.nameplate.text = nameplateComponent.getText(); - list.add(update); + list.add(new NameplateUpdate(nameplateComponent.getText())); } PredictedProjectile predictionComponent = store.getComponent(viewerRef, PredictedProjectile.getComponentType()); if (predictionComponent != null) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Prediction; - update.predictionId = predictionComponent.getUuid(); - list.add(update); + list.add(new PredictionUpdate(predictionComponent.getUuid())); } ModelComponent modelComponent = store.getComponent(viewerRef, ModelComponent.getComponentType()); - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Model; + ModelUpdate update = new ModelUpdate(); update.model = modelComponent != null ? modelComponent.getModel().toPacket() : null; EntityScaleComponent entityScaleComponent = store.getComponent(viewerRef, EntityScaleComponent.getComponentType()); if (entityScaleComponent != null) { @@ -624,19 +618,14 @@ public class PlayerSystems { } list.add(update); - update = new ComponentUpdate(); - update.type = ComponentUpdateType.PlayerSkin; PlayerSkinComponent playerSkinComponent = store.getComponent(viewerRef, PlayerSkinComponent.getComponentType()); - update.skin = playerSkinComponent != null ? playerSkinComponent.getPlayerSkin() : null; - list.add(update); + list.add(new PlayerSkinUpdate(playerSkinComponent != null ? playerSkinComponent.getPlayerSkin() : null)); Inventory inventory = playerComponent.getInventory(); - ComponentUpdate updatex = new ComponentUpdate(); - updatex.type = ComponentUpdateType.Equipment; - updatex.equipment = new Equipment(); + EquipmentUpdate updatex = new EquipmentUpdate(); ItemContainer armor = inventory.getArmor(); - updatex.equipment.armorIds = new String[armor.getCapacity()]; - Arrays.fill(updatex.equipment.armorIds, ""); - armor.forEachWithMeta((slot, itemStack, armorIds) -> armorIds[slot] = itemStack.getItemId(), updatex.equipment.armorIds); + updatex.armorIds = new String[armor.getCapacity()]; + Arrays.fill(updatex.armorIds, ""); + armor.forEachWithMeta((slot, itemStack, armorIds) -> armorIds[slot] = itemStack.getItemId(), updatex.armorIds); PlayerSettings playerSettingsComponent = store.getComponent(viewerRef, PlayerSettings.getComponentType()); if (playerSettingsComponent != null) { PlayerConfig.ArmorVisibilityOption armorVisibilityOption = store.getExternalData() @@ -645,32 +634,31 @@ public class PlayerSystems { .getPlayerConfig() .getArmorVisibilityOption(); if (armorVisibilityOption.canHideHelmet() && playerSettingsComponent.hideHelmet()) { - updatex.equipment.armorIds[ItemArmorSlot.Head.ordinal()] = ""; + updatex.armorIds[ItemArmorSlot.Head.ordinal()] = ""; } if (armorVisibilityOption.canHideCuirass() && playerSettingsComponent.hideCuirass()) { - updatex.equipment.armorIds[ItemArmorSlot.Chest.ordinal()] = ""; + updatex.armorIds[ItemArmorSlot.Chest.ordinal()] = ""; } if (armorVisibilityOption.canHideGauntlets() && playerSettingsComponent.hideGauntlets()) { - updatex.equipment.armorIds[ItemArmorSlot.Hands.ordinal()] = ""; + updatex.armorIds[ItemArmorSlot.Hands.ordinal()] = ""; } if (armorVisibilityOption.canHidePants() && playerSettingsComponent.hidePants()) { - updatex.equipment.armorIds[ItemArmorSlot.Legs.ordinal()] = ""; + updatex.armorIds[ItemArmorSlot.Legs.ordinal()] = ""; } } ItemStack itemInHand = inventory.getItemInHand(); - updatex.equipment.rightHandItemId = itemInHand != null ? itemInHand.getItemId() : "Empty"; + updatex.rightHandItemId = itemInHand != null ? itemInHand.getItemId() : "Empty"; ItemStack utilityItem = inventory.getUtilityItem(); - updatex.equipment.leftHandItemId = utilityItem != null ? utilityItem.getItemId() : "Empty"; + updatex.leftHandItemId = utilityItem != null ? utilityItem.getItemId() : "Empty"; list.add(updatex); TransformComponent transformComponent = store.getComponent(viewerRef, TransformComponent.getComponentType()); HeadRotation headRotationComponent = store.getComponent(viewerRef, HeadRotation.getComponentType()); if (transformComponent != null && headRotationComponent != null) { - ComponentUpdate updatexx = new ComponentUpdate(); - updatexx.type = ComponentUpdateType.Transform; + TransformUpdate updatexx = new TransformUpdate(); updatexx.transform = new ModelTransform(); updatexx.transform.position = PositionUtil.toPositionPacket(transformComponent.getPosition()); updatexx.transform.bodyOrientation = PositionUtil.toDirectionPacket(transformComponent.getRotation()); @@ -680,18 +668,12 @@ public class PlayerSystems { EffectControllerComponent effectControllerComponent = store.getComponent(viewerRef, EffectControllerComponent.getComponentType()); if (effectControllerComponent != null) { - ComponentUpdate updatexx = new ComponentUpdate(); - updatexx.type = ComponentUpdateType.EntityEffects; - updatexx.entityEffectUpdates = effectControllerComponent.createInitUpdates(); - list.add(updatexx); + list.add(new EntityEffectsUpdate(effectControllerComponent.createInitUpdates())); } EntityStatMap statMapComponent = store.getComponent(viewerRef, EntityStatMap.getComponentType()); if (statMapComponent != null) { - ComponentUpdate updatexx = new ComponentUpdate(); - updatexx.type = ComponentUpdateType.EntityStats; - updatexx.entityStatUpdates = statMapComponent.createInitUpdate(true); - list.add(updatexx); + list.add(new EntityStatsUpdate(statMapComponent.createInitUpdate(true))); } entityUpdate.updates = list.toArray(ComponentUpdate[]::new); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionConfigPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionConfigPacketGenerator.java index 564304ae..6791917c 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionConfigPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionConfigPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.entity.repulsion; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateRepulsionConfig; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class RepulsionConfigPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { Int2ObjectMap repulsionConfigs = new Int2ObjectOpenHashMap<>(); for (Entry entry : assets.entrySet()) { @@ -26,7 +26,7 @@ public class RepulsionConfigPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query @@ -41,7 +41,7 @@ public class RepulsionConfigPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap repulsionConfigs = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionSystems.java index e5f7359d..29c33ac1 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/repulsion/RepulsionSystems.java @@ -22,8 +22,8 @@ import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.vector.Vector2d; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.protocol.ChangeVelocityType; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.RepulsionUpdate; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; import com.hypixel.hytale.server.core.modules.entity.system.PlayerSpatialSystem; @@ -140,9 +140,7 @@ public class RepulsionSystems { private static void queueUpdatesFor( Ref ref, @Nonnull Repulsion repulsion, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Repulsion; - update.repulsionConfigIndex = repulsion.getRepulsionConfigIndex(); + RepulsionUpdate update = new RepulsionUpdate(repulsion.getRepulsionConfigIndex()); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/AudioSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/AudioSystems.java index f07c17ec..095c5fd1 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/AudioSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/AudioSystems.java @@ -11,9 +11,8 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.random.RandomExtra; import com.hypixel.hytale.math.vector.Vector3d; +import com.hypixel.hytale.protocol.AudioUpdate; import com.hypixel.hytale.protocol.BlockSoundEvent; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.SoundCategory; import com.hypixel.hytale.server.core.asset.type.blocksound.config.BlockSoundSet; import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; @@ -80,9 +79,7 @@ public class AudioSystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull AudioComponent audioComponent, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Audio; - update.soundEventIds = audioComponent.getSoundEventIds(); + AudioUpdate update = new AudioUpdate(audioComponent.getSoundEventIds()); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { entry.getValue().queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/EntityInteractableSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/EntityInteractableSystems.java index 6ecc671c..9bcdafd9 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/EntityInteractableSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/EntityInteractableSystems.java @@ -11,8 +11,8 @@ import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.InteractableUpdate; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.Interactable; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; @@ -122,8 +122,7 @@ public class EntityInteractableSystems { } private static void queueUpdatesFor(Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Interactable; + InteractableUpdate update = new InteractableUpdate(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/EntitySystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/EntitySystems.java index f58da529..bba831ed 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/EntitySystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/EntitySystems.java @@ -19,8 +19,9 @@ import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.protocol.ColorLight; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.DynamicLightUpdate; +import com.hypixel.hytale.protocol.NewSpawnUpdate; import com.hypixel.hytale.server.core.entity.UUIDComponent; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.DynamicLight; @@ -150,9 +151,7 @@ public class EntitySystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull ColorLight dynamicLight, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.DynamicLight; - update.dynamicLight = dynamicLight; + DynamicLightUpdate update = new DynamicLightUpdate(dynamicLight); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); @@ -209,8 +208,7 @@ public class EntitySystems { Ref ref = archetypeChunk.getReferenceTo(index); if (!visibleComponent.newlyVisibleTo.isEmpty()) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.NewSpawn; + NewSpawnUpdate update = new NewSpawnUpdate(); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleComponent.newlyVisibleTo.entrySet()) { entry.getValue().queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/IntangibleSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/IntangibleSystems.java index ca4b739a..e105c799 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/IntangibleSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/IntangibleSystems.java @@ -11,8 +11,8 @@ import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.IntangibleUpdate; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.Intangible; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; @@ -122,8 +122,7 @@ public class IntangibleSystems { } private static void queueUpdatesFor(Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Intangible; + IntangibleUpdate update = new IntangibleUpdate(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/InvulnerableSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/InvulnerableSystems.java index 3222484c..05fad920 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/InvulnerableSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/InvulnerableSystems.java @@ -11,8 +11,8 @@ import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.InvulnerableUpdate; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.Invulnerable; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; @@ -122,8 +122,7 @@ public class InvulnerableSystems { } private static void queueUpdatesFor(Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Invulnerable; + InvulnerableUpdate update = new InvulnerableUpdate(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/ModelSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/ModelSystems.java index d639b27a..8644615b 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/ModelSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/ModelSystems.java @@ -21,8 +21,7 @@ import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.shape.Box; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.ActiveAnimationsUpdate; import com.hypixel.hytale.protocol.MovementStates; import com.hypixel.hytale.protocol.PlayerSkin; import com.hypixel.hytale.server.core.asset.type.model.config.Model; @@ -108,9 +107,7 @@ public class ModelSystems { @Nonnull ActiveAnimationComponent animationComponent, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.ActiveAnimations; - update.activeAnimations = animationComponent.getActiveAnimations(); + ActiveAnimationsUpdate update = new ActiveAnimationsUpdate(animationComponent.getActiveAnimations()); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { entry.getValue().queueUpdate(ref, update); @@ -496,7 +493,7 @@ public class ModelSystems { } } - public static class UpdateCrouchingBoundingBox extends EntityTickingSystem { + public static class UpdateMovementStateBoundingBox extends EntityTickingSystem { @Nonnull public static final Set> DEPENDENCIES = Collections.singleton( new SystemDependency<>(Order.BEFORE, MovementStatesSystems.TickingSystem.class) @@ -541,7 +538,12 @@ public class ModelSystems { MovementStates newMovementStates = movementStatesComponent.getMovementStates(); MovementStates sentMovementStates = movementStatesComponent.getSentMovementStates(); - if (newMovementStates.crouching != sentMovementStates.crouching || newMovementStates.forcedCrouching != sentMovementStates.forcedCrouching) { + boolean crouchingChanged = newMovementStates.crouching != sentMovementStates.crouching + || newMovementStates.forcedCrouching != sentMovementStates.forcedCrouching; + boolean slidingChanged = newMovementStates.sliding != sentMovementStates.sliding; + boolean sittingChanged = newMovementStates.sitting != sentMovementStates.sitting; + boolean sleepingChanged = newMovementStates.sleeping != sentMovementStates.sleeping; + if (crouchingChanged || slidingChanged || sittingChanged || sleepingChanged) { ModelComponent modelComponent = archetypeChunk.getComponent(index, this.modelComponentType); assert modelComponent != null; diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/RespondToHitSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/RespondToHitSystems.java index 58726545..b797fb6a 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/RespondToHitSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/RespondToHitSystems.java @@ -11,9 +11,9 @@ import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.GameMode; +import com.hypixel.hytale.protocol.RespondToHitUpdate; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.RespondToHit; @@ -125,8 +125,7 @@ public class RespondToHitSystems { } private static void queueUpdatesFor(Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.RespondToHit; + RespondToHitUpdate update = new RespondToHitUpdate(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entity/system/TransformSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/system/TransformSystems.java index 9b011a3c..ae0cdcad 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/system/TransformSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/system/TransformSystems.java @@ -14,11 +14,10 @@ import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.Direction; import com.hypixel.hytale.protocol.ModelTransform; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.TransformUpdate; import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; @@ -99,9 +98,7 @@ public class TransformSystems { @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, boolean newlyVisible ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Transform; - update.transform = sentTransform; + TransformUpdate update = new TransformUpdate(sentTransform); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { if (newlyVisible || !ref.equals(entry.getKey())) { diff --git a/src/com/hypixel/hytale/server/core/modules/entity/tracker/EntityTrackerSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/tracker/EntityTrackerSystems.java index dc18659f..0e8278d5 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/tracker/EntityTrackerSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/tracker/EntityTrackerSystems.java @@ -24,6 +24,7 @@ import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.EntityEffectsUpdate; import com.hypixel.hytale.protocol.packets.entities.EntityUpdates; import com.hypixel.hytale.server.core.entity.effect.EffectControllerComponent; import com.hypixel.hytale.server.core.modules.entity.EntityModule; @@ -380,8 +381,7 @@ public class EntityTrackerSystems { @Nonnull EffectControllerComponent effectControllerComponent, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityEffects; + EntityEffectsUpdate update = new EntityEffectsUpdate(); update.entityEffectUpdates = effectControllerComponent.createInitUpdates(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { @@ -395,8 +395,7 @@ public class EntityTrackerSystems { @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, @Nonnull Map, EntityTrackerSystems.EntityViewer> exclude ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityEffects; + EntityEffectsUpdate update = new EntityEffectsUpdate(); update.entityEffectUpdates = effectControllerComponent.consumeChanges(); if (!exclude.isEmpty()) { for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { diff --git a/src/com/hypixel/hytale/server/core/modules/entity/tracker/LegacyEntityTrackerSystems.java b/src/com/hypixel/hytale/server/core/modules/entity/tracker/LegacyEntityTrackerSystems.java index c565d5c5..57ddbaa3 100644 --- a/src/com/hypixel/hytale/server/core/modules/entity/tracker/LegacyEntityTrackerSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entity/tracker/LegacyEntityTrackerSystems.java @@ -13,10 +13,11 @@ import com.hypixel.hytale.component.dependency.SystemDependency; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.math.vector.Vector3d; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; -import com.hypixel.hytale.protocol.Equipment; +import com.hypixel.hytale.protocol.EquipmentUpdate; import com.hypixel.hytale.protocol.ItemArmorSlot; +import com.hypixel.hytale.protocol.ModelUpdate; +import com.hypixel.hytale.protocol.PlayerSkinUpdate; +import com.hypixel.hytale.protocol.PropUpdate; import com.hypixel.hytale.server.core.asset.type.gameplay.PlayerConfig; import com.hypixel.hytale.server.core.entity.Entity; import com.hypixel.hytale.server.core.entity.EntityUtils; @@ -132,19 +133,14 @@ public class LegacyEntityTrackerSystems { boolean isProp, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Model; - update.model = model != null ? model.getModel().toPacket() : null; - update.entityScale = entityScale; + ModelUpdate update = new ModelUpdate(model != null ? model.getModel().toPacket() : null, entityScale); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); } if (isProp) { - ComponentUpdate propUpdate = new ComponentUpdate(); - propUpdate.type = ComponentUpdateType.Prop; - propUpdate.isProp = true; + PropUpdate propUpdate = new PropUpdate(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, propUpdate); @@ -211,8 +207,7 @@ public class LegacyEntityTrackerSystems { private static void queueUpdatesFor( Ref ref, @Nonnull PlayerSkinComponent component, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.PlayerSkin; + PlayerSkinUpdate update = new PlayerSkinUpdate(); update.skin = component.getPlayerSkin(); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { @@ -274,14 +269,12 @@ public class LegacyEntityTrackerSystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull LivingEntity entity, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Equipment; - update.equipment = new Equipment(); + EquipmentUpdate update = new EquipmentUpdate(); Inventory inventory = entity.getInventory(); ItemContainer armor = inventory.getArmor(); - update.equipment.armorIds = new String[armor.getCapacity()]; - Arrays.fill(update.equipment.armorIds, ""); - armor.forEachWithMeta((slot, itemStack, armorIds) -> armorIds[slot] = itemStack.getItemId(), update.equipment.armorIds); + update.armorIds = new String[armor.getCapacity()]; + Arrays.fill(update.armorIds, ""); + armor.forEachWithMeta((slot, itemStack, armorIds) -> armorIds[slot] = itemStack.getItemId(), update.armorIds); Store store = ref.getStore(); PlayerSettings playerSettings = store.getComponent(ref, PlayerSettings.getComponentType()); if (playerSettings != null) { @@ -291,26 +284,26 @@ public class LegacyEntityTrackerSystems { .getPlayerConfig() .getArmorVisibilityOption(); if (armorVisibilityOption.canHideHelmet() && playerSettings.hideHelmet()) { - update.equipment.armorIds[ItemArmorSlot.Head.ordinal()] = ""; + update.armorIds[ItemArmorSlot.Head.ordinal()] = ""; } if (armorVisibilityOption.canHideCuirass() && playerSettings.hideCuirass()) { - update.equipment.armorIds[ItemArmorSlot.Chest.ordinal()] = ""; + update.armorIds[ItemArmorSlot.Chest.ordinal()] = ""; } if (armorVisibilityOption.canHideGauntlets() && playerSettings.hideGauntlets()) { - update.equipment.armorIds[ItemArmorSlot.Hands.ordinal()] = ""; + update.armorIds[ItemArmorSlot.Hands.ordinal()] = ""; } if (armorVisibilityOption.canHidePants() && playerSettings.hidePants()) { - update.equipment.armorIds[ItemArmorSlot.Legs.ordinal()] = ""; + update.armorIds[ItemArmorSlot.Legs.ordinal()] = ""; } } ItemStack itemInHand = inventory.getItemInHand(); - update.equipment.rightHandItemId = itemInHand != null ? itemInHand.getItemId() : "Empty"; + update.rightHandItemId = itemInHand != null ? itemInHand.getItemId() : "Empty"; ItemStack utilityItem = inventory.getUtilityItem(); - update.equipment.leftHandItemId = utilityItem != null ? utilityItem.getItemId() : "Empty"; + update.leftHandItemId = utilityItem != null ? utilityItem.getItemId() : "Empty"; for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatMap.java b/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatMap.java index 8902ce7f..8b1bea91 100644 --- a/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatMap.java +++ b/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatMap.java @@ -505,12 +505,30 @@ public class EntityStatMap implements Component { map.update(); for (int i = 0; i < this.values.length; i++) { - map.values[i].set(this.values[i].get()); + if (this.values[i] != null) { + EntityStatValue value = this.values[i]; + map.values[i].set(value.get()); + Map modifiers = value.getModifiers(); + if (modifiers != null) { + for (java.util.Map.Entry entry : modifiers.entrySet()) { + map.values[i].putModifier(entry.getKey(), entry.getValue()); + } + } + } + } + + for (Entry> entry : this.selfUpdates.int2ObjectEntrySet()) { + map.selfUpdates.put(entry.getIntKey(), new ObjectArrayList<>(entry.getValue())); + } + + for (Entry entry : this.selfStatValues.int2ObjectEntrySet()) { + map.selfStatValues.put(entry.getIntKey(), new FloatArrayList(entry.getValue())); + } + + for (Entry> entry : this.otherUpdates.int2ObjectEntrySet()) { + map.otherUpdates.put(entry.getIntKey(), new ObjectArrayList<>(entry.getValue())); } - map.selfUpdates.putAll(this.selfUpdates); - map.selfStatValues.putAll(this.selfStatValues); - map.otherUpdates.putAll(this.otherUpdates); return map; } diff --git a/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatsSystems.java b/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatsSystems.java index 685dec47..eff8bc7a 100644 --- a/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatsSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entitystats/EntityStatsSystems.java @@ -19,9 +19,9 @@ import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.ISystem; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.EntityStatUpdate; +import com.hypixel.hytale.protocol.EntityStatsUpdate; import com.hypixel.hytale.protocol.InteractionType; import com.hypixel.hytale.server.core.asset.type.item.config.Item; import com.hypixel.hytale.server.core.entity.EntityUtils; @@ -320,17 +320,13 @@ public class EntityStatsSystems { if (statMap.consumeSelfNetworkOutdated()) { EntityTrackerSystems.EntityViewer selfEntityViewer = visible.visibleTo.get(ref); if (selfEntityViewer != null && !visible.newlyVisibleTo.containsKey(ref)) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityStats; - update.entityStatUpdates = statMap.consumeSelfUpdates(); + EntityStatsUpdate update = new EntityStatsUpdate(statMap.consumeSelfUpdates()); selfEntityViewer.queueUpdate(ref, update); } } if (statMap.consumeNetworkOutdated()) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityStats; - update.entityStatUpdates = statMap.consumeOtherUpdates(); + EntityStatsUpdate update = new EntityStatsUpdate(statMap.consumeOtherUpdates()); for (Entry, EntityTrackerSystems.EntityViewer> entry : visible.visibleTo.entrySet()) { Ref viewerRef = entry.getKey(); @@ -344,9 +340,7 @@ public class EntityStatsSystems { private static void queueUpdatesForNewlyVisible( @Nonnull Ref ref, @Nonnull EntityStatMap statMap, @Nonnull Map, EntityTrackerSystems.EntityViewer> newlyVisibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityStats; - update.entityStatUpdates = statMap.createInitUpdate(false); + EntityStatsUpdate update = new EntityStatsUpdate(statMap.createInitUpdate(false)); for (Entry, EntityTrackerSystems.EntityViewer> entry : newlyVisibleTo.entrySet()) { if (ref.equals(entry.getKey())) { @@ -360,9 +354,7 @@ public class EntityStatsSystems { private static void queueUpdateForNewlyVisibleSelf( Ref ref, @Nonnull EntityStatMap statMap, @Nonnull EntityTrackerSystems.EntityViewer viewer ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.EntityStats; - update.entityStatUpdates = statMap.createInitUpdate(true); + EntityStatsUpdate update = new EntityStatsUpdate(statMap.createInitUpdate(true)); viewer.queueUpdate(ref, update); } } diff --git a/src/com/hypixel/hytale/server/core/modules/entitystats/asset/EntityStatTypePacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/entitystats/asset/EntityStatTypePacketGenerator.java index b3bd114e..a50741e3 100644 --- a/src/com/hypixel/hytale/server/core/modules/entitystats/asset/EntityStatTypePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/entitystats/asset/EntityStatTypePacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.modules.entitystats.asset; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateEntityStatTypes; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -13,7 +13,7 @@ import javax.annotation.Nonnull; public class EntityStatTypePacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateEntityStatTypes packet = new UpdateEntityStatTypes(); packet.type = UpdateType.Init; packet.types = new Int2ObjectOpenHashMap<>(); @@ -33,7 +33,9 @@ public class EntityStatTypePacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateEntityStatTypes packet = new UpdateEntityStatTypes(); packet.type = UpdateType.AddOrUpdate; packet.types = new Int2ObjectOpenHashMap<>(); @@ -53,7 +55,7 @@ public class EntityStatTypePacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateEntityStatTypes packet = new UpdateEntityStatTypes(); packet.type = UpdateType.Remove; packet.types = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/entityui/UIComponentSystems.java b/src/com/hypixel/hytale/server/core/modules/entityui/UIComponentSystems.java index 2972872e..4132c1fa 100644 --- a/src/com/hypixel/hytale/server/core/modules/entityui/UIComponentSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/entityui/UIComponentSystems.java @@ -13,8 +13,8 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.UIComponentsUpdate; import com.hypixel.hytale.server.core.modules.entity.AllLegacyLivingEntityTypesQuery; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; @@ -153,9 +153,7 @@ public class UIComponentSystems { private static void queueUpdatesFor( Ref ref, @Nonnull UIComponentList uiComponentList, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.UIComponents; - update.entityUIComponents = uiComponentList.getComponentIds(); + UIComponentsUpdate update = new UIComponentsUpdate(uiComponentList.getComponentIds()); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/entityui/asset/EntityUIComponentPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/entityui/asset/EntityUIComponentPacketGenerator.java index 5d9c9744..bb5c4eeb 100644 --- a/src/com/hypixel/hytale/server/core/modules/entityui/asset/EntityUIComponentPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/entityui/asset/EntityUIComponentPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.entityui.asset; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateEntityUIComponents; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,9 @@ import javax.annotation.Nonnull; public class EntityUIComponentPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets + ) { Int2ObjectMap configs = new Int2ObjectOpenHashMap<>(); for (Entry entry : assets.entrySet()) { @@ -26,7 +28,7 @@ public class EntityUIComponentPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query @@ -41,7 +43,7 @@ public class EntityUIComponentPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap configs = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/InteractionPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/InteractionPacketGenerator.java index f27a3124..b0bbdf09 100644 --- a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/InteractionPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/InteractionPacketGenerator.java @@ -2,8 +2,8 @@ package com.hypixel.hytale.server.core.modules.interaction.interaction; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.SimpleInteraction; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateInteractions; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -17,7 +17,7 @@ import javax.annotation.Nonnull; public class InteractionPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { Int2ObjectMap interactions = new Int2ObjectOpenHashMap<>(); for (Entry entry : assets.entrySet()) { @@ -28,7 +28,7 @@ public class InteractionPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap interactions = new Int2ObjectOpenHashMap<>(); @@ -41,7 +41,7 @@ public class InteractionPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap interactions = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/RootInteractionPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/RootInteractionPacketGenerator.java index b99b401b..bf348407 100644 --- a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/RootInteractionPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/RootInteractionPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.interaction.interaction; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateRootInteractions; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -16,7 +16,7 @@ import javax.annotation.Nonnull; public class RootInteractionPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { Int2ObjectMap interactions = new Int2ObjectOpenHashMap<>(); for (Entry entry : assets.entrySet()) { @@ -27,7 +27,7 @@ public class RootInteractionPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query @@ -42,7 +42,7 @@ public class RootInteractionPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query ) { Int2ObjectMap interactions = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/UnarmedInteractionsPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/UnarmedInteractionsPacketGenerator.java index c5e253ad..1ae7aae4 100644 --- a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/UnarmedInteractionsPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/UnarmedInteractionsPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.interaction.interaction; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; import com.hypixel.hytale.protocol.InteractionType; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateUnarmedInteractions; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -16,7 +16,7 @@ import javax.annotation.Nonnull; public class UnarmedInteractionsPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { UpdateUnarmedInteractions packet = new UpdateUnarmedInteractions(); packet.type = UpdateType.Init; UnarmedInteractions unarmedInteraction = assetMap.getAsset("Empty"); @@ -32,7 +32,7 @@ public class UnarmedInteractionsPacketGenerator extends DefaultAssetPacketGenera @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateUnarmedInteractions packet = new UpdateUnarmedInteractions(); packet.type = UpdateType.AddOrUpdate; UnarmedInteractions unarmedInteraction = loadedAssets.get("Empty"); @@ -48,7 +48,7 @@ public class UnarmedInteractionsPacketGenerator extends DefaultAssetPacketGenera @Nonnull @Override - public Packet generateRemovePacket(Set removed) { + public ToClientPacket generateRemovePacket(Set removed) { UpdateUnarmedInteractions packet = new UpdateUnarmedInteractions(); packet.type = UpdateType.Remove; return packet; diff --git a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/config/server/ModifyInventoryInteraction.java b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/config/server/ModifyInventoryInteraction.java index b582645d..ee60cbd9 100644 --- a/src/com/hypixel/hytale/server/core/modules/interaction/interaction/config/server/ModifyInventoryInteraction.java +++ b/src/com/hypixel/hytale/server/core/modules/interaction/interaction/config/server/ModifyInventoryInteraction.java @@ -121,7 +121,7 @@ public class ModifyInventoryInteraction extends SimpleInstantInteraction { } else { boolean hasRequiredGameMode = this.requiredGameMode == null || playerComponent.getGameMode() == this.requiredGameMode; if (hasRequiredGameMode) { - CombinedItemContainer combinedHotbarFirst = playerComponent.getInventory().getCombinedHotbarFirst(); + CombinedItemContainer combinedHotbarFirst = playerComponent.getInventory().getCombinedBackpackStorageHotbarFirst(); if (this.itemToRemove != null) { ItemStackTransaction removeItemStack = combinedHotbarFirst.removeItemStack(this.itemToRemove, true, true); if (!removeItemStack.succeeded()) { diff --git a/src/com/hypixel/hytale/server/core/modules/interaction/system/InteractionSystems.java b/src/com/hypixel/hytale/server/core/modules/interaction/system/InteractionSystems.java index d0e62bd4..68c2756e 100644 --- a/src/com/hypixel/hytale/server/core/modules/interaction/system/InteractionSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/interaction/system/InteractionSystems.java @@ -15,9 +15,9 @@ import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.logger.HytaleLogger; -import com.hypixel.hytale.protocol.ComponentUpdate; import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.InteractionType; +import com.hypixel.hytale.protocol.InteractionsUpdate; import com.hypixel.hytale.protocol.packets.interaction.SyncInteractionChain; import com.hypixel.hytale.protocol.packets.interaction.SyncInteractionChains; import com.hypixel.hytale.server.core.entity.InteractionManager; @@ -241,16 +241,13 @@ public class InteractionSystems { private static void queueUpdatesFor( @Nonnull Ref ref, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo, @Nonnull Interactions component ) { - ComponentUpdate componentUpdate = new ComponentUpdate(); - componentUpdate.type = ComponentUpdateType.Interactions; Object2IntOpenHashMap interactions = new Object2IntOpenHashMap<>(); for (Entry entry : component.getInteractions().entrySet()) { interactions.put(entry.getKey(), RootInteraction.getRootInteractionIdOrUnknown(entry.getValue())); } - componentUpdate.interactions = interactions; - componentUpdate.interactionHint = component.getInteractionHint(); + InteractionsUpdate componentUpdate = new InteractionsUpdate(interactions, component.getInteractionHint()); for (EntityTrackerSystems.EntityViewer viewer : visibleTo.values()) { viewer.queueUpdate(ref, componentUpdate); diff --git a/src/com/hypixel/hytale/server/core/modules/item/CraftingRecipePacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/item/CraftingRecipePacketGenerator.java index 8521e2c5..0825ae83 100644 --- a/src/com/hypixel/hytale/server/core/modules/item/CraftingRecipePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/item/CraftingRecipePacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.item; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateRecipes; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class CraftingRecipePacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateRecipes packet = new UpdateRecipes(); packet.type = UpdateType.Init; packet.recipes = new Object2ObjectOpenHashMap<>(); @@ -28,7 +28,7 @@ public class CraftingRecipePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateRecipes packet = new UpdateRecipes(); @@ -43,7 +43,7 @@ public class CraftingRecipePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket(DefaultAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { UpdateRecipes packet = new UpdateRecipes(); packet.type = UpdateType.Remove; packet.removedRecipes = removed.toArray(String[]::new); diff --git a/src/com/hypixel/hytale/server/core/modules/item/ItemPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/item/ItemPacketGenerator.java index f3ff26de..07405044 100644 --- a/src/com/hypixel/hytale/server/core/modules/item/ItemPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/item/ItemPacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.item; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateItems; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class ItemPacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateItems packet = new UpdateItems(); packet.type = UpdateType.Init; packet.items = new Object2ObjectOpenHashMap<>(); @@ -30,7 +30,7 @@ public class ItemPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateUpdatePacket(DefaultAssetMap assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query) { UpdateItems packet = new UpdateItems(); packet.type = UpdateType.AddOrUpdate; packet.items = new Object2ObjectOpenHashMap<>(); @@ -46,7 +46,7 @@ public class ItemPacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket(DefaultAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { UpdateItems packet = new UpdateItems(); packet.type = UpdateType.Remove; packet.removedItems = removed.toArray(String[]::new); diff --git a/src/com/hypixel/hytale/server/core/modules/item/ItemQualityPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/item/ItemQualityPacketGenerator.java index f9d6ad79..767e4069 100644 --- a/src/com/hypixel/hytale/server/core/modules/item/ItemQualityPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/item/ItemQualityPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.modules.item; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateItemQualities; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -14,7 +14,7 @@ import javax.annotation.Nonnull; public class ItemQualityPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { UpdateItemQualities packet = new UpdateItemQualities(); packet.type = UpdateType.Init; packet.itemQualities = new Int2ObjectOpenHashMap<>(); @@ -34,7 +34,9 @@ public class ItemQualityPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Map loadedAssets) { + protected ToClientPacket generateUpdatePacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets + ) { UpdateItemQualities packet = new UpdateItemQualities(); packet.type = UpdateType.AddOrUpdate; packet.itemQualities = new Int2ObjectOpenHashMap<>(); @@ -54,7 +56,7 @@ public class ItemQualityPacketGenerator extends SimpleAssetPacketGenerator assetMap, @Nonnull Set removed) { + protected ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateItemQualities packet = new UpdateItemQualities(); packet.type = UpdateType.Remove; packet.itemQualities = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/item/ItemReticleConfigPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/item/ItemReticleConfigPacketGenerator.java index a105b638..c8477f8d 100644 --- a/src/com/hypixel/hytale/server/core/modules/item/ItemReticleConfigPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/item/ItemReticleConfigPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.modules.item; import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateItemReticles; import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator; @@ -15,7 +15,9 @@ import javax.annotation.Nonnull; public class ItemReticleConfigPacketGenerator extends SimpleAssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket( + @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map assets + ) { UpdateItemReticles packet = new UpdateItemReticles(); packet.type = UpdateType.Init; packet.itemReticleConfigs = new Int2ObjectOpenHashMap<>(); @@ -35,7 +37,7 @@ public class ItemReticleConfigPacketGenerator } @Nonnull - public Packet generateUpdatePacket( + public ToClientPacket generateUpdatePacket( @Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Map loadedAssets ) { UpdateItemReticles packet = new UpdateItemReticles(); @@ -57,7 +59,7 @@ public class ItemReticleConfigPacketGenerator } @Nonnull - public Packet generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull IndexedLookupTableAssetMap assetMap, @Nonnull Set removed) { UpdateItemReticles packet = new UpdateItemReticles(); packet.type = UpdateType.Remove; packet.itemReticleConfigs = new Int2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/item/RecipePacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/item/RecipePacketGenerator.java index 9fc4cf7e..b46966e9 100644 --- a/src/com/hypixel/hytale/server/core/modules/item/RecipePacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/item/RecipePacketGenerator.java @@ -2,7 +2,7 @@ package com.hypixel.hytale.server.core.modules.item; import com.hypixel.hytale.assetstore.AssetUpdateQuery; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateRecipes; import com.hypixel.hytale.server.core.asset.packet.AssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nonnull; public class RecipePacketGenerator extends AssetPacketGenerator> { @Nonnull - public Packet generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { + public ToClientPacket generateInitPacket(DefaultAssetMap assetMap, @Nonnull Map assets) { UpdateRecipes packet = new UpdateRecipes(); packet.type = UpdateType.Init; packet.recipes = new Object2ObjectOpenHashMap<>(); @@ -28,7 +28,7 @@ public class RecipePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Map loadedAssets, @Nonnull AssetUpdateQuery query ) { UpdateRecipes packet = new UpdateRecipes(); @@ -43,7 +43,7 @@ public class RecipePacketGenerator extends AssetPacketGenerator assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { + public ToClientPacket generateRemovePacket(DefaultAssetMap assetMap, @Nonnull Set removed, @Nonnull AssetUpdateQuery query) { UpdateRecipes packet = new UpdateRecipes(); packet.type = UpdateType.Remove; packet.recipes = new Object2ObjectOpenHashMap<>(); diff --git a/src/com/hypixel/hytale/server/core/modules/projectile/config/ProjectileConfigPacketGenerator.java b/src/com/hypixel/hytale/server/core/modules/projectile/config/ProjectileConfigPacketGenerator.java index afc33acc..cbc2862b 100644 --- a/src/com/hypixel/hytale/server/core/modules/projectile/config/ProjectileConfigPacketGenerator.java +++ b/src/com/hypixel/hytale/server/core/modules/projectile/config/ProjectileConfigPacketGenerator.java @@ -1,7 +1,7 @@ package com.hypixel.hytale.server.core.modules.projectile.config; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.UpdateType; import com.hypixel.hytale.protocol.packets.assets.UpdateProjectileConfigs; import com.hypixel.hytale.server.core.asset.packet.DefaultAssetPacketGenerator; @@ -15,7 +15,7 @@ import javax.annotation.Nullable; public class ProjectileConfigPacketGenerator extends DefaultAssetPacketGenerator { @Nonnull @Override - public Packet generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { + public ToClientPacket generateInitPacket(@Nonnull DefaultAssetMap assetMap, Map assets) { UpdateProjectileConfigs packet = new UpdateProjectileConfigs(); packet.type = UpdateType.Init; Map map = new Object2ObjectOpenHashMap<>(); @@ -32,7 +32,7 @@ public class ProjectileConfigPacketGenerator extends DefaultAssetPacketGenerator @Nonnull @Override - public Packet generateUpdatePacket(@Nonnull Map loadedAssets) { + public ToClientPacket generateUpdatePacket(@Nonnull Map loadedAssets) { UpdateProjectileConfigs packet = new UpdateProjectileConfigs(); packet.type = UpdateType.AddOrUpdate; Map map = new Object2ObjectOpenHashMap<>(); @@ -49,7 +49,7 @@ public class ProjectileConfigPacketGenerator extends DefaultAssetPacketGenerator @Nullable @Override - public Packet generateRemovePacket(@Nonnull Set removed) { + public ToClientPacket generateRemovePacket(@Nonnull Set removed) { UpdateProjectileConfigs packet = new UpdateProjectileConfigs(); packet.type = UpdateType.Remove; packet.removedConfigs = removed.toArray(String[]::new); diff --git a/src/com/hypixel/hytale/server/core/modules/projectile/system/PredictedProjectileSystems.java b/src/com/hypixel/hytale/server/core/modules/projectile/system/PredictedProjectileSystems.java index b40b7755..e15b9002 100644 --- a/src/com/hypixel/hytale/server/core/modules/projectile/system/PredictedProjectileSystems.java +++ b/src/com/hypixel/hytale/server/core/modules/projectile/system/PredictedProjectileSystems.java @@ -8,8 +8,7 @@ import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; +import com.hypixel.hytale.protocol.PredictionUpdate; import com.hypixel.hytale.server.core.modules.entity.tracker.EntityTrackerSystems; import com.hypixel.hytale.server.core.modules.projectile.component.PredictedProjectile; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; @@ -70,9 +69,7 @@ public class PredictedProjectileSystems { @Nonnull PredictedProjectile predictedProjectile, @Nonnull Map, EntityTrackerSystems.EntityViewer> visibleTo ) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Prediction; - update.predictionId = predictedProjectile.getUuid(); + PredictionUpdate update = new PredictionUpdate(predictedProjectile.getUuid()); for (Entry, EntityTrackerSystems.EntityViewer> entry : visibleTo.entrySet()) { entry.getValue().queueUpdate(ref, update); diff --git a/src/com/hypixel/hytale/server/core/modules/singleplayer/commands/PlayCommandBase.java b/src/com/hypixel/hytale/server/core/modules/singleplayer/commands/PlayCommandBase.java index c6170084..ecfc07c4 100644 --- a/src/com/hypixel/hytale/server/core/modules/singleplayer/commands/PlayCommandBase.java +++ b/src/com/hypixel/hytale/server/core/modules/singleplayer/commands/PlayCommandBase.java @@ -3,6 +3,7 @@ package com.hypixel.hytale.server.core.modules.singleplayer.commands; import com.hypixel.hytale.protocol.packets.serveraccess.Access; import com.hypixel.hytale.server.core.Constants; import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.Options; import com.hypixel.hytale.server.core.command.system.CommandContext; import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg; import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes; @@ -26,7 +27,9 @@ public abstract class PlayCommandBase extends CommandBase { @Override protected void executeSync(@Nonnull CommandContext context) { - if (!Constants.SINGLEPLAYER) { + if (Options.getOptionSet().valueOf(Options.AUTH_MODE) == Options.AuthMode.OFFLINE) { + context.sendMessage(Message.translation("server.commands.play.offlineMode")); + } else if (!Constants.SINGLEPLAYER) { switch (this.commandAccess) { case Private: context.sendMessage(Message.translation("server.commands.play.singleplayerOnlyPrivate")); diff --git a/src/com/hypixel/hytale/server/core/plugin/JavaPlugin.java b/src/com/hypixel/hytale/server/core/plugin/JavaPlugin.java index cd5f29f9..0638d888 100644 --- a/src/com/hypixel/hytale/server/core/plugin/JavaPlugin.java +++ b/src/com/hypixel/hytale/server/core/plugin/JavaPlugin.java @@ -1,10 +1,8 @@ package com.hypixel.hytale.server.core.plugin; -import com.hypixel.hytale.assetstore.AssetPack; import com.hypixel.hytale.common.plugin.PluginIdentifier; import com.hypixel.hytale.server.core.asset.AssetModule; import java.nio.file.Path; -import java.util.logging.Level; import javax.annotation.Nonnull; public abstract class JavaPlugin extends PluginBase { @@ -31,13 +29,7 @@ public abstract class JavaPlugin extends PluginBase { if (this.getManifest().includesAssetPack()) { AssetModule assetModule = AssetModule.get(); String id = new PluginIdentifier(this.getManifest()).toString(); - AssetPack existing = assetModule.getAssetPack(id); - if (existing != null) { - this.getLogger().at(Level.WARNING).log("Asset pack %s already exists, skipping embedded pack", id); - return; - } - - assetModule.registerPack(id, this.file, this.getManifest()); + assetModule.registerPack(id, this.file, this.getManifest(), true); } } diff --git a/src/com/hypixel/hytale/server/core/plugin/PluginManager.java b/src/com/hypixel/hytale/server/core/plugin/PluginManager.java index 6e286e77..1ce2d175 100644 --- a/src/com/hypixel/hytale/server/core/plugin/PluginManager.java +++ b/src/com/hypixel/hytale/server/core/plugin/PluginManager.java @@ -21,6 +21,7 @@ import com.hypixel.hytale.server.core.Options; import com.hypixel.hytale.server.core.ShutdownReason; import com.hypixel.hytale.server.core.asset.AssetModule; import com.hypixel.hytale.server.core.command.system.CommandManager; +import com.hypixel.hytale.server.core.config.ModConfig; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.event.events.player.AddPlayerToWorldEvent; import com.hypixel.hytale.server.core.plugin.commands.PluginCommand; @@ -114,7 +115,7 @@ public class PluginManager { private boolean canLoadOnBoot(@Nonnull PendingLoadPlugin plugin) { PluginIdentifier identifier = plugin.getIdentifier(); PluginManifest manifest = plugin.getManifest(); - HytaleServerConfig.ModConfig modConfig = HytaleServer.get().getConfig().getModConfig().get(identifier); + ModConfig modConfig = HytaleServer.get().getConfig().getModConfig().get(identifier); boolean enabled; if (modConfig != null && modConfig.getEnabled() != null) { enabled = modConfig.getEnabled(); @@ -296,9 +297,9 @@ public class PluginManager { StringBuilder sb = new StringBuilder(); - for (Entry entry : HytaleServer.get().getConfig().getModConfig().entrySet()) { + for (Entry entry : HytaleServer.get().getConfig().getModConfig().entrySet()) { PluginIdentifier identifier = entry.getKey(); - HytaleServerConfig.ModConfig modConfig = entry.getValue(); + ModConfig modConfig = entry.getValue(); SemverRange requiredVersion = modConfig.getRequiredVersion(); if (requiredVersion != null && !this.hasPlugin(identifier, requiredVersion)) { sb.append(String.format("%s, Version: %s\n", identifier, modConfig)); diff --git a/src/com/hypixel/hytale/server/core/plugin/commands/PluginCommand.java b/src/com/hypixel/hytale/server/core/plugin/commands/PluginCommand.java index 0f35e2c2..bbc0ba18 100644 --- a/src/com/hypixel/hytale/server/core/plugin/commands/PluginCommand.java +++ b/src/com/hypixel/hytale/server/core/plugin/commands/PluginCommand.java @@ -95,7 +95,7 @@ public class PluginCommand extends AbstractCommandCollection { if (identifier != null) { boolean onlyBootList = this.bootFlag.get(context); HytaleServerConfig serverConfig = HytaleServer.get().getConfig(); - HytaleServerConfig.ModConfig.setBoot(serverConfig, identifier, true); + HytaleServerConfig.setBoot(serverConfig, identifier, true); if (serverConfig.consumeHasChanged()) { HytaleServerConfig.save(serverConfig).join(); } @@ -221,7 +221,7 @@ public class PluginCommand extends AbstractCommandCollection { if (identifier != null) { boolean onlyBootList = this.bootFlag.get(context); HytaleServerConfig serverConfig = HytaleServer.get().getConfig(); - HytaleServerConfig.ModConfig.setBoot(serverConfig, identifier, false); + HytaleServerConfig.setBoot(serverConfig, identifier, false); if (serverConfig.consumeHasChanged()) { HytaleServerConfig.save(serverConfig).join(); } diff --git a/src/com/hypixel/hytale/server/core/receiver/IPacketReceiver.java b/src/com/hypixel/hytale/server/core/receiver/IPacketReceiver.java index 38171f17..7b10f9f4 100644 --- a/src/com/hypixel/hytale/server/core/receiver/IPacketReceiver.java +++ b/src/com/hypixel/hytale/server/core/receiver/IPacketReceiver.java @@ -1,10 +1,10 @@ package com.hypixel.hytale.server.core.receiver; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import javax.annotation.Nonnull; public interface IPacketReceiver { - void write(@Nonnull Packet var1); + void write(@Nonnull ToClientPacket var1); - void writeNoCache(@Nonnull Packet var1); + void writeNoCache(@Nonnull ToClientPacket var1); } diff --git a/src/com/hypixel/hytale/server/core/universe/Universe.java b/src/com/hypixel/hytale/server/core/universe/Universe.java index 0ecd55ac..64f0c8b9 100644 --- a/src/com/hypixel/hytale/server/core/universe/Universe.java +++ b/src/com/hypixel/hytale/server/core/universe/Universe.java @@ -22,8 +22,10 @@ import com.hypixel.hytale.math.vector.Transform; import com.hypixel.hytale.metrics.MetricProvider; import com.hypixel.hytale.metrics.MetricResults; import com.hypixel.hytale.metrics.MetricsRegistry; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.PlayerSkin; +import com.hypixel.hytale.protocol.ToClientPacket; +import com.hypixel.hytale.protocol.io.netty.ProtocolUtil; import com.hypixel.hytale.protocol.packets.setup.ServerTags; import com.hypixel.hytale.server.core.Constants; import com.hypixel.hytale.server.core.HytaleServer; @@ -33,6 +35,7 @@ import com.hypixel.hytale.server.core.NameMatching; import com.hypixel.hytale.server.core.Options; import com.hypixel.hytale.server.core.auth.PlayerAuthentication; import com.hypixel.hytale.server.core.command.system.CommandRegistry; +import com.hypixel.hytale.server.core.config.BackupConfig; import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule; import com.hypixel.hytale.server.core.entity.UUIDComponent; import com.hypixel.hytale.server.core.entity.entities.Player; @@ -83,6 +86,7 @@ import com.hypixel.hytale.server.core.universe.world.storage.provider.EmptyChunk import com.hypixel.hytale.server.core.universe.world.storage.provider.IChunkStorageProvider; import com.hypixel.hytale.server.core.universe.world.storage.provider.IndexedStorageChunkStorageProvider; import com.hypixel.hytale.server.core.universe.world.storage.provider.MigrationChunkStorageProvider; +import com.hypixel.hytale.server.core.universe.world.storage.provider.RocksDbChunkStorageProvider; import com.hypixel.hytale.server.core.universe.world.storage.resources.DefaultResourceStorageProvider; import com.hypixel.hytale.server.core.universe.world.storage.resources.DiskResourceStorageProvider; import com.hypixel.hytale.server.core.universe.world.storage.resources.EmptyResourceStorageProvider; @@ -102,6 +106,9 @@ import com.hypixel.hytale.server.core.util.backup.BackupTask; import com.hypixel.hytale.server.core.util.io.FileUtil; import com.hypixel.hytale.sneakythrow.SneakyThrow; import io.netty.channel.Channel; +import io.netty.handler.codec.quic.QuicChannel; +import io.netty.handler.codec.quic.QuicStreamChannel; +import io.netty.handler.codec.quic.QuicStreamType; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.io.IOException; @@ -156,7 +163,6 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv private final Map unmodifiableWorlds = Collections.unmodifiableMap(this.worlds); private PlayerStorage playerStorage; private WorldConfigProvider worldConfigProvider; - private ResourceType indexedStorageCacheResourceType; private ResourceType worldMarkersResourceType; private CompletableFuture universeReady; private final AtomicBoolean isBackingUp = new AtomicBoolean(false); @@ -171,13 +177,14 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv if (!Files.isDirectory(this.path) && !Options.getOptionSet().has(Options.BARE)) { try { Files.createDirectories(this.path); - } catch (IOException var3) { - throw new RuntimeException("Failed to create universe directory", var3); + } catch (IOException var4) { + throw new RuntimeException("Failed to create universe directory", var4); } } - if (Options.getOptionSet().has(Options.BACKUP)) { - int frequencyMinutes = Math.max(Options.getOptionSet().valueOf(Options.BACKUP_FREQUENCY_MINUTES), 1); + BackupConfig backupConfig = HytaleServer.get().getConfig().getBackupConfig(); + if (backupConfig.isConfigured()) { + int frequencyMinutes = backupConfig.getFrequencyMinutes(); this.getLogger().at(Level.INFO).log("Scheduled backup to run every %d minute(s)", frequencyMinutes); HytaleServer.SCHEDULED_EXECUTOR.scheduleWithFixedDelay(() -> { if (!this.isBackingUp.compareAndSet(false, true)) { @@ -204,18 +211,21 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv @Nonnull public CompletableFuture runBackup() { - return CompletableFuture.allOf(this.worlds.values().stream().map(world -> CompletableFuture.supplyAsync(() -> { - Store componentStore = world.getChunkStore().getStore(); - ChunkSavingSystems.Data data = componentStore.getResource(ChunkStore.SAVE_RESOURCE); - data.isSaving = false; - return data; - }, world).thenCompose(ChunkSavingSystems.Data::waitForSavingChunks)).toArray(CompletableFuture[]::new)) - .thenCompose(aVoid -> BackupTask.start(this.path, Options.getOptionSet().valueOf(Options.BACKUP_DIRECTORY))) - .thenCompose(success -> CompletableFuture.allOf(this.worlds.values().stream().map(world -> CompletableFuture.runAsync(() -> { - Store componentStore = world.getChunkStore().getStore(); - ChunkSavingSystems.Data data = componentStore.getResource(ChunkStore.SAVE_RESOURCE); - data.isSaving = true; - }, world)).toArray(CompletableFuture[]::new)).thenApply(aVoid -> success)); + Path backupDir = HytaleServer.get().getConfig().getBackupConfig().getDirectory(); + return backupDir == null + ? CompletableFuture.failedFuture(new IllegalStateException("Backup directory not configured")) + : CompletableFuture.allOf(this.worlds.values().stream().map(world -> CompletableFuture.supplyAsync(() -> { + Store componentStore = world.getChunkStore().getStore(); + ChunkSavingSystems.Data data = componentStore.getResource(ChunkStore.SAVE_RESOURCE); + data.isSaving = false; + return data; + }, world).thenCompose(ChunkSavingSystems.Data::waitForSavingChunks)).toArray(CompletableFuture[]::new)) + .thenCompose(aVoid -> BackupTask.start(this.path, backupDir)) + .thenCompose(success -> CompletableFuture.allOf(this.worlds.values().stream().map(world -> CompletableFuture.runAsync(() -> { + Store componentStore = world.getChunkStore().getStore(); + ChunkSavingSystems.Data data = componentStore.getResource(ChunkStore.SAVE_RESOURCE); + data.isSaving = true; + }, world)).toArray(CompletableFuture[]::new)).thenApply(aVoid -> success)); } @Override @@ -237,15 +247,12 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv IChunkStorageProvider.CODEC.register(Priority.DEFAULT, "Hytale", DefaultChunkStorageProvider.class, DefaultChunkStorageProvider.CODEC); IChunkStorageProvider.CODEC.register("Migration", MigrationChunkStorageProvider.class, MigrationChunkStorageProvider.CODEC); IChunkStorageProvider.CODEC.register("IndexedStorage", IndexedStorageChunkStorageProvider.class, IndexedStorageChunkStorageProvider.CODEC); + IChunkStorageProvider.CODEC.register("RocksDb", RocksDbChunkStorageProvider.class, RocksDbChunkStorageProvider.CODEC); IChunkStorageProvider.CODEC.register("Empty", EmptyChunkStorageProvider.class, EmptyChunkStorageProvider.CODEC); IResourceStorageProvider.CODEC.register(Priority.DEFAULT, "Hytale", DefaultResourceStorageProvider.class, DefaultResourceStorageProvider.CODEC); IResourceStorageProvider.CODEC.register("Disk", DiskResourceStorageProvider.class, DiskResourceStorageProvider.CODEC); IResourceStorageProvider.CODEC.register("Empty", EmptyResourceStorageProvider.class, EmptyResourceStorageProvider.CODEC); - this.indexedStorageCacheResourceType = chunkStoreRegistry.registerResource( - IndexedStorageChunkStorageProvider.IndexedStorageCache.class, IndexedStorageChunkStorageProvider.IndexedStorageCache::new - ); this.worldMarkersResourceType = chunkStoreRegistry.registerResource(WorldMarkersResource.class, "SharedUserMapMarkers", WorldMarkersResource.CODEC); - chunkStoreRegistry.registerSystem(new IndexedStorageChunkStorageProvider.IndexedStorageCacheSetupSystem()); chunkStoreRegistry.registerSystem(new WorldPregenerateSystem()); entityStoreRegistry.registerSystem(new WorldConfigSaveSystem()); this.playerRefComponentType = entityStoreRegistry.registerComponent(PlayerRef.class, () -> { @@ -387,10 +394,6 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv return this.universeReady; } - public ResourceType getIndexedStorageCacheResourceType() { - return this.indexedStorageCacheResourceType; - } - public ResourceType getWorldMarkersResourceType() { return this.worldMarkersResourceType; } @@ -429,12 +432,12 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv } if (chunkStorageType != null && !"default".equals(chunkStorageType)) { - BuilderCodec providerCodec = IChunkStorageProvider.CODEC.getCodecFor(chunkStorageType); + BuilderCodec> providerCodec = IChunkStorageProvider.CODEC.getCodecFor(chunkStorageType); if (providerCodec == null) { throw new IllegalArgumentException("Unknown chunkStorageType '" + chunkStorageType + "'"); } - IChunkStorageProvider provider = providerCodec.getDefaultValue(); + IChunkStorageProvider provider = (IChunkStorageProvider)providerCodec.getDefaultValue(); worldConfig.setChunkStorageProvider(provider); worldConfig.markChanged(); } @@ -700,8 +703,29 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv GamePacketHandler playerConnection = new GamePacketHandler(channel, protocolVersion, auth); playerConnection.setQueuePackets(false); this.getLogger().at(Level.INFO).log("Adding player '%s (%s)", username, uuid); - return this.playerStorage - .load(uuid) + CompletableFuture setupFuture; + if (channel instanceof QuicStreamChannel streamChannel) { + QuicChannel conn = streamChannel.parent(); + conn.attr(ProtocolUtil.STREAM_CHANNEL_KEY).set(NetworkChannel.Default); + streamChannel.updatePriority(PacketHandler.DEFAULT_STREAM_PRIORITIES.get(NetworkChannel.Default)); + CompletableFuture chunkFuture = NettyUtil.createStream( + conn, QuicStreamType.UNIDIRECTIONAL, NetworkChannel.Chunks, PacketHandler.DEFAULT_STREAM_PRIORITIES.get(NetworkChannel.Chunks), playerConnection + ); + CompletableFuture worldMapFuture = NettyUtil.createStream( + conn, + QuicStreamType.UNIDIRECTIONAL, + NetworkChannel.WorldMap, + PacketHandler.DEFAULT_STREAM_PRIORITIES.get(NetworkChannel.WorldMap), + playerConnection + ); + setupFuture = CompletableFuture.allOf(chunkFuture, worldMapFuture); + } else { + playerConnection.setChannel(NetworkChannel.WorldMap, channel); + playerConnection.setChannel(NetworkChannel.Chunks, channel); + setupFuture = CompletableFuture.completedFuture(null); + } + + return setupFuture., Holder>thenCombine(this.playerStorage.load(uuid), (setupResult, playerData) -> playerData) .exceptionally(throwable -> { throw new RuntimeException("Exception when adding player to universe:", throwable); }) @@ -945,19 +969,19 @@ public class Universe extends JavaPlugin implements IMessageReceiver, MetricProv } } - public void broadcastPacket(@Nonnull Packet packet) { + public void broadcastPacket(@Nonnull ToClientPacket packet) { for (PlayerRef player : this.players.values()) { player.getPacketHandler().write(packet); } } - public void broadcastPacketNoCache(@Nonnull Packet packet) { + public void broadcastPacketNoCache(@Nonnull ToClientPacket packet) { for (PlayerRef player : this.players.values()) { player.getPacketHandler().writeNoCache(packet); } } - public void broadcastPacket(@Nonnull Packet... packets) { + public void broadcastPacket(@Nonnull ToClientPacket... packets) { for (PlayerRef player : this.players.values()) { player.getPacketHandler().write(packets); } diff --git a/src/com/hypixel/hytale/server/core/universe/world/PlayerUtil.java b/src/com/hypixel/hytale/server/core/universe/world/PlayerUtil.java index ede7be56..f0afac45 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/PlayerUtil.java +++ b/src/com/hypixel/hytale/server/core/universe/world/PlayerUtil.java @@ -5,7 +5,7 @@ import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.function.consumer.TriConsumer; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.asset.type.model.config.Model; import com.hypixel.hytale.server.core.cosmetics.CosmeticsModule; @@ -78,7 +78,7 @@ public class PlayerUtil { } } - public static void broadcastPacketToPlayers(@Nonnull ComponentAccessor componentAccessor, @Nonnull Packet packet) { + public static void broadcastPacketToPlayers(@Nonnull ComponentAccessor componentAccessor, @Nonnull ToClientPacket packet) { World world = componentAccessor.getExternalData().getWorld(); for (PlayerRef targetPlayerRef : world.getPlayerRefs()) { @@ -86,7 +86,7 @@ public class PlayerUtil { } } - public static void broadcastPacketToPlayersNoCache(@Nonnull ComponentAccessor componentAccessor, @Nonnull Packet packet) { + public static void broadcastPacketToPlayersNoCache(@Nonnull ComponentAccessor componentAccessor, @Nonnull ToClientPacket packet) { World world = componentAccessor.getExternalData().getWorld(); for (PlayerRef targetPlayerRef : world.getPlayerRefs()) { @@ -94,7 +94,7 @@ public class PlayerUtil { } } - public static void broadcastPacketToPlayers(@Nonnull ComponentAccessor componentAccessor, @Nonnull Packet... packets) { + public static void broadcastPacketToPlayers(@Nonnull ComponentAccessor componentAccessor, @Nonnull ToClientPacket... packets) { World world = componentAccessor.getExternalData().getWorld(); for (PlayerRef targetPlayerRef : world.getPlayerRefs()) { diff --git a/src/com/hypixel/hytale/server/core/universe/world/World.java b/src/com/hypixel/hytale/server/core/universe/world/World.java index 73fd471d..c4ee429d 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/World.java +++ b/src/com/hypixel/hytale/server/core/universe/world/World.java @@ -398,6 +398,7 @@ public class World extends TickingThread implements Executor, ExecutorMetricsReg this.consumeTaskQueue(); this.entityStore.shutdown(); this.consumeTaskQueue(); + this.eventRegistry.shutdownAndCleanup(true); } finally { this.logger.at(Level.INFO).log("Saving Config..."); if (this.worldConfig.isSavingConfig()) { @@ -958,7 +959,7 @@ public class World extends TickingThread implements Executor, ExecutorMetricsReg LegacyEntityTrackerSystems.clear(playerComponent, holder); ChunkTracker chunkTrackerComponent = holder.getComponent(ChunkTracker.getComponentType()); if (chunkTrackerComponent != null) { - chunkTrackerComponent.clear(); + chunkTrackerComponent.unloadAll(playerRefComponent); } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/WorldConfig.java b/src/com/hypixel/hytale/server/core/universe/world/WorldConfig.java index 4df8241e..7977d7c4 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/WorldConfig.java +++ b/src/com/hypixel/hytale/server/core/universe/world/WorldConfig.java @@ -82,7 +82,7 @@ public class WorldConfig { .add() .append(new KeyedCodec<>("WorldMap", IWorldMapProvider.CODEC), (o, i) -> o.worldMapProvider = i, o -> o.worldMapProvider) .add() - .append( + .>append( new KeyedCodec<>("ChunkStorage", IChunkStorageProvider.CODEC), (o, i) -> o.chunkStorageProvider = i, o -> o.chunkStorageProvider ) .documentation("Sets the storage system that will be used by the world to store chunks.") @@ -229,7 +229,7 @@ public class WorldConfig { private ISpawnProvider spawnProvider = null; private IWorldGenProvider worldGenProvider = IWorldGenProvider.CODEC.getDefault(); private IWorldMapProvider worldMapProvider = IWorldMapProvider.CODEC.getDefault(); - private IChunkStorageProvider chunkStorageProvider = IChunkStorageProvider.CODEC.getDefault(); + private IChunkStorageProvider chunkStorageProvider = IChunkStorageProvider.CODEC.getDefault(); @Nonnull private WorldConfig.ChunkConfig chunkConfig = new WorldConfig.ChunkConfig(); private boolean isTicking = true; @@ -356,11 +356,11 @@ public class WorldConfig { this.worldMapProvider = worldMapProvider; } - public IChunkStorageProvider getChunkStorageProvider() { + public IChunkStorageProvider getChunkStorageProvider() { return this.chunkStorageProvider; } - public void setChunkStorageProvider(IChunkStorageProvider chunkStorageProvider) { + public void setChunkStorageProvider(IChunkStorageProvider chunkStorageProvider) { this.chunkStorageProvider = chunkStorageProvider; } diff --git a/src/com/hypixel/hytale/server/core/universe/world/WorldMapTracker.java b/src/com/hypixel/hytale/server/core/universe/world/WorldMapTracker.java index 8bc65441..0a70bb54 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/WorldMapTracker.java +++ b/src/com/hypixel/hytale/server/core/universe/world/WorldMapTracker.java @@ -14,6 +14,7 @@ import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.protocol.GameMode; +import com.hypixel.hytale.protocol.NetworkChannel; import com.hypixel.hytale.protocol.SoundCategory; import com.hypixel.hytale.protocol.packets.worldmap.ClearWorldMap; import com.hypixel.hytale.protocol.packets.worldmap.MapChunk; @@ -93,7 +94,7 @@ public class WorldMapTracker implements Tickable { } World world = this.player.getWorld(); - if (world != null) { + if (world != null && this.player.getPlayerConnection().getChannel(NetworkChannel.WorldMap).isWritable()) { if (this.transformComponent == null) { this.transformComponent = this.player.getTransformComponent(); if (this.transformComponent == null) { diff --git a/src/com/hypixel/hytale/server/core/universe/world/WorldNotificationHandler.java b/src/com/hypixel/hytale/server/core/universe/world/WorldNotificationHandler.java index 7977da13..9897f8ff 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/WorldNotificationHandler.java +++ b/src/com/hypixel/hytale/server/core/universe/world/WorldNotificationHandler.java @@ -4,8 +4,8 @@ import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.protocol.BlockParticleEvent; import com.hypixel.hytale.protocol.BlockPosition; -import com.hypixel.hytale.protocol.Packet; import com.hypixel.hytale.protocol.Position; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.SpawnBlockParticleSystem; import com.hypixel.hytale.protocol.packets.world.UpdateBlockDamage; import com.hypixel.hytale.server.core.modules.entity.player.ChunkTracker; @@ -33,7 +33,7 @@ public class WorldNotificationHandler { public void updateState(int x, int y, int z, BlockState state, BlockState oldState, @Nullable Predicate skip) { if (y >= 0 && y < 320) { - Consumer> removeOldState; + Consumer> removeOldState; Predicate canPlayerSeeOld; if (oldState instanceof SendableBlockState sendableBlockState && state != oldState) { removeOldState = sendableBlockState::unloadFrom; @@ -44,7 +44,7 @@ public class WorldNotificationHandler { } Predicate canPlayerSee; - Consumer> updateBlockState; + Consumer> updateBlockState; if (state instanceof SendableBlockState sendableBlockState) { updateBlockState = sendableBlockState::sendTo; canPlayerSee = sendableBlockState::canPlayerSee; @@ -55,7 +55,7 @@ public class WorldNotificationHandler { if (removeOldState != null || updateBlockState != null) { long indexChunk = ChunkUtil.indexChunkFromBlock(x, z); - List packets = new ObjectArrayList<>(); + List packets = new ObjectArrayList<>(); for (PlayerRef playerRef : this.world.getPlayerRefs()) { ChunkTracker chunkTracker = playerRef.getChunkTracker(); @@ -68,7 +68,7 @@ public class WorldNotificationHandler { updateBlockState.accept(packets); } - for (Packet packet : packets) { + for (ToClientPacket packet : packets) { playerRef.getPacketHandler().write(packet); } @@ -103,12 +103,12 @@ public class WorldNotificationHandler { this.sendPacketIfChunkLoaded(this.getBlockDamagePacket(x, y, z, health, healthDelta), x, z, filter); } - public void sendPacketIfChunkLoaded(@Nonnull Packet packet, int x, int z) { + public void sendPacketIfChunkLoaded(@Nonnull ToClientPacket packet, int x, int z) { long indexChunk = ChunkUtil.indexChunkFromBlock(x, z); this.sendPacketIfChunkLoaded(packet, indexChunk); } - public void sendPacketIfChunkLoaded(@Nonnull Packet packet, long indexChunk) { + public void sendPacketIfChunkLoaded(@Nonnull ToClientPacket packet, long indexChunk) { for (PlayerRef playerRef : this.world.getPlayerRefs()) { if (playerRef.getChunkTracker().isLoaded(indexChunk)) { playerRef.getPacketHandler().write(packet); @@ -116,12 +116,12 @@ public class WorldNotificationHandler { } } - public void sendPacketIfChunkLoaded(@Nonnull Packet packet, int x, int z, @Nullable Predicate filter) { + public void sendPacketIfChunkLoaded(@Nonnull ToClientPacket packet, int x, int z, @Nullable Predicate filter) { long indexChunk = ChunkUtil.indexChunkFromBlock(x, z); this.sendPacketIfChunkLoaded(packet, indexChunk, filter); } - public void sendPacketIfChunkLoaded(@Nonnull Packet packet, long indexChunk, @Nullable Predicate filter) { + public void sendPacketIfChunkLoaded(@Nonnull ToClientPacket packet, long indexChunk, @Nullable Predicate filter) { for (PlayerRef playerRef : this.world.getPlayerRefs()) { if ((filter == null || filter.test(playerRef)) && playerRef.getChunkTracker().isLoaded(indexChunk)) { playerRef.getPacketHandler().write(packet); @@ -129,12 +129,12 @@ public class WorldNotificationHandler { } } - private void sendPacketIfChunkLoaded(@Nonnull PlayerRef player, @Nonnull Packet packet, int x, int z) { + private void sendPacketIfChunkLoaded(@Nonnull PlayerRef player, @Nonnull ToClientPacket packet, int x, int z) { long indexChunk = ChunkUtil.indexChunkFromBlock(x, z); this.sendPacketIfChunkLoaded(player, packet, indexChunk); } - private void sendPacketIfChunkLoaded(@Nonnull PlayerRef playerRef, @Nonnull Packet packet, long indexChunk) { + private void sendPacketIfChunkLoaded(@Nonnull PlayerRef playerRef, @Nonnull ToClientPacket packet, long indexChunk) { if (playerRef.getChunkTracker().isLoaded(indexChunk)) { playerRef.getPacketHandler().write(packet); } diff --git a/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java b/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java index b3bd2429..d6ca098b 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java +++ b/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockChunk.java @@ -19,7 +19,7 @@ import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3i; import com.hypixel.hytale.protocol.CachedPacket; import com.hypixel.hytale.protocol.Opacity; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.protocol.packets.world.SetChunkEnvironments; import com.hypixel.hytale.protocol.packets.world.SetChunkHeightmap; import com.hypixel.hytale.protocol.packets.world.SetChunkTintmap; @@ -575,7 +575,7 @@ public class BlockChunk implements Component { Store store, CommandBuffer commandBuffer, PlayerRef player, - @Nonnull List> results + @Nonnull List> results ) { BlockChunk component = archetypeChunk.getComponent(index, this.componentType); results.add(component.getCachedHeightmapPacket().exceptionally(throwable -> { diff --git a/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockComponentChunk.java b/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockComponentChunk.java index d9f547de..d8d87904 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockComponentChunk.java +++ b/src/com/hypixel/hytale/server/core/universe/world/chunk/BlockComponentChunk.java @@ -21,7 +21,7 @@ import com.hypixel.hytale.component.system.RefChangeSystem; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.vector.Vector3i; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.modules.LegacyModule; import com.hypixel.hytale.server.core.modules.block.BlockModule; import com.hypixel.hytale.server.core.universe.PlayerRef; @@ -384,7 +384,7 @@ public class BlockComponentChunk implements Component { @Nonnull Store store, CommandBuffer commandBuffer, PlayerRef player, - @Nonnull List results + @Nonnull List results ) { BlockComponentChunk component = archetypeChunk.getComponent(index, this.componentType); ObjectCollection> references = component.entityReferences.values(); @@ -411,7 +411,7 @@ public class BlockComponentChunk implements Component { @Nonnull Store store, CommandBuffer commandBuffer, PlayerRef player, - @Nonnull List results + @Nonnull List results ) { BlockComponentChunk component = archetypeChunk.getComponent(index, this.componentType); ObjectCollection> references = component.entityReferences.values(); diff --git a/src/com/hypixel/hytale/server/core/universe/world/chunk/EntityChunk.java b/src/com/hypixel/hytale/server/core/universe/world/chunk/EntityChunk.java index f24e5c00..fa022a16 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/chunk/EntityChunk.java +++ b/src/com/hypixel/hytale/server/core/universe/world/chunk/EntityChunk.java @@ -290,10 +290,9 @@ public class EntityChunk implements Component { worldChunkComponent.markNeedsSaving(); } else { TransformComponent transformComponent = holder.getComponent(TransformComponent.getComponentType()); - - assert transformComponent != null; - - transformComponent.setChunkLocation(ref, worldChunkComponent); + if (transformComponent != null) { + transformComponent.setChunkLocation(ref, worldChunkComponent); + } } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/chunk/section/BlockSection.java b/src/com/hypixel/hytale/server/core/universe/world/chunk/section/BlockSection.java index 7e3b5e21..b85cc846 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/chunk/section/BlockSection.java +++ b/src/com/hypixel/hytale/server/core/universe/world/chunk/section/BlockSection.java @@ -249,64 +249,68 @@ public class BlockSection implements Component { } public boolean set(int blockIdx, int blockId, int rotation, int filler) { - long lock = this.chunkSectionLock.writeLock(); + if (rotation >= 0 && rotation < RotationTuple.VALUES.length) { + long lock = this.chunkSectionLock.writeLock(); - boolean changed; - try { - ISectionPalette.SetResult result = this.chunkSection.set(blockIdx, blockId); - if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { - this.chunkSection = this.chunkSection.promote(); - ISectionPalette.SetResult repeatResult = this.chunkSection.set(blockIdx, blockId); - if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { - throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); - } - } else { - if (result == ISectionPalette.SetResult.ADDED_OR_REMOVED) { - this.maximumHitboxExtent = -1.0; + boolean changed; + try { + ISectionPalette.SetResult result = this.chunkSection.set(blockIdx, blockId); + if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { + this.chunkSection = this.chunkSection.promote(); + ISectionPalette.SetResult repeatResult = this.chunkSection.set(blockIdx, blockId); + if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { + throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); + } + } else { + if (result == ISectionPalette.SetResult.ADDED_OR_REMOVED) { + this.maximumHitboxExtent = -1.0; + } + + if (this.chunkSection.shouldDemote()) { + this.chunkSection = this.chunkSection.demote(); + } } - if (this.chunkSection.shouldDemote()) { - this.chunkSection = this.chunkSection.demote(); + changed = result != ISectionPalette.SetResult.UNCHANGED; + result = this.fillerSection.set(blockIdx, filler); + if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { + this.fillerSection = this.fillerSection.promote(); + ISectionPalette.SetResult repeatResult = this.fillerSection.set(blockIdx, filler); + if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { + throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); + } + } else if (this.fillerSection.shouldDemote()) { + this.fillerSection = this.fillerSection.demote(); } + + changed |= result != ISectionPalette.SetResult.UNCHANGED; + result = this.rotationSection.set(blockIdx, rotation); + if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { + this.rotationSection = this.rotationSection.promote(); + ISectionPalette.SetResult repeatResult = this.rotationSection.set(blockIdx, rotation); + if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { + throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); + } + } else if (this.rotationSection.shouldDemote()) { + this.rotationSection = this.rotationSection.demote(); + } + + changed |= result != ISectionPalette.SetResult.UNCHANGED; + if (changed && this.loaded) { + this.changedPositions.add(blockIdx); + } + } finally { + this.chunkSectionLock.unlockWrite(lock); } - changed = result != ISectionPalette.SetResult.UNCHANGED; - result = this.fillerSection.set(blockIdx, filler); - if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { - this.fillerSection = this.fillerSection.promote(); - ISectionPalette.SetResult repeatResult = this.fillerSection.set(blockIdx, filler); - if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { - throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); - } - } else if (this.fillerSection.shouldDemote()) { - this.fillerSection = this.fillerSection.demote(); + if (changed) { + this.invalidateLocalLight(); } - changed |= result != ISectionPalette.SetResult.UNCHANGED; - result = this.rotationSection.set(blockIdx, rotation); - if (result == ISectionPalette.SetResult.REQUIRES_PROMOTE) { - this.rotationSection = this.rotationSection.promote(); - ISectionPalette.SetResult repeatResult = this.rotationSection.set(blockIdx, rotation); - if (repeatResult != ISectionPalette.SetResult.ADDED_OR_REMOVED) { - throw new IllegalStateException("Promoted chunk section failed to correctly add the new block!"); - } - } else if (this.rotationSection.shouldDemote()) { - this.rotationSection = this.rotationSection.demote(); - } - - changed |= result != ISectionPalette.SetResult.UNCHANGED; - if (changed && this.loaded) { - this.changedPositions.add(blockIdx); - } - } finally { - this.chunkSectionLock.unlockWrite(lock); + return changed; + } else { + throw new IllegalArgumentException("Rotation index out of bounds. Got " + rotation + " but expected 0-" + (RotationTuple.VALUES.length - 1)); } - - if (changed) { - this.invalidateLocalLight(); - } - - return changed; } @Nonnull diff --git a/src/com/hypixel/hytale/server/core/universe/world/commands/WorldSettingsCommand.java b/src/com/hypixel/hytale/server/core/universe/world/commands/WorldSettingsCommand.java index aeefb209..49ce377e 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/commands/WorldSettingsCommand.java +++ b/src/com/hypixel/hytale/server/core/universe/world/commands/WorldSettingsCommand.java @@ -54,8 +54,8 @@ public class WorldSettingsCommand extends AbstractCommandCollection { "type", ArgTypes.STRING, "ChunkStorage Type", - worldConfig -> IChunkStorageProvider.CODEC.getIdFor((Class)worldConfig.getChunkStorageProvider().getClass()), - (worldConfig, path) -> worldConfig.setChunkStorageProvider(IChunkStorageProvider.CODEC.getCodecFor(path).getDefaultValue()) + worldConfig -> IChunkStorageProvider.CODEC.getIdFor((Class>)worldConfig.getChunkStorageProvider().getClass()), + (worldConfig, path) -> worldConfig.setChunkStorageProvider((IChunkStorageProvider)IChunkStorageProvider.CODEC.getCodecFor(path).getDefaultValue()) ); this.generateSubCommand( "ticking", "server.commands.world.settings.ticking.desc", "ticking", ArgTypes.BOOLEAN, "Ticking", WorldConfig::isTicking, WorldConfig::setTicking diff --git a/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkFindHereCommand.java b/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkFindHereCommand.java index b89f6eb8..d45c1ff7 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkFindHereCommand.java +++ b/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkFindHereCommand.java @@ -83,7 +83,12 @@ public class BlockBulkFindHereCommand extends AbstractPlayerCommand { long diff = System.nanoTime() - start; BlockType findBlock = BlockType.getAssetMap().getAsset(blockId); String blockName = printBlockName ? " " + findBlock.getId() : ""; - playerRef.sendMessage(Message.translation("Found " + found.get() + blockName + " blocks in " + TimeUnit.NANOSECONDS.toSeconds(diff) + " seconds!")); + playerRef.sendMessage( + Message.translation("server.commands.block.find-here.result") + .param("count", found.get()) + .param("blockName", blockName) + .param("time", TimeUnit.NANOSECONDS.toSeconds(diff)) + ); } ); } diff --git a/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkReplaceCommand.java b/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkReplaceCommand.java index f13b2130..449ecad4 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkReplaceCommand.java +++ b/src/com/hypixel/hytale/server/core/universe/world/commands/block/bulk/BlockBulkReplaceCommand.java @@ -99,7 +99,9 @@ public class BlockBulkReplaceCommand extends AbstractPlayerCommand { long diff = System.nanoTime() - start; playerRef.sendMessage( - Message.translation("Found and replaced " + replaced.get() + " blocks in " + TimeUnit.NANOSECONDS.toSeconds(diff) + " seconds!") + Message.translation("server.commands.block.bulk.replace.result") + .param("count", replaced.get()) + .param("time", TimeUnit.NANOSECONDS.toSeconds(diff)) ); } ); diff --git a/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldCommand.java b/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldCommand.java index 636a4ea9..9ff22d7a 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldCommand.java +++ b/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldCommand.java @@ -23,5 +23,6 @@ public class WorldCommand extends AbstractCommandCollection { this.addSubCommand(new WorldSettingsCommand()); this.addSubCommand(new WorldPerfCommand()); this.addSubCommand(new WorldTpsCommand()); + this.addSubCommand(new WorldRocksDbCommand()); } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldRocksDbCommand.java b/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldRocksDbCommand.java new file mode 100644 index 00000000..6400ee34 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/universe/world/commands/world/WorldRocksDbCommand.java @@ -0,0 +1,44 @@ +package com.hypixel.hytale.server.core.universe.world.commands.world; + +import com.hypixel.fastutil.util.SneakyThrow; +import com.hypixel.hytale.server.core.Message; +import com.hypixel.hytale.server.core.command.system.CommandContext; +import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncWorldCommand; +import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection; +import com.hypixel.hytale.server.core.universe.world.World; +import com.hypixel.hytale.server.core.universe.world.storage.provider.RocksDbChunkStorageProvider; +import java.util.concurrent.CompletableFuture; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; + +public class WorldRocksDbCommand extends AbstractCommandCollection { + public WorldRocksDbCommand() { + super("rocksdb", "server.commands.world.rocksdb"); + this.addSubCommand(new WorldRocksDbCommand.CompactCommand()); + } + + public static class CompactCommand extends AbstractAsyncWorldCommand { + public CompactCommand() { + super("compact", "server.commands.world.rocksdb.compact"); + } + + @NonNullDecl + @Override + protected CompletableFuture executeAsync(@NonNullDecl CommandContext context, @NonNullDecl World world) { + if (world.getChunkStore().getStorageData() instanceof RocksDbChunkStorageProvider.RocksDbResource rocksDbResource) { + context.sendMessage(Message.translation("server.commands.world.rocksdb.compact.start")); + return CompletableFuture.runAsync(() -> { + try { + rocksDbResource.db.compactRange(rocksDbResource.chunkColumn); + } catch (Exception var3) { + throw SneakyThrow.sneakyThrow(var3); + } + + context.sendMessage(Message.translation("server.commands.world.rocksdb.compact.end")); + }); + } else { + context.sendMessage(Message.translation("server.commands.world.rocksdb.compact.wrong")); + return CompletableFuture.completedFuture(null); + } + } + } +} diff --git a/src/com/hypixel/hytale/server/core/universe/world/meta/BlockStateModule.java b/src/com/hypixel/hytale/server/core/universe/world/meta/BlockStateModule.java index eaa50c63..1a500d65 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/meta/BlockStateModule.java +++ b/src/com/hypixel/hytale/server/core/universe/world/meta/BlockStateModule.java @@ -28,7 +28,7 @@ import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.math.vector.Vector3i; import com.hypixel.hytale.metrics.MetricResults; import com.hypixel.hytale.metrics.MetricsRegistry; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.HytaleServer; import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType; import com.hypixel.hytale.server.core.asset.type.blocktype.config.StateData; @@ -419,7 +419,7 @@ public class BlockStateModule extends JavaPlugin { Store store, CommandBuffer commandBuffer, PlayerRef player, - List results + List results ) { SendableBlockState state = (SendableBlockState)BlockState.getBlockState(index, archetypeChunk); if (state.canPlayerSee(player)) { @@ -501,7 +501,7 @@ public class BlockStateModule extends JavaPlugin { Store store, CommandBuffer commandBuffer, PlayerRef player, - List results + List results ) { SendableBlockState state = (SendableBlockState)BlockState.getBlockState(index, archetypeChunk); if (state.canPlayerSee(player)) { diff --git a/src/com/hypixel/hytale/server/core/universe/world/meta/state/SendableBlockState.java b/src/com/hypixel/hytale/server/core/universe/world/meta/state/SendableBlockState.java index 97a8636a..6f22b243 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/meta/state/SendableBlockState.java +++ b/src/com/hypixel/hytale/server/core/universe/world/meta/state/SendableBlockState.java @@ -1,14 +1,14 @@ package com.hypixel.hytale.server.core.universe.world.meta.state; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.universe.PlayerRef; import java.util.List; @Deprecated public interface SendableBlockState { - void sendTo(List var1); + void sendTo(List var1); - void unloadFrom(List var1); + void unloadFrom(List var1); default boolean canPlayerSee(PlayerRef player) { return true; diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/ChunkStore.java b/src/com/hypixel/hytale/server/core/universe/world/storage/ChunkStore.java index 44d38fab..c8c706d8 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/ChunkStore.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/ChunkStore.java @@ -2,6 +2,8 @@ package com.hypixel.hytale.server.core.universe.world.storage; import com.hypixel.fastutil.longs.Long2ObjectConcurrentHashMap; import com.hypixel.hytale.codec.Codec; +import com.hypixel.hytale.codec.KeyedCodec; +import com.hypixel.hytale.codec.builder.BuilderCodec; import com.hypixel.hytale.codec.store.CodecKey; import com.hypixel.hytale.codec.store.CodecStore; import com.hypixel.hytale.common.util.FormatUtil; @@ -14,6 +16,7 @@ import com.hypixel.hytale.component.Holder; import com.hypixel.hytale.component.IResourceStorage; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.RemoveReason; +import com.hypixel.hytale.component.Resource; import com.hypixel.hytale.component.ResourceType; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.SystemGroup; @@ -25,7 +28,7 @@ import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.metrics.MetricProvider; import com.hypixel.hytale.metrics.MetricsRegistry; -import com.hypixel.hytale.protocol.Packet; +import com.hypixel.hytale.protocol.ToClientPacket; import com.hypixel.hytale.server.core.HytaleServer; import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.World; @@ -93,6 +96,7 @@ public class ChunkStore implements WorldProvider { @Nonnull private final Long2ObjectConcurrentHashMap chunks = new Long2ObjectConcurrentHashMap<>(true, ChunkUtil.NOT_FOUND); private Store store; + private Object storageData; @Nullable private IChunkLoader loader; @Nullable @@ -120,6 +124,10 @@ public class ChunkStore implements WorldProvider { return this.store; } + public Object getStorageData() { + return this.storageData; + } + @Nullable public IChunkLoader getLoader() { return this.loader; @@ -753,6 +761,10 @@ public class ChunkStore implements WorldProvider { } public static class ChunkLoaderSaverSetupSystem extends StoreSystem { + private final ResourceType chunkStorageResourceType = this.registerResource( + ChunkStore.ChunkStorage.class, "ChunkStorage", ChunkStore.ChunkStorage.CODEC + ); + @Nullable @Override public SystemGroup getGroup() { @@ -763,13 +775,21 @@ public class ChunkStore implements WorldProvider { public void onSystemAddedToStore(@Nonnull Store store) { ChunkStore data = store.getExternalData(); World world = data.getWorld(); - IChunkStorageProvider chunkStorageProvider = world.getWorldConfig().getChunkStorageProvider(); + IChunkStorageProvider chunkStorageProvider = world.getWorldConfig().getChunkStorageProvider(); + ChunkStore.ChunkStorage chunkStorage = store.getResource(this.chunkStorageResourceType); try { - data.loader = chunkStorageProvider.getLoader(store); - data.saver = chunkStorageProvider.getSaver(store); - } catch (IOException var6) { - throw SneakyThrow.sneakyThrow(var6); + if (chunkStorage.currentProvider != null && !chunkStorage.currentProvider.isSame(chunkStorageProvider)) { + data.storageData = chunkStorageProvider.migrateFrom(store, chunkStorage.currentProvider); + } else { + data.storageData = chunkStorageProvider.initialize(store); + } + + chunkStorage.currentProvider = chunkStorageProvider; + data.loader = ((IChunkStorageProvider)chunkStorageProvider).getLoader(data.storageData, store); + data.saver = ((IChunkStorageProvider)chunkStorageProvider).getSaver(data.storageData, store); + } catch (IOException var7) { + throw SneakyThrow.sneakyThrow(var7); } } @@ -789,18 +809,44 @@ public class ChunkStore implements WorldProvider { data.saver = null; oldSaver.close(); } - } catch (IOException var4) { - ChunkStore.LOGGER.at(Level.SEVERE).withCause(var4).log("Failed to close storage!"); + + World world = data.getWorld(); + IChunkStorageProvider chunkStorageProvider = world.getWorldConfig().getChunkStorageProvider(); + ((IChunkStorageProvider)chunkStorageProvider).close(data.storageData, store); + } catch (IOException var5) { + ChunkStore.LOGGER.at(Level.SEVERE).withCause(var5).log("Failed to close storage!"); } } } - public abstract static class LoadFuturePacketDataQuerySystem extends EntityDataSystem> { + private static class ChunkStorage implements Resource { + public static final BuilderCodec CODEC = BuilderCodec.builder(ChunkStore.ChunkStorage.class, ChunkStore.ChunkStorage::new) + .append(new KeyedCodec<>("CurrentProvider", IChunkStorageProvider.CODEC), (o, i) -> o.currentProvider = i, o -> o.currentProvider) + .add() + .build(); + @Nullable + private IChunkStorageProvider currentProvider; + + public ChunkStorage(@Nullable IChunkStorageProvider currentProvider) { + this.currentProvider = currentProvider; + } + + public ChunkStorage() { + } + + @Nullable + @Override + public Resource clone() { + return new ChunkStore.ChunkStorage(this.currentProvider); + } } - public abstract static class LoadPacketDataQuerySystem extends EntityDataSystem { + public abstract static class LoadFuturePacketDataQuerySystem extends EntityDataSystem> { } - public abstract static class UnloadPacketDataQuerySystem extends EntityDataSystem { + public abstract static class LoadPacketDataQuerySystem extends EntityDataSystem { + } + + public abstract static class UnloadPacketDataQuerySystem extends EntityDataSystem { } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/DefaultChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/DefaultChunkStorageProvider.java index a3bf827e..2ce60ef1 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/DefaultChunkStorageProvider.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/DefaultChunkStorageProvider.java @@ -7,33 +7,53 @@ import com.hypixel.hytale.server.core.universe.world.storage.IChunkLoader; import com.hypixel.hytale.server.core.universe.world.storage.IChunkSaver; import java.io.IOException; import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; -public class DefaultChunkStorageProvider implements IChunkStorageProvider { - @Nonnull - public static final DefaultChunkStorageProvider INSTANCE = new DefaultChunkStorageProvider(); +public class DefaultChunkStorageProvider implements IChunkStorageProvider { + public static final int VERSION = 0; public static final String ID = "Hytale"; @Nonnull - public static final BuilderCodec CODEC = BuilderCodec.builder(DefaultChunkStorageProvider.class, () -> INSTANCE) + private static final IChunkStorageProvider DEFAULT_INDEXED = new IndexedStorageChunkStorageProvider(); + @Nonnull + public static final BuilderCodec CODEC = BuilderCodec.builder( + DefaultChunkStorageProvider.class, DefaultChunkStorageProvider::new + ) + .versioned() + .codecVersion(0) .documentation("Selects the default recommended storage as decided by the server.") .build(); - @Nonnull - public static final IChunkStorageProvider DEFAULT = new IndexedStorageChunkStorageProvider(); + private IChunkStorageProvider provider = DEFAULT_INDEXED; - @Nonnull @Override - public IChunkLoader getLoader(@Nonnull Store store) throws IOException { - return DEFAULT.getLoader(store); + public Object initialize(@Nonnull Store store) throws IOException { + return this.provider.initialize(store); + } + + @Override + public void close(@Nonnull Object o, @NonNullDecl Store store) throws IOException { + ((IChunkStorageProvider)this.provider).close(o, store); } @Nonnull @Override - public IChunkSaver getSaver(@Nonnull Store store) throws IOException { - return DEFAULT.getSaver(store); + public IChunkLoader getLoader(@Nonnull Object o, @Nonnull Store store) throws IOException { + return ((IChunkStorageProvider)this.provider).getLoader(o, store); + } + + @Nonnull + @Override + public IChunkSaver getSaver(@Nonnull Object o, @Nonnull Store store) throws IOException { + return ((IChunkStorageProvider)this.provider).getSaver(o, store); + } + + @Override + public boolean isSame(IChunkStorageProvider other) { + return other.getClass().equals(this.getClass()) || this.provider.isSame(other); } @Nonnull @Override public String toString() { - return "DefaultChunkStorageProvider{DEFAULT=" + DEFAULT + "}"; + return "DefaultChunkStorageProvider{DEFAULT=" + this.provider + "}"; } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/EmptyChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/EmptyChunkStorageProvider.java index 52d20207..926970f7 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/EmptyChunkStorageProvider.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/EmptyChunkStorageProvider.java @@ -8,10 +8,12 @@ import com.hypixel.hytale.server.core.universe.world.storage.IChunkLoader; import com.hypixel.hytale.server.core.universe.world.storage.IChunkSaver; import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.longs.LongSets; +import java.io.IOException; import java.util.concurrent.CompletableFuture; import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; -public class EmptyChunkStorageProvider implements IChunkStorageProvider { +public class EmptyChunkStorageProvider implements IChunkStorageProvider { public static final String ID = "Empty"; @Nonnull public static final EmptyChunkStorageProvider INSTANCE = new EmptyChunkStorageProvider(); @@ -20,19 +22,24 @@ public class EmptyChunkStorageProvider implements IChunkStorageProvider { .documentation("A chunk storage provider that discards any chunks to save and will always fail to find chunks.") .build(); @Nonnull - public static final EmptyChunkStorageProvider.EmptyChunkLoader EMPTY_CHUNK_LOADER = new EmptyChunkStorageProvider.EmptyChunkLoader(); + private static final EmptyChunkStorageProvider.EmptyChunkLoader EMPTY_CHUNK_LOADER = new EmptyChunkStorageProvider.EmptyChunkLoader(); @Nonnull - public static final EmptyChunkStorageProvider.EmptyChunkSaver EMPTY_CHUNK_SAVER = new EmptyChunkStorageProvider.EmptyChunkSaver(); + private static final EmptyChunkStorageProvider.EmptyChunkSaver EMPTY_CHUNK_SAVER = new EmptyChunkStorageProvider.EmptyChunkSaver(); + + public Void initialize(@NonNullDecl Store store) throws IOException { + return null; + } + + public void close(@NonNullDecl Void o, @NonNullDecl Store store) throws IOException { + } @Nonnull - @Override - public IChunkLoader getLoader(@Nonnull Store store) { + public IChunkLoader getLoader(@Nonnull Void object, @Nonnull Store store) { return EMPTY_CHUNK_LOADER; } @Nonnull - @Override - public IChunkSaver getSaver(@Nonnull Store store) { + public IChunkSaver getSaver(@Nonnull Void object, @Nonnull Store store) { return EMPTY_CHUNK_SAVER; } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IChunkStorageProvider.java index e69af576..c32adab1 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IChunkStorageProvider.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IChunkStorageProvider.java @@ -1,20 +1,87 @@ package com.hypixel.hytale.server.core.universe.world.storage.provider; import com.hypixel.hytale.codec.lookup.BuilderCodecMapCodec; +import com.hypixel.hytale.component.Holder; import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.logger.HytaleLogger; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.math.util.MathUtil; +import com.hypixel.hytale.server.core.HytaleServer; +import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; import com.hypixel.hytale.server.core.universe.world.storage.IChunkLoader; import com.hypixel.hytale.server.core.universe.world.storage.IChunkSaver; +import it.unimi.dsi.fastutil.longs.LongIterator; +import it.unimi.dsi.fastutil.longs.LongSet; import java.io.IOException; +import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ForkJoinPool; import javax.annotation.Nonnull; -public interface IChunkStorageProvider { +public interface IChunkStorageProvider { @Nonnull - BuilderCodecMapCodec CODEC = new BuilderCodecMapCodec<>("Type", true); + BuilderCodecMapCodec> CODEC = new BuilderCodecMapCodec<>("Type", true); + + Data initialize(@Nonnull Store var1) throws IOException; + + default Data migrateFrom(@Nonnull Store store, IChunkStorageProvider other) throws IOException { + OtherData oldData = other.initialize(store); + Data newData = this.initialize(store); + + try ( + IChunkLoader oldLoader = other.getLoader(oldData, store); + IChunkSaver newSaver = this.getSaver(newData, store); + ) { + World world = store.getExternalData().getWorld(); + HytaleLogger logger = world.getLogger(); + LongSet chunks = oldLoader.getIndexes(); + LongIterator iterator = chunks.iterator(); + logger.atInfo().log("Migrating %d chunks", chunks.size()); + HytaleServer.get().reportSingleplayerStatus(String.format("Migrating chunks for %s", world.getName()), 0.0); + int count = 0; + ArrayList> inFlight = new ArrayList<>(); + + while (iterator.hasNext()) { + long chunk = iterator.nextLong(); + int chunkX = ChunkUtil.xOfChunkIndex(chunk); + int chunkZ = ChunkUtil.zOfChunkIndex(chunk); + inFlight.add(oldLoader.loadHolder(chunkX, chunkZ).thenCompose(v -> newSaver.saveHolder(chunkX, chunkZ, (Holder)v)).exceptionally(t -> { + logger.atSevere().withCause(t).log("Failed to load chunk at %d, %d, skipping", chunkX, chunkZ); + return null; + })); + if (++count % 100 == 0) { + logger.atInfo().log("Migrated %d/%d chunks", count, chunks.size()); + double progress = MathUtil.round((double)count / chunks.size(), 2) * 100.0; + HytaleServer.get().reportSingleplayerStatus(String.format("Migrating chunks for %s", world.getName()), progress); + } + + inFlight.removeIf(CompletableFuture::isDone); + if (inFlight.size() >= ForkJoinPool.getCommonPoolParallelism()) { + CompletableFuture.anyOf(inFlight.toArray(CompletableFuture[]::new)).join(); + inFlight.removeIf(CompletableFuture::isDone); + } + } + + CompletableFuture.allOf(inFlight.toArray(CompletableFuture[]::new)).join(); + inFlight.clear(); + logger.atInfo().log("Finished migrating %d chunks", chunks.size()); + } finally { + other.close(oldData, store); + } + + return newData; + } + + void close(@Nonnull Data var1, @Nonnull Store var2) throws IOException; @Nonnull - IChunkLoader getLoader(@Nonnull Store var1) throws IOException; + IChunkLoader getLoader(@Nonnull Data var1, @Nonnull Store var2) throws IOException; @Nonnull - IChunkSaver getSaver(@Nonnull Store var1) throws IOException; + IChunkSaver getSaver(@Nonnull Data var1, @Nonnull Store var2) throws IOException; + + default boolean isSame(IChunkStorageProvider other) { + return other.getClass().equals(this.getClass()); + } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IndexedStorageChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IndexedStorageChunkStorageProvider.java index c8bd04fa..2c6e1bc7 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IndexedStorageChunkStorageProvider.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/IndexedStorageChunkStorageProvider.java @@ -6,15 +6,11 @@ import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.builder.BuilderCodec; import com.hypixel.hytale.codec.codecs.array.ArrayCodec; import com.hypixel.hytale.component.Resource; -import com.hypixel.hytale.component.ResourceType; import com.hypixel.hytale.component.Store; -import com.hypixel.hytale.component.SystemGroup; -import com.hypixel.hytale.component.system.StoreSystem; import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.metrics.MetricProvider; import com.hypixel.hytale.metrics.MetricResults; import com.hypixel.hytale.metrics.MetricsRegistry; -import com.hypixel.hytale.server.core.universe.Universe; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.BufferChunkLoader; import com.hypixel.hytale.server.core.universe.world.storage.BufferChunkSaver; @@ -42,8 +38,9 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; -public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider { +public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider { public static final String ID = "IndexedStorage"; @Nonnull public static final BuilderCodec CODEC = BuilderCodec.builder( @@ -60,16 +57,25 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider .build(); private boolean flushOnWrite = false; - @Nonnull - @Override - public IChunkLoader getLoader(@Nonnull Store store) { - return new IndexedStorageChunkStorageProvider.IndexedStorageChunkLoader(store, this.flushOnWrite); + public IndexedStorageChunkStorageProvider.IndexedStorageCache initialize(@NonNullDecl Store store) throws IOException { + World world = store.getExternalData().getWorld(); + IndexedStorageChunkStorageProvider.IndexedStorageCache cache = new IndexedStorageChunkStorageProvider.IndexedStorageCache(); + cache.path = world.getSavePath().resolve("chunks"); + return cache; + } + + public void close(@NonNullDecl IndexedStorageChunkStorageProvider.IndexedStorageCache cache, @NonNullDecl Store store) throws IOException { + cache.close(); } @Nonnull - @Override - public IChunkSaver getSaver(@Nonnull Store store) { - return new IndexedStorageChunkStorageProvider.IndexedStorageChunkSaver(store, this.flushOnWrite); + public IChunkLoader getLoader(@Nonnull IndexedStorageChunkStorageProvider.IndexedStorageCache cache, @Nonnull Store store) { + return new IndexedStorageChunkStorageProvider.IndexedStorageChunkLoader(store, cache, this.flushOnWrite); + } + + @Nonnull + public IChunkSaver getSaver(@Nonnull IndexedStorageChunkStorageProvider.IndexedStorageCache cache, @Nonnull Store store) { + return new IndexedStorageChunkStorageProvider.IndexedStorageChunkSaver(store, cache, this.flushOnWrite); } @Nonnull @@ -116,10 +122,6 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider private final Long2ObjectConcurrentHashMap cache = new Long2ObjectConcurrentHashMap<>(true, ChunkUtil.NOT_FOUND); private Path path; - public static ResourceType getResourceType() { - return Universe.get().getIndexedStorageCacheResourceType(); - } - @Nonnull public Long2ObjectConcurrentHashMap getCache() { return this.cache; @@ -286,35 +288,21 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider } } - public static class IndexedStorageCacheSetupSystem extends StoreSystem { - @Nullable - @Override - public SystemGroup getGroup() { - return ChunkStore.INIT_GROUP; - } - - @Override - public void onSystemAddedToStore(@Nonnull Store store) { - World world = store.getExternalData().getWorld(); - store.getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).path = world.getSavePath().resolve("chunks"); - } - - @Override - public void onSystemRemovedFromStore(@Nonnull Store store) { - } - } - public static class IndexedStorageChunkLoader extends BufferChunkLoader implements MetricProvider { + @Nonnull + private final IndexedStorageChunkStorageProvider.IndexedStorageCache cache; private final boolean flushOnWrite; - public IndexedStorageChunkLoader(@Nonnull Store store, boolean flushOnWrite) { + public IndexedStorageChunkLoader( + @Nonnull Store store, @Nonnull IndexedStorageChunkStorageProvider.IndexedStorageCache cache, boolean flushOnWrite + ) { super(store); + this.cache = cache; this.flushOnWrite = flushOnWrite; } @Override public void close() throws IOException { - this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).close(); } @Nonnull @@ -325,10 +313,8 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider int localX = x & 31; int localZ = z & 31; int index = ChunkUtil.indexColumn(localX, localZ); - IndexedStorageChunkStorageProvider.IndexedStorageCache indexedStorageCache = this.getStore() - .getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()); return CompletableFuture.supplyAsync(SneakyThrow.sneakySupplier(() -> { - IndexedStorageFile chunks = indexedStorageCache.getOrTryOpen(regionX, regionZ, this.flushOnWrite); + IndexedStorageFile chunks = this.cache.getOrTryOpen(regionX, regionZ, this.flushOnWrite); return chunks == null ? null : chunks.readBlob(index); })); } @@ -336,7 +322,7 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider @Nonnull @Override public LongSet getIndexes() throws IOException { - return this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).getIndexes(); + return this.cache.getIndexes(); } @Nullable @@ -344,23 +330,25 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider public MetricResults toMetricResults() { return this.getStore().getExternalData().getSaver() instanceof IndexedStorageChunkStorageProvider.IndexedStorageChunkSaver ? null - : this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).toMetricResults(); + : this.cache.toMetricResults(); } } public static class IndexedStorageChunkSaver extends BufferChunkSaver implements MetricProvider { + @Nonnull + private final IndexedStorageChunkStorageProvider.IndexedStorageCache cache; private final boolean flushOnWrite; - protected IndexedStorageChunkSaver(@Nonnull Store store, boolean flushOnWrite) { + protected IndexedStorageChunkSaver( + @Nonnull Store store, @Nonnull IndexedStorageChunkStorageProvider.IndexedStorageCache cache, boolean flushOnWrite + ) { super(store); + this.cache = cache; this.flushOnWrite = flushOnWrite; } @Override public void close() throws IOException { - IndexedStorageChunkStorageProvider.IndexedStorageCache indexedStorageCache = this.getStore() - .getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()); - indexedStorageCache.close(); } @Nonnull @@ -371,10 +359,8 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider int localX = x & 31; int localZ = z & 31; int index = ChunkUtil.indexColumn(localX, localZ); - IndexedStorageChunkStorageProvider.IndexedStorageCache indexedStorageCache = this.getStore() - .getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()); return CompletableFuture.runAsync(SneakyThrow.sneakyRunnable(() -> { - IndexedStorageFile chunks = indexedStorageCache.getOrCreate(regionX, regionZ, this.flushOnWrite); + IndexedStorageFile chunks = this.cache.getOrCreate(regionX, regionZ, this.flushOnWrite); chunks.writeBlob(index, buffer); })); } @@ -387,10 +373,8 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider int localX = x & 31; int localZ = z & 31; int index = ChunkUtil.indexColumn(localX, localZ); - IndexedStorageChunkStorageProvider.IndexedStorageCache indexedStorageCache = this.getStore() - .getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()); return CompletableFuture.runAsync(SneakyThrow.sneakyRunnable(() -> { - IndexedStorageFile chunks = indexedStorageCache.getOrTryOpen(regionX, regionZ, this.flushOnWrite); + IndexedStorageFile chunks = this.cache.getOrTryOpen(regionX, regionZ, this.flushOnWrite); if (chunks != null) { chunks.removeBlob(index); } @@ -400,17 +384,17 @@ public class IndexedStorageChunkStorageProvider implements IChunkStorageProvider @Nonnull @Override public LongSet getIndexes() throws IOException { - return this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).getIndexes(); + return this.cache.getIndexes(); } @Override public void flush() throws IOException { - this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).flush(); + this.cache.flush(); } @Override public MetricResults toMetricResults() { - return this.getStore().getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()).toMetricResults(); + return this.cache.toMetricResults(); } } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/MigrationChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/MigrationChunkStorageProvider.java index 124cccb0..9ec57078 100644 --- a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/MigrationChunkStorageProvider.java +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/MigrationChunkStorageProvider.java @@ -16,8 +16,9 @@ import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.function.Function; import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; -public class MigrationChunkStorageProvider implements IChunkStorageProvider { +public class MigrationChunkStorageProvider implements IChunkStorageProvider { public static final String ID = "Migration"; @Nonnull public static final BuilderCodec CODEC = BuilderCodec.builder( @@ -26,7 +27,7 @@ public class MigrationChunkStorageProvider implements IChunkStorageProvider { .documentation( "A provider that combines multiple storage providers in a chain to assist with migrating worlds between storage formats.\n\nCan also be used to set storage to load chunks but block saving them if combined with the **Empty** storage provider" ) - .append( + .[]>append( new KeyedCodec<>("Loaders", new ArrayCodec<>(IChunkStorageProvider.CODEC, IChunkStorageProvider[]::new)), (migration, o) -> migration.from = o, migration -> migration.from @@ -35,12 +36,12 @@ public class MigrationChunkStorageProvider implements IChunkStorageProvider { "A list of storage providers to use as chunk loaders.\n\nEach loader will be tried in order to load a chunk, returning the chunk if found otherwise trying the next loaded until found or none are left." ) .add() - .append(new KeyedCodec<>("Saver", IChunkStorageProvider.CODEC), (migration, o) -> migration.to = o, migration -> migration.to) + .>append(new KeyedCodec<>("Saver", IChunkStorageProvider.CODEC), (migration, o) -> migration.to = o, migration -> migration.to) .documentation("The storage provider to use to save chunks.") .add() .build(); - private IChunkStorageProvider[] from; - private IChunkStorageProvider to; + private IChunkStorageProvider[] from; + private IChunkStorageProvider to; public MigrationChunkStorageProvider() { } @@ -50,22 +51,40 @@ public class MigrationChunkStorageProvider implements IChunkStorageProvider { this.to = to; } + public MigrationChunkStorageProvider.MigrationData initialize(@NonNullDecl Store store) throws IOException { + MigrationChunkStorageProvider.MigrationData data = new MigrationChunkStorageProvider.MigrationData(); + data.loaderData = new Object[this.from.length]; + + for (int i = 0; i < this.from.length; i++) { + data.loaderData[i] = this.from[i].initialize(store); + } + + data.saverData = this.to.initialize(store); + return data; + } + + public void close(@NonNullDecl MigrationChunkStorageProvider.MigrationData migrationData, @NonNullDecl Store store) throws IOException { + for (int i = 0; i < this.from.length; i++) { + ((IChunkStorageProvider)this.from[i]).close(migrationData.loaderData[i], store); + } + + ((IChunkStorageProvider)this.to).close(migrationData.saverData, store); + } + @Nonnull - @Override - public IChunkLoader getLoader(@Nonnull Store store) throws IOException { + public IChunkLoader getLoader(@Nonnull MigrationChunkStorageProvider.MigrationData migrationData, @Nonnull Store store) throws IOException { IChunkLoader[] loaders = new IChunkLoader[this.from.length]; for (int i = 0; i < this.from.length; i++) { - loaders[i] = this.from[i].getLoader(store); + loaders[i] = ((IChunkStorageProvider)this.from[i]).getLoader(migrationData.loaderData[i], store); } return new MigrationChunkStorageProvider.MigrationChunkLoader(loaders); } @Nonnull - @Override - public IChunkSaver getSaver(@Nonnull Store store) throws IOException { - return this.to.getSaver(store); + public IChunkSaver getSaver(@Nonnull MigrationChunkStorageProvider.MigrationData migrationData, @Nonnull Store store) throws IOException { + return ((IChunkStorageProvider)this.to).getSaver(migrationData.saverData, store); } @Nonnull @@ -138,4 +157,9 @@ public class MigrationChunkStorageProvider implements IChunkStorageProvider { return indexes; } } + + public static class MigrationData { + private Object[] loaderData; + private Object saverData; + } } diff --git a/src/com/hypixel/hytale/server/core/universe/world/storage/provider/RocksDbChunkStorageProvider.java b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/RocksDbChunkStorageProvider.java new file mode 100644 index 00000000..8adfdb73 --- /dev/null +++ b/src/com/hypixel/hytale/server/core/universe/world/storage/provider/RocksDbChunkStorageProvider.java @@ -0,0 +1,229 @@ +package com.hypixel.hytale.server.core.universe.world.storage.provider; + +import com.hypixel.hytale.codec.builder.BuilderCodec; +import com.hypixel.hytale.component.Store; +import com.hypixel.hytale.math.util.ChunkUtil; +import com.hypixel.hytale.server.core.universe.world.storage.BufferChunkLoader; +import com.hypixel.hytale.server.core.universe.world.storage.BufferChunkSaver; +import com.hypixel.hytale.server.core.universe.world.storage.ChunkStore; +import com.hypixel.hytale.server.core.universe.world.storage.IChunkLoader; +import com.hypixel.hytale.server.core.universe.world.storage.IChunkSaver; +import com.hypixel.hytale.sneakythrow.SneakyThrow; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ForkJoinPool; +import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.compatqual.NonNullDecl; +import org.rocksdb.BlockBasedTableConfig; +import org.rocksdb.BloomFilter; +import org.rocksdb.ColumnFamilyDescriptor; +import org.rocksdb.ColumnFamilyHandle; +import org.rocksdb.ColumnFamilyOptions; +import org.rocksdb.CompactionPriority; +import org.rocksdb.CompactionStyle; +import org.rocksdb.CompressionType; +import org.rocksdb.DBOptions; +import org.rocksdb.FlushOptions; +import org.rocksdb.IndexType; +import org.rocksdb.Options; +import org.rocksdb.RocksDB; +import org.rocksdb.RocksDBException; +import org.rocksdb.RocksIterator; + +public class RocksDbChunkStorageProvider implements IChunkStorageProvider { + public static final String ID = "RocksDb"; + public static final BuilderCodec CODEC = BuilderCodec.builder( + RocksDbChunkStorageProvider.class, RocksDbChunkStorageProvider::new + ) + .build(); + + public RocksDbChunkStorageProvider.RocksDbResource initialize(@NonNullDecl Store store) throws IOException { + try { + RocksDbChunkStorageProvider.RocksDbResource var9; + try ( + Options options = new Options() + .setCreateIfMissing(true) + .setCreateMissingColumnFamilies(true) + .setIncreaseParallelism(ForkJoinPool.getCommonPoolParallelism()); + BloomFilter bloomFilter = new BloomFilter(9.9); + ColumnFamilyOptions chunkColumnOptions = new ColumnFamilyOptions() + .setCompressionType(CompressionType.LZ4_COMPRESSION) + .setBottommostCompressionType(CompressionType.ZSTD_COMPRESSION) + .setTableFormatConfig( + new BlockBasedTableConfig().setIndexType(IndexType.kHashSearch).setFilterPolicy(bloomFilter).setOptimizeFiltersForMemory(true) + ) + .setCompactionStyle(CompactionStyle.LEVEL) + .optimizeLevelStyleCompaction(134217728L) + .setLevelCompactionDynamicLevelBytes(true) + .setCompactionPriority(CompactionPriority.MinOverlappingRatio) + .useFixedLengthPrefixExtractor(8) + .setEnableBlobFiles(true) + .setEnableBlobGarbageCollection(true) + .setBlobCompressionType(CompressionType.ZSTD_COMPRESSION); + DBOptions dbOptions = new DBOptions(options); + ) { + RocksDbChunkStorageProvider.RocksDbResource resource = new RocksDbChunkStorageProvider.RocksDbResource(); + List columns = List.of( + new ColumnFamilyDescriptor("default".getBytes(StandardCharsets.UTF_8)), + new ColumnFamilyDescriptor("chunks".getBytes(StandardCharsets.UTF_8), chunkColumnOptions) + ); + ArrayList handles = new ArrayList<>(); + resource.db = RocksDB.open(dbOptions, String.valueOf(store.getExternalData().getWorld().getSavePath().resolve("db")), columns, handles); + resource.chunkColumn = handles.get(1); + handles.get(0).close(); + var9 = resource; + } + + return var9; + } catch (RocksDBException var18) { + throw SneakyThrow.sneakyThrow(var18); + } + } + + public void close(@NonNullDecl RocksDbChunkStorageProvider.RocksDbResource resource, @NonNullDecl Store store) throws IOException { + try { + resource.db.syncWal(); + } catch (RocksDBException var4) { + throw SneakyThrow.sneakyThrow(var4); + } + + resource.chunkColumn.close(); + resource.db.close(); + resource.db = null; + } + + @Nonnull + public IChunkLoader getLoader(@Nonnull RocksDbChunkStorageProvider.RocksDbResource resource, @Nonnull Store store) throws IOException { + return new RocksDbChunkStorageProvider.Loader(store, resource); + } + + @Nonnull + public IChunkSaver getSaver(@Nonnull RocksDbChunkStorageProvider.RocksDbResource resource, @Nonnull Store store) throws IOException { + return new RocksDbChunkStorageProvider.Saver(store, resource); + } + + private static byte[] toKey(int x, int z) { + return new byte[]{(byte)(x >>> 24), (byte)(x >>> 16), (byte)(x >>> 8), (byte)x, (byte)(z >>> 24), (byte)(z >>> 16), (byte)(z >>> 8), (byte)z}; + } + + private static int keyToX(byte[] key) { + return (key[0] & 0xFF) << 24 | (key[1] & 0xFF) << 16 | (key[2] & 0xFF) << 8 | key[3] & 0xFF; + } + + private static int keyToZ(byte[] key) { + return (key[4] & 0xFF) << 24 | (key[5] & 0xFF) << 16 | (key[6] & 0xFF) << 8 | key[7] & 0xFF; + } + + public static class Loader extends BufferChunkLoader implements IChunkLoader { + private final RocksDbChunkStorageProvider.RocksDbResource db; + + public Loader(Store store, RocksDbChunkStorageProvider.RocksDbResource db) { + super(store); + this.db = db; + } + + @Override + public CompletableFuture loadBuffer(int x, int z) { + return CompletableFuture.supplyAsync(SneakyThrow.sneakySupplier(() -> { + byte[] key = RocksDbChunkStorageProvider.toKey(x, z); + byte[] data = this.db.db.get(this.db.chunkColumn, key); + return data == null ? null : ByteBuffer.wrap(data); + })); + } + + @Nonnull + @Override + public LongSet getIndexes() throws IOException { + LongOpenHashSet set = new LongOpenHashSet(); + + try (RocksIterator iter = this.db.db.newIterator(this.db.chunkColumn)) { + iter.seekToFirst(); + + while (iter.isValid()) { + byte[] key = iter.key(); + set.add(ChunkUtil.indexChunk(RocksDbChunkStorageProvider.keyToX(key), RocksDbChunkStorageProvider.keyToZ(key))); + iter.next(); + } + } + + return set; + } + + @Override + public void close() throws IOException { + } + } + + public static class RocksDbResource { + public RocksDB db; + public ColumnFamilyHandle chunkColumn; + } + + public static class Saver extends BufferChunkSaver implements IChunkSaver { + private final RocksDbChunkStorageProvider.RocksDbResource db; + + public Saver(Store store, RocksDbChunkStorageProvider.RocksDbResource db) { + super(store); + this.db = db; + } + + @Nonnull + @Override + public CompletableFuture saveBuffer(int x, int z, @Nonnull ByteBuffer buffer) { + return CompletableFuture.runAsync(SneakyThrow.sneakyRunnable(() -> { + if (buffer.hasArray()) { + this.db.db.put(this.db.chunkColumn, RocksDbChunkStorageProvider.toKey(x, z), buffer.array()); + } else { + byte[] buf = new byte[buffer.remaining()]; + buffer.get(buf); + this.db.db.put(this.db.chunkColumn, RocksDbChunkStorageProvider.toKey(x, z), buf); + } + })); + } + + @Nonnull + @Override + public CompletableFuture removeBuffer(int x, int z) { + return CompletableFuture.runAsync(SneakyThrow.sneakyRunnable(() -> this.db.db.delete(this.db.chunkColumn, RocksDbChunkStorageProvider.toKey(x, z)))); + } + + @Nonnull + @Override + public LongSet getIndexes() throws IOException { + LongOpenHashSet set = new LongOpenHashSet(); + + try (RocksIterator iter = this.db.db.newIterator(this.db.chunkColumn)) { + iter.seekToFirst(); + + while (iter.isValid()) { + byte[] key = iter.key(); + set.add(ChunkUtil.indexChunk(RocksDbChunkStorageProvider.keyToX(key), RocksDbChunkStorageProvider.keyToZ(key))); + iter.next(); + } + } + + return set; + } + + @Override + public void flush() throws IOException { + try { + try (FlushOptions opts = new FlushOptions().setWaitForFlush(true)) { + this.db.db.flush(opts); + } + } catch (RocksDBException var6) { + throw SneakyThrow.sneakyThrow(var6); + } + } + + @Override + public void close() throws IOException { + } + } +} diff --git a/src/com/hypixel/hytale/server/core/update/UpdateModule.java b/src/com/hypixel/hytale/server/core/update/UpdateModule.java index a0c4d58c..4337b7af 100644 --- a/src/com/hypixel/hytale/server/core/update/UpdateModule.java +++ b/src/com/hypixel/hytale/server/core/update/UpdateModule.java @@ -6,10 +6,10 @@ import com.hypixel.hytale.common.util.java.ManifestUtil; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.server.core.Constants; import com.hypixel.hytale.server.core.HytaleServer; -import com.hypixel.hytale.server.core.HytaleServerConfig; import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.ShutdownReason; import com.hypixel.hytale.server.core.auth.ServerAuthManager; +import com.hypixel.hytale.server.core.config.UpdateConfig; import com.hypixel.hytale.server.core.permissions.PermissionsModule; import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPluginInit; @@ -31,10 +31,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; public class UpdateModule extends JavaPlugin { + @Nonnull public static final PluginManifest MANIFEST = PluginManifest.corePlugin(UpdateModule.class).build(); + @Nonnull private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); public static final boolean KILL_SWITCH_ENABLED = SystemUtil.getEnvBoolean("HYTALE_DISABLE_UPDATES"); private static UpdateModule instance; + @Nonnull private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(r -> { Thread t = new Thread(r, "UpdateChecker"); t.setDaemon(true); @@ -83,7 +86,7 @@ public class UpdateModule extends JavaPlugin { } if (this.shouldEnableUpdateChecker()) { - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); int intervalSeconds = config.getCheckIntervalSeconds(); LOGGER.at(Level.INFO).log("Update checker enabled (interval: %ds)", intervalSeconds); this.updateCheckTask = this.scheduler.scheduleAtFixedRate(this::performUpdateCheck, 60L, intervalSeconds, TimeUnit.SECONDS); @@ -93,9 +96,9 @@ public class UpdateModule extends JavaPlugin { private synchronized void startAutoApplyTaskIfNeeded() { if (this.autoApplyTask == null) { - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); - HytaleServerConfig.UpdateConfig.AutoApplyMode autoApplyMode = config.getAutoApplyMode(); - if (autoApplyMode != HytaleServerConfig.UpdateConfig.AutoApplyMode.DISABLED) { + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig.AutoApplyMode autoApplyMode = config.getAutoApplyMode(); + if (autoApplyMode != UpdateConfig.AutoApplyMode.DISABLED) { LOGGER.at(Level.INFO).log("Starting auto-apply task (mode: %s, delay: %d min)", autoApplyMode, config.getAutoApplyDelayMinutes()); this.autoApplyTask = this.scheduler.scheduleAtFixedRate(this::performAutoApplyCheck, 0L, 60L, TimeUnit.SECONDS); } @@ -216,7 +219,7 @@ public class UpdateModule extends JavaPlugin { LOGGER.at(Level.INFO).log("Update checker disabled: singleplayer mode"); return false; } else { - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); if (!config.isEnabled()) { LOGGER.at(Level.INFO).log("Update checker disabled: disabled in config"); return false; @@ -263,12 +266,12 @@ public class UpdateModule extends JavaPlugin { LOGGER.at(Level.FINE).log("Already running latest version: %s", currentVersion); } else { this.logUpdateAvailable(currentVersion, manifest.version); - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); if (config.isNotifyPlayersOnAvailable()) { this.notifyPlayers(manifest.version); } - if (config.getAutoApplyMode() != HytaleServerConfig.UpdateConfig.AutoApplyMode.DISABLED) { + if (config.getAutoApplyMode() != UpdateConfig.AutoApplyMode.DISABLED) { LOGGER.at(Level.INFO).log("Auto-downloading update %s...", manifest.version); this.autoDownloadUpdate(updateService, manifest); } @@ -317,8 +320,8 @@ public class UpdateModule extends JavaPlugin { private void logUpdateAvailable(@Nullable String currentVersion, @Nonnull String latestVersion) { LOGGER.at(Level.INFO).log("Update available: %s (current: %s)", latestVersion, currentVersion); - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); - if (config.getAutoApplyMode() == HytaleServerConfig.UpdateConfig.AutoApplyMode.DISABLED) { + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + if (config.getAutoApplyMode() == UpdateConfig.AutoApplyMode.DISABLED) { LOGGER.at(Level.INFO).log("Run '/update download' to stage the update"); } } @@ -338,16 +341,16 @@ public class UpdateModule extends JavaPlugin { } private void checkAutoApply(@Nonnull String stagedVersion) { - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); - HytaleServerConfig.UpdateConfig.AutoApplyMode mode = config.getAutoApplyMode(); - if (mode != HytaleServerConfig.UpdateConfig.AutoApplyMode.DISABLED) { + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig.AutoApplyMode mode = config.getAutoApplyMode(); + if (mode != UpdateConfig.AutoApplyMode.DISABLED) { Universe universe = Universe.get(); if (universe != null) { int playerCount = universe.getPlayers().size(); if (playerCount == 0) { LOGGER.at(Level.INFO).log("No players online - auto-applying update %s", stagedVersion); this.triggerAutoApply(); - } else if (mode != HytaleServerConfig.UpdateConfig.AutoApplyMode.WHEN_EMPTY) { + } else if (mode != UpdateConfig.AutoApplyMode.WHEN_EMPTY) { int delayMinutes = config.getAutoApplyDelayMinutes(); long now = System.currentTimeMillis(); long applyTime = now + delayMinutes * 60 * 1000L; diff --git a/src/com/hypixel/hytale/server/core/update/UpdateService.java b/src/com/hypixel/hytale/server/core/update/UpdateService.java index 22141926..da062ecd 100644 --- a/src/com/hypixel/hytale/server/core/update/UpdateService.java +++ b/src/com/hypixel/hytale/server/core/update/UpdateService.java @@ -8,9 +8,9 @@ import com.hypixel.hytale.codec.util.RawJsonReader; import com.hypixel.hytale.common.util.java.ManifestUtil; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.server.core.HytaleServer; -import com.hypixel.hytale.server.core.HytaleServerConfig; import com.hypixel.hytale.server.core.auth.AuthConfig; import com.hypixel.hytale.server.core.auth.ServerAuthManager; +import com.hypixel.hytale.server.core.config.UpdateConfig; import com.hypixel.hytale.server.core.util.ServiceHttpClientFactory; import com.hypixel.hytale.server.core.util.io.FileUtil; import java.io.IOException; @@ -238,7 +238,7 @@ public class UpdateService { @Nonnull public static String getEffectivePatchline() { - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); String patchline = config.getPatchline(); if (patchline != null && !patchline.isEmpty()) { return patchline; diff --git a/src/com/hypixel/hytale/server/core/update/command/UpdateApplyCommand.java b/src/com/hypixel/hytale/server/core/update/command/UpdateApplyCommand.java index ea667483..2c1bf2a3 100644 --- a/src/com/hypixel/hytale/server/core/update/command/UpdateApplyCommand.java +++ b/src/com/hypixel/hytale/server/core/update/command/UpdateApplyCommand.java @@ -2,13 +2,13 @@ package com.hypixel.hytale.server.core.update.command; import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.server.core.HytaleServer; -import com.hypixel.hytale.server.core.HytaleServerConfig; import com.hypixel.hytale.server.core.Message; -import com.hypixel.hytale.server.core.Options; import com.hypixel.hytale.server.core.ShutdownReason; import com.hypixel.hytale.server.core.command.system.CommandContext; import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg; import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase; +import com.hypixel.hytale.server.core.config.BackupConfig; +import com.hypixel.hytale.server.core.config.UpdateConfig; import com.hypixel.hytale.server.core.universe.Universe; import com.hypixel.hytale.server.core.update.UpdateService; import com.hypixel.hytale.server.core.util.io.FileUtil; @@ -20,9 +20,13 @@ import java.util.logging.Level; import javax.annotation.Nonnull; public class UpdateApplyCommand extends CommandBase { + @Nonnull private static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); + @Nonnull private static final Message MSG_NO_STAGED = Message.translation("server.commands.update.no_staged"); + @Nonnull private static final Message MSG_BACKUP_FAILED = Message.translation("server.commands.update.backup_failed"); + @Nonnull private final FlagArg confirmFlag = this.withFlagArg("confirm", "server.commands.update.apply.confirm.desc"); private static final String[] CONFIG_FILES = new String[]{"config.json", "permissions.json", "bans.json", "whitelist.json"}; @@ -45,11 +49,12 @@ public class UpdateApplyCommand extends CommandBase { context.sendMessage(Message.translation("server.commands.update.applying").param("version", stagedVersion)); } - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); try { this.backupCurrentFiles(); - if (config.isRunBackupBeforeUpdate() && Options.getOptionSet().has(Options.BACKUP_DIRECTORY)) { + BackupConfig backupConfig = HytaleServer.get().getConfig().getBackupConfig(); + if (config.isRunBackupBeforeUpdate() && backupConfig.getDirectory() != null) { Universe universe = Universe.get(); if (universe != null) { LOGGER.at(Level.INFO).log("Running server backup before update..."); @@ -57,14 +62,14 @@ public class UpdateApplyCommand extends CommandBase { LOGGER.at(Level.INFO).log("Server backup completed"); } } else if (config.isRunBackupBeforeUpdate()) { - LOGGER.at(Level.WARNING).log("RunBackupBeforeUpdate is enabled but backups are not configured (no --backup-dir)"); + LOGGER.at(Level.WARNING).log("RunBackupBeforeUpdate is enabled but backups are not configured"); } if (config.isBackupConfigBeforeUpdate()) { this.backupConfigFiles(); } - } catch (IOException var5) { - LOGGER.at(Level.SEVERE).withCause(var5).log("Failed to create backups before update"); + } catch (IOException var6) { + LOGGER.at(Level.SEVERE).withCause(var6).log("Failed to create backups before update"); context.sendMessage(MSG_BACKUP_FAILED); return; } diff --git a/src/com/hypixel/hytale/server/core/update/command/UpdatePatchlineCommand.java b/src/com/hypixel/hytale/server/core/update/command/UpdatePatchlineCommand.java index fe993d3c..865fe56e 100644 --- a/src/com/hypixel/hytale/server/core/update/command/UpdatePatchlineCommand.java +++ b/src/com/hypixel/hytale/server/core/update/command/UpdatePatchlineCommand.java @@ -1,12 +1,12 @@ package com.hypixel.hytale.server.core.update.command; import com.hypixel.hytale.server.core.HytaleServer; -import com.hypixel.hytale.server.core.HytaleServerConfig; import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.command.system.CommandContext; import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg; import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes; import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase; +import com.hypixel.hytale.server.core.config.UpdateConfig; import com.hypixel.hytale.server.core.update.UpdateService; import javax.annotation.Nonnull; @@ -33,7 +33,7 @@ public class UpdatePatchlineCommand extends CommandBase { @Override protected void executeSync(@Nonnull CommandContext context) { String newPatchline = this.patchlineArg.get(context); - HytaleServerConfig.UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); + UpdateConfig config = HytaleServer.get().getConfig().getUpdateConfig(); config.setPatchline(newPatchline); context.sendMessage(Message.translation("server.commands.update.patchline.changed").param("patchline", newPatchline)); } diff --git a/src/com/hypixel/hytale/server/core/util/DumpUtil.java b/src/com/hypixel/hytale/server/core/util/DumpUtil.java index eace33d6..95cb36ea 100644 --- a/src/com/hypixel/hytale/server/core/util/DumpUtil.java +++ b/src/com/hypixel/hytale/server/core/util/DumpUtil.java @@ -1,6 +1,5 @@ package com.hypixel.hytale.server.core.util; -import com.hypixel.fastutil.longs.Long2ObjectConcurrentHashMap; import com.hypixel.hytale.common.plugin.PluginManifest; import com.hypixel.hytale.common.util.FormatUtil; import com.hypixel.hytale.common.util.StringUtil; @@ -10,7 +9,6 @@ import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.metric.ArchetypeChunkData; import com.hypixel.hytale.component.system.ISystem; import com.hypixel.hytale.logger.backend.HytaleFileHandler; -import com.hypixel.hytale.math.util.ChunkUtil; import com.hypixel.hytale.math.util.MathUtil; import com.hypixel.hytale.metrics.InitStackThread; import com.hypixel.hytale.metrics.MetricsRegistry; @@ -33,14 +31,11 @@ import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.Universe; import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; -import com.hypixel.hytale.server.core.universe.world.storage.provider.IndexedStorageChunkStorageProvider; import com.hypixel.hytale.server.core.universe.world.worldgen.WorldGenTimingsCollector; -import com.hypixel.hytale.storage.IndexedStorageFile; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; @@ -618,9 +613,9 @@ public class DumpUtil { printComponentStore(writer, width, height, "Chunks", startNanos, world.getChunkStore().getStore()); printComponentStore(writer, width, height, "Entities", startNanos, world.getEntityStore().getStore()); }, world).orTimeout(30L, TimeUnit.SECONDS).join(); - } catch (CompletionException var41) { - if (!(var41.getCause() instanceof TimeoutException)) { - var41.printStackTrace(); + } catch (CompletionException var40) { + if (!(var40.getCause() instanceof TimeoutException)) { + var40.printStackTrace(); writer.println("\t\tFAILED TO DUMP COMPONENT STORES! EXCEPTION!"); } else { writer.println("\t\tFAILED TO DUMP COMPONENT STORES! TIMEOUT!"); @@ -644,35 +639,6 @@ public class DumpUtil { } else { writer.println("\t\tNo Timings Data Collected!"); } - - IndexedStorageChunkStorageProvider.IndexedStorageCache storageCache = world.getChunkStore() - .getStore() - .getResource(IndexedStorageChunkStorageProvider.IndexedStorageCache.getResourceType()); - if (storageCache != null) { - Long2ObjectConcurrentHashMap cache = storageCache.getCache(); - writer.println(); - writer.println("\tIndexed Storage Cache:"); - - for (Entry entry : cache.long2ObjectEntrySet()) { - long key = entry.getLongKey(); - writer.println("\t\t" + ChunkUtil.xOfChunkIndex(key) + ", " + ChunkUtil.zOfChunkIndex(key)); - IndexedStorageFile storageFile = entry.getValue(); - - try { - writer.println("\t\t- Size: " + FormatUtil.bytesToString(storageFile.size())); - } catch (IOException var40) { - writer.println("\t\t- Size: ERROR: " + var40.getMessage()); - } - - writer.println("\t\t- Blob Count: " + storageFile.keys().size()); - int segmentSize = storageFile.segmentSize(); - int segmentCount = storageFile.segmentCount(); - writer.println("\t\t- Segment Size: " + segmentSize); - writer.println("\t\t- Segment Count: " + segmentCount); - writer.println("\t\t- Segment Used %: " + (double)(segmentCount * 100) / segmentSize + "%"); - writer.println("\t\t- " + storageFile); - } - } } ); List playersNotInWorld = Universe.get().getPlayers().stream().filter(refx -> refx.getReference() == null).toList(); diff --git a/src/com/hypixel/hytale/server/core/util/backup/BackupTask.java b/src/com/hypixel/hytale/server/core/util/backup/BackupTask.java index e02ca526..2f15958c 100644 --- a/src/com/hypixel/hytale/server/core/util/backup/BackupTask.java +++ b/src/com/hypixel/hytale/server/core/util/backup/BackupTask.java @@ -1,7 +1,8 @@ package com.hypixel.hytale.server.core.util.backup; import com.hypixel.hytale.logger.HytaleLogger; -import com.hypixel.hytale.server.core.Options; +import com.hypixel.hytale.server.core.HytaleServer; +import com.hypixel.hytale.server.core.config.BackupConfig; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -65,7 +66,8 @@ public class BackupTask { } private static void cleanOrArchiveOldBackups(@Nonnull Path sourceDir, @Nonnull Path archiveDir) throws IOException { - int maxCount = Options.getOptionSet().valueOf(Options.BACKUP_MAX_COUNT); + BackupConfig backupConfig = HytaleServer.get().getConfig().getBackupConfig(); + int maxCount = backupConfig.getMaxCount(); if (maxCount >= 1) { List oldBackups = BackupUtil.findOldBackups(sourceDir, maxCount); if (oldBackups != null && !oldBackups.isEmpty()) { @@ -89,7 +91,8 @@ public class BackupTask { } private static void cleanOldArchives(@Nonnull Path dir) throws IOException { - int maxCount = Options.getOptionSet().valueOf(Options.BACKUP_ARCHIVE_MAX_COUNT); + BackupConfig backupConfig = HytaleServer.get().getConfig().getBackupConfig(); + int maxCount = backupConfig.getArchiveMaxCount(); if (maxCount >= 1) { List oldBackups = BackupUtil.findOldBackups(dir, maxCount); if (oldBackups != null && !oldBackups.isEmpty()) { diff --git a/src/com/hypixel/hytale/server/flock/Flock.java b/src/com/hypixel/hytale/server/flock/Flock.java index fe7fda68..5522f36c 100644 --- a/src/com/hypixel/hytale/server/flock/Flock.java +++ b/src/com/hypixel/hytale/server/flock/Flock.java @@ -19,6 +19,7 @@ public class Flock implements Component { private DamageData nextLeaderDamageData = new DamageData(); private DamageData currentLeaderDamageData = new DamageData(); private Flock.FlockRemovedStatus removedStatus = Flock.FlockRemovedStatus.NOT_REMOVED; + private int visFlockMemberCount; public static ComponentType getComponentType() { return FlockPlugin.get().getFlockComponentType(); @@ -71,6 +72,20 @@ public class Flock implements Component { this.removedStatus = status; } + public boolean hasVisFlockMember() { + return this.visFlockMemberCount > 0; + } + + public void incrementVisFlockMemberCount() { + this.visFlockMemberCount++; + } + + public void decrementVisFlockMemberCount() { + if (this.visFlockMemberCount > 0) { + this.visFlockMemberCount--; + } + } + public void onTargetKilled(@Nonnull ComponentAccessor componentAccessor, @Nonnull Ref targetEntityReference) { TransformComponent targetTransformComponent = componentAccessor.getComponent(targetEntityReference, TransformComponent.getComponentType()); if (targetTransformComponent != null) { diff --git a/src/com/hypixel/hytale/server/flock/FlockMembership.java b/src/com/hypixel/hytale/server/flock/FlockMembership.java index 83c394ba..0fa79edf 100644 --- a/src/com/hypixel/hytale/server/flock/FlockMembership.java +++ b/src/com/hypixel/hytale/server/flock/FlockMembership.java @@ -8,11 +8,14 @@ import com.hypixel.hytale.component.Component; import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import com.hypixel.hytale.server.npc.role.RoleDebugFlags; +import com.hypixel.hytale.server.npc.role.support.DebugSupport; +import java.util.EnumSet; import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FlockMembership implements Component { +public class FlockMembership implements Component, DebugSupport.DebugFlagsChangeListener { public static final int VERSION = 5; public static final BuilderCodec CODEC = BuilderCodec.builder(FlockMembership.class, FlockMembership::new) .legacyVersioned() @@ -31,6 +34,8 @@ public class FlockMembership implements Component { private FlockMembership.Type membershipType; @Nullable private Ref flockRef; + private transient boolean wasVisFlock; + private transient boolean listenerRegistered; public static ComponentType getComponentType() { return FlockPlugin.get().getFlockMembershipComponentType(); @@ -49,7 +54,7 @@ public class FlockMembership implements Component { return this.flockRef; } - public void setFlockRef(Ref flockRef) { + public void setFlockRef(@Nullable Ref flockRef) { this.flockRef = flockRef; } @@ -65,13 +70,52 @@ public class FlockMembership implements Component { this.flockRef = null; } + public void registerAsDebugListener(@Nonnull DebugSupport debugSupport, @Nonnull Flock flock) { + if (!this.listenerRegistered) { + this.wasVisFlock = debugSupport.isDebugFlagSet(RoleDebugFlags.VisFlock); + debugSupport.registerDebugFlagsListener(this); + this.listenerRegistered = true; + if (this.wasVisFlock) { + flock.incrementVisFlockMemberCount(); + } + } + } + + public void unregisterAsDebugListener(@Nonnull DebugSupport debugSupport, @Nonnull Flock flock) { + if (this.listenerRegistered) { + debugSupport.removeDebugFlagsListener(this); + this.listenerRegistered = false; + if (this.wasVisFlock) { + flock.decrementVisFlockMemberCount(); + } + } + } + + @Override + public void onDebugFlagsChanged(EnumSet newFlags) { + boolean isVisFlock = newFlags.contains(RoleDebugFlags.VisFlock); + if (isVisFlock != this.wasVisFlock) { + this.wasVisFlock = isVisFlock; + if (this.flockRef != null && this.flockRef.isValid()) { + Flock flock = this.flockRef.getStore().getComponent(this.flockRef, Flock.getComponentType()); + if (flock != null) { + if (isVisFlock) { + flock.incrementVisFlockMemberCount(); + } else { + flock.decrementVisFlockMemberCount(); + } + } + } + } + } + @Nonnull @Override public Component clone() { FlockMembership membership = new FlockMembership(); - membership.setFlockId(this.flockId); - membership.setFlockRef(this.flockRef); - membership.setMembershipType(this.membershipType); + membership.flockId = this.flockId; + membership.flockRef = this.flockRef; + membership.membershipType = this.membershipType; return membership; } diff --git a/src/com/hypixel/hytale/server/flock/FlockMembershipSystems.java b/src/com/hypixel/hytale/server/flock/FlockMembershipSystems.java index 24613c94..55424273 100644 --- a/src/com/hypixel/hytale/server/flock/FlockMembershipSystems.java +++ b/src/com/hypixel/hytale/server/flock/FlockMembershipSystems.java @@ -4,6 +4,7 @@ import com.hypixel.hytale.component.AddReason; import com.hypixel.hytale.component.Archetype; import com.hypixel.hytale.component.ArchetypeChunk; import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Holder; import com.hypixel.hytale.component.Ref; @@ -92,6 +93,30 @@ public class FlockMembershipSystems { } } + private static void registerFlockDebugListener( + @Nonnull Ref ref, @Nonnull FlockMembership membership, @Nonnull Flock flock, @Nonnull ComponentAccessor accessor + ) { + NPCEntity npcComponent = accessor.getComponent(ref, NPCEntity.getComponentType()); + if (npcComponent != null) { + Role role = npcComponent.getRole(); + if (role != null) { + membership.registerAsDebugListener(role.getDebugSupport(), flock); + } + } + } + + private static void unregisterFlockDebugListener( + @Nonnull Ref ref, @Nonnull FlockMembership membership, @Nonnull Flock flock, @Nonnull ComponentAccessor accessor + ) { + NPCEntity npcComponent = accessor.getComponent(ref, NPCEntity.getComponentType()); + if (npcComponent != null) { + Role role = npcComponent.getRole(); + if (role != null) { + membership.unregisterAsDebugListener(role.getDebugSupport(), flock); + } + } + } + public static class EntityRef extends RefSystem { @Nonnull private final ComponentType flockMembershipComponentType; @@ -144,6 +169,7 @@ public class FlockMembershipSystems { throw new IllegalStateException(String.format("Entity %s attempting to reload into group with ID %s despite already being a member", ref, flockId)); } else { entityGroup.add(ref); + FlockMembershipSystems.registerFlockDebugListener(ref, flockMembershipComponent, flock, store); if (flockMembershipComponent.getMembershipType() == FlockMembership.Type.LEADER) { PersistentFlockData persistentFlockData = store.getComponent(ref, PersistentFlockData.getComponentType()); if (persistentFlockData != null) { @@ -208,6 +234,7 @@ public class FlockMembershipSystems { UUID flockId = uuidComponent.getUuid(); if (reason == RemoveReason.REMOVE || store.getArchetype(ref).contains(Player.getComponentType())) { + FlockMembershipSystems.unregisterFlockDebugListener(ref, membership, flockComponent, store); entityGroupComponent.remove(ref); if (flockComponent.isTrace()) { FlockPlugin.get() @@ -279,6 +306,7 @@ public class FlockMembershipSystems { .log("Flock %s: Set new leader, old=%s, new=%s, size=%s", flockId, ref, newLeader, entityGroupComponent.size()); } } else if (reason == RemoveReason.UNLOAD) { + FlockMembershipSystems.unregisterFlockDebugListener(ref, membership, flockComponent, store); entityGroupComponent.remove(ref); if (!entityGroupComponent.isDissolved() && membership.getMembershipType().isActingAsLeader()) { Ref interimLeader = entityGroupComponent.testMembers(member -> true, true); @@ -641,6 +669,7 @@ public class FlockMembershipSystems { } entityGroupComponent.add(ref); + FlockMembershipSystems.registerFlockDebugListener(ref, membershipComponent, flockComponent, store); if (mustBecomeLeader) { setNewLeader(flockId, entityGroupComponent, flockComponent, ref, store, commandBuffer); if (wasFirstJoiner && flockComponent.isTrace()) { @@ -702,6 +731,7 @@ public class FlockMembershipSystems { assert uuidComponent != null; UUID flockId = uuidComponent.getUuid(); + FlockMembershipSystems.unregisterFlockDebugListener(ref, membershipComponent, flockComponent, store); entityGroupComponent.remove(ref); if (flockComponent.isTrace()) { FlockPlugin.get() diff --git a/src/com/hypixel/hytale/server/flock/FlockPlugin.java b/src/com/hypixel/hytale/server/flock/FlockPlugin.java index ac47283a..fc616833 100644 --- a/src/com/hypixel/hytale/server/flock/FlockPlugin.java +++ b/src/com/hypixel/hytale/server/flock/FlockPlugin.java @@ -100,6 +100,7 @@ public class FlockPlugin extends JavaPlugin { }); entityStoreRegistry.registerSystem(new FlockSystems.EntityRemoved(this.flockComponentType)); entityStoreRegistry.registerSystem(new FlockSystems.Ticking(this.flockComponentType)); + entityStoreRegistry.registerSystem(new FlockSystems.FlockDebugSystem(this.flockComponentType)); entityStoreRegistry.registerSystem(new FlockSystems.PlayerChangeGameModeEventSystem()); this.flockMembershipComponentType = entityStoreRegistry.registerComponent(FlockMembership.class, "FlockMembership", FlockMembership.CODEC); this.persistentFlockDataComponentType = entityStoreRegistry.registerComponent(PersistentFlockData.class, "FlockData", PersistentFlockData.CODEC); diff --git a/src/com/hypixel/hytale/server/flock/FlockSystems.java b/src/com/hypixel/hytale/server/flock/FlockSystems.java index 7b7fae7c..4f659ad0 100644 --- a/src/com/hypixel/hytale/server/flock/FlockSystems.java +++ b/src/com/hypixel/hytale/server/flock/FlockSystems.java @@ -12,11 +12,17 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.EntityEventSystem; import com.hypixel.hytale.component.system.RefSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; +import com.hypixel.hytale.math.shape.Box; +import com.hypixel.hytale.math.vector.Vector3d; +import com.hypixel.hytale.math.vector.Vector3f; import com.hypixel.hytale.protocol.GameMode; import com.hypixel.hytale.server.core.entity.UUIDComponent; import com.hypixel.hytale.server.core.entity.group.EntityGroup; import com.hypixel.hytale.server.core.event.events.ecs.ChangeGameModeEvent; +import com.hypixel.hytale.server.core.modules.debug.DebugUtils; +import com.hypixel.hytale.server.core.modules.entity.component.BoundingBox; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; +import com.hypixel.hytale.server.core.universe.world.World; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import java.util.UUID; import java.util.logging.Level; @@ -82,6 +88,148 @@ public class FlockSystems { } } + public static class FlockDebugSystem extends EntityTickingSystem { + private static final float DEBUG_SHAPE_TIME = 0.1F; + private static final float FLOCK_VIS_RING_OUTER_RADIUS_OFFSET = 0.3F; + private static final float FLOCK_VIS_RING_THICKNESS = 0.08F; + private static final float FLOCK_VIS_LINE_THICKNESS = 0.04F; + private static final int FLOCK_VIS_RING_SEGMENTS = 8; + private static final float FLOCK_VIS_LEADER_EXTRA_RING_OFFSET = 0.15F; + private final ComponentType flockComponentType; + private final ComponentType entityGroupComponentType; + private final ComponentType uuidComponentType; + private final ComponentType transformComponentType; + private final ComponentType boundingBoxComponentType; + @Nonnull + private final Query query; + + public FlockDebugSystem(@Nonnull ComponentType flockComponentType) { + this.flockComponentType = flockComponentType; + this.entityGroupComponentType = EntityGroup.getComponentType(); + this.uuidComponentType = UUIDComponent.getComponentType(); + this.transformComponentType = TransformComponent.getComponentType(); + this.boundingBoxComponentType = BoundingBox.getComponentType(); + this.query = Query.and(flockComponentType, this.entityGroupComponentType, this.uuidComponentType); + } + + @Nonnull + @Override + public Query getQuery() { + return this.query; + } + + @Override + public boolean isParallel(int archetypeChunkSize, int taskCount) { + return EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount); + } + + @Override + public void tick( + float dt, + int index, + @Nonnull ArchetypeChunk archetypeChunk, + @Nonnull Store store, + @Nonnull CommandBuffer commandBuffer + ) { + Flock flock = archetypeChunk.getComponent(index, this.flockComponentType); + + assert flock != null; + + if (flock.hasVisFlockMember()) { + EntityGroup entityGroup = archetypeChunk.getComponent(index, this.entityGroupComponentType); + + assert entityGroup != null; + + if (!entityGroup.isDissolved() && entityGroup.size() >= 2) { + UUIDComponent uuidComponent = archetypeChunk.getComponent(index, this.uuidComponentType); + + assert uuidComponent != null; + + World world = store.getExternalData().getWorld(); + int colorIndex = Math.abs(uuidComponent.getUuid().hashCode()) % DebugUtils.INDEXED_COLORS.length; + Vector3f color = DebugUtils.INDEXED_COLORS[colorIndex]; + Ref leaderRef = entityGroup.getLeaderRef(); + if (leaderRef != null && leaderRef.isValid()) { + TransformComponent leaderTransform = store.getComponent(leaderRef, this.transformComponentType); + BoundingBox leaderBoundingBox = store.getComponent(leaderRef, this.boundingBoxComponentType); + if (leaderTransform != null && leaderBoundingBox != null) { + Vector3d leaderPos = leaderTransform.getPosition(); + Box leaderBox = leaderBoundingBox.getBoundingBox(); + double leaderMidY = leaderPos.y + leaderBox.max.y / 2.0; + double leaderWidth = Math.max(leaderBox.max.x - leaderBox.min.x, leaderBox.max.z - leaderBox.min.z); + double leaderRingOuterRadius = leaderWidth / 2.0 + 0.3F; + double leaderRingInnerRadius = leaderRingOuterRadius - 0.08F; + double leaderOuterRingRadius = leaderRingOuterRadius + 0.15F; + double leaderOuterRingInnerRadius = leaderOuterRingRadius - 0.08F; + DebugUtils.addDisc(world, leaderPos.x, leaderMidY, leaderPos.z, leaderRingOuterRadius, leaderRingInnerRadius, color, 0.8F, 8, 0.1F, false); + DebugUtils.addDisc( + world, leaderPos.x, leaderMidY, leaderPos.z, leaderOuterRingRadius, leaderOuterRingInnerRadius, color, 0.8F, 8, 0.1F, false + ); + + for (Ref memberRef : entityGroup.getMemberList()) { + if (memberRef.isValid() && !memberRef.equals(leaderRef)) { + TransformComponent memberTransform = store.getComponent(memberRef, this.transformComponentType); + BoundingBox memberBoundingBox = store.getComponent(memberRef, this.boundingBoxComponentType); + if (memberTransform != null && memberBoundingBox != null) { + Vector3d memberPos = memberTransform.getPosition(); + Box memberBox = memberBoundingBox.getBoundingBox(); + double memberMidY = memberPos.y + memberBox.max.y / 2.0; + double memberWidth = Math.max(memberBox.max.x - memberBox.min.x, memberBox.max.z - memberBox.min.z); + double memberRingOuterRadius = memberWidth / 2.0 + 0.3F; + double memberRingInnerRadius = memberRingOuterRadius - 0.08F; + DebugUtils.addDisc( + world, memberPos.x, memberMidY, memberPos.z, memberRingOuterRadius, memberRingInnerRadius, color, 0.8F, 8, 0.1F, false + ); + renderConnectingLine( + world, + memberPos.x, + memberMidY, + memberPos.z, + memberRingOuterRadius, + leaderPos.x, + leaderMidY, + leaderPos.z, + leaderOuterRingRadius, + color + ); + } + } + } + } + } + } + } + } + + private static void renderConnectingLine( + @Nonnull World world, + double memberX, + double memberY, + double memberZ, + double memberRadius, + double leaderX, + double leaderY, + double leaderZ, + double leaderRadius, + @Nonnull Vector3f color + ) { + double dirX = leaderX - memberX; + double dirZ = leaderZ - memberZ; + double horizontalDist = Math.sqrt(dirX * dirX + dirZ * dirZ); + if (horizontalDist < 0.001) { + DebugUtils.addLine(world, memberX, memberY, memberZ, leaderX, leaderY, leaderZ, color, 0.04F, 0.1F, false); + } else { + double hDirX = dirX / horizontalDist; + double hDirZ = dirZ / horizontalDist; + double startX = memberX + hDirX * memberRadius; + double startZ = memberZ + hDirZ * memberRadius; + double endX = leaderX - hDirX * leaderRadius; + double endZ = leaderZ - hDirZ * leaderRadius; + DebugUtils.addLine(world, startX, memberY, startZ, endX, leaderY, endZ, color, 0.04F, 0.1F, false); + } + } + } + public static class PlayerChangeGameModeEventSystem extends EntityEventSystem { public PlayerChangeGameModeEventSystem() { super(ChangeGameModeEvent.class); diff --git a/src/com/hypixel/hytale/server/npc/blackboard/view/event/EventView.java b/src/com/hypixel/hytale/server/npc/blackboard/view/event/EventView.java index 25820bf7..ce4ff555 100644 --- a/src/com/hypixel/hytale/server/npc/blackboard/view/event/EventView.java +++ b/src/com/hypixel/hytale/server/npc/blackboard/view/event/EventView.java @@ -54,7 +54,7 @@ public abstract class EventView, Even public void onWorldRemoved() { this.shutdown = true; if (this.eventRegistry != null) { - this.eventRegistry.shutdown(); + this.eventRegistry.shutdownAndCleanup(true); this.eventRegistry = null; } } diff --git a/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/ActionSpawnParticles.java b/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/ActionSpawnParticles.java index 4468058e..83834aa4 100644 --- a/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/ActionSpawnParticles.java +++ b/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/ActionSpawnParticles.java @@ -4,9 +4,13 @@ import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; import com.hypixel.hytale.component.spatial.SpatialResource; import com.hypixel.hytale.math.vector.Vector3d; +import com.hypixel.hytale.protocol.ModelParticle; +import com.hypixel.hytale.protocol.Vector3f; +import com.hypixel.hytale.protocol.packets.entities.SpawnModelParticles; import com.hypixel.hytale.server.core.modules.entity.EntityModule; import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent; -import com.hypixel.hytale.server.core.universe.world.ParticleUtil; +import com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId; +import com.hypixel.hytale.server.core.universe.PlayerRef; import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport; import com.hypixel.hytale.server.npc.corecomponents.ActionBase; @@ -20,12 +24,19 @@ public class ActionSpawnParticles extends ActionBase { protected final String particleSystem; protected final double range; protected final Vector3d offset; + protected final ModelParticle[] modelParticlesProtocol; public ActionSpawnParticles(@Nonnull BuilderActionSpawnParticles builder, @Nonnull BuilderSupport support) { super(builder); this.particleSystem = builder.getParticleSystem(support); this.offset = builder.getOffset(support); this.range = builder.getRange(support); + com.hypixel.hytale.server.core.asset.type.model.config.ModelParticle particle = new com.hypixel.hytale.server.core.asset.type.model.config.ModelParticle(); + particle.setSystemId(this.particleSystem); + particle.setPositionOffset(new Vector3f((float)this.offset.x, (float)this.offset.y, (float)this.offset.z)); + particle.setTargetNodeName(builder.getTargetNodeName(support)); + particle.setDetachedFromModel(builder.isDetachedFromModel(support)); + this.modelParticlesProtocol = new ModelParticle[]{particle.toPacket()}; } @Override @@ -39,7 +50,20 @@ public class ActionSpawnParticles extends ActionBase { SpatialResource, EntityStore> playerSpatialResource = store.getResource(EntityModule.get().getPlayerSpatialResourceType()); ObjectList> results = SpatialResource.getThreadLocalReferenceList(); playerSpatialResource.getSpatialStructure().collect(position, this.range, results); - ParticleUtil.spawnParticleEffect(this.particleSystem, position, results, store); - return true; + NetworkId networkIdComponent = store.getComponent(ref, NetworkId.getComponentType()); + if (networkIdComponent == null) { + return true; + } else { + SpawnModelParticles packet = new SpawnModelParticles(networkIdComponent.getId(), this.modelParticlesProtocol); + + for (Ref playerRef : results) { + PlayerRef playerRefComponent = store.getComponent(playerRef, PlayerRef.getComponentType()); + if (playerRefComponent != null) { + playerRefComponent.getPacketHandler().write(packet); + } + } + + return true; + } } } diff --git a/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/builders/BuilderActionSpawnParticles.java b/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/builders/BuilderActionSpawnParticles.java index 43f3500a..ec27cc60 100644 --- a/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/builders/BuilderActionSpawnParticles.java +++ b/src/com/hypixel/hytale/server/npc/corecomponents/audiovisual/builders/BuilderActionSpawnParticles.java @@ -5,8 +5,10 @@ import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState; import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport; import com.hypixel.hytale.server.npc.asset.builder.holder.AssetHolder; +import com.hypixel.hytale.server.npc.asset.builder.holder.BooleanHolder; import com.hypixel.hytale.server.npc.asset.builder.holder.DoubleHolder; import com.hypixel.hytale.server.npc.asset.builder.holder.NumberArrayHolder; +import com.hypixel.hytale.server.npc.asset.builder.holder.StringHolder; import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator; import com.hypixel.hytale.server.npc.asset.builder.validators.asset.ParticleSystemExistsValidator; import com.hypixel.hytale.server.npc.corecomponents.audiovisual.ActionSpawnParticles; @@ -17,6 +19,8 @@ public class BuilderActionSpawnParticles extends BuilderActionBase { protected final AssetHolder particleSystem = new AssetHolder(); protected final DoubleHolder range = new DoubleHolder(); protected final NumberArrayHolder offset = new NumberArrayHolder(); + protected final StringHolder targetNodeName = new StringHolder(); + protected final BooleanHolder isDetachedFromModel = new BooleanHolder(); @Nonnull public ActionSpawnParticles build(@Nonnull BuilderSupport builderSupport) { @@ -48,6 +52,10 @@ public class BuilderActionSpawnParticles extends BuilderActionBase { ); this.getDouble(data, "Range", this.range, 75.0, DoubleSingleValidator.greater0(), BuilderDescriptorState.Stable, "Maximum visibility range", null); this.getVector3d(data, "Offset", this.offset, null, null, BuilderDescriptorState.Stable, "Offset relative to footpoint in view direction of NPC", null); + this.getString(data, "TargetNodeName", this.targetNodeName, null, null, BuilderDescriptorState.Stable, "Target node name to position particles at", null); + this.getBoolean( + data, "IsDetachedFromModel", this.isDetachedFromModel, false, BuilderDescriptorState.Stable, "Whether to attach particles to the model", null + ); return this; } @@ -62,4 +70,12 @@ public class BuilderActionSpawnParticles extends BuilderActionBase { public Vector3d getOffset(BuilderSupport support) { return createVector3d(this.offset.get(support.getExecutionContext()), Vector3d.ZERO::clone); } + + public String getTargetNodeName(BuilderSupport support) { + return this.targetNodeName.get(support.getExecutionContext()); + } + + public boolean isDetachedFromModel(BuilderSupport support) { + return this.isDetachedFromModel.get(support.getExecutionContext()); + } } diff --git a/src/com/hypixel/hytale/server/npc/role/RoleDebugFlags.java b/src/com/hypixel/hytale/server/npc/role/RoleDebugFlags.java index 6dd395f2..64e07737 100644 --- a/src/com/hypixel/hytale/server/npc/role/RoleDebugFlags.java +++ b/src/com/hypixel/hytale/server/npc/role/RoleDebugFlags.java @@ -40,6 +40,8 @@ public enum RoleDebugFlags implements Supplier { VisAiming("Visualize aiming"), VisMarkedTargets("Visualize arrows to marked targets"), VisSensorRanges("Visualize entity sensor detection ranges"), + VisLeashPosition("Visualize NPC leash position"), + VisFlock("Visualize flock member connections"), BeaconMessages("Enable debugging of beacon message sending and receiving"); private static final RoleDebugFlags.RoleDebugPreset[] presets = new RoleDebugFlags.RoleDebugPreset[]{ diff --git a/src/com/hypixel/hytale/server/npc/role/support/DebugSupport.java b/src/com/hypixel/hytale/server/npc/role/support/DebugSupport.java index 49a1e5c9..a753b451 100644 --- a/src/com/hypixel/hytale/server/npc/role/support/DebugSupport.java +++ b/src/com/hypixel/hytale/server/npc/role/support/DebugSupport.java @@ -136,6 +136,10 @@ public class DebugSupport { this.debugFlagsChangeListeners.add(listener); } + public void removeDebugFlagsListener(DebugSupport.DebugFlagsChangeListener listener) { + this.debugFlagsChangeListeners.remove(listener); + } + public void notifyDebugFlagsListeners(EnumSet flags) { for (DebugSupport.DebugFlagsChangeListener listener : this.debugFlagsChangeListeners) { listener.onDebugFlagsChanged(flags); diff --git a/src/com/hypixel/hytale/server/npc/role/support/StateSupport.java b/src/com/hypixel/hytale/server/npc/role/support/StateSupport.java index 93db22b1..ff0e6870 100644 --- a/src/com/hypixel/hytale/server/npc/role/support/StateSupport.java +++ b/src/com/hypixel/hytale/server/npc/role/support/StateSupport.java @@ -4,9 +4,8 @@ import com.hypixel.hytale.component.ComponentAccessor; import com.hypixel.hytale.component.ComponentType; import com.hypixel.hytale.component.Ref; import com.hypixel.hytale.component.Store; -import com.hypixel.hytale.protocol.ComponentUpdate; -import com.hypixel.hytale.protocol.ComponentUpdateType; import com.hypixel.hytale.protocol.GameMode; +import com.hypixel.hytale.protocol.InteractableUpdate; import com.hypixel.hytale.server.core.entity.entities.Player; import com.hypixel.hytale.server.core.entity.group.EntityGroup; import com.hypixel.hytale.server.core.modules.entity.component.Interactable; @@ -316,22 +315,24 @@ public class StateSupport { this.interactablePlayers.remove(playerReference); } - if (showPrompt) { - boolean hasComponent = store.getArchetype(entityRef).contains(Interactable.getComponentType()); - if (interactable) { - boolean needsHint = hint != null && !hint.equals(this.lastHint); - if (!hasComponent) { - store.ensureComponent(entityRef, Interactable.getComponentType()); - needsHint = hint != null; - } - - if (needsHint) { - this.sendInteractionHintToPlayer(entityRef, playerReference, hint, store); - this.lastHint = hint; - } - } else if (hasComponent && this.interactablePlayers.isEmpty()) { - store.removeComponent(entityRef, Interactable.getComponentType()); + boolean hasComponent = store.getArchetype(entityRef).contains(Interactable.getComponentType()); + if (interactable) { + if (!showPrompt) { + hint = ""; } + + boolean needsHint = hint != null && !hint.equals(this.lastHint); + if (!hasComponent) { + store.ensureComponent(entityRef, Interactable.getComponentType()); + needsHint = hint != null && !hint.isEmpty(); + } + + if (needsHint) { + this.sendInteractionHintToPlayer(entityRef, playerReference, hint, store); + this.lastHint = hint; + } + } else if (hasComponent && this.interactablePlayers.isEmpty()) { + store.removeComponent(entityRef, Interactable.getComponentType()); } } @@ -340,9 +341,7 @@ public class StateSupport { ) { EntityTrackerSystems.EntityViewer viewerComponent = store.getComponent(playerReference, EntityTrackerSystems.EntityViewer.getComponentType()); if (viewerComponent != null && viewerComponent.visible.contains(entityRef)) { - ComponentUpdate update = new ComponentUpdate(); - update.type = ComponentUpdateType.Interactable; - update.interactionHint = hint; + InteractableUpdate update = new InteractableUpdate(hint); viewerComponent.queueUpdate(entityRef, update); } } diff --git a/src/com/hypixel/hytale/server/npc/systems/RoleSystems.java b/src/com/hypixel/hytale/server/npc/systems/RoleSystems.java index 3ea5417e..17d44512 100644 --- a/src/com/hypixel/hytale/server/npc/systems/RoleSystems.java +++ b/src/com/hypixel/hytale/server/npc/systems/RoleSystems.java @@ -15,6 +15,8 @@ import com.hypixel.hytale.component.query.Query; import com.hypixel.hytale.component.system.HolderSystem; import com.hypixel.hytale.component.system.tick.EntityTickingSystem; import com.hypixel.hytale.component.system.tick.TickingSystem; +import com.hypixel.hytale.math.matrix.Matrix4d; +import com.hypixel.hytale.math.shape.Box; import com.hypixel.hytale.math.vector.Transform; import com.hypixel.hytale.math.vector.Vector3d; import com.hypixel.hytale.math.vector.Vector3f; @@ -349,6 +351,12 @@ public class RoleSystems { private static final float DEBUG_SHAPE_TIME = 0.1F; private static final float SENSOR_VIS_OPACITY = 0.4F; private static final double FULL_CIRCLE_EPSILON = 0.01; + private static final float LEASH_SPHERE_RADIUS = 0.3F; + private static final float LEASH_RING_OUTER_RADIUS = 0.5F; + private static final float LEASH_RING_INNER_RADIUS = 0.4F; + private static final float NPC_RING_THICKNESS = 0.1F; + private static final float NPC_RING_OFFSET = 0.1F; + private static final float LEASH_LINE_THICKNESS = 0.05F; @Nonnull private final ComponentType npcComponentType; @Nonnull @@ -400,9 +408,26 @@ public class RoleSystems { renderMarkedTargetArrows(role, index, archetypeChunk, commandBuffer); } - if (debugSupport.hasSensorVisData()) { + boolean hasSensorVis = debugSupport.hasSensorVisData(); + boolean hasLeashVis = debugSupport.isDebugFlagSet(RoleDebugFlags.VisLeashPosition); + if (hasSensorVis || hasLeashVis) { Ref npcRef = archetypeChunk.getReferenceTo(index); - renderSensorVisualization(debugSupport, npcRef, commandBuffer); + TransformComponent transformComponent = archetypeChunk.getComponent(index, TransformComponent.getComponentType()); + + assert transformComponent != null; + + BoundingBox boundingBoxComponent = archetypeChunk.getComponent(index, BoundingBox.getComponentType()); + + assert boundingBoxComponent != null; + + World world = commandBuffer.getExternalData().getWorld(); + if (hasSensorVis) { + renderSensorVisualization(debugSupport, npcRef, transformComponent, boundingBoxComponent, world, commandBuffer); + } + + if (hasLeashVis) { + renderLeashPositionVisualization(npcComponent, npcRef, transformComponent, boundingBoxComponent, world); + } } } } @@ -432,24 +457,20 @@ public class RoleSystems { } private static void renderSensorVisualization( - @Nonnull DebugSupport debugSupport, @Nonnull Ref npcRef, @Nonnull CommandBuffer commandBuffer + @Nonnull DebugSupport debugSupport, + @Nonnull Ref npcRef, + @Nonnull TransformComponent transformComponent, + @Nonnull BoundingBox boundingBoxComponent, + @Nonnull World world, + @Nonnull CommandBuffer commandBuffer ) { List sensorDataList = debugSupport.getSensorVisData(); if (sensorDataList != null) { - TransformComponent transformComponent = commandBuffer.getComponent(npcRef, TransformComponent.getComponentType()); - - assert transformComponent != null; - Vector3d npcPosition = transformComponent.getPosition(); - BoundingBox boundingBoxComponent = commandBuffer.getComponent(npcRef, BoundingBox.getComponentType()); - - assert boundingBoxComponent != null; - double npcMidHeight = boundingBoxComponent.getBoundingBox().max.y / 2.0; HeadRotation headRotation = commandBuffer.getComponent(npcRef, HeadRotation.getComponentType()); double heading = headRotation != null ? headRotation.getRotation().getYaw() : transformComponent.getRotation().getYaw(); sensorDataList.sort((a, b) -> Double.compare(b.range(), a.range())); - World world = commandBuffer.getExternalData().getWorld(); double discStackOffset = 0.1; for (int i = 0; i < sensorDataList.size(); i++) { @@ -538,5 +559,73 @@ public class RoleSystems { debugSupport.clearSensorVisData(); } } + + private static void renderLeashPositionVisualization( + @Nonnull NPCEntity npcComponent, + @Nonnull Ref npcRef, + @Nonnull TransformComponent transformComponent, + @Nonnull BoundingBox boundingBoxComponent, + @Nonnull World world + ) { + if (npcComponent.requiresLeashPosition()) { + Box boundingBox = boundingBoxComponent.getBoundingBox(); + double npcWidth = boundingBox.max.x - boundingBox.min.x; + double npcDepth = boundingBox.max.z - boundingBox.min.z; + double npcRingOuterRadius = Math.max(npcWidth, npcDepth) / 2.0 + 0.1F; + double npcRingInnerRadius = npcRingOuterRadius - 0.1F; + int colorIndex = Math.abs(npcRef.getIndex()) % DebugUtils.INDEXED_COLORS.length; + Vector3f color = DebugUtils.INDEXED_COLORS[colorIndex]; + Vector3d leashPoint = npcComponent.getLeashPoint(); + DebugUtils.addSphere(world, leashPoint, color, 0.3F, 0.1F); + Vector3d npcPosition = transformComponent.getPosition(); + double npcMidHeight = boundingBox.max.y / 2.0; + double npcMidY = npcPosition.y + npcMidHeight; + double dirX = npcPosition.x - leashPoint.x; + double dirZ = npcPosition.z - leashPoint.z; + double horizontalDist = Math.sqrt(dirX * dirX + dirZ * dirZ); + if (horizontalDist > 0.001) { + double verticalDist = npcMidY - leashPoint.y; + double pitchAngle = Math.atan2(verticalDist, horizontalDist); + double yawAngle = Math.atan2(dirZ, dirX); + addChainRing(world, leashPoint.x, leashPoint.y, leashPoint.z, 0.5, 0.4F, yawAngle, -pitchAngle, color); + addChainRing(world, npcPosition.x, npcMidY, npcPosition.z, npcRingOuterRadius, npcRingInnerRadius, yawAngle + Math.PI, pitchAngle, color); + double hDirX = dirX / horizontalDist; + double hDirZ = dirZ / horizontalDist; + double cosPitch = Math.cos(pitchAngle); + double sinPitch = Math.sin(pitchAngle); + double leashEdgeX = leashPoint.x + hDirX * 0.5 * cosPitch; + double leashEdgeY = leashPoint.y + sinPitch * 0.5; + double leashEdgeZ = leashPoint.z + hDirZ * 0.5 * cosPitch; + double npcEdgeX = npcPosition.x - hDirX * npcRingOuterRadius * cosPitch; + double npcEdgeY = npcMidY - sinPitch * npcRingOuterRadius; + double npcEdgeZ = npcPosition.z - hDirZ * npcRingOuterRadius * cosPitch; + DebugUtils.addLine(world, leashEdgeX, leashEdgeY, leashEdgeZ, npcEdgeX, npcEdgeY, npcEdgeZ, color, 0.05F, 0.1F, false); + } else { + DebugUtils.addDisc(world, leashPoint.x, leashPoint.y, leashPoint.z, 0.5, 0.4F, color, 0.8F, 0.1F, false); + DebugUtils.addDisc(world, npcPosition.x, npcMidY, npcPosition.z, npcRingOuterRadius, npcRingInnerRadius, color, 0.8F, 0.1F, false); + DebugUtils.addLine(world, leashPoint.x, leashPoint.y, leashPoint.z, npcPosition.x, npcMidY, npcPosition.z, color, 0.05F, 0.1F, false); + } + } + } + + private static void addChainRing( + @Nonnull World world, + double x, + double y, + double z, + double outerRadius, + double innerRadius, + double yawAngle, + double pitchAngle, + @Nonnull Vector3f color + ) { + Matrix4d matrix = new Matrix4d(); + matrix.identity(); + matrix.translate(x, y, z); + Matrix4d tmp = new Matrix4d(); + matrix.rotateAxis(yawAngle, 0.0, 1.0, 0.0, tmp); + matrix.rotateAxis(pitchAngle, 0.0, 0.0, 1.0, tmp); + DebugUtils.addDisc(world, matrix, outerRadius, innerRadius, color, 0.8F, 0.1F, false); + } } } diff --git a/src/com/hypixel/hytale/server/spawning/suppression/system/ChunkSuppressionSystems.java b/src/com/hypixel/hytale/server/spawning/suppression/system/ChunkSuppressionSystems.java index 8ed36fc7..19bfc2ab 100644 --- a/src/com/hypixel/hytale/server/spawning/suppression/system/ChunkSuppressionSystems.java +++ b/src/com/hypixel/hytale/server/spawning/suppression/system/ChunkSuppressionSystems.java @@ -84,8 +84,10 @@ public class ChunkSuppressionSystems { for (int i = 0; i < addQueue.size(); i++) { Entry, ChunkSuppressionEntry> entry = addQueue.get(i); Ref ref = entry.getKey(); - store.putComponent(ref, this.chunkSuppressionEntryComponentType, entry.getValue()); - SpawningPlugin.get().getLogger().at(Level.FINEST).log("Annotated chunk %s from queue", ref); + if (ref.isValid()) { + store.putComponent(ref, this.chunkSuppressionEntryComponentType, entry.getValue()); + SpawningPlugin.get().getLogger().at(Level.FINEST).log("Annotated chunk %s from queue", ref); + } } addQueue.clear(); @@ -93,10 +95,12 @@ public class ChunkSuppressionSystems { List> removeQueue = queue.getToRemove(); if (!removeQueue.isEmpty()) { - for (int i = 0; i < removeQueue.size(); i++) { - Ref ref = removeQueue.get(i); - store.tryRemoveComponent(ref, this.chunkSuppressionEntryComponentType); - SpawningPlugin.get().getLogger().at(Level.FINEST).log("Removed annotation from chunk %s from queue", ref); + for (int ix = 0; ix < removeQueue.size(); ix++) { + Ref ref = removeQueue.get(ix); + if (ref.isValid()) { + store.tryRemoveComponent(ref, this.chunkSuppressionEntryComponentType); + SpawningPlugin.get().getLogger().at(Level.FINEST).log("Removed annotation from chunk %s from queue", ref); + } } removeQueue.clear(); diff --git a/src/com/hypixel/hytale/server/spawning/suppression/system/SpawnSuppressionSystems.java b/src/com/hypixel/hytale/server/spawning/suppression/system/SpawnSuppressionSystems.java index d3096a11..4e72b6cf 100644 --- a/src/com/hypixel/hytale/server/spawning/suppression/system/SpawnSuppressionSystems.java +++ b/src/com/hypixel/hytale/server/spawning/suppression/system/SpawnSuppressionSystems.java @@ -208,7 +208,7 @@ public class SpawnSuppressionSystems { @Override public void onSystemUnregistered() { - this.eventRegistry.shutdown(); + this.eventRegistry.shutdownAndCleanup(true); } private void onSpawnSuppressionsLoaded(@Nonnull LoadedAssetsEvent> event) { diff --git a/src/com/hypixel/hytale/server/spawning/world/system/WorldSpawningSystem.java b/src/com/hypixel/hytale/server/spawning/world/system/WorldSpawningSystem.java index 2514d2c4..f2283af2 100644 --- a/src/com/hypixel/hytale/server/spawning/world/system/WorldSpawningSystem.java +++ b/src/com/hypixel/hytale/server/spawning/world/system/WorldSpawningSystem.java @@ -74,28 +74,27 @@ public class WorldSpawningSystem extends TickingSystem { if (chunkRef != null) { int environmentIndex = entry.getEnvironmentIndex(); ChunkSpawnData chunkSpawnDataComponent = store.getComponent(chunkRef, this.chunkSpawnDataComponentType); - - assert chunkSpawnDataComponent != null; - - ChunkEnvironmentSpawnData environmentSpawnData = chunkSpawnDataComponent.getEnvironmentSpawnData(environmentIndex); - int segmentCount = -environmentSpawnData.getSegmentCount(); - worldSpawnDataResource.adjustSegmentCount(segmentCount); - WorldEnvironmentSpawnData worldEnvironmentSpawnData = worldSpawnDataResource.getWorldEnvironmentSpawnData(environmentIndex); - double expectedNPCs = worldEnvironmentSpawnData.getExpectedNPCs(); - worldEnvironmentSpawnData.adjustSegmentCount(segmentCount); - worldEnvironmentSpawnData.updateExpectedNPCs(worldTimeResource.getMoonPhase()); - environmentSpawnData.markProcessedAsUnspawnable(); - HytaleLogger.Api context = LOGGER.at(Level.FINEST); - if (context.isEnabled()) { - Environment environmentAsset = Environment.getAssetMap().getAsset(environmentIndex); - if (environmentAsset != null) { - String environment = environmentAsset.getId(); - context.log( - "Reducing expected NPC count for %s due to un-spawnable chunk. Was %s, now %s", - environment, - expectedNPCs, - worldEnvironmentSpawnData.getExpectedNPCs() - ); + if (chunkSpawnDataComponent != null) { + ChunkEnvironmentSpawnData environmentSpawnData = chunkSpawnDataComponent.getEnvironmentSpawnData(environmentIndex); + int segmentCount = -environmentSpawnData.getSegmentCount(); + worldSpawnDataResource.adjustSegmentCount(segmentCount); + WorldEnvironmentSpawnData worldEnvironmentSpawnData = worldSpawnDataResource.getWorldEnvironmentSpawnData(environmentIndex); + double expectedNPCs = worldEnvironmentSpawnData.getExpectedNPCs(); + worldEnvironmentSpawnData.adjustSegmentCount(segmentCount); + worldEnvironmentSpawnData.updateExpectedNPCs(worldTimeResource.getMoonPhase()); + environmentSpawnData.markProcessedAsUnspawnable(); + HytaleLogger.Api context = LOGGER.at(Level.FINEST); + if (context.isEnabled()) { + Environment environmentAsset = Environment.getAssetMap().getAsset(environmentIndex); + if (environmentAsset != null) { + String environment = environmentAsset.getId(); + context.log( + "Reducing expected NPC count for %s due to un-spawnable chunk. Was %s, now %s", + environment, + expectedNPCs, + worldEnvironmentSpawnData.getExpectedNPCs() + ); + } } } } diff --git a/src/com/hypixel/hytale/server/worldgen/loader/AssetFileSystem.java b/src/com/hypixel/hytale/server/worldgen/loader/AssetFileSystem.java index 61e2c223..459e25ce 100644 --- a/src/com/hypixel/hytale/server/worldgen/loader/AssetFileSystem.java +++ b/src/com/hypixel/hytale/server/worldgen/loader/AssetFileSystem.java @@ -1,7 +1,6 @@ package com.hypixel.hytale.server.worldgen.loader; import com.hypixel.hytale.assetstore.AssetPack; -import com.hypixel.hytale.builtin.worldgen.FeatureFlags; import com.hypixel.hytale.builtin.worldgen.WorldGenPlugin; import com.hypixel.hytale.procedurallib.file.AssetLoader; import com.hypixel.hytale.procedurallib.file.AssetPath; @@ -32,6 +31,7 @@ public class AssetFileSystem implements FileIOSystem { }; private final Path root; private final FileIOSystem.PathArray packRoots; + private final List packs; private final Object2ObjectMap files = new Object2ObjectOpenCustomHashMap<>(PATH_STRATEGY); private final Object2ObjectMap> resources = new Object2ObjectOpenHashMap<>(); @@ -39,7 +39,8 @@ public class AssetFileSystem implements FileIOSystem { Path root = AssetModule.get().getBaseAssetPack().getRoot(); Path assetPath = FileIO.relativize(config.path(), root); this.root = root; - this.packRoots = new FileIOSystem.PathArray(getAssetRoots(config, packRoot -> FileIO.exists(packRoot, assetPath))); + this.packs = getAssetPacks(config, packRoot -> FileIO.exists(packRoot, assetPath)); + this.packRoots = new FileIOSystem.PathArray(getAssetRoots(this.packs)); } @Nonnull @@ -89,32 +90,42 @@ public class AssetFileSystem implements FileIOSystem { FileIO.closeFileIOSystem(this); } - public static Path[] getAssetRoots(@Nonnull WorldGenConfig config, @Nonnull Predicate filter) { + public List packs() { + return this.packs; + } + + public static List getAssetPacks(@Nonnull WorldGenConfig config, @Nonnull Predicate filter) { AssetModule assets = AssetModule.get(); - List packs = assets.getAssetPacks(); - ObjectArrayList roots = new ObjectArrayList<>(packs.size()); Path versionsDir = WorldGenPlugin.getVersionsPath(); + List allPacks = assets.getAssetPacks(); + ObjectArrayList packs = new ObjectArrayList<>(allPacks.size()); - for (int i = packs.size() - 1; i >= 1; i--) { - AssetPack pack = packs.get(i); + for (int i = allPacks.size() - 1; i >= 1; i--) { + AssetPack pack = allPacks.get(i); if (!FileIO.startsWith(pack.getRoot(), versionsDir) && filter.test(pack.getRoot())) { - roots.add(packs.get(i).getRoot()); + packs.add(allPacks.get(i)); } } - if (FeatureFlags.VERSION_OVERRIDES) { - for (int ix = packs.size() - 1; ix >= 1; ix--) { - AssetPack pack = packs.get(ix); - if (FileIO.startsWith(pack.getRoot(), versionsDir) - && pack.getManifest().getVersion().compareTo(config.version()) <= 0 - && filter.test(pack.getRoot())) { - roots.add(packs.get(ix).getRoot()); - } + for (int ix = allPacks.size() - 1; ix >= 1; ix--) { + AssetPack pack = allPacks.get(ix); + if (FileIO.startsWith(pack.getRoot(), versionsDir) && pack.getManifest().getVersion().compareTo(config.version()) <= 0 && filter.test(pack.getRoot())) { + packs.add(allPacks.get(ix)); } } - roots.add(packs.getFirst().getRoot()); - return roots.toArray(Path[]::new); + packs.add(allPacks.getFirst()); + return List.copyOf(packs); + } + + public static Path[] getAssetRoots(@Nonnull List packs) { + Path[] roots = new Path[packs.size()]; + + for (int i = 0; i < packs.size(); i++) { + roots[i] = packs.get(i).getRoot(); + } + + return roots; } public record Resource(@Nonnull T value, @Nonnull Class type) { diff --git a/src/com/hypixel/hytale/server/worldgen/loader/ChunkGeneratorJsonLoader.java b/src/com/hypixel/hytale/server/worldgen/loader/ChunkGeneratorJsonLoader.java index 1debbb98..23a94a14 100644 --- a/src/com/hypixel/hytale/server/worldgen/loader/ChunkGeneratorJsonLoader.java +++ b/src/com/hypixel/hytale/server/worldgen/loader/ChunkGeneratorJsonLoader.java @@ -3,14 +3,16 @@ package com.hypixel.hytale.server.worldgen.loader; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.hypixel.hytale.assetstore.AssetPack; import com.hypixel.hytale.common.map.IWeightedMap; import com.hypixel.hytale.common.map.WeightedMap; +import com.hypixel.hytale.common.semver.Semver; import com.hypixel.hytale.common.util.ArrayUtil; import com.hypixel.hytale.common.util.PathUtil; +import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.math.util.FastRandom; import com.hypixel.hytale.math.vector.Vector2i; import com.hypixel.hytale.procedurallib.file.FileIO; -import com.hypixel.hytale.procedurallib.file.FileIOSystem; import com.hypixel.hytale.procedurallib.json.JsonLoader; import com.hypixel.hytale.procedurallib.json.Loader; import com.hypixel.hytale.procedurallib.json.SeedString; @@ -23,9 +25,12 @@ import com.hypixel.hytale.server.worldgen.loader.context.FileContextLoader; import com.hypixel.hytale.server.worldgen.loader.context.FileLoadingContext; import com.hypixel.hytale.server.worldgen.loader.zone.ZonePatternProviderJsonLoader; import com.hypixel.hytale.server.worldgen.prefab.PrefabStoreRoot; +import com.hypixel.hytale.server.worldgen.util.LogUtil; import com.hypixel.hytale.server.worldgen.zone.Zone; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; +import java.util.Objects; import javax.annotation.Nonnull; public class ChunkGeneratorJsonLoader extends Loader { @@ -50,7 +55,8 @@ public class ChunkGeneratorJsonLoader extends Loader packs) { + HytaleLogger.Api logger = LogUtil.getLogger().atInfo(); + Semver unversioned = new Semver(0L, 0L, 0L); + logger.log("Loading world-gen with the following asset-packs (highest priority first):"); + + for (int i = 0; i < packs.size(); i++) { + AssetPack pack = packs.get(i); + String name = pack.getName(); + Semver version = Objects.requireNonNullElse(pack.getManifest().getVersion(), unversioned); + Path location = pack.getPackLocation(); + logger.log("- [%3d] %s:%s - [%s]", i, name, version, location); + } + } + public interface Constants { String KEY_WIDTH = "Width"; String KEY_HEIGHT = "Height"; diff --git a/src/com/hypixel/hytale/server/worldgen/loader/WorldGenPrefabLoader.java b/src/com/hypixel/hytale/server/worldgen/loader/WorldGenPrefabLoader.java index c807dc5f..0b8f125a 100644 --- a/src/com/hypixel/hytale/server/worldgen/loader/WorldGenPrefabLoader.java +++ b/src/com/hypixel/hytale/server/worldgen/loader/WorldGenPrefabLoader.java @@ -1,5 +1,6 @@ package com.hypixel.hytale.server.worldgen.loader; +import com.hypixel.hytale.assetstore.AssetPack; import com.hypixel.hytale.procedurallib.file.FileIO; import com.hypixel.hytale.server.core.asset.AssetModule; import com.hypixel.hytale.server.core.prefab.selection.buffer.PrefabLoader; @@ -14,6 +15,7 @@ import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; import java.io.IOException; import java.nio.file.Path; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import javax.annotation.Nonnull; @@ -77,7 +79,8 @@ public class WorldGenPrefabLoader { AssetModule assets = AssetModule.get(); Path root = assets.getBaseAssetPack().getRoot(); Path assetPath = FileIO.relativize(prefabStorePath, root); - Path[] roots = AssetFileSystem.getAssetRoots(config, packRoot -> FileIO.exists(packRoot, assetPath)); + List packs = AssetFileSystem.getAssetPacks(config, packRoot -> FileIO.exists(packRoot, assetPath)); + Path[] roots = AssetFileSystem.getAssetRoots(packs); PrefabLoader[] loaders = new PrefabLoader[roots.length]; for (int i = 0; i < roots.length; i++) { diff --git a/src/manifests.json b/src/manifests.json index 007b808a..06286898 100644 --- a/src/manifests.json +++ b/src/manifests.json @@ -534,7 +534,19 @@ "ServerVersion": "*", "Dependencies": { "Hytale:I18nModule": "*", - "Hytale:Instances": "*" + "Hytale:Instances": "*", + "Hytale:AnchorActionModule": "*" + } +} +,{ + "Group": "Hytale", + "Name": "RandomTick", + "Version": "1.0.0", + "Website": "https://hypixel.com/", + "Main": "com.hypixel.hytale.builtin.randomtick.RandomTickPlugin", + "ServerVersion": "*", + "Dependencies": { + "Hytale:LegacyModule": "*" } } ] \ No newline at end of file