From f9906c44925f45e3cda87e8f9ad16066ae2becb2 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 11 May 2023 02:23:43 +0000 Subject: [PATCH] Format code [skip actions] --- .../auth/AuthenticationSystem.java | 266 ++--- .../emu/grasscutter/auth/Authenticator.java | 44 +- .../auth/DefaultAuthenticators.java | 726 ++++++------- .../auth/ExternalAuthenticator.java | 64 +- .../grasscutter/auth/OAuthAuthenticator.java | 68 +- .../java/emu/grasscutter/command/Command.java | 56 +- .../grasscutter/command/CommandHandler.java | 176 ++-- .../emu/grasscutter/command/CommandMap.java | 708 ++++++------- .../command/DefaultPermissionHandler.java | 66 +- .../command/PermissionHandler.java | 20 +- .../command/commands/AccountCommand.java | 40 +- .../command/commands/AnnounceCommand.java | 156 +-- .../command/commands/BanCommand.java | 124 +-- .../command/commands/ClearCommand.java | 210 ++-- .../command/commands/CoopCommand.java | 114 +- .../command/commands/EnterDungeonCommand.java | 100 +- .../command/commands/GiveCommand.java | 163 +-- .../command/commands/HealCommand.java | 88 +- .../command/commands/HelpCommand.java | 184 ++-- .../command/commands/KickCommand.java | 68 +- .../command/commands/KillAllCommand.java | 108 +- .../commands/KillCharacterCommand.java | 82 +- .../command/commands/LanguageCommand.java | 116 +-- .../command/commands/ListCommand.java | 112 +- .../command/commands/PermissionCommand.java | 148 +-- .../command/commands/PositionCommand.java | 58 +- .../command/commands/ResetConstCommand.java | 86 +- .../commands/ResetShopLimitCommand.java | 46 +- .../command/commands/SendMailCommand.java | 482 ++++----- .../command/commands/SendMessageCommand.java | 74 +- .../command/commands/SetConstCommand.java | 184 ++-- .../commands/SetFetterLevelCommand.java | 100 +- .../command/commands/StopCommand.java | 54 +- .../command/commands/TeamCommand.java | 536 +++++----- .../command/commands/TeleportAllCommand.java | 72 +- .../command/commands/TeleportCommand.java | 156 +-- .../command/commands/UnBanCommand.java | 78 +- .../command/commands/UnlockAllCommand.java | 86 +- .../command/commands/WeatherCommand.java | 104 +- .../emu/grasscutter/data/GameResource.java | 20 +- .../emu/grasscutter/data/ResourceType.java | 80 +- .../data/binout/AbilityEmbryoEntry.java | 42 +- .../grasscutter/data/binout/ConfigGadget.java | 26 +- .../binout/ConfigGadgetCombatProperty.java | 36 +- .../data/binout/HomeworldDefaultSaveData.java | 122 +-- .../data/binout/SceneNpcBornData.java | 48 +- .../data/binout/SceneNpcBornEntry.java | 84 +- .../data/binout/ScenePointEntry.java | 48 +- .../data/binout/ScriptSceneData.java | 36 +- .../grasscutter/data/common/CurveInfo.java | 38 +- .../grasscutter/data/common/DynamicFloat.java | 210 ++-- .../data/common/FightPropData.java | 50 +- .../data/common/ItemParamData.java | 78 +- .../data/common/ItemParamStringData.java | 52 +- .../grasscutter/data/common/OpenCondData.java | 48 +- .../data/common/PropGrowCurve.java | 28 +- .../data/excels/BattlePassMissionData.java | 148 +-- .../data/excels/BattlePassRewardData.java | 50 +- .../excels/BlossomRefreshExcelConfigData.java | 92 +- .../emu/grasscutter/data/excels/BuffData.java | 56 +- .../emu/grasscutter/data/excels/CityData.java | 48 +- .../grasscutter/data/excels/CombineData.java | 164 +-- .../data/excels/CookBonusData.java | 86 +- .../data/excels/CookRecipeData.java | 48 +- .../excels/EnvAnimalGatherConfigData.java | 72 +- .../data/excels/EquipAffixData.java | 118 +-- .../data/excels/FetterCharacterCardData.java | 46 +- .../grasscutter/data/excels/FetterData.java | 76 +- .../grasscutter/data/excels/ForgeData.java | 58 +- .../data/excels/FurnitureMakeConfigData.java | 68 +- .../grasscutter/data/excels/GatherData.java | 94 +- .../data/excels/HomeWorldBgmData.java | 62 +- .../data/excels/HomeWorldLevelData.java | 62 +- .../data/excels/InvestigationMonsterData.java | 66 +- .../data/excels/MusicGameBasicData.java | 36 +- .../data/excels/PersonalLineData.java | 46 +- .../data/excels/ProudSkillData.java | 114 +- .../grasscutter/data/excels/RewardData.java | 52 +- .../data/excels/RewardPreviewData.java | 70 +- .../data/excels/ShopGoodsData.java | 224 ++-- .../data/excels/TriggerExcelConfigData.java | 28 +- .../grasscutter/database/DatabaseCounter.java | 44 +- .../grasscutter/database/DatabaseManager.java | 252 ++--- .../emu/grasscutter/game/CoopRequest.java | 62 +- .../AchievementControlReturns.java | 94 +- .../game/activity/ActivityWatcherType.java | 26 +- .../game/activity/DefaultActivityHandler.java | 30 +- .../game/activity/DefaultWatcher.java | 22 +- .../game/activity/GameActivity.java | 26 +- .../musicgame/MusicGameActivityHandler.java | 210 ++-- .../activity/musicgame/MusicGameBeatmap.java | 194 ++-- .../musicgame/MusicGamePlayerData.java | 172 +-- .../musicgame/MusicGameScoreTrigger.java | 46 +- .../game/battlepass/BattlePassManager.java | 830 +++++++-------- .../game/battlepass/BattlePassMission.java | 150 +-- .../game/battlepass/BattlePassReward.java | 102 +- .../game/battlepass/BattlePassSystem.java | 160 +-- .../emu/grasscutter/game/chat/ChatSystem.java | 430 ++++---- .../game/chat/ChatSystemHandler.java | 52 +- .../game/combine/CombineManger.java | 286 ++--- .../game/combine/CombineResult.java | 86 +- .../game/combine/ReliquaryDecomposeEntry.java | 48 +- .../emu/grasscutter/game/drop/DropInfo.java | 32 +- .../game/dungeons/DungeonDrop.java | 48 +- .../game/dungeons/DungeonDropEntry.java | 102 +- .../challenge/trigger/KillGadgetTrigger.java | 48 +- .../grasscutter/game/entity/EntityItem.java | 286 ++--- .../game/entity/gadget/GadgetContent.java | 44 +- .../game/entity/gadget/GadgetObject.java | 40 +- .../chest/NormalChestInteractHandler.java | 100 +- .../worktop/WorktopWorktopOptionHandler.java | 14 +- .../game/expedition/ExpeditionInfo.java | 50 +- .../game/expedition/ExpeditionRewardData.java | 30 +- .../expedition/ExpeditionRewardDataList.java | 38 +- .../game/expedition/ExpeditionRewardInfo.java | 18 +- .../game/expedition/ExpeditionSystem.java | 84 +- .../grasscutter/game/friends/FriendsList.java | 508 ++++----- .../grasscutter/game/friends/Friendship.java | 232 ++--- .../game/friends/PlayerProfile.java | 210 ++-- .../grasscutter/game/gacha/GachaRecord.java | 150 +-- .../grasscutter/game/gacha/GachaSystem.java | 982 +++++++++--------- .../game/gacha/PlayerGachaBannerInfo.java | 244 ++--- .../game/home/FurnitureMakeSlotItem.java | 62 +- .../emu/grasscutter/game/home/GameHome.java | 716 ++++++------- .../grasscutter/game/home/HomeAnimalItem.java | 70 +- .../grasscutter/game/home/HomeBlockItem.java | 174 ++-- .../game/home/HomeFurnitureItem.java | 164 +-- .../grasscutter/game/home/HomeNPCItem.java | 76 +- .../grasscutter/game/home/HomeSceneItem.java | 192 ++-- .../game/inventory/EquipInventoryTab.java | 78 +- .../game/inventory/InventoryTab.java | 26 +- .../grasscutter/game/inventory/ItemDef.java | 54 +- .../game/inventory/MaterialInventoryTab.java | 78 +- .../grasscutter/game/mail/MailHandler.java | 222 ++-- .../game/managers/FurnitureManager.java | 356 +++---- .../game/managers/SatiationManager.java | 230 ++-- .../game/managers/SotSManager.java | 422 ++++---- .../game/managers/blossom/BlossomConfig.java | 24 +- .../game/managers/blossom/BlossomType.java | 70 +- .../cooking/ActiveCookCompoundData.java | 106 +- .../game/managers/cooking/CookingManager.java | 370 +++---- .../deforestation/DeforestationManager.java | 202 ++-- .../managers/deforestation/HitTreeRecord.java | 96 +- .../energy/SkillParticleGenerationEntry.java | 32 +- .../energy/SkillParticleGenerationInfo.java | 28 +- .../managers/forging/ActiveForgeData.java | 192 ++-- .../game/managers/forging/ForgingManager.java | 636 ++++++------ .../managers/mapmark/MapMarksManager.java | 176 ++-- .../stamina/AfterUpdateStaminaListener.java | 24 +- .../stamina/BeforeUpdateStaminaListener.java | 48 +- .../game/managers/stamina/Consumption.java | 34 +- .../managers/stamina/ConsumptionType.java | 74 +- .../game/player/BasePlayerDataManager.java | 46 +- .../game/player/BasePlayerManager.java | 40 +- .../game/player/InvokeHandler.java | 128 +-- .../game/player/PlayerBirthday.java | 128 +-- .../game/player/PlayerCollectionRecords.java | 136 +-- .../grasscutter/game/props/ActionReason.java | 426 ++++---- .../props/BattlePassMissionRefreshType.java | 36 +- .../game/props/BattlePassMissionStatus.java | 52 +- .../grasscutter/game/props/ClimateType.java | 112 +- .../grasscutter/game/props/EnterReason.java | 144 +-- .../grasscutter/game/props/EntityIdType.java | 44 +- .../grasscutter/game/props/FetterState.java | 88 +- .../emu/grasscutter/game/props/GrowCurve.java | 210 ++-- .../ItemUseAction/ItemUseAcceptQuest.java | 38 +- .../props/ItemUseAction/ItemUseAction.java | 166 +-- .../ItemUseAction/ItemUseAddAllEnergy.java | 48 +- .../ItemUseAction/ItemUseAddCurStamina.java | 38 +- .../ItemUseAction/ItemUseAddElemEnergy.java | 68 +- .../props/ItemUseAction/ItemUseAddExp.java | 36 +- .../ItemUseAction/ItemUseAddReliquaryExp.java | 28 +- .../ItemUseAction/ItemUseAddSelectItem.java | 44 +- .../ItemUseAction/ItemUseAddServerBuff.java | 50 +- .../ItemUseAction/ItemUseAddWeaponExp.java | 28 +- .../ItemUseAction/ItemUseCombineItem.java | 62 +- .../ItemUseAction/ItemUseGainAvatar.java | 102 +- .../ItemUseAction/ItemUseGainCardProduct.java | 34 +- .../ItemUseAction/ItemUseGainCostume.java | 46 +- .../ItemUseAction/ItemUseGainFlycloak.java | 46 +- .../ItemUseAction/ItemUseGainNameCard.java | 36 +- .../ItemUseGrantSelectReward.java | 44 +- .../game/props/ItemUseAction/ItemUseInt.java | 28 +- .../ItemUseAction/ItemUseMakeGadget.java | 52 +- .../ItemUseAction/ItemUseOpenRandomChest.java | 54 +- .../ItemUseAction/ItemUseReliveAvatar.java | 34 +- .../ItemUseAction/ItemUseUnlockCodex.java | 38 +- .../ItemUseAction/ItemUseUnlockCombine.java | 48 +- .../ItemUseUnlockCookRecipe.java | 48 +- .../ItemUseAction/ItemUseUnlockForge.java | 48 +- .../ItemUseUnlockFurnitureFormula.java | 48 +- .../ItemUseUnlockFurnitureSuite.java | 48 +- .../ItemUseAction/ItemUseUnlockHomeBgm.java | 40 +- .../ItemUseUnlockPaidBattlePassNormal.java | 38 +- .../props/ItemUseAction/UseItemParams.java | 72 +- .../emu/grasscutter/game/props/ItemUseOp.java | 148 +-- .../grasscutter/game/props/ItemUseTarget.java | 76 +- .../emu/grasscutter/game/props/LifeState.java | 88 +- .../grasscutter/game/props/MonsterType.java | 92 +- .../game/props/PlayerProperty.java | 194 ++-- .../emu/grasscutter/game/props/SceneType.java | 94 +- .../game/props/ServerBuffType.java | 72 +- .../game/props/WatcherTriggerType.java | 678 ++++++------ .../grasscutter/game/props/WeaponType.java | 140 +-- .../game/quest/enums/ParentQuestState.java | 36 +- .../game/quest/enums/QuestGuideType.java | 34 +- .../game/quest/enums/QuestShowType.java | 32 +- .../game/quest/enums/QuestType.java | 44 +- .../quest/exec/ExecSetGameTimeLocked.java | 1 - .../emu/grasscutter/game/shop/ShopLimit.java | 86 +- .../emu/grasscutter/game/shop/ShopSystem.java | 230 ++-- .../emu/grasscutter/game/shop/ShopType.java | 214 ++-- .../game/systems/AnnouncementSystem.java | 214 ++-- .../emu/grasscutter/game/tower/TowerData.java | 38 +- .../game/tower/TowerLevelRecord.java | 112 +- .../game/tower/TowerScheduleConfig.java | 68 +- .../grasscutter/game/world/ChestReward.java | 40 +- .../emu/grasscutter/game/world/Scene.java | 3 +- .../grasscutter/net/packet/BasePacket.java | 286 ++--- .../emu/grasscutter/net/packet/Opcodes.java | 26 +- .../grasscutter/net/packet/PacketHandler.java | 18 +- .../grasscutter/net/packet/PacketWriter.java | 352 +++---- .../java/emu/grasscutter/plugin/Plugin.java | 248 ++--- .../emu/grasscutter/plugin/PluginConfig.java | 38 +- .../grasscutter/plugin/PluginIdentifier.java | 44 +- .../emu/grasscutter/plugin/PluginManager.java | 642 ++++++------ .../java/emu/grasscutter/plugin/api/Item.java | 10 +- .../grasscutter/plugin/api/PlayerHook.java | 244 ++--- .../grasscutter/plugin/api/ServerHook.java | 252 ++--- .../scripts/SceneIndexManager.java | 70 +- .../scripts/constants/EventType.java | 252 ++--- .../scripts/constants/ScriptGadgetState.java | 48 +- .../scripts/constants/ScriptRegionShape.java | 18 +- .../scripts/data/SceneBusiness.java | 20 +- .../scripts/data/SceneGarbage.java | 22 +- .../grasscutter/scripts/data/SceneMeta.java | 148 +-- .../grasscutter/scripts/data/SceneNPC.java | 20 +- .../grasscutter/scripts/data/SceneRegion.java | 76 +- .../grasscutter/scripts/data/SceneVar.java | 26 +- .../serializer/LuaTableJacksonSerializer.java | 390 +++---- .../scripts/serializer/Serializer.java | 26 +- .../service/ScriptMonsterSpawnService.java | 76 +- .../grasscutter/server/event/Cancellable.java | 12 +- .../emu/grasscutter/server/event/Event.java | 46 +- .../server/event/EventHandler.java | 180 ++-- .../server/event/HandlerPriority.java | 24 +- .../event/dispatch/QueryAllRegionsEvent.java | 42 +- .../dispatch/QueryCurrentRegionEvent.java | 42 +- .../server/event/entity/EntityDeathEvent.java | 38 +- .../server/event/entity/EntityMoveEvent.java | 64 +- .../event/game/PlayerCreationEvent.java | 54 +- .../game/ReceiveCommandFeedbackEvent.java | 60 +- .../server/event/game/ReceivePacketEvent.java | 70 +- .../server/event/game/SendPacketEvent.java | 60 +- .../server/event/game/ServerTickEvent.java | 46 +- .../event/internal/ServerStartEvent.java | 36 +- .../event/internal/ServerStopEvent.java | 36 +- .../server/event/player/PlayerMoveEvent.java | 80 +- .../server/event/player/PlayerQuitEvent.java | 20 +- .../event/player/PlayerReceiveMailEvent.java | 48 +- .../event/player/PlayerTeamDeathEvent.java | 40 +- .../event/player/PlayerUseFoodEvent.java | 44 +- .../server/event/types/EntityEvent.java | 34 +- .../server/event/types/GameEvent.java | 12 +- .../server/event/types/PlayerEvent.java | 34 +- .../server/event/types/ServerEvent.java | 42 +- .../server/game/GameServerPacketHandler.java | 220 ++-- .../grasscutter/server/game/GameSession.java | 540 +++++----- .../server/game/GameSessionManager.java | 230 ++-- .../emu/grasscutter/server/http/Router.java | 66 +- .../server/http/dispatch/DispatchHandler.java | 320 +++--- .../DocumentationServerHandler.java | 40 +- .../http/documentation/HandbookHandler.java | 30 +- .../documentation/RootRequestHandler.java | 84 +- .../http/handlers/AnnouncementsHandler.java | 242 ++--- .../server/http/handlers/GachaHandler.java | 306 +++--- .../server/http/handlers/GenericHandler.java | 170 +-- .../server/http/handlers/LogHandler.java | 42 +- .../http/objects/ComboTokenReqJson.java | 30 +- .../http/objects/ComboTokenResJson.java | 34 +- .../server/http/objects/HttpJsonResponse.java | 104 +- .../http/objects/LoginAccountRequestJson.java | 14 +- .../server/http/objects/LoginResultJson.java | 76 +- .../http/objects/LoginTokenRequestJson.java | 12 +- .../objects/WebStaticVersionResponse.java | 70 +- .../server/packet/recv/Handler.java | 30 +- .../recv/HandlerAbilityInvocationsNotify.java | 48 +- .../HandlerActivityTakeWatcherRewardReq.java | 58 +- .../recv/HandlerAddBackupAvatarTeamReq.java | 28 +- .../packet/recv/HandlerAskAddFriendReq.java | 36 +- .../recv/HandlerAvatarChangeCostumeReq.java | 56 +- .../recv/HandlerAvatarDieAnimationEndReq.java | 36 +- .../HandlerAvatarExpeditionAllDataReq.java | 36 +- .../HandlerAvatarExpeditionGetRewardReq.java | 94 +- .../HandlerAvatarFetterLevelRewardReq.java | 110 +- .../packet/recv/HandlerAvatarPromoteReq.java | 38 +- .../recv/HandlerAvatarSkillUpgradeReq.java | 44 +- .../packet/recv/HandlerAvatarUpgradeReq.java | 44 +- .../recv/HandlerAvatarWearFlycloakReq.java | 54 +- .../packet/recv/HandlerBackMyWorldReq.java | 70 +- .../recv/HandlerBuyBattlePassLevelReq.java | 42 +- .../packet/recv/HandlerBuyGoodsReq.java | 174 ++-- ...andlerCalcWeaponUpgradeReturnItemsReq.java | 72 +- .../packet/recv/HandlerChangeAvatarReq.java | 36 +- .../recv/HandlerChangeMailStarNotify.java | 68 +- .../recv/HandlerChangeMpTeamAvatarReq.java | 36 +- .../packet/recv/HandlerChangeTeamNameReq.java | 36 +- .../recv/HandlerChooseCurAvatarTeamReq.java | 36 +- .../HandlerClientAbilityInitFinishNotify.java | 64 +- .../server/packet/recv/HandlerCombineReq.java | 104 +- .../packet/recv/HandlerCreateVehicleReq.java | 52 +- .../packet/recv/HandlerDealAddFriendReq.java | 42 +- .../recv/HandlerDelBackupAvatarTeamReq.java | 32 +- .../server/packet/recv/HandlerDelMailReq.java | 36 +- .../packet/recv/HandlerDeleteFriendReq.java | 36 +- .../recv/HandlerDestroyMaterialReq.java | 42 +- .../server/packet/recv/HandlerDoGachaReq.java | 40 +- .../packet/recv/HandlerEnterSceneDoneReq.java | 108 +- .../recv/HandlerEnterSceneReadyReq.java | 36 +- .../HandlerEnterTransPointRegionNotify.java | 28 +- .../packet/recv/HandlerEnterWorldAreaReq.java | 44 +- .../recv/HandlerEntityAiSyncNotify.java | 42 +- ...andlerEvtAiSyncCombatThreatInfoNotify.java | 30 +- .../recv/HandlerEvtAiSyncSkillCdNotify.java | 30 +- .../recv/HandlerEvtAvatarLockChairReq.java | 50 +- .../recv/HandlerEvtAvatarSitDownNotify.java | 38 +- .../recv/HandlerEvtAvatarStandUpNotify.java | 38 +- .../recv/HandlerEvtCreateGadgetNotify.java | 76 +- .../recv/HandlerEvtDestroyGadgetNotify.java | 36 +- ...andlerEvtEntityRenderersChangedNotify.java | 74 +- .../HandlerExitTransPointRegionNotify.java | 28 +- .../recv/HandlerForgeGetQueueDataReq.java | 28 +- .../recv/HandlerForgeQueueManipulateReq.java | 32 +- .../packet/recv/HandlerForgeStartReq.java | 36 +- .../packet/recv/HandlerFurnitureMakeReq.java | 30 +- .../recv/HandlerFurnitureMakeStartReq.java | 36 +- .../packet/recv/HandlerGachaWishReq.java | 68 +- .../recv/HandlerGetActivityInfoReq.java | 42 +- .../HandlerGetActivityShopSheetInfoReq.java | 36 +- .../recv/HandlerGetAllH5ActivityInfoReq.java | 32 +- .../recv/HandlerGetAllUnlockNameCardReq.java | 32 +- .../packet/recv/HandlerGetAuthkeyReq.java | 32 +- .../HandlerGetDailyDungeonEntryInfoReq.java | 38 +- .../HandlerGetFriendShowAvatarInfoReq.java | 52 +- .../HandlerGetFriendShowNameCardInfoReq.java | 48 +- ...rGetFurnitureCurModuleArrangeCountReq.java | 32 +- .../packet/recv/HandlerGetGachaInfoReq.java | 34 +- .../recv/HandlerGetHomeLevelUpRewardReq.java | 82 +- .../HandlerGetInvestigationMonsterReq.java | 46 +- .../packet/recv/HandlerGetMailItemReq.java | 38 +- .../HandlerGetPlayerAskFriendListReq.java | 30 +- .../recv/HandlerGetPlayerBlacklistReq.java | 32 +- .../recv/HandlerGetPlayerFriendListReq.java | 32 +- .../recv/HandlerGetPlayerHomeCompInfoReq.java | 32 +- .../recv/HandlerGetPlayerSocialDetailReq.java | 52 +- .../packet/recv/HandlerGetPlayerTokenReq.java | 292 +++--- .../recv/HandlerGetRegionSearchReq.java | 30 +- .../packet/recv/HandlerGetSceneAreaReq.java | 38 +- .../packet/recv/HandlerGetScenePointReq.java | 38 +- .../server/packet/recv/HandlerGetShopReq.java | 36 +- .../recv/HandlerGetShopmallDataReq.java | 34 +- .../packet/recv/HandlerGetWidgetSlotReq.java | 36 +- .../packet/recv/HandlerGetWorldMpInfoReq.java | 32 +- .../packet/recv/HandlerHitTreeNotify.java | 34 +- .../recv/HandlerHomeChangeEditModeReq.java | 52 +- .../recv/HandlerHomeChangeModuleReq.java | 74 +- .../recv/HandlerHomeChooseModuleReq.java | 50 +- .../HandlerHomeEnterEditModeFinishReq.java | 38 +- .../HandlerHomeGetArrangementInfoReq.java | 40 +- .../recv/HandlerHomeGetBasicInfoReq.java | 34 +- .../HandlerHomeResourceTakeFetterExpReq.java | 34 +- .../HandlerHomeResourceTakeHomeCoinReq.java | 34 +- .../recv/HandlerHomeSceneInitFinishReq.java | 32 +- .../packet/recv/HandlerHomeSceneJumpReq.java | 102 +- .../HandlerHomeUpdateArrangementInfoReq.java | 54 +- .../server/packet/recv/HandlerMarkMapReq.java | 34 +- .../recv/HandlerMcoinExchangeHcoinReq.java | 62 +- .../HandlerMonsterAIConfigHashNotify.java | 30 +- .../HandlerMusicGameCreateBeatmapReq.java | 136 +-- .../recv/HandlerMusicGameGetBeatmapReq.java | 62 +- .../HandlerMusicGameSearchBeatmapReq.java | 58 +- .../packet/recv/HandlerMusicGameStartReq.java | 38 +- ...rMusicGameStartToPlayOthersBeatmapReq.java | 42 +- .../recv/HandlerObstacleModifyNotify.java | 30 +- .../recv/HandlerPathfindingEnterSceneReq.java | 36 +- .../recv/HandlerPersonalLineAllDataReq.java | 36 +- .../recv/HandlerPersonalSceneJumpReq.java | 68 +- .../server/packet/recv/HandlerPingReq.java | 46 +- .../recv/HandlerPlayerApplyEnterMpReq.java | 46 +- .../HandlerPlayerApplyEnterMpResultReq.java | 46 +- .../packet/recv/HandlerPlayerChatReq.java | 66 +- .../HandlerPlayerCompoundMaterialReq.java | 32 +- .../packet/recv/HandlerPlayerCookArgsReq.java | 34 +- .../packet/recv/HandlerPlayerCookReq.java | 34 +- .../recv/HandlerPlayerForceExitReq.java | 56 +- .../HandlerPlayerGetForceQuitBanInfoReq.java | 52 +- .../packet/recv/HandlerPlayerLoginReq.java | 102 +- .../packet/recv/HandlerPrivateChatReq.java | 58 +- .../recv/HandlerPullPrivateChatReq.java | 46 +- .../packet/recv/HandlerPullRecentChatReq.java | 28 +- ...andlerQueryCodexMonsterBeKilledNumReq.java | 38 +- .../packet/recv/HandlerQueryPathReq.java | 44 +- .../packet/recv/HandlerQuickUseWidgetReq.java | 106 +- .../packet/recv/HandlerReadMailNotify.java | 68 +- .../recv/HandlerReliquaryDecomposeReq.java | 40 +- .../recv/HandlerReliquaryUpgradeReq.java | 50 +- .../recv/HandlerSceneEntityDrownReq.java | 72 +- .../recv/HandlerSceneInitFinishReq.java | 80 +- .../recv/HandlerSceneKickPlayerReq.java | 56 +- .../recv/HandlerSceneTransToPointReq.java | 78 +- .../HandlerSetEntityClientDataNotify.java | 56 +- .../recv/HandlerSetEquipLockStateReq.java | 42 +- .../packet/recv/HandlerSetNameCardReq.java | 34 +- .../recv/HandlerSetPlayerBirthdayReq.java | 132 +-- .../recv/HandlerSetPlayerHeadImageReq.java | 46 +- .../packet/recv/HandlerSetPlayerNameReq.java | 46 +- .../packet/recv/HandlerSetPlayerPropReq.java | 66 +- .../recv/HandlerSetPlayerSignatureReq.java | 46 +- .../recv/HandlerSetUpAvatarTeamReq.java | 42 +- .../recv/HandlerSetUpLunchBoxWidgetReq.java | 36 +- .../packet/recv/HandlerSetWidgetSlotReq.java | 76 +- .../HandlerTakeAchievementGoalRewardReq.java | 34 +- .../recv/HandlerTakeBattlePassRewardReq.java | 34 +- .../recv/HandlerTakeFurnitureMakeReq.java | 42 +- .../recv/HandlerTakePlayerLevelRewardReq.java | 78 +- .../packet/recv/HandlerTakeoffEquipReq.java | 42 +- .../packet/recv/HandlerTowerAllDataReq.java | 36 +- .../recv/HandlerTowerEnterLevelReq.java | 42 +- .../recv/HandlerTowerTeamSelectReq.java | 54 +- .../packet/recv/HandlerTryEnterHomeReq.java | 144 +-- .../packet/recv/HandlerUnionCmdNotify.java | 90 +- .../recv/HandlerUnlockAvatarTalentReq.java | 42 +- .../recv/HandlerUnlockTransPointReq.java | 58 +- .../HandlerUpdatePlayerShowAvatarListReq.java | 48 +- ...andlerUpdatePlayerShowNameCardListReq.java | 44 +- .../server/packet/recv/HandlerUseItemReq.java | 70 +- .../recv/HandlerVehicleInteractReq.java | 50 +- .../packet/recv/HandlerWeaponAwakenReq.java | 44 +- .../packet/recv/HandlerWeaponPromoteReq.java | 44 +- .../packet/recv/HandlerWeaponUpgradeReq.java | 52 +- .../packet/recv/HandlerWearEquipReq.java | 42 +- .../packet/recv/HandlerWidgetDoBagReq.java | 88 +- .../recv/HandlerWorldPlayerReviveReq.java | 34 +- .../send/PackageTakeCompoundOutputRsp.java | 30 +- .../server/packet/send/Packet.java | 22 +- .../send/PacketAbilityChangeNotify.java | 42 +- .../send/PacketAbilityInvocationsNotify.java | 56 +- .../send/PacketAchievementAllDataNotify.java | 50 +- .../send/PacketAchievementUpdateNotify.java | 40 +- .../packet/send/PacketActivityInfoNotify.java | 38 +- .../PacketActivityScheduleInfoNotify.java | 64 +- .../PacketActivityTakeWatcherRewardRsp.java | 36 +- .../PacketActivityUpdateWatcherNotify.java | 40 +- .../send/PacketAddBackupAvatarTeamRsp.java | 42 +- .../PacketAddQuestContentProgressRsp.java | 36 +- .../send/PacketAllWidgetDataNotify.java | 110 +- .../packet/send/PacketAskAddFriendNotify.java | 42 +- .../packet/send/PacketAskAddFriendRsp.java | 32 +- .../packet/send/PacketAvatarAddNotify.java | 36 +- .../send/PacketAvatarChangeCostumeNotify.java | 36 +- .../send/PacketAvatarChangeCostumeRsp.java | 64 +- .../PacketAvatarChangeElementTypeRsp.java | 46 +- .../packet/send/PacketAvatarDataNotify.java | 84 +- .../send/PacketAvatarDieAnimationEndRsp.java | 34 +- .../send/PacketAvatarEquipChangeNotify.java | 82 +- .../PacketAvatarExpeditionAllDataRsp.java | 60 +- .../PacketAvatarExpeditionCallBackRsp.java | 36 +- .../PacketAvatarExpeditionDataNotify.java | 42 +- .../PacketAvatarExpeditionGetRewardRsp.java | 44 +- .../send/PacketAvatarExpeditionStartRsp.java | 36 +- .../send/PacketAvatarFetterDataNotify.java | 98 +- .../PacketAvatarFetterLevelRewardRsp.java | 72 +- .../send/PacketAvatarFightPropNotify.java | 42 +- .../PacketAvatarFlycloakChangeNotify.java | 42 +- .../send/PacketAvatarGainCostumeNotify.java | 34 +- .../send/PacketAvatarGainFlycloakNotify.java | 34 +- .../PacketAvatarLifeStateChangeNotify.java | 134 +-- .../packet/send/PacketAvatarPromoteRsp.java | 34 +- .../packet/send/PacketAvatarPropNotify.java | 102 +- .../send/PacketAvatarSatiationDataNotify.java | 92 +- .../send/PacketAvatarSkillChangeNotify.java | 50 +- .../PacketAvatarSkillDepotChangeNotify.java | 54 +- .../send/PacketAvatarSkillInfoNotify.java | 44 +- ...PacketAvatarSkillMaxChargeCountNotify.java | 44 +- .../send/PacketAvatarSkillUpgradeRsp.java | 46 +- .../send/PacketAvatarTeamAllDataNotify.java | 58 +- .../send/PacketAvatarUnlockTalentNotify.java | 46 +- .../packet/send/PacketAvatarUpgradeRsp.java | 54 +- .../send/PacketAvatarWearFlycloakRsp.java | 62 +- .../packet/send/PacketBackMyWorldRsp.java | 32 +- .../send/PacketBattlePassAllDataNotify.java | 70 +- ...cketBattlePassCurScheduleUpdateNotify.java | 44 +- .../PacketBattlePassMissionUpdateNotify.java | 64 +- .../send/PacketBlossomBriefInfoNotify.java | 32 +- .../send/PacketBuyBattlePassLevelRsp.java | 32 +- .../server/packet/send/PacketBuyGoodsRsp.java | 44 +- ...PacketCalcWeaponUpgradeReturnItemsRsp.java | 68 +- .../packet/send/PacketCanUseSkillNotify.java | 38 +- .../send/PacketCardProductRewardNotify.java | 46 +- .../send/PacketChallengeDataNotify.java | 44 +- .../packet/send/PacketChangeAvatarRsp.java | 42 +- .../send/PacketChangeMpTeamAvatarRsp.java | 48 +- .../packet/send/PacketChangeTeamNameRsp.java | 34 +- .../packet/send/PacketChapterStateNotify.java | 38 +- .../send/PacketChooseCurAvatarTeamRsp.java | 32 +- .../PacketClientAbilityInitFinishNotify.java | 58 +- .../send/PacketCodexDataFullNotify.java | 232 ++--- .../send/PacketCodexDataUpdateNotify.java | 52 +- .../send/PacketCombatInvocationsNotify.java | 56 +- .../packet/send/PacketCombineDataNotify.java | 34 +- .../send/PacketCombineFormulaDataNotify.java | 34 +- .../server/packet/send/PacketCombineRsp.java | 114 +- .../packet/send/PacketCompoundDataNotify.java | 44 +- .../packet/send/PacketCookDataNotify.java | 36 +- .../send/PacketCookRecipeDataNotify.java | 54 +- .../packet/send/PacketCreateVehicleRsp.java | 124 +-- .../packet/send/PacketDealAddFriendRsp.java | 42 +- .../send/PacketDelBackupAvatarTeamRsp.java | 48 +- .../server/packet/send/PacketDelMailRsp.java | 36 +- .../send/PacketDelTeamEntityNotify.java | 60 +- .../packet/send/PacketDeleteFriendNotify.java | 32 +- .../packet/send/PacketDeleteFriendRsp.java | 32 +- .../packet/send/PacketDestroyMaterialRsp.java | 46 +- .../server/packet/send/PacketDoGachaRsp.java | 134 +-- .../PacketDungeonChallengeBeginNotify.java | 46 +- .../PacketDungeonChallengeFinishNotify.java | 44 +- .../send/PacketDungeonShowReminderNotify.java | 36 +- .../packet/send/PacketEnterSceneDoneRsp.java | 36 +- .../send/PacketEnterScenePeerNotify.java | 46 +- .../packet/send/PacketEnterSceneReadyRsp.java | 36 +- .../packet/send/PacketEnterWorldAreaRsp.java | 42 +- .../packet/send/PacketEntityAiSyncNotify.java | 42 +- ...cketEntityFightPropChangeReasonNotify.java | 176 ++-- .../send/PacketEvtAvatarLockChairRsp.java | 50 +- .../send/PacketEvtAvatarSitDownNotify.java | 42 +- .../send/PacketEvtAvatarStandUpNotify.java | 44 +- ...PacketEvtEntityRenderersChangedNotify.java | 30 +- .../packet/send/PacketForgeDataNotify.java | 50 +- .../send/PacketForgeFormulaDataNotify.java | 34 +- .../send/PacketForgeGetQueueDataRsp.java | 52 +- .../send/PacketForgeQueueDataNotify.java | 52 +- .../send/PacketForgeQueueManipulateRsp.java | 90 +- .../packet/send/PacketForgeStartRsp.java | 34 +- ...tFurnitureCurModuleArrangeCountNotify.java | 40 +- .../packet/send/PacketFurnitureMakeRsp.java | 54 +- .../send/PacketFurnitureMakeStartRsp.java | 58 +- .../packet/send/PacketGachaWishRsp.java | 48 +- .../PacketGadgetAutoPickDropInfoNotify.java | 40 +- .../packet/send/PacketGadgetInteractRsp.java | 86 +- .../packet/send/PacketGadgetStateNotify.java | 44 +- .../packet/send/PacketGetActivityInfoRsp.java | 42 +- .../PacketGetActivityShopSheetInfoRsp.java | 104 +- .../send/PacketGetAllUnlockNameCardRsp.java | 36 +- .../packet/send/PacketGetAuthkeyRsp.java | 40 +- .../send/PacketGetChatEmojiCollectionRsp.java | 44 +- .../packet/send/PacketGetCompoundDataRsp.java | 46 +- .../PacketGetFriendShowAvatarInfoRsp.java | 46 +- .../PacketGetFriendShowNameCardInfoRsp.java | 42 +- .../packet/send/PacketGetGachaInfoRsp.java | 30 +- .../send/PacketGetHomeLevelUpRewardRsp.java | 46 +- .../PacketGetInvestigationMonsterRsp.java | 50 +- .../packet/send/PacketGetMailItemRsp.java | 146 +-- .../send/PacketGetOnlinePlayerListRsp.java | 58 +- .../send/PacketGetPlayerAskFriendListRsp.java | 50 +- .../send/PacketGetPlayerFriendListRsp.java | 94 +- .../send/PacketGetPlayerSocialDetailRsp.java | 48 +- .../packet/send/PacketGetPlayerTokenRsp.java | 168 +-- .../packet/send/PacketGetSceneAreaRsp.java | 54 +- .../packet/send/PacketGetScenePointRsp.java | 64 +- .../server/packet/send/PacketGetShopRsp.java | 182 ++-- .../packet/send/PacketGetShopmallDataRsp.java | 40 +- .../packet/send/PacketGetWidgetSlotRsp.java | 80 +- .../packet/send/PacketGetWorldMpInfoRsp.java | 36 +- .../packet/send/PacketGroupSuiteNotify.java | 90 +- .../packet/send/PacketGroupUnloadNotify.java | 38 +- .../send/PacketH5ActivityIdsNotify.java | 32 +- .../PacketHomeAllUnlockedBgmIdListNotify.java | 50 +- .../send/PacketHomeBasicInfoNotify.java | 74 +- .../send/PacketHomeChangeBgmNotify.java | 32 +- .../packet/send/PacketHomeChangeBgmRsp.java | 30 +- .../send/PacketHomeChangeEditModeRsp.java | 36 +- .../send/PacketHomeChangeModuleRsp.java | 40 +- .../send/PacketHomeChooseModuleRsp.java | 40 +- .../send/PacketHomeComfortInfoNotify.java | 90 +- .../PacketHomeEnterEditModeFinishRsp.java | 22 +- .../send/PacketHomeGetArrangementInfoRsp.java | 56 +- .../send/PacketHomeMarkPointNotify.java | 92 +- .../packet/send/PacketHomeModuleSeenRsp.java | 34 +- .../send/PacketHomeModuleUnlockNotify.java | 34 +- .../PacketHomeNewUnlockedBgmIdListNotify.java | 36 +- .../packet/send/PacketHomeResourceNotify.java | 76 +- .../PacketHomeResourceTakeFetterExpRsp.java | 62 +- .../PacketHomeResourceTakeHomeCoinRsp.java | 62 +- .../send/PacketHomeSceneInitFinishRsp.java | 32 +- .../packet/send/PacketHomeSceneJumpRsp.java | 36 +- .../PacketHomeUpdateArrangementInfoRsp.java | 22 +- .../packet/send/PacketHostPlayerNotify.java | 42 +- .../packet/send/PacketItemAddHintNotify.java | 70 +- .../packet/send/PacketLaunchFireworksRsp.java | 22 +- .../send/PacketLifeStateChangeNotify.java | 148 +-- .../packet/send/PacketMailChangeNotify.java | 152 +-- .../server/packet/send/PacketMarkMapRsp.java | 68 +- .../packet/send/PacketMarkNewNotify.java | 40 +- .../send/PacketMcoinExchangeHcoinRsp.java | 38 +- .../send/PacketMusicGameCreateBeatmapRsp.java | 42 +- .../send/PacketMusicGameGetBeatmapRsp.java | 58 +- .../send/PacketMusicGameSearchBeatmapRsp.java | 72 +- .../packet/send/PacketMusicGameStartRsp.java | 36 +- ...tMusicGameStartToPlayOthersBeatmapRsp.java | 44 +- .../server/packet/send/PacketNpcTalkRsp.java | 40 +- .../send/PacketOpenStateChangeNotify.java | 56 +- .../send/PacketPathfindingEnterSceneRsp.java | 22 +- .../send/PacketPersonalLineAllDataRsp.java | 68 +- .../send/PacketPersonalSceneJumpRsp.java | 36 +- .../server/packet/send/PacketPingRsp.java | 32 +- .../send/PacketPlayerApplyEnterMpNotify.java | 40 +- .../PacketPlayerApplyEnterMpResultNotify.java | 90 +- .../PacketPlayerApplyEnterMpResultRsp.java | 40 +- .../send/PacketPlayerApplyEnterMpRsp.java | 34 +- .../packet/send/PacketPlayerChatNotify.java | 116 +-- .../packet/send/PacketPlayerChatRsp.java | 32 +- .../send/PacketPlayerCompoundMaterialRsp.java | 72 +- .../packet/send/PacketPlayerCookArgsRsp.java | 32 +- .../packet/send/PacketPlayerCookRsp.java | 78 +- .../packet/send/PacketPlayerDataNotify.java | 62 +- .../PacketPlayerEnterSceneInfoNotify.java | 116 +-- .../PacketPlayerGetForceQuitBanInfoRsp.java | 34 +- .../PacketPlayerLevelRewardUpdateNotify.java | 42 +- .../packet/send/PacketPlayerLoginRsp.java | 148 +-- .../send/PacketPlayerPropChangeNotify.java | 42 +- .../PacketPlayerPropChangeReasonNotify.java | 64 +- .../packet/send/PacketPlayerPropNotify.java | 48 +- .../packet/send/PacketPlayerStoreNotify.java | 64 +- .../packet/send/PacketPlayerTimeNotify.java | 44 +- .../PacketPlayerWorldSceneInfoListNotify.java | 124 +-- .../packet/send/PacketPostEnterSceneRsp.java | 36 +- .../send/PacketProudSkillChangeNotify.java | 46 +- .../PacketProudSkillExtraLevelNotify.java | 46 +- .../packet/send/PacketPullPrivateChatRsp.java | 54 +- .../packet/send/PacketPullRecentChatRsp.java | 34 +- ...PacketQueryCodexMonsterBeKilledNumRsp.java | 54 +- .../packet/send/PacketQueryPathRsp.java | 50 +- .../packet/send/PacketQuestListNotify.java | 54 +- .../send/PacketQuestListUpdateNotify.java | 60 +- .../send/PacketQuestProgressUpdateNotify.java | 60 +- .../send/PacketReliquaryDecomposeRsp.java | 52 +- .../send/PacketReliquaryUpgradeRsp.java | 54 +- .../send/PacketSceneAreaUnlockNotify.java | 50 +- .../send/PacketSceneAreaWeatherNotify.java | 42 +- .../send/PacketSceneEntityAppearNotify.java | 102 +- .../PacketSceneEntityDisappearNotify.java | 70 +- .../send/PacketSceneEntityDrownRsp.java | 32 +- .../send/PacketSceneEntityMoveNotify.java | 46 +- .../packet/send/PacketSceneInitFinishRsp.java | 36 +- .../packet/send/PacketSceneKickPlayerRsp.java | 56 +- .../send/PacketScenePlayerInfoNotify.java | 68 +- .../send/PacketScenePlayerLocationNotify.java | 46 +- .../send/PacketSceneTransToPointRsp.java | 68 +- .../send/PacketSelectWorktopOptionRsp.java | 40 +- .../send/PacketServerAnnounceNotify.java | 76 +- .../PacketServerAnnounceRevokeNotify.java | 36 +- .../send/PacketServerBuffChangeNotify.java | 78 +- .../packet/send/PacketServerTimeNotify.java | 34 +- .../send/PacketSetBattlePassViewedRsp.java | 34 +- .../send/PacketSetEquipLockStateRsp.java | 46 +- .../packet/send/PacketSetNameCardRsp.java | 32 +- .../packet/send/PacketSetOpenStateRsp.java | 48 +- .../send/PacketSetPlayerBirthdayRsp.java | 52 +- .../send/PacketSetPlayerHeadImageRsp.java | 42 +- .../packet/send/PacketSetPlayerNameRsp.java | 36 +- .../packet/send/PacketSetPlayerPropRsp.java | 36 +- .../send/PacketSetPlayerSignatureRsp.java | 36 +- .../packet/send/PacketSetUpAvatarTeamRsp.java | 50 +- .../send/PacketSetUpLunchBoxWidgetRsp.java | 34 +- .../packet/send/PacketSetWidgetSlotRsp.java | 34 +- .../send/PacketSkipPlayerGameTimeRsp.java | 40 +- .../send/PacketStoreItemChangeNotify.java | 74 +- .../packet/send/PacketStoreItemDelNotify.java | 74 +- .../send/PacketStoreWeightLimitNotify.java | 54 +- .../PacketSyncScenePlayTeamEntityNotify.java | 36 +- .../send/PacketSyncTeamEntityNotify.java | 78 +- .../PacketTakeAchievementGoalRewardRsp.java | 62 +- .../send/PacketTakeAchievementRewardReq.java | 34 +- .../send/PacketTakeAchievementRewardRsp.java | 62 +- .../PacketTakeBattlePassMissionPointRsp.java | 20 +- .../send/PacketTakeBattlePassRewardRsp.java | 54 +- .../send/PacketTakeFurnitureMakeRsp.java | 74 +- .../send/PacketTakePlayerLevelRewardRsp.java | 54 +- .../packet/send/PacketTakeoffEquipRsp.java | 34 +- .../packet/send/PacketTowerAllDataRsp.java | 148 +-- ...PacketTowerCurLevelRecordChangeNotify.java | 50 +- .../packet/send/PacketTowerEnterLevelRsp.java | 46 +- .../PacketTowerFloorRecordChangeNotify.java | 66 +- .../send/PacketTowerLevelStarCondNotify.java | 66 +- ...acketTowerMiddleLevelChangeTeamNotify.java | 36 +- .../packet/send/PacketTowerTeamSelectRsp.java | 32 +- .../packet/send/PacketTryEnterHomeRsp.java | 88 +- .../send/PacketUnlockAvatarTalentRsp.java | 42 +- .../send/PacketUnlockNameCardNotify.java | 32 +- .../send/PacketUnlockTransPointRsp.java | 34 +- ...ketUnlockedFurnitureFormulaDataNotify.java | 44 +- ...acketUnlockedFurnitureSuiteDataNotify.java | 42 +- .../PacketUpdatePlayerShowAvatarListRsp.java | 44 +- ...PacketUpdatePlayerShowNameCardListRsp.java | 40 +- .../server/packet/send/PacketUseItemRsp.java | 64 +- .../send/PacketVehicleStaminaNotify.java | 36 +- .../packet/send/PacketWeaponAwakenRsp.java | 62 +- .../packet/send/PacketWeaponPromoteRsp.java | 44 +- .../packet/send/PacketWeaponUpgradeRsp.java | 50 +- .../packet/send/PacketWearEquipRsp.java | 34 +- .../send/PacketWidgetCoolDownNotify.java | 50 +- .../packet/send/PacketWidgetDoBagRsp.java | 58 +- .../send/PacketWidgetGadgetDataNotify.java | 84 +- .../send/PacketWidgetSlotChangeNotify.java | 88 +- .../send/PacketWindSeedClientNotify.java | 11 +- .../send/PacketWorktopOptionNotify.java | 46 +- .../packet/send/PacketWorldDataNotify.java | 54 +- .../send/PacketWorldPlayerDieNotify.java | 36 +- .../send/PacketWorldPlayerInfoNotify.java | 50 +- .../send/PacketWorldPlayerLocationNotify.java | 44 +- .../send/PacketWorldPlayerRTTNotify.java | 54 +- .../send/PacketWorldPlayerReviveRsp.java | 32 +- .../server/scheduler/AsyncServerTask.java | 194 ++-- .../server/scheduler/ServerTaskScheduler.java | 302 +++--- src/main/java/emu/grasscutter/task/Task.java | 70 +- .../java/emu/grasscutter/task/TaskMap.java | 346 +++--- .../emu/grasscutter/task/tasks/MoonCard.java | 72 +- .../java/emu/grasscutter/tools/Dumpers.java | 162 +-- .../emu/grasscutter/utils/DateHelper.java | 40 +- .../grasscutter/utils/StartupArguments.java | 3 +- 730 files changed, 29212 insertions(+), 29159 deletions(-) diff --git a/src/main/java/emu/grasscutter/auth/AuthenticationSystem.java b/src/main/java/emu/grasscutter/auth/AuthenticationSystem.java index 34b910f0a..e50ad288f 100644 --- a/src/main/java/emu/grasscutter/auth/AuthenticationSystem.java +++ b/src/main/java/emu/grasscutter/auth/AuthenticationSystem.java @@ -1,133 +1,133 @@ -package emu.grasscutter.auth; - -import emu.grasscutter.game.Account; -import emu.grasscutter.server.http.objects.*; -import io.javalin.http.Context; -import javax.annotation.Nullable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; - -/** Defines an authenticator for the server. Can be changed by plugins. */ -public interface AuthenticationSystem { - - /** - * Generates an authentication request from a {@link LoginAccountRequestJson} object. - * - * @param ctx The Javalin context. - * @param jsonData The JSON data. - * @return An authentication request. - */ - static AuthenticationRequest fromPasswordRequest(Context ctx, LoginAccountRequestJson jsonData) { - return AuthenticationRequest.builder().context(ctx).passwordRequest(jsonData).build(); - } - - /** - * Generates an authentication request from a {@link LoginTokenRequestJson} object. - * - * @param ctx The Javalin context. - * @param jsonData The JSON data. - * @return An authentication request. - */ - static AuthenticationRequest fromTokenRequest(Context ctx, LoginTokenRequestJson jsonData) { - return AuthenticationRequest.builder().context(ctx).tokenRequest(jsonData).build(); - } - - /** - * Generates an authentication request from a {@link ComboTokenReqJson} object. - * - * @param ctx The Javalin context. - * @param jsonData The JSON data. - * @return An authentication request. - */ - static AuthenticationRequest fromComboTokenRequest( - Context ctx, ComboTokenReqJson jsonData, ComboTokenReqJson.LoginTokenData tokenData) { - return AuthenticationRequest.builder() - .context(ctx) - .sessionKeyRequest(jsonData) - .sessionKeyData(tokenData) - .build(); - } - - /** - * Generates an authentication request from a {@link Context} object. - * - * @param ctx The Javalin context. - * @return An authentication request. - */ - static AuthenticationRequest fromExternalRequest(Context ctx) { - return AuthenticationRequest.builder().context(ctx).build(); - } - - /** - * Called when a user requests to make an account. - * - * @param username The provided username. - * @param password The provided password. (SHA-256'ed) - */ - void createAccount(String username, String password); - - /** - * Called when a user requests to reset their password. - * - * @param username The username of the account to reset. - */ - void resetPassword(String username); - - /** - * Called by plugins to internally verify a user's identity. - * - * @param details A unique identifier to identify the user. (For example: a JWT token) - * @return The user's account if the verification was successful, null if the user was unable to - * be verified. - */ - Account verifyUser(String details); - - /** - * This is the authenticator used for password authentication. - * - * @return An authenticator. - */ - Authenticator getPasswordAuthenticator(); - - /** - * This is the authenticator used for token authentication. - * - * @return An authenticator. - */ - Authenticator getTokenAuthenticator(); - - /** - * This is the authenticator used for session authentication. - * - * @return An authenticator. - */ - Authenticator getSessionKeyAuthenticator(); - - /** - * This is the authenticator used for handling external authentication requests. - * - * @return An authenticator. - */ - ExternalAuthenticator getExternalAuthenticator(); - - /** - * This is the authenticator used for handling OAuth authentication requests. - * - * @return An authenticator. - */ - OAuthAuthenticator getOAuthAuthenticator(); - - /** A data container that holds relevant data for authenticating a client. */ - @Builder - @AllArgsConstructor - @Getter - class AuthenticationRequest { - private final Context context; - - @Nullable private final LoginAccountRequestJson passwordRequest; - @Nullable private final LoginTokenRequestJson tokenRequest; - @Nullable private final ComboTokenReqJson sessionKeyRequest; - @Nullable private final ComboTokenReqJson.LoginTokenData sessionKeyData; - } -} +package emu.grasscutter.auth; + +import emu.grasscutter.game.Account; +import emu.grasscutter.server.http.objects.*; +import io.javalin.http.Context; +import javax.annotation.Nullable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +/** Defines an authenticator for the server. Can be changed by plugins. */ +public interface AuthenticationSystem { + + /** + * Generates an authentication request from a {@link LoginAccountRequestJson} object. + * + * @param ctx The Javalin context. + * @param jsonData The JSON data. + * @return An authentication request. + */ + static AuthenticationRequest fromPasswordRequest(Context ctx, LoginAccountRequestJson jsonData) { + return AuthenticationRequest.builder().context(ctx).passwordRequest(jsonData).build(); + } + + /** + * Generates an authentication request from a {@link LoginTokenRequestJson} object. + * + * @param ctx The Javalin context. + * @param jsonData The JSON data. + * @return An authentication request. + */ + static AuthenticationRequest fromTokenRequest(Context ctx, LoginTokenRequestJson jsonData) { + return AuthenticationRequest.builder().context(ctx).tokenRequest(jsonData).build(); + } + + /** + * Generates an authentication request from a {@link ComboTokenReqJson} object. + * + * @param ctx The Javalin context. + * @param jsonData The JSON data. + * @return An authentication request. + */ + static AuthenticationRequest fromComboTokenRequest( + Context ctx, ComboTokenReqJson jsonData, ComboTokenReqJson.LoginTokenData tokenData) { + return AuthenticationRequest.builder() + .context(ctx) + .sessionKeyRequest(jsonData) + .sessionKeyData(tokenData) + .build(); + } + + /** + * Generates an authentication request from a {@link Context} object. + * + * @param ctx The Javalin context. + * @return An authentication request. + */ + static AuthenticationRequest fromExternalRequest(Context ctx) { + return AuthenticationRequest.builder().context(ctx).build(); + } + + /** + * Called when a user requests to make an account. + * + * @param username The provided username. + * @param password The provided password. (SHA-256'ed) + */ + void createAccount(String username, String password); + + /** + * Called when a user requests to reset their password. + * + * @param username The username of the account to reset. + */ + void resetPassword(String username); + + /** + * Called by plugins to internally verify a user's identity. + * + * @param details A unique identifier to identify the user. (For example: a JWT token) + * @return The user's account if the verification was successful, null if the user was unable to + * be verified. + */ + Account verifyUser(String details); + + /** + * This is the authenticator used for password authentication. + * + * @return An authenticator. + */ + Authenticator getPasswordAuthenticator(); + + /** + * This is the authenticator used for token authentication. + * + * @return An authenticator. + */ + Authenticator getTokenAuthenticator(); + + /** + * This is the authenticator used for session authentication. + * + * @return An authenticator. + */ + Authenticator getSessionKeyAuthenticator(); + + /** + * This is the authenticator used for handling external authentication requests. + * + * @return An authenticator. + */ + ExternalAuthenticator getExternalAuthenticator(); + + /** + * This is the authenticator used for handling OAuth authentication requests. + * + * @return An authenticator. + */ + OAuthAuthenticator getOAuthAuthenticator(); + + /** A data container that holds relevant data for authenticating a client. */ + @Builder + @AllArgsConstructor + @Getter + class AuthenticationRequest { + private final Context context; + + @Nullable private final LoginAccountRequestJson passwordRequest; + @Nullable private final LoginTokenRequestJson tokenRequest; + @Nullable private final ComboTokenReqJson sessionKeyRequest; + @Nullable private final ComboTokenReqJson.LoginTokenData sessionKeyData; + } +} diff --git a/src/main/java/emu/grasscutter/auth/Authenticator.java b/src/main/java/emu/grasscutter/auth/Authenticator.java index ae8a21a29..ac324a7ba 100644 --- a/src/main/java/emu/grasscutter/auth/Authenticator.java +++ b/src/main/java/emu/grasscutter/auth/Authenticator.java @@ -1,22 +1,22 @@ -package emu.grasscutter.auth; - -import emu.grasscutter.server.http.objects.ComboTokenResJson; -import emu.grasscutter.server.http.objects.LoginResultJson; - -/** - * Handles username/password authentication from the client. - * - * @param The response object type. Should be {@link LoginResultJson} or {@link - * ComboTokenResJson} - */ -public interface Authenticator { - - /** - * Attempt to authenticate the client with the provided credentials. - * - * @param request The authentication request wrapped in a {@link - * AuthenticationSystem.AuthenticationRequest} object. - * @return The result of the login in an object. - */ - T authenticate(AuthenticationSystem.AuthenticationRequest request); -} +package emu.grasscutter.auth; + +import emu.grasscutter.server.http.objects.ComboTokenResJson; +import emu.grasscutter.server.http.objects.LoginResultJson; + +/** + * Handles username/password authentication from the client. + * + * @param The response object type. Should be {@link LoginResultJson} or {@link + * ComboTokenResJson} + */ +public interface Authenticator { + + /** + * Attempt to authenticate the client with the provided credentials. + * + * @param request The authentication request wrapped in a {@link + * AuthenticationSystem.AuthenticationRequest} object. + * @return The result of the login in an object. + */ + T authenticate(AuthenticationSystem.AuthenticationRequest request); +} diff --git a/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java b/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java index a30191910..f2ce46a47 100644 --- a/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java +++ b/src/main/java/emu/grasscutter/auth/DefaultAuthenticators.java @@ -1,363 +1,363 @@ -package emu.grasscutter.auth; - -import static emu.grasscutter.config.Configuration.ACCOUNT; -import static emu.grasscutter.utils.Language.translate; - -import at.favre.lib.crypto.bcrypt.BCrypt; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.Account; -import emu.grasscutter.server.http.objects.ComboTokenResJson; -import emu.grasscutter.server.http.objects.LoginResultJson; -import emu.grasscutter.utils.FileUtils; -import emu.grasscutter.utils.Utils; -import java.nio.charset.StandardCharsets; -import java.security.KeyFactory; -import java.security.interfaces.RSAPrivateKey; -import java.security.spec.PKCS8EncodedKeySpec; -import javax.crypto.Cipher; - -/** A class containing default authenticators. */ -public final class DefaultAuthenticators { - - /** Handles the authentication request from the username and password form. */ - public static class PasswordAuthenticator implements Authenticator { - @Override - public LoginResultJson authenticate(AuthenticationRequest request) { - var response = new LoginResultJson(); - - var requestData = request.getPasswordRequest(); - assert requestData != null; // This should never be null. - int playerCount = Grasscutter.getGameServer().getPlayers().size(); - - boolean successfulLogin = false; - String address = request.getContext().ip(); - String responseMessage = translate("messages.dispatch.account.username_error"); - String loggerMessage = ""; - - // Get account from database. - Account account = DatabaseHelper.getAccountByName(requestData.account); - if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { - // Check if account exists. - if (account == null && ACCOUNT.autoCreate) { - // This account has been created AUTOMATICALLY. There will be no permissions added. - account = DatabaseHelper.createAccountWithUid(requestData.account, 0); - - // Check if the account was created successfully. - if (account == null) { - responseMessage = translate("messages.dispatch.account.username_create_error"); - Grasscutter.getLogger() - .info(translate("messages.dispatch.account.account_login_create_error", address)); - } else { - // Continue with login. - successfulLogin = true; - - // Log the creation. - Grasscutter.getLogger() - .info( - translate( - "messages.dispatch.account.account_login_create_success", - address, - response.data.account.uid)); - } - } else if (account != null) successfulLogin = true; - else - loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address); - - } else { - responseMessage = translate("messages.dispatch.account.server_max_player_limit"); - loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); - } - - // Set response data. - if (successfulLogin) { - response.message = "OK"; - response.data.account.uid = account.getId(); - response.data.account.token = account.generateSessionKey(); - response.data.account.email = account.getEmail(); - - loggerMessage = - translate("messages.dispatch.account.login_success", address, account.getId()); - } else { - response.retcode = -201; - response.message = responseMessage; - } - Grasscutter.getLogger().info(loggerMessage); - - return response; - } - } - - public static class ExperimentalPasswordAuthenticator implements Authenticator { - @Override - public LoginResultJson authenticate(AuthenticationRequest request) { - var response = new LoginResultJson(); - - var requestData = request.getPasswordRequest(); - assert requestData != null; // This should never be null. - int playerCount = Grasscutter.getGameServer().getPlayers().size(); - - boolean successfulLogin = false; - String address = request.getContext().ip(); - String responseMessage = translate("messages.dispatch.account.username_error"); - String loggerMessage = ""; - String decryptedPassword = ""; - try { - byte[] key = FileUtils.readResource("/keys/auth_private-key.der"); - PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(key); - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - RSAPrivateKey private_key = (RSAPrivateKey) keyFactory.generatePrivate(keySpec); - - Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); - - cipher.init(Cipher.DECRYPT_MODE, private_key); - - decryptedPassword = - new String( - cipher.doFinal(Utils.base64Decode(request.getPasswordRequest().password)), - StandardCharsets.UTF_8); - } catch (Exception ignored) { - decryptedPassword = request.getPasswordRequest().password; - } - - if (decryptedPassword == null) { - successfulLogin = false; - loggerMessage = translate("messages.dispatch.account.login_password_error", address); - responseMessage = translate("messages.dispatch.account.password_error"); - } - - // Get account from database. - Account account = DatabaseHelper.getAccountByName(requestData.account); - if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { - // Check if account exists. - if (account == null && ACCOUNT.autoCreate) { - // This account has been created AUTOMATICALLY. There will be no permissions added. - if (decryptedPassword.length() >= 8) { - account = DatabaseHelper.createAccountWithUid(requestData.account, 0); - account.setPassword( - BCrypt.withDefaults().hashToString(12, decryptedPassword.toCharArray())); - account.save(); - - // Check if the account was created successfully. - if (account == null) { - responseMessage = translate("messages.dispatch.account.username_create_error"); - loggerMessage = - translate("messages.dispatch.account.account_login_create_error", address); - } else { - // Continue with login. - successfulLogin = true; - - // Log the creation. - Grasscutter.getLogger() - .info( - translate( - "messages.dispatch.account.account_login_create_success", - address, - response.data.account.uid)); - } - } else { - successfulLogin = false; - loggerMessage = translate("messages.dispatch.account.login_password_error", address); - responseMessage = translate("messages.dispatch.account.password_length_error"); - } - } else if (account != null) { - if (account.getPassword() != null && !account.getPassword().isEmpty()) { - if (BCrypt.verifyer() - .verify(decryptedPassword.toCharArray(), account.getPassword()) - .verified) { - successfulLogin = true; - } else { - successfulLogin = false; - loggerMessage = translate("messages.dispatch.account.login_password_error", address); - responseMessage = translate("messages.dispatch.account.password_error"); - } - } else { - successfulLogin = false; - loggerMessage = - translate("messages.dispatch.account.login_password_storage_error", address); - responseMessage = translate("messages.dispatch.account.password_storage_error"); - } - } else { - loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address); - } - } else { - responseMessage = translate("messages.dispatch.account.server_max_player_limit"); - loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); - } - - // Set response data. - if (successfulLogin) { - response.message = "OK"; - response.data.account.uid = account.getId(); - response.data.account.token = account.generateSessionKey(); - response.data.account.email = account.getEmail(); - - loggerMessage = - translate("messages.dispatch.account.login_success", address, account.getId()); - } else { - response.retcode = -201; - response.message = responseMessage; - } - Grasscutter.getLogger().info(loggerMessage); - - return response; - } - } - - /** Handles the authentication request from the game when using a registry token. */ - public static class TokenAuthenticator implements Authenticator { - @Override - public LoginResultJson authenticate(AuthenticationRequest request) { - var response = new LoginResultJson(); - - var requestData = request.getTokenRequest(); - assert requestData != null; - - boolean successfulLogin; - String address = request.getContext().ip(); - String loggerMessage; - int playerCount = Grasscutter.getGameServer().getPlayers().size(); - - // Log the attempt. - Grasscutter.getLogger() - .info(translate("messages.dispatch.account.login_token_attempt", address)); - - if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { - - // Get account from database. - Account account = DatabaseHelper.getAccountById(requestData.uid); - - // Check if account exists/token is valid. - successfulLogin = account != null && account.getSessionKey().equals(requestData.token); - - // Set response data. - if (successfulLogin) { - response.message = "OK"; - response.data.account.uid = account.getId(); - response.data.account.token = account.getSessionKey(); - response.data.account.email = account.getEmail(); - - // Log the login. - loggerMessage = - translate("messages.dispatch.account.login_token_success", address, requestData.uid); - } else { - response.retcode = -201; - response.message = translate("messages.dispatch.account.account_cache_error"); - - // Log the failure. - loggerMessage = translate("messages.dispatch.account.login_token_error", address); - } - - } else { - response.retcode = -201; - response.message = translate("messages.dispatch.account.server_max_player_limit"); - - loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); - } - - Grasscutter.getLogger().info(loggerMessage); - return response; - } - } - - /** Handles the authentication request from the game when using a combo token/session key. */ - public static class SessionKeyAuthenticator implements Authenticator { - @Override - public ComboTokenResJson authenticate(AuthenticationRequest request) { - var response = new ComboTokenResJson(); - - var requestData = request.getSessionKeyRequest(); - var loginData = request.getSessionKeyData(); - assert requestData != null; - assert loginData != null; - - boolean successfulLogin; - String address = request.getContext().ip(); - String loggerMessage; - int playerCount = Grasscutter.getGameServer().getPlayers().size(); - - if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { - // Get account from database. - Account account = DatabaseHelper.getAccountById(loginData.uid); - - // Check if account exists/token is valid. - successfulLogin = account != null && account.getSessionKey().equals(loginData.token); - - // Set response data. - if (successfulLogin) { - response.message = "OK"; - response.data.open_id = account.getId(); - response.data.combo_id = "157795300"; - response.data.combo_token = account.generateLoginToken(); - - // Log the login. - loggerMessage = translate("messages.dispatch.account.combo_token_success", address); - - } else { - response.retcode = -201; - response.message = translate("messages.dispatch.account.session_key_error"); - - // Log the failure. - loggerMessage = translate("messages.dispatch.account.combo_token_error", address); - } - } else { - response.retcode = -201; - response.message = translate("messages.dispatch.account.server_max_player_limit"); - - loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); - } - - Grasscutter.getLogger().info(loggerMessage); - return response; - } - } - - /** Handles authentication requests from external sources. */ - public static class ExternalAuthentication implements ExternalAuthenticator { - @Override - public void handleLogin(AuthenticationRequest request) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - - @Override - public void handleAccountCreation(AuthenticationRequest request) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - - @Override - public void handlePasswordReset(AuthenticationRequest request) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - } - - /** Handles authentication requests from OAuth sources.Zenlith */ - public static class OAuthAuthentication implements OAuthAuthenticator { - @Override - public void handleLogin(AuthenticationRequest request) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - - @Override - public void handleRedirection(AuthenticationRequest request, ClientType type) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - - @Override - public void handleTokenProcess(AuthenticationRequest request) { - request - .getContext() - .result("Authentication is not available with the default authentication method."); - } - } -} +package emu.grasscutter.auth; + +import static emu.grasscutter.config.Configuration.ACCOUNT; +import static emu.grasscutter.utils.Language.translate; + +import at.favre.lib.crypto.bcrypt.BCrypt; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.Account; +import emu.grasscutter.server.http.objects.ComboTokenResJson; +import emu.grasscutter.server.http.objects.LoginResultJson; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.Utils; +import java.nio.charset.StandardCharsets; +import java.security.KeyFactory; +import java.security.interfaces.RSAPrivateKey; +import java.security.spec.PKCS8EncodedKeySpec; +import javax.crypto.Cipher; + +/** A class containing default authenticators. */ +public final class DefaultAuthenticators { + + /** Handles the authentication request from the username and password form. */ + public static class PasswordAuthenticator implements Authenticator { + @Override + public LoginResultJson authenticate(AuthenticationRequest request) { + var response = new LoginResultJson(); + + var requestData = request.getPasswordRequest(); + assert requestData != null; // This should never be null. + int playerCount = Grasscutter.getGameServer().getPlayers().size(); + + boolean successfulLogin = false; + String address = request.getContext().ip(); + String responseMessage = translate("messages.dispatch.account.username_error"); + String loggerMessage = ""; + + // Get account from database. + Account account = DatabaseHelper.getAccountByName(requestData.account); + if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { + // Check if account exists. + if (account == null && ACCOUNT.autoCreate) { + // This account has been created AUTOMATICALLY. There will be no permissions added. + account = DatabaseHelper.createAccountWithUid(requestData.account, 0); + + // Check if the account was created successfully. + if (account == null) { + responseMessage = translate("messages.dispatch.account.username_create_error"); + Grasscutter.getLogger() + .info(translate("messages.dispatch.account.account_login_create_error", address)); + } else { + // Continue with login. + successfulLogin = true; + + // Log the creation. + Grasscutter.getLogger() + .info( + translate( + "messages.dispatch.account.account_login_create_success", + address, + response.data.account.uid)); + } + } else if (account != null) successfulLogin = true; + else + loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address); + + } else { + responseMessage = translate("messages.dispatch.account.server_max_player_limit"); + loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); + } + + // Set response data. + if (successfulLogin) { + response.message = "OK"; + response.data.account.uid = account.getId(); + response.data.account.token = account.generateSessionKey(); + response.data.account.email = account.getEmail(); + + loggerMessage = + translate("messages.dispatch.account.login_success", address, account.getId()); + } else { + response.retcode = -201; + response.message = responseMessage; + } + Grasscutter.getLogger().info(loggerMessage); + + return response; + } + } + + public static class ExperimentalPasswordAuthenticator implements Authenticator { + @Override + public LoginResultJson authenticate(AuthenticationRequest request) { + var response = new LoginResultJson(); + + var requestData = request.getPasswordRequest(); + assert requestData != null; // This should never be null. + int playerCount = Grasscutter.getGameServer().getPlayers().size(); + + boolean successfulLogin = false; + String address = request.getContext().ip(); + String responseMessage = translate("messages.dispatch.account.username_error"); + String loggerMessage = ""; + String decryptedPassword = ""; + try { + byte[] key = FileUtils.readResource("/keys/auth_private-key.der"); + PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(key); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + RSAPrivateKey private_key = (RSAPrivateKey) keyFactory.generatePrivate(keySpec); + + Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + + cipher.init(Cipher.DECRYPT_MODE, private_key); + + decryptedPassword = + new String( + cipher.doFinal(Utils.base64Decode(request.getPasswordRequest().password)), + StandardCharsets.UTF_8); + } catch (Exception ignored) { + decryptedPassword = request.getPasswordRequest().password; + } + + if (decryptedPassword == null) { + successfulLogin = false; + loggerMessage = translate("messages.dispatch.account.login_password_error", address); + responseMessage = translate("messages.dispatch.account.password_error"); + } + + // Get account from database. + Account account = DatabaseHelper.getAccountByName(requestData.account); + if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { + // Check if account exists. + if (account == null && ACCOUNT.autoCreate) { + // This account has been created AUTOMATICALLY. There will be no permissions added. + if (decryptedPassword.length() >= 8) { + account = DatabaseHelper.createAccountWithUid(requestData.account, 0); + account.setPassword( + BCrypt.withDefaults().hashToString(12, decryptedPassword.toCharArray())); + account.save(); + + // Check if the account was created successfully. + if (account == null) { + responseMessage = translate("messages.dispatch.account.username_create_error"); + loggerMessage = + translate("messages.dispatch.account.account_login_create_error", address); + } else { + // Continue with login. + successfulLogin = true; + + // Log the creation. + Grasscutter.getLogger() + .info( + translate( + "messages.dispatch.account.account_login_create_success", + address, + response.data.account.uid)); + } + } else { + successfulLogin = false; + loggerMessage = translate("messages.dispatch.account.login_password_error", address); + responseMessage = translate("messages.dispatch.account.password_length_error"); + } + } else if (account != null) { + if (account.getPassword() != null && !account.getPassword().isEmpty()) { + if (BCrypt.verifyer() + .verify(decryptedPassword.toCharArray(), account.getPassword()) + .verified) { + successfulLogin = true; + } else { + successfulLogin = false; + loggerMessage = translate("messages.dispatch.account.login_password_error", address); + responseMessage = translate("messages.dispatch.account.password_error"); + } + } else { + successfulLogin = false; + loggerMessage = + translate("messages.dispatch.account.login_password_storage_error", address); + responseMessage = translate("messages.dispatch.account.password_storage_error"); + } + } else { + loggerMessage = translate("messages.dispatch.account.account_login_exist_error", address); + } + } else { + responseMessage = translate("messages.dispatch.account.server_max_player_limit"); + loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); + } + + // Set response data. + if (successfulLogin) { + response.message = "OK"; + response.data.account.uid = account.getId(); + response.data.account.token = account.generateSessionKey(); + response.data.account.email = account.getEmail(); + + loggerMessage = + translate("messages.dispatch.account.login_success", address, account.getId()); + } else { + response.retcode = -201; + response.message = responseMessage; + } + Grasscutter.getLogger().info(loggerMessage); + + return response; + } + } + + /** Handles the authentication request from the game when using a registry token. */ + public static class TokenAuthenticator implements Authenticator { + @Override + public LoginResultJson authenticate(AuthenticationRequest request) { + var response = new LoginResultJson(); + + var requestData = request.getTokenRequest(); + assert requestData != null; + + boolean successfulLogin; + String address = request.getContext().ip(); + String loggerMessage; + int playerCount = Grasscutter.getGameServer().getPlayers().size(); + + // Log the attempt. + Grasscutter.getLogger() + .info(translate("messages.dispatch.account.login_token_attempt", address)); + + if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { + + // Get account from database. + Account account = DatabaseHelper.getAccountById(requestData.uid); + + // Check if account exists/token is valid. + successfulLogin = account != null && account.getSessionKey().equals(requestData.token); + + // Set response data. + if (successfulLogin) { + response.message = "OK"; + response.data.account.uid = account.getId(); + response.data.account.token = account.getSessionKey(); + response.data.account.email = account.getEmail(); + + // Log the login. + loggerMessage = + translate("messages.dispatch.account.login_token_success", address, requestData.uid); + } else { + response.retcode = -201; + response.message = translate("messages.dispatch.account.account_cache_error"); + + // Log the failure. + loggerMessage = translate("messages.dispatch.account.login_token_error", address); + } + + } else { + response.retcode = -201; + response.message = translate("messages.dispatch.account.server_max_player_limit"); + + loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); + } + + Grasscutter.getLogger().info(loggerMessage); + return response; + } + } + + /** Handles the authentication request from the game when using a combo token/session key. */ + public static class SessionKeyAuthenticator implements Authenticator { + @Override + public ComboTokenResJson authenticate(AuthenticationRequest request) { + var response = new ComboTokenResJson(); + + var requestData = request.getSessionKeyRequest(); + var loginData = request.getSessionKeyData(); + assert requestData != null; + assert loginData != null; + + boolean successfulLogin; + String address = request.getContext().ip(); + String loggerMessage; + int playerCount = Grasscutter.getGameServer().getPlayers().size(); + + if (ACCOUNT.maxPlayer <= -1 || playerCount < ACCOUNT.maxPlayer) { + // Get account from database. + Account account = DatabaseHelper.getAccountById(loginData.uid); + + // Check if account exists/token is valid. + successfulLogin = account != null && account.getSessionKey().equals(loginData.token); + + // Set response data. + if (successfulLogin) { + response.message = "OK"; + response.data.open_id = account.getId(); + response.data.combo_id = "157795300"; + response.data.combo_token = account.generateLoginToken(); + + // Log the login. + loggerMessage = translate("messages.dispatch.account.combo_token_success", address); + + } else { + response.retcode = -201; + response.message = translate("messages.dispatch.account.session_key_error"); + + // Log the failure. + loggerMessage = translate("messages.dispatch.account.combo_token_error", address); + } + } else { + response.retcode = -201; + response.message = translate("messages.dispatch.account.server_max_player_limit"); + + loggerMessage = translate("messages.dispatch.account.login_max_player_limit", address); + } + + Grasscutter.getLogger().info(loggerMessage); + return response; + } + } + + /** Handles authentication requests from external sources. */ + public static class ExternalAuthentication implements ExternalAuthenticator { + @Override + public void handleLogin(AuthenticationRequest request) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + + @Override + public void handleAccountCreation(AuthenticationRequest request) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + + @Override + public void handlePasswordReset(AuthenticationRequest request) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + } + + /** Handles authentication requests from OAuth sources.Zenlith */ + public static class OAuthAuthentication implements OAuthAuthenticator { + @Override + public void handleLogin(AuthenticationRequest request) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + + @Override + public void handleRedirection(AuthenticationRequest request, ClientType type) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + + @Override + public void handleTokenProcess(AuthenticationRequest request) { + request + .getContext() + .result("Authentication is not available with the default authentication method."); + } + } +} diff --git a/src/main/java/emu/grasscutter/auth/ExternalAuthenticator.java b/src/main/java/emu/grasscutter/auth/ExternalAuthenticator.java index 024306e23..9100e6d00 100644 --- a/src/main/java/emu/grasscutter/auth/ExternalAuthenticator.java +++ b/src/main/java/emu/grasscutter/auth/ExternalAuthenticator.java @@ -1,32 +1,32 @@ -package emu.grasscutter.auth; - -import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; - -/** Handles authentication via external routes. */ -public interface ExternalAuthenticator { - - /** - * Called when an external login request is made. - * - * @param request The authentication request. - */ - void handleLogin(AuthenticationRequest request); - - /** - * Called when an external account creation request is made. - * - * @param request The authentication request. - *

For developers: Use AuthenticationRequest#getRequest() to get the request body. Use - * AuthenticationRequest#getResponse() to get the response body. - */ - void handleAccountCreation(AuthenticationRequest request); - - /** - * Called when an external password reset request is made. - * - * @param request The authentication request. - *

For developers: Use AuthenticationRequest#getRequest() to get the request body. Use - * AuthenticationRequest#getResponse() to get the response body. - */ - void handlePasswordReset(AuthenticationRequest request); -} +package emu.grasscutter.auth; + +import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; + +/** Handles authentication via external routes. */ +public interface ExternalAuthenticator { + + /** + * Called when an external login request is made. + * + * @param request The authentication request. + */ + void handleLogin(AuthenticationRequest request); + + /** + * Called when an external account creation request is made. + * + * @param request The authentication request. + *

For developers: Use AuthenticationRequest#getRequest() to get the request body. Use + * AuthenticationRequest#getResponse() to get the response body. + */ + void handleAccountCreation(AuthenticationRequest request); + + /** + * Called when an external password reset request is made. + * + * @param request The authentication request. + *

For developers: Use AuthenticationRequest#getRequest() to get the request body. Use + * AuthenticationRequest#getResponse() to get the response body. + */ + void handlePasswordReset(AuthenticationRequest request); +} diff --git a/src/main/java/emu/grasscutter/auth/OAuthAuthenticator.java b/src/main/java/emu/grasscutter/auth/OAuthAuthenticator.java index b0214a925..eef6c380a 100644 --- a/src/main/java/emu/grasscutter/auth/OAuthAuthenticator.java +++ b/src/main/java/emu/grasscutter/auth/OAuthAuthenticator.java @@ -1,34 +1,34 @@ -package emu.grasscutter.auth; - -import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; - -/** Handles authentication via OAuth routes. */ -public interface OAuthAuthenticator { - - /** - * Called when an OAuth login request is made. - * - * @param request The authentication request. - */ - void handleLogin(AuthenticationRequest request); - - /** - * Called when a client requests to redirect to login page. - * - * @param request The authentication request. - */ - void handleRedirection(AuthenticationRequest request, ClientType clientType); - - /** - * Called when an OAuth login requests callback. - * - * @param request The authentication request. - */ - void handleTokenProcess(AuthenticationRequest request); - - /** The type of the client. Used for handling redirection. */ - enum ClientType { - DESKTOP, - MOBILE - } -} +package emu.grasscutter.auth; + +import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; + +/** Handles authentication via OAuth routes. */ +public interface OAuthAuthenticator { + + /** + * Called when an OAuth login request is made. + * + * @param request The authentication request. + */ + void handleLogin(AuthenticationRequest request); + + /** + * Called when a client requests to redirect to login page. + * + * @param request The authentication request. + */ + void handleRedirection(AuthenticationRequest request, ClientType clientType); + + /** + * Called when an OAuth login requests callback. + * + * @param request The authentication request. + */ + void handleTokenProcess(AuthenticationRequest request); + + /** The type of the client. Used for handling redirection. */ + enum ClientType { + DESKTOP, + MOBILE + } +} diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index f3c58bc51..0a454cd4c 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -1,28 +1,28 @@ -package emu.grasscutter.command; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Command { - String label() default ""; - - String[] aliases() default {}; - - String[] usage() default {""}; - - String permission() default ""; - - String permissionTargeted() default ""; - - TargetRequirement targetRequirement() default TargetRequirement.ONLINE; - - boolean threading() default false; - - enum TargetRequirement { - NONE, // targetPlayer is not required - OFFLINE, // targetPlayer must be offline - PLAYER, // targetPlayer can be online or offline - ONLINE // targetPlayer must be online - } -} +package emu.grasscutter.command; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Command { + String label() default ""; + + String[] aliases() default {}; + + String[] usage() default {""}; + + String permission() default ""; + + String permissionTargeted() default ""; + + TargetRequirement targetRequirement() default TargetRequirement.ONLINE; + + boolean threading() default false; + + enum TargetRequirement { + NONE, // targetPlayer is not required + OFFLINE, // targetPlayer must be offline + PLAYER, // targetPlayer can be online or offline + ONLINE // targetPlayer must be online + } +} diff --git a/src/main/java/emu/grasscutter/command/CommandHandler.java b/src/main/java/emu/grasscutter/command/CommandHandler.java index b9f072941..213c79627 100644 --- a/src/main/java/emu/grasscutter/command/CommandHandler.java +++ b/src/main/java/emu/grasscutter/command/CommandHandler.java @@ -1,88 +1,88 @@ -package emu.grasscutter.command; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent; -import java.util.List; -import java.util.StringJoiner; - -public interface CommandHandler { - - /** - * Send a message to the target. - * - * @param player The player to send the message to, or null for the server console. - * @param message The message to send. - */ - static void sendMessage(Player player, String message) { - // Call command feedback event. - ReceiveCommandFeedbackEvent event = new ReceiveCommandFeedbackEvent(player, message); - event.call(); - if (event.isCanceled()) { // If event is not cancelled, continue. - return; - } - - // Send message to target. - if (player == null) { - Grasscutter.getLogger().info(event.getMessage()); - } else { - player.dropMessage(event.getMessage().replace("\n\t", "\n\n")); - } - } - - static void sendTranslatedMessage(Player player, String messageKey, Object... args) { - sendMessage(player, translate(player, messageKey, args)); - } - - default String getUsageString(Player player, String... args) { - Command annotation = this.getClass().getAnnotation(Command.class); - String usage_prefix = translate(player, "commands.execution.usage_prefix"); - String command = annotation.label(); - for (String alias : annotation.aliases()) { - if (alias.length() < command.length()) command = alias; - } - if (player != null) { - command = "/" + command; - } - String target = - switch (annotation.targetRequirement()) { - case NONE -> ""; - case OFFLINE -> "@ "; // TODO: make translation keys for offline and online players - case ONLINE -> (player == null) - ? "@ " - : "[@] "; // TODO: make translation keys for offline and online players - case PLAYER -> (player == null) ? "@ " : "[@] "; - }; - String[] usages = annotation.usage(); - StringJoiner joiner = new StringJoiner("\n\t"); - for (String usage : usages) joiner.add(usage_prefix + command + " " + target + usage); - return joiner.toString(); - } - - default void sendUsageMessage(Player player, String... args) { - sendMessage(player, getUsageString(player, args)); - } - - default String getLabel() { - return this.getClass().getAnnotation(Command.class).label(); - } - - default String getDescriptionKey() { - Command annotation = this.getClass().getAnnotation(Command.class); - return "commands.%s.description".formatted(annotation.label()); - } - - default String getDescriptionString(Player player) { - return translate(player, getDescriptionKey()); - } - - /** - * Called when a player/console invokes a command. - * - * @param sender The player/console that invoked the command. - * @param args The arguments to the command. - */ - default void execute(Player sender, Player targetPlayer, List args) {} -} +package emu.grasscutter.command; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent; +import java.util.List; +import java.util.StringJoiner; + +public interface CommandHandler { + + /** + * Send a message to the target. + * + * @param player The player to send the message to, or null for the server console. + * @param message The message to send. + */ + static void sendMessage(Player player, String message) { + // Call command feedback event. + ReceiveCommandFeedbackEvent event = new ReceiveCommandFeedbackEvent(player, message); + event.call(); + if (event.isCanceled()) { // If event is not cancelled, continue. + return; + } + + // Send message to target. + if (player == null) { + Grasscutter.getLogger().info(event.getMessage()); + } else { + player.dropMessage(event.getMessage().replace("\n\t", "\n\n")); + } + } + + static void sendTranslatedMessage(Player player, String messageKey, Object... args) { + sendMessage(player, translate(player, messageKey, args)); + } + + default String getUsageString(Player player, String... args) { + Command annotation = this.getClass().getAnnotation(Command.class); + String usage_prefix = translate(player, "commands.execution.usage_prefix"); + String command = annotation.label(); + for (String alias : annotation.aliases()) { + if (alias.length() < command.length()) command = alias; + } + if (player != null) { + command = "/" + command; + } + String target = + switch (annotation.targetRequirement()) { + case NONE -> ""; + case OFFLINE -> "@ "; // TODO: make translation keys for offline and online players + case ONLINE -> (player == null) + ? "@ " + : "[@] "; // TODO: make translation keys for offline and online players + case PLAYER -> (player == null) ? "@ " : "[@] "; + }; + String[] usages = annotation.usage(); + StringJoiner joiner = new StringJoiner("\n\t"); + for (String usage : usages) joiner.add(usage_prefix + command + " " + target + usage); + return joiner.toString(); + } + + default void sendUsageMessage(Player player, String... args) { + sendMessage(player, getUsageString(player, args)); + } + + default String getLabel() { + return this.getClass().getAnnotation(Command.class).label(); + } + + default String getDescriptionKey() { + Command annotation = this.getClass().getAnnotation(Command.class); + return "commands.%s.description".formatted(annotation.label()); + } + + default String getDescriptionString(Player player) { + return translate(player, getDescriptionKey()); + } + + /** + * Called when a player/console invokes a command. + * + * @param sender The player/console that invoked the command. + * @param args The arguments to the command. + */ + default void execute(Player sender, Player targetPlayer, List args) {} +} diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index 89f387471..0a734cd46 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -1,354 +1,354 @@ -package emu.grasscutter.command; - -import static emu.grasscutter.config.Configuration.SERVER; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.player.Player; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import java.util.*; -import org.reflections.Reflections; - -@SuppressWarnings({"UnusedReturnValue", "unused"}) -public final class CommandMap { - private static final int INVALID_UID = Integer.MIN_VALUE; - private static final String consoleId = "console"; - private final Map commands = new TreeMap<>(); - private final Map aliases = new TreeMap<>(); - private final Map annotations = new TreeMap<>(); - private final Object2IntMap targetPlayerIds = new Object2IntOpenHashMap<>(); - - public CommandMap() { - this(false); - } - - public CommandMap(boolean scan) { - if (scan) this.scan(); - } - - public static CommandMap getInstance() { - return Grasscutter.getCommandMap(); - } - - private static int getUidFromString(String input) { - try { - return Integer.parseInt(input); - } catch (NumberFormatException ignored) { - var account = DatabaseHelper.getAccountByName(input); - if (account == null) return INVALID_UID; - var player = DatabaseHelper.getPlayerByAccount(account); - if (player == null) return INVALID_UID; - // We will be immediately fetching the player again after this, - // but offline vs online Player safety is more important than saving a lookup - return player.getUid(); - } - } - - /** - * Register a command handler. - * - * @param label The command label. - * @param command The command handler. - * @return Instance chaining. - */ - public CommandMap registerCommand(String label, CommandHandler command) { - Grasscutter.getLogger().debug("Registered command: " + label); - label = label.toLowerCase(); - - // Get command data. - Command annotation = command.getClass().getAnnotation(Command.class); - this.annotations.put(label, annotation); - this.commands.put(label, command); - - // Register aliases. - for (String alias : annotation.aliases()) { - this.aliases.put(alias, command); - this.annotations.put(alias, annotation); - } - return this; - } - - /** - * Removes a registered command handler. - * - * @param label The command label. - * @return Instance chaining. - */ - public CommandMap unregisterCommand(String label) { - Grasscutter.getLogger().debug("Unregistered command: " + label); - - CommandHandler handler = this.commands.get(label); - if (handler == null) return this; - - Command annotation = handler.getClass().getAnnotation(Command.class); - this.annotations.remove(label); - this.commands.remove(label); - - // Unregister aliases. - for (String alias : annotation.aliases()) { - this.aliases.remove(alias); - this.annotations.remove(alias); - } - - return this; - } - - public List getAnnotationsAsList() { - return new ArrayList<>(this.annotations.values()); - } - - public Map getAnnotations() { - return new LinkedHashMap<>(this.annotations); - } - - /** - * Returns a list of all registered commands. - * - * @return All command handlers as a list. - */ - public List getHandlersAsList() { - return new ArrayList<>(this.commands.values()); - } - - public Map getHandlers() { - return this.commands; - } - - /** - * Returns a handler by label/alias. - * - * @param label The command label. - * @return The command handler. - */ - public CommandHandler getHandler(String label) { - CommandHandler handler = this.commands.get(label); - if (handler == null) { - // Try getting by alias - handler = this.aliases.get(label); - } - return handler; - } - - private Player getTargetPlayer( - String playerId, Player player, Player targetPlayer, List args) { - // Top priority: If any @UID argument is present, override targetPlayer with it. - for (int i = 0; i < args.size(); i++) { - String arg = args.get(i); - if (arg.startsWith("@")) { - arg = args.remove(i).substring(1); - if (arg.equals("")) { - // This is a special case to target nothing, distinct from failing to assign a target. - // This is specifically to allow in-game players to run a command without targeting - // themselves or anyone else. - return null; - } - int uid = getUidFromString(arg); - if (uid == INVALID_UID) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid"); - throw new IllegalArgumentException(); - } - targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid, true); - if (targetPlayer == null) { - CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); - throw new IllegalArgumentException(); - } - return targetPlayer; - } - } - - // Next priority: If we invoked with a target, use that. - // By default, this only happens when you message another player in-game with a command. - if (targetPlayer != null) { - return targetPlayer; - } - - // Next priority: Use previously-set target. (see /target [[@]UID]) - if (targetPlayerIds.containsKey(playerId)) { - targetPlayer = - Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.getInt(playerId), true); - // We check every time in case the target is deleted after being targeted - if (targetPlayer == null) { - CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); - throw new IllegalArgumentException(); - } - return targetPlayer; - } - - // Lowest priority: Target the player invoking the command. In the case of the console, this - // will return null. - return player; - } - - private boolean setPlayerTarget(String playerId, Player player, String targetUid) { - if (targetUid.equals("")) { // Clears the default targetPlayer. - targetPlayerIds.removeInt(playerId); - CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target"); - return true; - } - - // Sets default targetPlayer to the UID provided. - int uid = getUidFromString(targetUid); - if (uid == INVALID_UID) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid"); - return false; - } - Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid, true); - if (targetPlayer == null) { - CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); - return false; - } - - targetPlayerIds.put(playerId, uid); - String target = uid + " (" + targetPlayer.getAccount().getUsername() + ")"; - CommandHandler.sendTranslatedMessage(player, "commands.execution.set_target", target); - CommandHandler.sendTranslatedMessage( - player, - targetPlayer.isOnline() - ? "commands.execution.set_target_online" - : "commands.execution.set_target_offline", - target); - return true; - } - - /** - * Invoke a command handler with the given arguments. - * - * @param player The player invoking the command or null for the server console. - * @param rawMessage The messaged used to invoke the command. - */ - public void invoke(Player player, Player targetPlayer, String rawMessage) { - // The console outputs in-game command. [{Account Username} (Player UID: {Player Uid})] - if (SERVER.logCommands) { - if (player != null) { - Grasscutter.getLogger() - .info( - "Command used by [" - + player.getAccount().getUsername() - + " (Player UID: " - + player.getUid() - + ")]: " - + rawMessage); - } else { - Grasscutter.getLogger().info("Command used by server console: " + rawMessage); - } - } - - rawMessage = rawMessage.trim(); - if (rawMessage.length() == 0) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.not_specified"); - return; - } - - // Parse message. - String[] split = rawMessage.split(" "); - String label = split[0].toLowerCase(); - List args = new ArrayList<>(Arrays.asList(split).subList(1, split.length)); - String playerId = (player == null) ? consoleId : player.getAccount().getId(); - - // Check for special cases - currently only target command. - if (label.startsWith("@")) { // @[UID] - this.setPlayerTarget(playerId, player, label.substring(1)); - return; - } else if (label.equalsIgnoreCase("target")) { // target [[@]UID] - if (args.size() > 0) { - String targetUidStr = args.get(0); - if (targetUidStr.startsWith("@")) { - targetUidStr = targetUidStr.substring(1); - } - this.setPlayerTarget(playerId, player, targetUidStr); - return; - } else { - this.setPlayerTarget(playerId, player, ""); - return; - } - } - - // Get command handler. - CommandHandler handler = this.getHandler(label); - - // Check if the handler is null. - if (handler == null) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.unknown_command", label); - return; - } - - // Get the command's annotation. - Command annotation = this.annotations.get(label); - - // Resolve targetPlayer - try { - targetPlayer = getTargetPlayer(playerId, player, targetPlayer, args); - } catch (IllegalArgumentException e) { - return; - } - - // Check for permissions. - if (!Grasscutter.getPermissionHandler() - .checkPermission( - player, - targetPlayer, - annotation.permission(), - this.annotations.get(label).permissionTargeted())) { - return; - } - - // Check if command has unfulfilled constraints on targetPlayer - Command.TargetRequirement targetRequirement = annotation.targetRequirement(); - if (targetRequirement != Command.TargetRequirement.NONE) { - if (targetPlayer == null) { - handler.sendUsageMessage(player); - CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target"); - return; - } - - if ((targetRequirement == Command.TargetRequirement.ONLINE) && !targetPlayer.isOnline()) { - handler.sendUsageMessage(player); - CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target_online"); - return; - } - - if ((targetRequirement == Command.TargetRequirement.OFFLINE) && targetPlayer.isOnline()) { - handler.sendUsageMessage(player); - CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target_offline"); - return; - } - } - - // Copy player and handler to final properties. - final Player targetPlayerF = targetPlayer; // Is there a better way to do this? - final CommandHandler handlerF = handler; // Is there a better way to do this? - - // Invoke execute method for handler. - Runnable runnable = () -> handlerF.execute(player, targetPlayerF, args); - if (annotation.threading()) { - new Thread(runnable).start(); - } else { - runnable.run(); - } - } - - /** Scans for all classes annotated with {@link Command} and registers them. */ - private void scan() { - Reflections reflector = Grasscutter.reflector; - Set> classes = reflector.getTypesAnnotatedWith(Command.class); - - classes.forEach( - annotated -> { - try { - Command cmdData = annotated.getAnnotation(Command.class); - Object object = annotated.getDeclaredConstructor().newInstance(); - if (object instanceof CommandHandler) - this.registerCommand(cmdData.label(), (CommandHandler) object); - else - Grasscutter.getLogger() - .error("Class " + annotated.getName() + " is not a CommandHandler!"); - } catch (Exception exception) { - Grasscutter.getLogger() - .error( - "Failed to register command handler for " + annotated.getSimpleName(), - exception); - } - }); - } -} +package emu.grasscutter.command; + +import static emu.grasscutter.config.Configuration.SERVER; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.player.Player; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import java.util.*; +import org.reflections.Reflections; + +@SuppressWarnings({"UnusedReturnValue", "unused"}) +public final class CommandMap { + private static final int INVALID_UID = Integer.MIN_VALUE; + private static final String consoleId = "console"; + private final Map commands = new TreeMap<>(); + private final Map aliases = new TreeMap<>(); + private final Map annotations = new TreeMap<>(); + private final Object2IntMap targetPlayerIds = new Object2IntOpenHashMap<>(); + + public CommandMap() { + this(false); + } + + public CommandMap(boolean scan) { + if (scan) this.scan(); + } + + public static CommandMap getInstance() { + return Grasscutter.getCommandMap(); + } + + private static int getUidFromString(String input) { + try { + return Integer.parseInt(input); + } catch (NumberFormatException ignored) { + var account = DatabaseHelper.getAccountByName(input); + if (account == null) return INVALID_UID; + var player = DatabaseHelper.getPlayerByAccount(account); + if (player == null) return INVALID_UID; + // We will be immediately fetching the player again after this, + // but offline vs online Player safety is more important than saving a lookup + return player.getUid(); + } + } + + /** + * Register a command handler. + * + * @param label The command label. + * @param command The command handler. + * @return Instance chaining. + */ + public CommandMap registerCommand(String label, CommandHandler command) { + Grasscutter.getLogger().debug("Registered command: " + label); + label = label.toLowerCase(); + + // Get command data. + Command annotation = command.getClass().getAnnotation(Command.class); + this.annotations.put(label, annotation); + this.commands.put(label, command); + + // Register aliases. + for (String alias : annotation.aliases()) { + this.aliases.put(alias, command); + this.annotations.put(alias, annotation); + } + return this; + } + + /** + * Removes a registered command handler. + * + * @param label The command label. + * @return Instance chaining. + */ + public CommandMap unregisterCommand(String label) { + Grasscutter.getLogger().debug("Unregistered command: " + label); + + CommandHandler handler = this.commands.get(label); + if (handler == null) return this; + + Command annotation = handler.getClass().getAnnotation(Command.class); + this.annotations.remove(label); + this.commands.remove(label); + + // Unregister aliases. + for (String alias : annotation.aliases()) { + this.aliases.remove(alias); + this.annotations.remove(alias); + } + + return this; + } + + public List getAnnotationsAsList() { + return new ArrayList<>(this.annotations.values()); + } + + public Map getAnnotations() { + return new LinkedHashMap<>(this.annotations); + } + + /** + * Returns a list of all registered commands. + * + * @return All command handlers as a list. + */ + public List getHandlersAsList() { + return new ArrayList<>(this.commands.values()); + } + + public Map getHandlers() { + return this.commands; + } + + /** + * Returns a handler by label/alias. + * + * @param label The command label. + * @return The command handler. + */ + public CommandHandler getHandler(String label) { + CommandHandler handler = this.commands.get(label); + if (handler == null) { + // Try getting by alias + handler = this.aliases.get(label); + } + return handler; + } + + private Player getTargetPlayer( + String playerId, Player player, Player targetPlayer, List args) { + // Top priority: If any @UID argument is present, override targetPlayer with it. + for (int i = 0; i < args.size(); i++) { + String arg = args.get(i); + if (arg.startsWith("@")) { + arg = args.remove(i).substring(1); + if (arg.equals("")) { + // This is a special case to target nothing, distinct from failing to assign a target. + // This is specifically to allow in-game players to run a command without targeting + // themselves or anyone else. + return null; + } + int uid = getUidFromString(arg); + if (uid == INVALID_UID) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid"); + throw new IllegalArgumentException(); + } + targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid, true); + if (targetPlayer == null) { + CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); + throw new IllegalArgumentException(); + } + return targetPlayer; + } + } + + // Next priority: If we invoked with a target, use that. + // By default, this only happens when you message another player in-game with a command. + if (targetPlayer != null) { + return targetPlayer; + } + + // Next priority: Use previously-set target. (see /target [[@]UID]) + if (targetPlayerIds.containsKey(playerId)) { + targetPlayer = + Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.getInt(playerId), true); + // We check every time in case the target is deleted after being targeted + if (targetPlayer == null) { + CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); + throw new IllegalArgumentException(); + } + return targetPlayer; + } + + // Lowest priority: Target the player invoking the command. In the case of the console, this + // will return null. + return player; + } + + private boolean setPlayerTarget(String playerId, Player player, String targetUid) { + if (targetUid.equals("")) { // Clears the default targetPlayer. + targetPlayerIds.removeInt(playerId); + CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target"); + return true; + } + + // Sets default targetPlayer to the UID provided. + int uid = getUidFromString(targetUid); + if (uid == INVALID_UID) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.invalid.uid"); + return false; + } + Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid, true); + if (targetPlayer == null) { + CommandHandler.sendTranslatedMessage(player, "commands.execution.player_exist_error"); + return false; + } + + targetPlayerIds.put(playerId, uid); + String target = uid + " (" + targetPlayer.getAccount().getUsername() + ")"; + CommandHandler.sendTranslatedMessage(player, "commands.execution.set_target", target); + CommandHandler.sendTranslatedMessage( + player, + targetPlayer.isOnline() + ? "commands.execution.set_target_online" + : "commands.execution.set_target_offline", + target); + return true; + } + + /** + * Invoke a command handler with the given arguments. + * + * @param player The player invoking the command or null for the server console. + * @param rawMessage The messaged used to invoke the command. + */ + public void invoke(Player player, Player targetPlayer, String rawMessage) { + // The console outputs in-game command. [{Account Username} (Player UID: {Player Uid})] + if (SERVER.logCommands) { + if (player != null) { + Grasscutter.getLogger() + .info( + "Command used by [" + + player.getAccount().getUsername() + + " (Player UID: " + + player.getUid() + + ")]: " + + rawMessage); + } else { + Grasscutter.getLogger().info("Command used by server console: " + rawMessage); + } + } + + rawMessage = rawMessage.trim(); + if (rawMessage.length() == 0) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.not_specified"); + return; + } + + // Parse message. + String[] split = rawMessage.split(" "); + String label = split[0].toLowerCase(); + List args = new ArrayList<>(Arrays.asList(split).subList(1, split.length)); + String playerId = (player == null) ? consoleId : player.getAccount().getId(); + + // Check for special cases - currently only target command. + if (label.startsWith("@")) { // @[UID] + this.setPlayerTarget(playerId, player, label.substring(1)); + return; + } else if (label.equalsIgnoreCase("target")) { // target [[@]UID] + if (args.size() > 0) { + String targetUidStr = args.get(0); + if (targetUidStr.startsWith("@")) { + targetUidStr = targetUidStr.substring(1); + } + this.setPlayerTarget(playerId, player, targetUidStr); + return; + } else { + this.setPlayerTarget(playerId, player, ""); + return; + } + } + + // Get command handler. + CommandHandler handler = this.getHandler(label); + + // Check if the handler is null. + if (handler == null) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.unknown_command", label); + return; + } + + // Get the command's annotation. + Command annotation = this.annotations.get(label); + + // Resolve targetPlayer + try { + targetPlayer = getTargetPlayer(playerId, player, targetPlayer, args); + } catch (IllegalArgumentException e) { + return; + } + + // Check for permissions. + if (!Grasscutter.getPermissionHandler() + .checkPermission( + player, + targetPlayer, + annotation.permission(), + this.annotations.get(label).permissionTargeted())) { + return; + } + + // Check if command has unfulfilled constraints on targetPlayer + Command.TargetRequirement targetRequirement = annotation.targetRequirement(); + if (targetRequirement != Command.TargetRequirement.NONE) { + if (targetPlayer == null) { + handler.sendUsageMessage(player); + CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target"); + return; + } + + if ((targetRequirement == Command.TargetRequirement.ONLINE) && !targetPlayer.isOnline()) { + handler.sendUsageMessage(player); + CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target_online"); + return; + } + + if ((targetRequirement == Command.TargetRequirement.OFFLINE) && targetPlayer.isOnline()) { + handler.sendUsageMessage(player); + CommandHandler.sendTranslatedMessage(player, "commands.execution.need_target_offline"); + return; + } + } + + // Copy player and handler to final properties. + final Player targetPlayerF = targetPlayer; // Is there a better way to do this? + final CommandHandler handlerF = handler; // Is there a better way to do this? + + // Invoke execute method for handler. + Runnable runnable = () -> handlerF.execute(player, targetPlayerF, args); + if (annotation.threading()) { + new Thread(runnable).start(); + } else { + runnable.run(); + } + } + + /** Scans for all classes annotated with {@link Command} and registers them. */ + private void scan() { + Reflections reflector = Grasscutter.reflector; + Set> classes = reflector.getTypesAnnotatedWith(Command.class); + + classes.forEach( + annotated -> { + try { + Command cmdData = annotated.getAnnotation(Command.class); + Object object = annotated.getDeclaredConstructor().newInstance(); + if (object instanceof CommandHandler) + this.registerCommand(cmdData.label(), (CommandHandler) object); + else + Grasscutter.getLogger() + .error("Class " + annotated.getName() + " is not a CommandHandler!"); + } catch (Exception exception) { + Grasscutter.getLogger() + .error( + "Failed to register command handler for " + annotated.getSimpleName(), + exception); + } + }); + } +} diff --git a/src/main/java/emu/grasscutter/command/DefaultPermissionHandler.java b/src/main/java/emu/grasscutter/command/DefaultPermissionHandler.java index 593c1b924..95257e95d 100644 --- a/src/main/java/emu/grasscutter/command/DefaultPermissionHandler.java +++ b/src/main/java/emu/grasscutter/command/DefaultPermissionHandler.java @@ -1,33 +1,33 @@ -package emu.grasscutter.command; - -import emu.grasscutter.game.Account; -import emu.grasscutter.game.player.Player; - -public class DefaultPermissionHandler implements PermissionHandler { - @Override - public boolean EnablePermissionCommand() { - return true; - } - - @Override - public boolean checkPermission( - Player player, Player targetPlayer, String permissionNode, String permissionNodeTargeted) { - if (player == null) { - return true; - } - - Account account = player.getAccount(); - if (player != targetPlayer) { // Additional permission required for targeting another player - if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error"); - return false; - } - } - if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { - CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error"); - return false; - } - - return true; - } -} +package emu.grasscutter.command; + +import emu.grasscutter.game.Account; +import emu.grasscutter.game.player.Player; + +public class DefaultPermissionHandler implements PermissionHandler { + @Override + public boolean EnablePermissionCommand() { + return true; + } + + @Override + public boolean checkPermission( + Player player, Player targetPlayer, String permissionNode, String permissionNodeTargeted) { + if (player == null) { + return true; + } + + Account account = player.getAccount(); + if (player != targetPlayer) { // Additional permission required for targeting another player + if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error"); + return false; + } + } + if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { + CommandHandler.sendTranslatedMessage(player, "commands.generic.permission_error"); + return false; + } + + return true; + } +} diff --git a/src/main/java/emu/grasscutter/command/PermissionHandler.java b/src/main/java/emu/grasscutter/command/PermissionHandler.java index d16e027bc..e1f19c205 100644 --- a/src/main/java/emu/grasscutter/command/PermissionHandler.java +++ b/src/main/java/emu/grasscutter/command/PermissionHandler.java @@ -1,10 +1,10 @@ -package emu.grasscutter.command; - -import emu.grasscutter.game.player.Player; - -public interface PermissionHandler { - boolean EnablePermissionCommand(); - - boolean checkPermission( - Player player, Player targetPlayer, String permissionNode, String permissionNodeTargeted); -} +package emu.grasscutter.command; + +import emu.grasscutter.game.player.Player; + +public interface PermissionHandler { + boolean EnablePermissionCommand(); + + boolean checkPermission( + Player player, Player targetPlayer, String permissionNode, String permissionNodeTargeted); +} diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 5591e2189..fa9f5be23 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -47,7 +47,7 @@ public final class AccountCommand implements CommandHandler { if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) { if (args.size() < 3) { CommandHandler.sendMessage( - sender, "EXPERIMENTAL_RealPassword requires a password argument"); + sender, "EXPERIMENTAL_RealPassword requires a password argument"); CommandHandler.sendMessage(sender, "Usage: account create [uid]"); return; } @@ -60,10 +60,10 @@ public final class AccountCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid")); if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) { CommandHandler.sendMessage( - sender, - "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"); + sender, + "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"); CommandHandler.sendMessage( - sender, "Usage: account create [uid]"); + sender, "Usage: account create [uid]"); } return; } @@ -90,7 +90,7 @@ public final class AccountCommand implements CommandHandler { account.save(); // Save account to database. CommandHandler.sendMessage( - sender, translate(sender, "commands.account.create", account.getReservedPlayerUid())); + sender, translate(sender, "commands.account.create", account.getReservedPlayerUid())); } } case "delete" -> { @@ -106,7 +106,7 @@ public final class AccountCommand implements CommandHandler { case "resetpass" -> { if (!Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) { CommandHandler.sendMessage( - sender, "resetpass requires EXPERIMENTAL_RealPassword to be true."); + sender, "resetpass requires EXPERIMENTAL_RealPassword to be true."); return; } if (args.size() != 3) { @@ -128,23 +128,27 @@ public final class AccountCommand implements CommandHandler { } case "list" -> { CommandHandler.sendMessage(sender, "Note: This command might take a while to complete."); - CommandHandler.sendMessage(sender, - "Accounts: \n" + DatabaseManager.getAccountDatastore() - .find(Account.class).stream() - .map(acc -> "%s: %s (%s)".formatted( - acc.getId(), acc.getUsername(), - acc.getReservedPlayerUid() == 0 ? - this.getPlayerUid(acc) : - acc.getReservedPlayerUid())) - .collect(Collectors.joining("\n")) - ); + CommandHandler.sendMessage( + sender, + "Accounts: \n" + + DatabaseManager.getAccountDatastore().find(Account.class).stream() + .map( + acc -> + "%s: %s (%s)" + .formatted( + acc.getId(), + acc.getUsername(), + acc.getReservedPlayerUid() == 0 + ? this.getPlayerUid(acc) + : acc.getReservedPlayerUid())) + .collect(Collectors.joining("\n"))); } } } /** - * Returns the UID of the player associated with the given account. - * If the player is not found, returns "no UID". + * Returns the UID of the player associated with the given account. If the player is not found, + * returns "no UID". * * @param account The account to get the UID of. * @return The UID of the player associated with the given account. diff --git a/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java b/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java index 81f5a41a9..ce1aadee6 100644 --- a/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AnnounceCommand.java @@ -1,78 +1,78 @@ -package emu.grasscutter.command.commands; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.packet.send.PacketServerAnnounceNotify; -import java.util.Collections; -import java.util.List; -import java.util.Random; - -@Command( - label = "announce", - usage = {"", "refresh", "(tpl|revoke) "}, - permission = "server.announce", - aliases = {"a"}, - targetRequirement = Command.TargetRequirement.NONE) -public final class AnnounceCommand implements CommandHandler { - - @Override - public void execute(Player sender, Player targetPlayer, List args) { - var manager = Grasscutter.getGameServer().getAnnouncementSystem(); - if (args.size() < 1) { - sendUsageMessage(sender); - return; - } - - switch (args.get(0)) { - case "tpl": - if (args.size() < 2) { - sendUsageMessage(sender); - return; - } - - var templateId = Integer.parseInt(args.get(1)); - var tpl = manager.getAnnounceConfigItemMap().get(templateId); - if (tpl == null) { - CommandHandler.sendMessage( - sender, translate(sender, "commands.announce.not_found", templateId)); - return; - } - - manager.broadcast(Collections.singletonList(tpl)); - CommandHandler.sendMessage( - sender, translate(sender, "commands.announce.send_success", tpl.getTemplateId())); - break; - - case "refresh": - var num = manager.refresh(); - CommandHandler.sendMessage( - sender, translate(sender, "commands.announce.refresh_success", num)); - break; - - case "revoke": - if (args.size() < 2) { - sendUsageMessage(sender); - return; - } - - var templateId1 = Integer.parseInt(args.get(1)); - manager.revoke(templateId1); - CommandHandler.sendMessage( - sender, translate(sender, "commands.announce.revoke_done", templateId1)); - break; - - default: - var id = new Random().nextInt(10000, 99999); - var text = String.join(" ", args); - manager - .getOnlinePlayers() - .forEach(i -> i.sendPacket(new PacketServerAnnounceNotify(text, id))); - - CommandHandler.sendMessage(sender, translate(sender, "commands.announce.send_success", id)); - } - } -} +package emu.grasscutter.command.commands; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.packet.send.PacketServerAnnounceNotify; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +@Command( + label = "announce", + usage = {"", "refresh", "(tpl|revoke) "}, + permission = "server.announce", + aliases = {"a"}, + targetRequirement = Command.TargetRequirement.NONE) +public final class AnnounceCommand implements CommandHandler { + + @Override + public void execute(Player sender, Player targetPlayer, List args) { + var manager = Grasscutter.getGameServer().getAnnouncementSystem(); + if (args.size() < 1) { + sendUsageMessage(sender); + return; + } + + switch (args.get(0)) { + case "tpl": + if (args.size() < 2) { + sendUsageMessage(sender); + return; + } + + var templateId = Integer.parseInt(args.get(1)); + var tpl = manager.getAnnounceConfigItemMap().get(templateId); + if (tpl == null) { + CommandHandler.sendMessage( + sender, translate(sender, "commands.announce.not_found", templateId)); + return; + } + + manager.broadcast(Collections.singletonList(tpl)); + CommandHandler.sendMessage( + sender, translate(sender, "commands.announce.send_success", tpl.getTemplateId())); + break; + + case "refresh": + var num = manager.refresh(); + CommandHandler.sendMessage( + sender, translate(sender, "commands.announce.refresh_success", num)); + break; + + case "revoke": + if (args.size() < 2) { + sendUsageMessage(sender); + return; + } + + var templateId1 = Integer.parseInt(args.get(1)); + manager.revoke(templateId1); + CommandHandler.sendMessage( + sender, translate(sender, "commands.announce.revoke_done", templateId1)); + break; + + default: + var id = new Random().nextInt(10000, 99999); + var text = String.join(" ", args); + manager + .getOnlinePlayers() + .forEach(i -> i.sendPacket(new PacketServerAnnounceNotify(text, id))); + + CommandHandler.sendMessage(sender, translate(sender, "commands.announce.send_success", id)); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/BanCommand.java b/src/main/java/emu/grasscutter/command/commands/BanCommand.java index dd13616dc..b9de6e268 100644 --- a/src/main/java/emu/grasscutter/command/commands/BanCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/BanCommand.java @@ -1,62 +1,62 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.game.GameSession; -import java.util.List; - -@Command( - label = "ban", - usage = {"[

Set plugin variables. - * - * @param identifier The plugin's identifier. - */ - private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) { - if (this.identifier != null) { - Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt."); - return; - } - - this.identifier = identifier; - this.classLoader = classLoader; - this.dataFolder = FileUtils.getPluginPath(identifier.name).toFile(); - this.logger = LoggerFactory.getLogger(identifier.name); - - if (!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { - Grasscutter.getLogger() - .warn("Failed to create plugin data folder for " + this.identifier.name); - } - } - - /** - * The plugin's identifier instance. - * - * @return An instance of {@link PluginIdentifier}. - */ - public final PluginIdentifier getIdentifier() { - return this.identifier; - } - - /** Get the plugin's name. */ - public final String getName() { - return this.identifier.name; - } - - /** Get the plugin's description. */ - public final String getDescription() { - return this.identifier.description; - } - - /** Get the plugin's version. */ - public final String getVersion() { - return this.identifier.version; - } - - /** - * Returns the server that initialized the plugin. - * - * @return A server instance. - */ - public final GameServer getServer() { - return this.server.getGameServer(); - } - - /** - * Returns an input stream for a resource in the JAR file. - * - * @param resourceName The name of the resource. - * @return An input stream. - */ - public final InputStream getResource(String resourceName) { - return this.classLoader.getResourceAsStream(resourceName); - } - - /** - * Returns a directory where plugins can store data files. - * - * @return A directory on the file system. - */ - public final File getDataFolder() { - return this.dataFolder; - } - - /** - * Returns the server hook. - * - * @return A server hook singleton. - */ - public final ServerHook getHandle() { - return this.server; - } - - /** - * Returns the plugin's logger. - * - * @return A SLF4J logger. - */ - public final Logger getLogger() { - return this.logger; - } - - /* Called when the plugin is first loaded. */ - public void onLoad() {} - - /* Called after (most of) the server enables. */ - public void onEnable() {} - - /* Called before the server disables. */ - public void onDisable() {} -} +package emu.grasscutter.plugin; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.plugin.api.ServerHook; +import emu.grasscutter.server.game.GameServer; +import emu.grasscutter.utils.FileUtils; +import java.io.File; +import java.io.InputStream; +import java.net.URLClassLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** The base class for all plugins to extend. */ +public abstract class Plugin { + private final ServerHook server = ServerHook.getInstance(); + + private PluginIdentifier identifier; + private URLClassLoader classLoader; + private File dataFolder; + private Logger logger; + + /** + * This method is reflected into. + * + *

Set plugin variables. + * + * @param identifier The plugin's identifier. + */ + private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) { + if (this.identifier != null) { + Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt."); + return; + } + + this.identifier = identifier; + this.classLoader = classLoader; + this.dataFolder = FileUtils.getPluginPath(identifier.name).toFile(); + this.logger = LoggerFactory.getLogger(identifier.name); + + if (!this.dataFolder.exists() && !this.dataFolder.mkdirs()) { + Grasscutter.getLogger() + .warn("Failed to create plugin data folder for " + this.identifier.name); + } + } + + /** + * The plugin's identifier instance. + * + * @return An instance of {@link PluginIdentifier}. + */ + public final PluginIdentifier getIdentifier() { + return this.identifier; + } + + /** Get the plugin's name. */ + public final String getName() { + return this.identifier.name; + } + + /** Get the plugin's description. */ + public final String getDescription() { + return this.identifier.description; + } + + /** Get the plugin's version. */ + public final String getVersion() { + return this.identifier.version; + } + + /** + * Returns the server that initialized the plugin. + * + * @return A server instance. + */ + public final GameServer getServer() { + return this.server.getGameServer(); + } + + /** + * Returns an input stream for a resource in the JAR file. + * + * @param resourceName The name of the resource. + * @return An input stream. + */ + public final InputStream getResource(String resourceName) { + return this.classLoader.getResourceAsStream(resourceName); + } + + /** + * Returns a directory where plugins can store data files. + * + * @return A directory on the file system. + */ + public final File getDataFolder() { + return this.dataFolder; + } + + /** + * Returns the server hook. + * + * @return A server hook singleton. + */ + public final ServerHook getHandle() { + return this.server; + } + + /** + * Returns the plugin's logger. + * + * @return A SLF4J logger. + */ + public final Logger getLogger() { + return this.logger; + } + + /* Called when the plugin is first loaded. */ + public void onLoad() {} + + /* Called after (most of) the server enables. */ + public void onEnable() {} + + /* Called before the server disables. */ + public void onDisable() {} +} diff --git a/src/main/java/emu/grasscutter/plugin/PluginConfig.java b/src/main/java/emu/grasscutter/plugin/PluginConfig.java index 8287b5da8..bdda5aa84 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginConfig.java +++ b/src/main/java/emu/grasscutter/plugin/PluginConfig.java @@ -1,19 +1,19 @@ -package emu.grasscutter.plugin; - -/** The data contained in the plugin's `plugin.json` file. */ -public final class PluginConfig { - public String name, description, version; - public String mainClass; - public String[] authors; - public String[] loadAfter; - - /** - * Attempts to validate this config instance. - * - * @return True if the config is valid, false otherwise. - */ - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean validate() { - return name != null && description != null && mainClass != null; - } -} +package emu.grasscutter.plugin; + +/** The data contained in the plugin's `plugin.json` file. */ +public final class PluginConfig { + public String name, description, version; + public String mainClass; + public String[] authors; + public String[] loadAfter; + + /** + * Attempts to validate this config instance. + * + * @return True if the config is valid, false otherwise. + */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public boolean validate() { + return name != null && description != null && mainClass != null; + } +} diff --git a/src/main/java/emu/grasscutter/plugin/PluginIdentifier.java b/src/main/java/emu/grasscutter/plugin/PluginIdentifier.java index 2a4671e89..816a3751c 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginIdentifier.java +++ b/src/main/java/emu/grasscutter/plugin/PluginIdentifier.java @@ -1,22 +1,22 @@ -package emu.grasscutter.plugin; - -// TODO: Potentially replace with Lombok? -public final class PluginIdentifier { - public final String name, description, version; - public final String[] authors; - - public PluginIdentifier(String name, String description, String version, String[] authors) { - this.name = name; - this.description = description; - this.version = version; - this.authors = authors; - } - - /** Converts a {@link PluginConfig} into a {@link PluginIdentifier}. */ - public static PluginIdentifier fromPluginConfig(PluginConfig config) { - if (!config.validate()) - throw new IllegalArgumentException( - "A valid plugin config is required to convert into a plugin identifier."); - return new PluginIdentifier(config.name, config.description, config.version, config.authors); - } -} +package emu.grasscutter.plugin; + +// TODO: Potentially replace with Lombok? +public final class PluginIdentifier { + public final String name, description, version; + public final String[] authors; + + public PluginIdentifier(String name, String description, String version, String[] authors) { + this.name = name; + this.description = description; + this.version = version; + this.authors = authors; + } + + /** Converts a {@link PluginConfig} into a {@link PluginIdentifier}. */ + public static PluginIdentifier fromPluginConfig(PluginConfig config) { + if (!config.validate()) + throw new IllegalArgumentException( + "A valid plugin config is required to convert into a plugin identifier."); + return new PluginIdentifier(config.name, config.description, config.version, config.authors); + } +} diff --git a/src/main/java/emu/grasscutter/plugin/PluginManager.java b/src/main/java/emu/grasscutter/plugin/PluginManager.java index 9fbbbfb3b..ad111b4bc 100644 --- a/src/main/java/emu/grasscutter/plugin/PluginManager.java +++ b/src/main/java/emu/grasscutter/plugin/PluginManager.java @@ -1,321 +1,321 @@ -package emu.grasscutter.plugin; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.server.event.Event; -import emu.grasscutter.server.event.EventHandler; -import emu.grasscutter.server.event.HandlerPriority; -import emu.grasscutter.utils.FileUtils; -import emu.grasscutter.utils.JsonUtils; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.*; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import javax.annotation.Nullable; -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** Manages the server's plugins and the event system. */ -public final class PluginManager { - /* All loaded plugins. */ - private final Map plugins = new LinkedHashMap<>(); - /* All currently registered listeners per plugin. */ - private final Map>> listeners = new LinkedHashMap<>(); - - public PluginManager() { - this.loadPlugins(); // Load all plugins from the plugins directory. - } - - /** Loads plugins from the config-specified directory. */ - private void loadPlugins() { - File pluginsDir = FileUtils.getPluginPath("").toFile(); - if (!pluginsDir.exists() && !pluginsDir.mkdirs()) { - Grasscutter.getLogger() - .error(translate("plugin.directory_failed", pluginsDir.getAbsolutePath())); - return; - } - - File[] files = pluginsDir.listFiles(); - if (files == null) { - // The directory is empty, there aren't any plugins to load. - return; - } - - List plugins = - Arrays.stream(files).filter(file -> file.getName().endsWith(".jar")).toList(); - - URL[] pluginNames = new URL[plugins.size()]; - plugins.forEach( - plugin -> { - try { - pluginNames[plugins.indexOf(plugin)] = plugin.toURI().toURL(); - } catch (MalformedURLException exception) { - Grasscutter.getLogger().warn(translate("plugin.unable_to_load"), exception); - } - }); - - // Create a class loader for the plugins. - URLClassLoader classLoader = new URLClassLoader(pluginNames); - // Create a list of plugins that require dependencies. - List dependencies = new ArrayList<>(); - - // Initialize all plugins. - for (var plugin : plugins) { - try { - URL url = plugin.toURI().toURL(); - try (URLClassLoader loader = new URLClassLoader(new URL[] {url})) { - // Find the plugin.json file for each plugin. - URL configFile = loader.findResource("plugin.json"); - // Open the config file for reading. - InputStreamReader fileReader = new InputStreamReader(configFile.openStream()); - - // Create a plugin config instance from the config file. - PluginConfig pluginConfig = JsonUtils.loadToClass(fileReader, PluginConfig.class); - // Check if the plugin config is valid. - if (!pluginConfig.validate()) { - Grasscutter.getLogger().warn(translate("plugin.invalid_config", plugin.getName())); - return; - } - - // Create a JAR file instance from the plugin's URL. - JarFile jarFile = new JarFile(plugin); - // Load all class files from the JAR file. - Enumeration entries = jarFile.entries(); - while (entries.hasMoreElements()) { - JarEntry entry = entries.nextElement(); - if (entry.isDirectory() - || !entry.getName().endsWith(".class") - || entry.getName().contains("module-info")) continue; - String className = entry.getName().replace(".class", "").replace("/", "."); - classLoader.loadClass(className); // Use the same class loader for ALL plugins. - } - - // Create a plugin instance. - Class pluginClass = classLoader.loadClass(pluginConfig.mainClass); - Plugin pluginInstance = (Plugin) pluginClass.getDeclaredConstructor().newInstance(); - // Close the file reader. - fileReader.close(); - - // Check if the plugin has alternate dependencies. - if (pluginConfig.loadAfter != null && pluginConfig.loadAfter.length > 0) { - // Add the plugin to a "load later" list. - dependencies.add( - new PluginData( - pluginInstance, - PluginIdentifier.fromPluginConfig(pluginConfig), - loader, - pluginConfig.loadAfter)); - continue; - } - - // Load the plugin. - this.loadPlugin(pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), loader); - } catch (ClassNotFoundException ignored) { - Grasscutter.getLogger().warn(translate("plugin.invalid_main_class", plugin.getName())); - } catch (FileNotFoundException ignored) { - Grasscutter.getLogger().warn(translate("plugin.missing_config", plugin.getName())); - } - } catch (Exception exception) { - Grasscutter.getLogger() - .error(translate("plugin.failed_to_load_plugin", plugin.getName()), exception); - } - } - - // Load plugins with dependencies. - int depth = 0; - final int maxDepth = 30; - while (!dependencies.isEmpty()) { - // Check if the depth is too high. - if (depth >= maxDepth) { - Grasscutter.getLogger().error(translate("plugin.failed_to_load_dependencies")); - break; - } - - try { - // Get the next plugin to load. - var pluginData = dependencies.get(0); - - // Check if the plugin's dependencies are loaded. - if (!this.plugins.keySet().containsAll(List.of(pluginData.getDependencies()))) { - depth++; // Increase depth counter. - continue; // Continue to next plugin. - } - - // Remove the plugin from the list of dependencies. - dependencies.remove(pluginData); - - // Load the plugin. - this.loadPlugin( - pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader()); - } catch (Exception exception) { - Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception); - depth++; - } - } - } - - /** - * Load the specified plugin. - * - * @param plugin The plugin instance. - */ - private void loadPlugin(Plugin plugin, PluginIdentifier identifier, URLClassLoader classLoader) { - Grasscutter.getLogger().info(translate("plugin.loading_plugin", identifier.name)); - - // Add the plugin's identifier. - try { - Class pluginClass = Plugin.class; - Method method = - pluginClass.getDeclaredMethod( - "initializePlugin", PluginIdentifier.class, URLClassLoader.class); - method.setAccessible(true); - method.invoke(plugin, identifier, classLoader); - method.setAccessible(false); - } catch (Exception ignored) { - Grasscutter.getLogger().warn(translate("plugin.failed_add_id", identifier.name)); - } - - // Add the plugin to the list of loaded plugins. - this.plugins.put(identifier.name, plugin); - // Create a collection for the plugin's listeners. - this.listeners.put(plugin, new ArrayList<>()); - - // Call the plugin's onLoad method. - try { - plugin.onLoad(); - } catch (Throwable exception) { - Grasscutter.getLogger() - .error(translate("plugin.failed_to_load_plugin", identifier.name), exception); - } - } - - /** Enables all registered plugins. */ - public void enablePlugins() { - this.plugins.forEach( - (name, plugin) -> { - Grasscutter.getLogger().info(translate("plugin.enabling_plugin", name)); - try { - plugin.onEnable(); - } catch (Throwable exception) { - Grasscutter.getLogger().error(translate("plugin.enabling_failed", name), exception); - } - }); - } - - /** Disables all registered plugins. */ - public void disablePlugins() { - this.plugins.forEach( - (name, plugin) -> { - Grasscutter.getLogger().info(translate("plugin.disabling_plugin", name)); - this.disablePlugin(plugin); - }); - } - - /** - * Registers a plugin's event listener. - * - * @param plugin The plugin registering the listener. - * @param listener The event listener. - */ - public void registerListener(Plugin plugin, EventHandler listener) { - this.listeners.get(plugin).add(listener); - } - - /** - * Invoke the provided event on all registered event listeners. - * - * @param event The event to invoke. - */ - public void invokeEvent(Event event) { - EnumSet.allOf(HandlerPriority.class).forEach(priority -> this.checkAndFilter(event, priority)); - } - - /** - * Check an event to handlers for the priority. - * - * @param event The event being called. - * @param priority The priority to call for. - */ - private void checkAndFilter(Event event, HandlerPriority priority) { - // Add all listeners from every plugin. - this.listeners.values().stream() - .flatMap(Collection::stream) - // Filter the listeners by priority. - .filter(handler -> handler.handles().isInstance(event)) - .filter(handler -> handler.getPriority() == priority) - // Invoke the event. - .forEach(handler -> this.invokeHandler(event, handler)); - } - - /** - * Gets a plugin's instance by its name. - * - * @param name The name of the plugin. - * @return Either null, or the plugin's instance. - */ - @Nullable public Plugin getPlugin(String name) { - return this.plugins.get(name); - } - - /** - * Enables a plugin. - * - * @param plugin The plugin to enable. - */ - public void enablePlugin(Plugin plugin) { - try { - // Call the plugin's onEnable method. - plugin.onEnable(); - } catch (Exception exception) { - Grasscutter.getLogger() - .error(translate("plugin.enabling_failed", plugin.getName()), exception); - } - } - - /** - * Disables a plugin. - * - * @param plugin The plugin to disable. - */ - public void disablePlugin(Plugin plugin) { - try { - // Call the plugin's onDisable method. - plugin.onDisable(); - } catch (Exception exception) { - Grasscutter.getLogger() - .error(translate("plugin.disabling_failed", plugin.getName()), exception); - } - - // Un-register all listeners. - this.listeners.remove(plugin); - } - - /** - * Performs logic checks then invokes the provided event handler. - * - * @param event The event passed through to the handler. - * @param handler The handler to invoke. - */ - @SuppressWarnings("unchecked") - private void invokeHandler(Event event, EventHandler handler) { - if (!event.isCanceled() || (event.isCanceled() && handler.ignoresCanceled())) - handler.getCallback().consume((T) event); - } - - /* Data about an unloaded plugin. */ - @AllArgsConstructor - @Getter - static class PluginData { - private Plugin plugin; - private PluginIdentifier identifier; - private URLClassLoader classLoader; - private String[] dependencies; - } -} +package emu.grasscutter.plugin; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.server.event.Event; +import emu.grasscutter.server.event.EventHandler; +import emu.grasscutter.server.event.HandlerPriority; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.JsonUtils; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import javax.annotation.Nullable; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** Manages the server's plugins and the event system. */ +public final class PluginManager { + /* All loaded plugins. */ + private final Map plugins = new LinkedHashMap<>(); + /* All currently registered listeners per plugin. */ + private final Map>> listeners = new LinkedHashMap<>(); + + public PluginManager() { + this.loadPlugins(); // Load all plugins from the plugins directory. + } + + /** Loads plugins from the config-specified directory. */ + private void loadPlugins() { + File pluginsDir = FileUtils.getPluginPath("").toFile(); + if (!pluginsDir.exists() && !pluginsDir.mkdirs()) { + Grasscutter.getLogger() + .error(translate("plugin.directory_failed", pluginsDir.getAbsolutePath())); + return; + } + + File[] files = pluginsDir.listFiles(); + if (files == null) { + // The directory is empty, there aren't any plugins to load. + return; + } + + List plugins = + Arrays.stream(files).filter(file -> file.getName().endsWith(".jar")).toList(); + + URL[] pluginNames = new URL[plugins.size()]; + plugins.forEach( + plugin -> { + try { + pluginNames[plugins.indexOf(plugin)] = plugin.toURI().toURL(); + } catch (MalformedURLException exception) { + Grasscutter.getLogger().warn(translate("plugin.unable_to_load"), exception); + } + }); + + // Create a class loader for the plugins. + URLClassLoader classLoader = new URLClassLoader(pluginNames); + // Create a list of plugins that require dependencies. + List dependencies = new ArrayList<>(); + + // Initialize all plugins. + for (var plugin : plugins) { + try { + URL url = plugin.toURI().toURL(); + try (URLClassLoader loader = new URLClassLoader(new URL[] {url})) { + // Find the plugin.json file for each plugin. + URL configFile = loader.findResource("plugin.json"); + // Open the config file for reading. + InputStreamReader fileReader = new InputStreamReader(configFile.openStream()); + + // Create a plugin config instance from the config file. + PluginConfig pluginConfig = JsonUtils.loadToClass(fileReader, PluginConfig.class); + // Check if the plugin config is valid. + if (!pluginConfig.validate()) { + Grasscutter.getLogger().warn(translate("plugin.invalid_config", plugin.getName())); + return; + } + + // Create a JAR file instance from the plugin's URL. + JarFile jarFile = new JarFile(plugin); + // Load all class files from the JAR file. + Enumeration entries = jarFile.entries(); + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + if (entry.isDirectory() + || !entry.getName().endsWith(".class") + || entry.getName().contains("module-info")) continue; + String className = entry.getName().replace(".class", "").replace("/", "."); + classLoader.loadClass(className); // Use the same class loader for ALL plugins. + } + + // Create a plugin instance. + Class pluginClass = classLoader.loadClass(pluginConfig.mainClass); + Plugin pluginInstance = (Plugin) pluginClass.getDeclaredConstructor().newInstance(); + // Close the file reader. + fileReader.close(); + + // Check if the plugin has alternate dependencies. + if (pluginConfig.loadAfter != null && pluginConfig.loadAfter.length > 0) { + // Add the plugin to a "load later" list. + dependencies.add( + new PluginData( + pluginInstance, + PluginIdentifier.fromPluginConfig(pluginConfig), + loader, + pluginConfig.loadAfter)); + continue; + } + + // Load the plugin. + this.loadPlugin(pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), loader); + } catch (ClassNotFoundException ignored) { + Grasscutter.getLogger().warn(translate("plugin.invalid_main_class", plugin.getName())); + } catch (FileNotFoundException ignored) { + Grasscutter.getLogger().warn(translate("plugin.missing_config", plugin.getName())); + } + } catch (Exception exception) { + Grasscutter.getLogger() + .error(translate("plugin.failed_to_load_plugin", plugin.getName()), exception); + } + } + + // Load plugins with dependencies. + int depth = 0; + final int maxDepth = 30; + while (!dependencies.isEmpty()) { + // Check if the depth is too high. + if (depth >= maxDepth) { + Grasscutter.getLogger().error(translate("plugin.failed_to_load_dependencies")); + break; + } + + try { + // Get the next plugin to load. + var pluginData = dependencies.get(0); + + // Check if the plugin's dependencies are loaded. + if (!this.plugins.keySet().containsAll(List.of(pluginData.getDependencies()))) { + depth++; // Increase depth counter. + continue; // Continue to next plugin. + } + + // Remove the plugin from the list of dependencies. + dependencies.remove(pluginData); + + // Load the plugin. + this.loadPlugin( + pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader()); + } catch (Exception exception) { + Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception); + depth++; + } + } + } + + /** + * Load the specified plugin. + * + * @param plugin The plugin instance. + */ + private void loadPlugin(Plugin plugin, PluginIdentifier identifier, URLClassLoader classLoader) { + Grasscutter.getLogger().info(translate("plugin.loading_plugin", identifier.name)); + + // Add the plugin's identifier. + try { + Class pluginClass = Plugin.class; + Method method = + pluginClass.getDeclaredMethod( + "initializePlugin", PluginIdentifier.class, URLClassLoader.class); + method.setAccessible(true); + method.invoke(plugin, identifier, classLoader); + method.setAccessible(false); + } catch (Exception ignored) { + Grasscutter.getLogger().warn(translate("plugin.failed_add_id", identifier.name)); + } + + // Add the plugin to the list of loaded plugins. + this.plugins.put(identifier.name, plugin); + // Create a collection for the plugin's listeners. + this.listeners.put(plugin, new ArrayList<>()); + + // Call the plugin's onLoad method. + try { + plugin.onLoad(); + } catch (Throwable exception) { + Grasscutter.getLogger() + .error(translate("plugin.failed_to_load_plugin", identifier.name), exception); + } + } + + /** Enables all registered plugins. */ + public void enablePlugins() { + this.plugins.forEach( + (name, plugin) -> { + Grasscutter.getLogger().info(translate("plugin.enabling_plugin", name)); + try { + plugin.onEnable(); + } catch (Throwable exception) { + Grasscutter.getLogger().error(translate("plugin.enabling_failed", name), exception); + } + }); + } + + /** Disables all registered plugins. */ + public void disablePlugins() { + this.plugins.forEach( + (name, plugin) -> { + Grasscutter.getLogger().info(translate("plugin.disabling_plugin", name)); + this.disablePlugin(plugin); + }); + } + + /** + * Registers a plugin's event listener. + * + * @param plugin The plugin registering the listener. + * @param listener The event listener. + */ + public void registerListener(Plugin plugin, EventHandler listener) { + this.listeners.get(plugin).add(listener); + } + + /** + * Invoke the provided event on all registered event listeners. + * + * @param event The event to invoke. + */ + public void invokeEvent(Event event) { + EnumSet.allOf(HandlerPriority.class).forEach(priority -> this.checkAndFilter(event, priority)); + } + + /** + * Check an event to handlers for the priority. + * + * @param event The event being called. + * @param priority The priority to call for. + */ + private void checkAndFilter(Event event, HandlerPriority priority) { + // Add all listeners from every plugin. + this.listeners.values().stream() + .flatMap(Collection::stream) + // Filter the listeners by priority. + .filter(handler -> handler.handles().isInstance(event)) + .filter(handler -> handler.getPriority() == priority) + // Invoke the event. + .forEach(handler -> this.invokeHandler(event, handler)); + } + + /** + * Gets a plugin's instance by its name. + * + * @param name The name of the plugin. + * @return Either null, or the plugin's instance. + */ + @Nullable public Plugin getPlugin(String name) { + return this.plugins.get(name); + } + + /** + * Enables a plugin. + * + * @param plugin The plugin to enable. + */ + public void enablePlugin(Plugin plugin) { + try { + // Call the plugin's onEnable method. + plugin.onEnable(); + } catch (Exception exception) { + Grasscutter.getLogger() + .error(translate("plugin.enabling_failed", plugin.getName()), exception); + } + } + + /** + * Disables a plugin. + * + * @param plugin The plugin to disable. + */ + public void disablePlugin(Plugin plugin) { + try { + // Call the plugin's onDisable method. + plugin.onDisable(); + } catch (Exception exception) { + Grasscutter.getLogger() + .error(translate("plugin.disabling_failed", plugin.getName()), exception); + } + + // Un-register all listeners. + this.listeners.remove(plugin); + } + + /** + * Performs logic checks then invokes the provided event handler. + * + * @param event The event passed through to the handler. + * @param handler The handler to invoke. + */ + @SuppressWarnings("unchecked") + private void invokeHandler(Event event, EventHandler handler) { + if (!event.isCanceled() || (event.isCanceled() && handler.ignoresCanceled())) + handler.getCallback().consume((T) event); + } + + /* Data about an unloaded plugin. */ + @AllArgsConstructor + @Getter + static class PluginData { + private Plugin plugin; + private PluginIdentifier identifier; + private URLClassLoader classLoader; + private String[] dependencies; + } +} diff --git a/src/main/java/emu/grasscutter/plugin/api/Item.java b/src/main/java/emu/grasscutter/plugin/api/Item.java index 6ecc10c8d..7043710df 100644 --- a/src/main/java/emu/grasscutter/plugin/api/Item.java +++ b/src/main/java/emu/grasscutter/plugin/api/Item.java @@ -1,5 +1,5 @@ -package emu.grasscutter.plugin.api; - -public enum Item { -/* TODO: Use handbook to generate an Item enum. */ -} +package emu.grasscutter.plugin.api; + +public enum Item { +/* TODO: Use handbook to generate an Item enum. */ +} diff --git a/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java b/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java index 028b93b7c..f26b0dd24 100644 --- a/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java +++ b/src/main/java/emu/grasscutter/plugin/api/PlayerHook.java @@ -1,122 +1,122 @@ -package emu.grasscutter.plugin.api; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.EnterReason; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; -import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; -import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; -import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify; -import emu.grasscutter.utils.Position; - -/** Hooks into the {@link Player} class, adding convenient ways to do certain things. */ -public final class PlayerHook { - private final Player player; - - /** - * Hooks into the player. - * - * @param player The player to hook into. - */ - public PlayerHook(Player player) { - this.player = player; - } - - /** Kicks a player from the server. TODO: Refactor to kick using a packet. */ - public void kick() { - this.player.getSession().close(); - } - - /** - * Sends a player to another scene. - * - * @param sceneId The scene to send the player to. - */ - public void changeScenes(int sceneId) { - this.player.getWorld().transferPlayerToScene(this.player, sceneId, this.player.getPosition()); - } - - /** - * Broadcasts an avatar property notify to all world players. - * - * @param property The property that was updated. - */ - public void updateFightProperty(FightProperty property) { - this.broadcastPacketToWorld( - new PacketAvatarFightPropUpdateNotify(this.getCurrentAvatar(), property)); - } - - /** - * Broadcasts the packet sent to all world players. - * - * @param packet The packet to send. - */ - public void broadcastPacketToWorld(BasePacket packet) { - this.player.getWorld().broadcastPacket(packet); - } - - /** - * Set the currently equipped avatar's health. - * - * @param health The health to set the avatar to. - */ - public void setHealth(float health) { - this.getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); - this.updateFightProperty(FightProperty.FIGHT_PROP_CUR_HP); - } - - /** - * Revives the specified avatar. - * - * @param avatar The avatar to revive. - */ - public void reviveAvatar(Avatar avatar) { - this.broadcastPacketToWorld(new PacketAvatarLifeStateChangeNotify(avatar)); - } - - /** - * Teleports a player to a position. This will **not** transfer the player to another scene. - * - * @param position The position to teleport the player to. - */ - public void teleport(Position position) { - this.player.getPosition().set(position); - this.player.sendPacket( - new PacketPlayerEnterSceneNotify( - this.player, - EnterType.ENTER_TYPE_JUMP, - EnterReason.TransPoint, - this.player.getSceneId(), - position)); - } - - /** - * Gets the currently selected avatar's max health. - * - * @return The max health as a float. - */ - public float getMaxHealth() { - return this.getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); - } - - /** - * Gets the currently selected avatar in entity form. - * - * @return The avatar as an {@link EntityAvatar}. - */ - public EntityAvatar getCurrentAvatarEntity() { - return this.player.getTeamManager().getCurrentAvatarEntity(); - } - - /** - * Gets the currently selected avatar. - * - * @return The avatar as an {@link Avatar}. - */ - public Avatar getCurrentAvatar() { - return this.getCurrentAvatarEntity().getAvatar(); - } -} +package emu.grasscutter.plugin.api; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.EnterReason; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; +import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; +import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; +import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify; +import emu.grasscutter.utils.Position; + +/** Hooks into the {@link Player} class, adding convenient ways to do certain things. */ +public final class PlayerHook { + private final Player player; + + /** + * Hooks into the player. + * + * @param player The player to hook into. + */ + public PlayerHook(Player player) { + this.player = player; + } + + /** Kicks a player from the server. TODO: Refactor to kick using a packet. */ + public void kick() { + this.player.getSession().close(); + } + + /** + * Sends a player to another scene. + * + * @param sceneId The scene to send the player to. + */ + public void changeScenes(int sceneId) { + this.player.getWorld().transferPlayerToScene(this.player, sceneId, this.player.getPosition()); + } + + /** + * Broadcasts an avatar property notify to all world players. + * + * @param property The property that was updated. + */ + public void updateFightProperty(FightProperty property) { + this.broadcastPacketToWorld( + new PacketAvatarFightPropUpdateNotify(this.getCurrentAvatar(), property)); + } + + /** + * Broadcasts the packet sent to all world players. + * + * @param packet The packet to send. + */ + public void broadcastPacketToWorld(BasePacket packet) { + this.player.getWorld().broadcastPacket(packet); + } + + /** + * Set the currently equipped avatar's health. + * + * @param health The health to set the avatar to. + */ + public void setHealth(float health) { + this.getCurrentAvatarEntity().setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); + this.updateFightProperty(FightProperty.FIGHT_PROP_CUR_HP); + } + + /** + * Revives the specified avatar. + * + * @param avatar The avatar to revive. + */ + public void reviveAvatar(Avatar avatar) { + this.broadcastPacketToWorld(new PacketAvatarLifeStateChangeNotify(avatar)); + } + + /** + * Teleports a player to a position. This will **not** transfer the player to another scene. + * + * @param position The position to teleport the player to. + */ + public void teleport(Position position) { + this.player.getPosition().set(position); + this.player.sendPacket( + new PacketPlayerEnterSceneNotify( + this.player, + EnterType.ENTER_TYPE_JUMP, + EnterReason.TransPoint, + this.player.getSceneId(), + position)); + } + + /** + * Gets the currently selected avatar's max health. + * + * @return The max health as a float. + */ + public float getMaxHealth() { + return this.getCurrentAvatarEntity().getFightProperty(FightProperty.FIGHT_PROP_MAX_HP); + } + + /** + * Gets the currently selected avatar in entity form. + * + * @return The avatar as an {@link EntityAvatar}. + */ + public EntityAvatar getCurrentAvatarEntity() { + return this.player.getTeamManager().getCurrentAvatarEntity(); + } + + /** + * Gets the currently selected avatar. + * + * @return The avatar as an {@link Avatar}. + */ + public Avatar getCurrentAvatar() { + return this.getCurrentAvatarEntity().getAvatar(); + } +} diff --git a/src/main/java/emu/grasscutter/plugin/api/ServerHook.java b/src/main/java/emu/grasscutter/plugin/api/ServerHook.java index 8a116e3da..8dc909625 100644 --- a/src/main/java/emu/grasscutter/plugin/api/ServerHook.java +++ b/src/main/java/emu/grasscutter/plugin/api/ServerHook.java @@ -1,126 +1,126 @@ -package emu.grasscutter.plugin.api; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.auth.AuthenticationSystem; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.command.CommandMap; -import emu.grasscutter.command.PermissionHandler; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.game.GameServer; -import emu.grasscutter.server.http.HttpServer; -import emu.grasscutter.server.http.Router; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -/** Hooks into the {@link GameServer} class, adding convenient ways to do certain things. */ -public final class ServerHook { - private static ServerHook instance; - private final GameServer gameServer; - private final HttpServer httpServer; - - /** - * Hooks into a server. - * - * @param gameServer The game server to hook into. - * @param httpServer The HTTP server to hook into. - */ - public ServerHook(GameServer gameServer, HttpServer httpServer) { - this.gameServer = gameServer; - this.httpServer = httpServer; - - instance = this; - } - - /** - * Gets the server hook instance. - * - * @return A {@link ServerHook} singleton. - */ - public static ServerHook getInstance() { - return instance; - } - - /** - * @return The game server. - */ - public GameServer getGameServer() { - return this.gameServer; - } - - /** - * @return The HTTP server. - */ - public HttpServer getHttpServer() { - return this.httpServer; - } - - /** - * Gets all online players. - * - * @return Players connected to the server. - */ - @Deprecated(forRemoval = true) - public List getOnlinePlayers() { - return new ArrayList<>(this.gameServer.getPlayers().values()); - } - - /** - * Gets all online players. - * - * @return Players connected to the server. - */ - public Stream getOnlinePlayersStream() { - return this.gameServer.getPlayers().values().stream(); - } - - /** - * Registers a command to the {@link emu.grasscutter.command.CommandMap}. - * - * @param handler The command handler. - */ - public void registerCommand(CommandHandler handler) { - Class clazz = handler.getClass(); - if (!clazz.isAnnotationPresent(Command.class)) - throw new IllegalArgumentException("Command handler must be annotated with @Command."); - Command commandData = clazz.getAnnotation(Command.class); - CommandMap.getInstance().registerCommand(commandData.label(), handler); - } - - /** - * Adds a router using an instance of a class. - * - * @param router A router instance. - */ - public void addRouter(Router router) { - this.addRouter(router.getClass()); - } - - /** - * Adds a router using a class. - * - * @param router The class of the router. - */ - public void addRouter(Class router) { - this.httpServer.addRouter(router); - } - - /** - * Sets the server's authentication system. - * - * @param authSystem An instance of the authentication system. - */ - public void setAuthSystem(AuthenticationSystem authSystem) { - Grasscutter.setAuthenticationSystem(authSystem); - } - - /** - * Sets the server's permission handler. - * - * @param permHandler An instance of the permission handler. - */ - public void setPermissionHandler(PermissionHandler permHandler) { - Grasscutter.setPermissionHandler(permHandler); - } -} +package emu.grasscutter.plugin.api; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.auth.AuthenticationSystem; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.command.CommandMap; +import emu.grasscutter.command.PermissionHandler; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.game.GameServer; +import emu.grasscutter.server.http.HttpServer; +import emu.grasscutter.server.http.Router; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +/** Hooks into the {@link GameServer} class, adding convenient ways to do certain things. */ +public final class ServerHook { + private static ServerHook instance; + private final GameServer gameServer; + private final HttpServer httpServer; + + /** + * Hooks into a server. + * + * @param gameServer The game server to hook into. + * @param httpServer The HTTP server to hook into. + */ + public ServerHook(GameServer gameServer, HttpServer httpServer) { + this.gameServer = gameServer; + this.httpServer = httpServer; + + instance = this; + } + + /** + * Gets the server hook instance. + * + * @return A {@link ServerHook} singleton. + */ + public static ServerHook getInstance() { + return instance; + } + + /** + * @return The game server. + */ + public GameServer getGameServer() { + return this.gameServer; + } + + /** + * @return The HTTP server. + */ + public HttpServer getHttpServer() { + return this.httpServer; + } + + /** + * Gets all online players. + * + * @return Players connected to the server. + */ + @Deprecated(forRemoval = true) + public List getOnlinePlayers() { + return new ArrayList<>(this.gameServer.getPlayers().values()); + } + + /** + * Gets all online players. + * + * @return Players connected to the server. + */ + public Stream getOnlinePlayersStream() { + return this.gameServer.getPlayers().values().stream(); + } + + /** + * Registers a command to the {@link emu.grasscutter.command.CommandMap}. + * + * @param handler The command handler. + */ + public void registerCommand(CommandHandler handler) { + Class clazz = handler.getClass(); + if (!clazz.isAnnotationPresent(Command.class)) + throw new IllegalArgumentException("Command handler must be annotated with @Command."); + Command commandData = clazz.getAnnotation(Command.class); + CommandMap.getInstance().registerCommand(commandData.label(), handler); + } + + /** + * Adds a router using an instance of a class. + * + * @param router A router instance. + */ + public void addRouter(Router router) { + this.addRouter(router.getClass()); + } + + /** + * Adds a router using a class. + * + * @param router The class of the router. + */ + public void addRouter(Class router) { + this.httpServer.addRouter(router); + } + + /** + * Sets the server's authentication system. + * + * @param authSystem An instance of the authentication system. + */ + public void setAuthSystem(AuthenticationSystem authSystem) { + Grasscutter.setAuthenticationSystem(authSystem); + } + + /** + * Sets the server's permission handler. + * + * @param permHandler An instance of the permission handler. + */ + public void setPermissionHandler(PermissionHandler permHandler) { + Grasscutter.setPermissionHandler(permHandler); + } +} diff --git a/src/main/java/emu/grasscutter/scripts/SceneIndexManager.java b/src/main/java/emu/grasscutter/scripts/SceneIndexManager.java index c998fe53c..b5533cc7e 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneIndexManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneIndexManager.java @@ -1,35 +1,35 @@ -package emu.grasscutter.scripts; - -import com.github.davidmoten.rtreemulti.Entry; -import com.github.davidmoten.rtreemulti.RTree; -import com.github.davidmoten.rtreemulti.geometry.Geometry; -import com.github.davidmoten.rtreemulti.geometry.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Function; - -public class SceneIndexManager { - - public static RTree buildIndex( - int dimensions, Collection elements, Function extractor) { - RTree rtree = RTree.dimensions(dimensions).create(); - return rtree.add(elements.stream().map(e -> Entry.entry(e, extractor.apply(e))).toList()); - } - - public static List queryNeighbors(RTree tree, double[] position, int range) { - var result = new ArrayList(); - Rectangle rectangle = Rectangle.create(calRange(position, -range), calRange(position, range)); - var queryResult = tree.search(rectangle); - queryResult.forEach(q -> result.add(q.value())); - return result; - } - - private static double[] calRange(double[] position, int range) { - var newPos = position.clone(); - for (int i = 0; i < newPos.length; i++) { - newPos[i] += range; - } - return newPos; - } -} +package emu.grasscutter.scripts; + +import com.github.davidmoten.rtreemulti.Entry; +import com.github.davidmoten.rtreemulti.RTree; +import com.github.davidmoten.rtreemulti.geometry.Geometry; +import com.github.davidmoten.rtreemulti.geometry.Rectangle; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; + +public class SceneIndexManager { + + public static RTree buildIndex( + int dimensions, Collection elements, Function extractor) { + RTree rtree = RTree.dimensions(dimensions).create(); + return rtree.add(elements.stream().map(e -> Entry.entry(e, extractor.apply(e))).toList()); + } + + public static List queryNeighbors(RTree tree, double[] position, int range) { + var result = new ArrayList(); + Rectangle rectangle = Rectangle.create(calRange(position, -range), calRange(position, range)); + var queryResult = tree.search(rectangle); + queryResult.forEach(q -> result.add(q.value())); + return result; + } + + private static double[] calRange(double[] position, int range) { + var newPos = position.clone(); + for (int i = 0; i < newPos.length; i++) { + newPos[i] += range; + } + return newPos; + } +} diff --git a/src/main/java/emu/grasscutter/scripts/constants/EventType.java b/src/main/java/emu/grasscutter/scripts/constants/EventType.java index 5c5015126..8d9048927 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/EventType.java +++ b/src/main/java/emu/grasscutter/scripts/constants/EventType.java @@ -1,126 +1,126 @@ -package emu.grasscutter.scripts.constants; - -public class EventType { - public static final int EVENT_NONE = 0; - /** param1: monster.configId */ - public static final int EVENT_ANY_MONSTER_DIE = 1; - - public static final int EVENT_ANY_GADGET_DIE = 2; - public static final int EVENT_VARIABLE_CHANGE = 3; - public static final int EVENT_ENTER_REGION = 4; - public static final int EVENT_LEAVE_REGION = 5; - public static final int EVENT_GADGET_CREATE = 6; - public static final int EVENT_GADGET_STATE_CHANGE = 7; - public static final int EVENT_DUNGEON_SETTLE = 8; - public static final int EVENT_SELECT_OPTION = 9; - public static final int EVENT_CLIENT_EXECUTE = 10; - public static final int EVENT_ANY_MONSTER_LIVE = 11; - public static final int EVENT_SPECIFIC_MONSTER_HP_CHANGE = 12; - public static final int EVENT_CITY_LEVELUP_UNLOCK_DUNGEON_ENTRY = 13; - public static final int EVENT_DUNGEON_BROADCAST_ONTIMER = 14; - public static final int EVENT_TIMER_EVENT = 15; - public static final int EVENT_CHALLENGE_SUCCESS = 16; - public static final int EVENT_CHALLENGE_FAIL = 17; - public static final int EVENT_SEAL_BATTLE_BEGIN = 18; - public static final int EVENT_SEAL_BATTLE_END = 19; - public static final int EVENT_GATHER = 20; - public static final int EVENT_QUEST_FINISH = 21; - public static final int EVENT_MONSTER_BATTLE = 22; - public static final int EVENT_CITY_LEVELUP = 23; - public static final int EVENT_CUTSCENE_END = 24; - public static final int EVENT_AVATAR_NEAR_PLATFORM = 25; - public static final int EVENT_PLATFORM_REACH_POINT = 26; - public static final int EVENT_UNLOCK_TRANS_POINT = 27; - public static final int EVENT_QUEST_START = 28; - public static final int EVENT_GROUP_LOAD = 29; - public static final int EVENT_GROUP_WILL_UNLOAD = 30; - public static final int EVENT_GROUP_WILL_REFRESH = 31; - public static final int EVENT_GROUP_REFRESH = 32; - public static final int EVENT_DUNGEON_REWARD_GET = 33; - public static final int EVENT_SPECIFIC_GADGET_HP_CHANGE = 34; - public static final int EVENT_MONSTER_TIDE_OVER = 35; - public static final int EVENT_MONSTER_TIDE_CREATE = 36; - public static final int EVENT_MONSTER_TIDE_DIE = 37; - public static final int EVENT_SEALAMP_PHASE_CHANGE = 38; - public static final int EVENT_BLOSSOM_PROGRESS_FINISH = 39; - public static final int EVENT_BLOSSOM_CHEST_DIE = 40; - public static final int EVENT_GADGET_PLAY_START = 41; - public static final int EVENT_GADGET_PLAY_START_CD = 42; - public static final int EVENT_GADGET_PLAY_STOP = 43; - public static final int EVENT_GADGET_LUA_NOTIFY = 44; - public static final int EVENT_MP_PLAY_PREPARE = 45; - public static final int EVENT_MP_PLAY_BATTLE = 46; - public static final int EVENT_MP_PLAY_PREPARE_INTERRUPT = 47; - public static final int EVENT_SELECT_DIFFICULTY = 48; - public static final int EVENT_SCENE_MP_PLAY_BATTLE_STATE = 49; - public static final int EVENT_SCENE_MP_PLAY_BATTLE_STAGE_CHANGE = 50; - public static final int EVENT_SCENE_MP_PLAY_BATTLE_RESULT = 51; - public static final int EVENT_SEAL_BATTLE_PROGRESS_DECREASE = 52; - public static final int EVENT_GENERAL_REWARD_DIE = 53; - public static final int EVENT_SCENE_MP_PLAY_BATTLE_INTERRUPT = 54; - public static final int EVENT_MONSTER_DIE_BEFORE_LEAVE_SCENE = 55; - public static final int EVENT_SCENE_MP_PLAY_OPEN = 56; - public static final int EVENT_OFFERING_LEVELUP = 57; - public static final int EVENT_DUNGEON_REVIVE = 58; - public static final int EVENT_SCENE_MP_PLAY_ALL_AVATAR_DIE = 59; - public static final int EVENT_DUNGEON_ALL_AVATAR_DIE = 60; - public static final int EVENT_GENERAL_REWARD_TAKEN = 61; - public static final int EVENT_PLATFORM_REACH_ARRAYPOINT = 62; - public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_END = 63; - public static final int EVENT_SCENE_MULTISTAGE_PLAY_END_STAGE_REQ = 64; - public static final int EVENT_MECHANICUS_PICKED_CARD = 65; - public static final int EVENT_POOL_MONSTER_TIDE_OVER = 66; - public static final int EVENT_POOL_MONSTER_TIDE_CREATE = 67; - public static final int EVENT_POOL_MONSTER_TIDE_DIE = 68; - public static final int EVENT_DUNGEON_AVATAR_SLIP_DIE = 69; - public static final int EVENT_GALLERY_START = 70; - public static final int EVENT_GALLERY_STOP = 71; - public static final int EVENT_TIME_AXIS_PASS = 72; - public static final int EVENT_FLEUR_FAIR_DUNGEON_ALL_PLAYER_ENTER = 73; - public static final int EVENT_GADGETTALK_DONE = 74; - public static final int EVENT_SET_GAME_TIME = 75; - public static final int EVENT_HIDE_AND_SEEK_PLAYER_QUIT = 76; - public static final int EVENT_AVATAR_DIE = 77; - public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_START = 78; - public static final int EVENT_GALLERY_PROGRESS_PASS = 79; - public static final int EVENT_GALLERY_PROGRESS_EMPTY = 80; - public static final int EVENT_GALLERY_PROGRESS_FULL = 81; - public static final int EVENT_HUNTING_FINISH_FINAL = 82; - public static final int EVENT_USE_WIDGET_TOY_FOX_CAMERA = 83; - public static final int EVENT_LUNA_RITE_SACRIFICE = 84; - public static final int EVENT_SUMO_SWITCH_TEAM_EVENT = 85; - public static final int EVENT_FISHING_START = 86; - public static final int EVENT_FISHING_STOP = 87; - public static final int EVENT_FISHING_QTE_FINISH = 88; - public static final int EVENT_FISHING_TIMEOUT_FLEE = 89; - public static final int EVENT_ROGUE_CELL_STATE_CHANGE = 90; - public static final int EVENT_ROGUE_CELL_CONSTRUCT = 91; - public static final int EVENT_ROGUE_CELL_FINISH_SELECT_CARD = 92; - public static final int EVENT_ANY_MONSTER_CAPTURE = 93; - public static final int EVENT_ACTIVITY_INTERACT_GADGET = 94; - public static final int EVENT_CHALLENGE_PAUSE = 95; - public static final int EVENT_LEVEL_TAG_CHANGE = 96; - public static final int EVENT_CUSTOM_DUNGEON_START = 97; - public static final int EVENT_CUSTOM_DUNGEON_RESTART = 98; - public static final int EVENT_CUSTOM_DUNGEON_REACTIVE = 99; - public static final int EVENT_CUSTOM_DUNGEON_OUT_STUCK = 100; - public static final int EVENT_CUSTOM_DUNGEON_EXIT_TRY = 101; - public static final int EVENT_CUSTOM_DUNGEON_OFFICIAL_RESTART = 102; - public static final int EVENT_ANY_MONSTER_CAPTURE_AND_DISAPPEAR = 103; - public static final int EVENT_MICHIAE_INTERACT = 104; - public static final int EVENT_SELECT_UIINTERACT = 105; - public static final int EVENT_LUA_NOTIFY = 106; - public static final int EVENT_PHOTO_FINISH = 107; - public static final int EVENT_IRODORI_MASTER_READY = 108; - public static final int EVENT_ROGUE_START_FIGHT = 109; - public static final int EVENT_ROGUE_CREAGE_FIGHT_GADGET = 110; - public static final int EVENT_ROGUE_CREAGE_REPAIR_GADGET = 111; - public static final int EVENT_ROGUE_OPEN_ACCESS = 112; - public static final int EVENT_GADGET_GIVING_FINISHED = 113; - public static final int EVENT_OBSERVATION_POINT_NOTIFY = 114; - public static final int EVENT_GADGET_GIVING_TAKEBACK = 115; - public static final int EVENT_ECHO_SHELL_INTERACT = 116; - public static final int EVENT_PLATFORM_ARRIVAL = 2701; - public static final int EVENT_PLAYER_BACK_GALLERY_REVIVE_POINT = 2800; - public static final int EVENT_GALLERY_CANNOT_START_AFTER_COUNTDOWN = 2801; -} +package emu.grasscutter.scripts.constants; + +public class EventType { + public static final int EVENT_NONE = 0; + /** param1: monster.configId */ + public static final int EVENT_ANY_MONSTER_DIE = 1; + + public static final int EVENT_ANY_GADGET_DIE = 2; + public static final int EVENT_VARIABLE_CHANGE = 3; + public static final int EVENT_ENTER_REGION = 4; + public static final int EVENT_LEAVE_REGION = 5; + public static final int EVENT_GADGET_CREATE = 6; + public static final int EVENT_GADGET_STATE_CHANGE = 7; + public static final int EVENT_DUNGEON_SETTLE = 8; + public static final int EVENT_SELECT_OPTION = 9; + public static final int EVENT_CLIENT_EXECUTE = 10; + public static final int EVENT_ANY_MONSTER_LIVE = 11; + public static final int EVENT_SPECIFIC_MONSTER_HP_CHANGE = 12; + public static final int EVENT_CITY_LEVELUP_UNLOCK_DUNGEON_ENTRY = 13; + public static final int EVENT_DUNGEON_BROADCAST_ONTIMER = 14; + public static final int EVENT_TIMER_EVENT = 15; + public static final int EVENT_CHALLENGE_SUCCESS = 16; + public static final int EVENT_CHALLENGE_FAIL = 17; + public static final int EVENT_SEAL_BATTLE_BEGIN = 18; + public static final int EVENT_SEAL_BATTLE_END = 19; + public static final int EVENT_GATHER = 20; + public static final int EVENT_QUEST_FINISH = 21; + public static final int EVENT_MONSTER_BATTLE = 22; + public static final int EVENT_CITY_LEVELUP = 23; + public static final int EVENT_CUTSCENE_END = 24; + public static final int EVENT_AVATAR_NEAR_PLATFORM = 25; + public static final int EVENT_PLATFORM_REACH_POINT = 26; + public static final int EVENT_UNLOCK_TRANS_POINT = 27; + public static final int EVENT_QUEST_START = 28; + public static final int EVENT_GROUP_LOAD = 29; + public static final int EVENT_GROUP_WILL_UNLOAD = 30; + public static final int EVENT_GROUP_WILL_REFRESH = 31; + public static final int EVENT_GROUP_REFRESH = 32; + public static final int EVENT_DUNGEON_REWARD_GET = 33; + public static final int EVENT_SPECIFIC_GADGET_HP_CHANGE = 34; + public static final int EVENT_MONSTER_TIDE_OVER = 35; + public static final int EVENT_MONSTER_TIDE_CREATE = 36; + public static final int EVENT_MONSTER_TIDE_DIE = 37; + public static final int EVENT_SEALAMP_PHASE_CHANGE = 38; + public static final int EVENT_BLOSSOM_PROGRESS_FINISH = 39; + public static final int EVENT_BLOSSOM_CHEST_DIE = 40; + public static final int EVENT_GADGET_PLAY_START = 41; + public static final int EVENT_GADGET_PLAY_START_CD = 42; + public static final int EVENT_GADGET_PLAY_STOP = 43; + public static final int EVENT_GADGET_LUA_NOTIFY = 44; + public static final int EVENT_MP_PLAY_PREPARE = 45; + public static final int EVENT_MP_PLAY_BATTLE = 46; + public static final int EVENT_MP_PLAY_PREPARE_INTERRUPT = 47; + public static final int EVENT_SELECT_DIFFICULTY = 48; + public static final int EVENT_SCENE_MP_PLAY_BATTLE_STATE = 49; + public static final int EVENT_SCENE_MP_PLAY_BATTLE_STAGE_CHANGE = 50; + public static final int EVENT_SCENE_MP_PLAY_BATTLE_RESULT = 51; + public static final int EVENT_SEAL_BATTLE_PROGRESS_DECREASE = 52; + public static final int EVENT_GENERAL_REWARD_DIE = 53; + public static final int EVENT_SCENE_MP_PLAY_BATTLE_INTERRUPT = 54; + public static final int EVENT_MONSTER_DIE_BEFORE_LEAVE_SCENE = 55; + public static final int EVENT_SCENE_MP_PLAY_OPEN = 56; + public static final int EVENT_OFFERING_LEVELUP = 57; + public static final int EVENT_DUNGEON_REVIVE = 58; + public static final int EVENT_SCENE_MP_PLAY_ALL_AVATAR_DIE = 59; + public static final int EVENT_DUNGEON_ALL_AVATAR_DIE = 60; + public static final int EVENT_GENERAL_REWARD_TAKEN = 61; + public static final int EVENT_PLATFORM_REACH_ARRAYPOINT = 62; + public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_END = 63; + public static final int EVENT_SCENE_MULTISTAGE_PLAY_END_STAGE_REQ = 64; + public static final int EVENT_MECHANICUS_PICKED_CARD = 65; + public static final int EVENT_POOL_MONSTER_TIDE_OVER = 66; + public static final int EVENT_POOL_MONSTER_TIDE_CREATE = 67; + public static final int EVENT_POOL_MONSTER_TIDE_DIE = 68; + public static final int EVENT_DUNGEON_AVATAR_SLIP_DIE = 69; + public static final int EVENT_GALLERY_START = 70; + public static final int EVENT_GALLERY_STOP = 71; + public static final int EVENT_TIME_AXIS_PASS = 72; + public static final int EVENT_FLEUR_FAIR_DUNGEON_ALL_PLAYER_ENTER = 73; + public static final int EVENT_GADGETTALK_DONE = 74; + public static final int EVENT_SET_GAME_TIME = 75; + public static final int EVENT_HIDE_AND_SEEK_PLAYER_QUIT = 76; + public static final int EVENT_AVATAR_DIE = 77; + public static final int EVENT_SCENE_MULTISTAGE_PLAY_STAGE_START = 78; + public static final int EVENT_GALLERY_PROGRESS_PASS = 79; + public static final int EVENT_GALLERY_PROGRESS_EMPTY = 80; + public static final int EVENT_GALLERY_PROGRESS_FULL = 81; + public static final int EVENT_HUNTING_FINISH_FINAL = 82; + public static final int EVENT_USE_WIDGET_TOY_FOX_CAMERA = 83; + public static final int EVENT_LUNA_RITE_SACRIFICE = 84; + public static final int EVENT_SUMO_SWITCH_TEAM_EVENT = 85; + public static final int EVENT_FISHING_START = 86; + public static final int EVENT_FISHING_STOP = 87; + public static final int EVENT_FISHING_QTE_FINISH = 88; + public static final int EVENT_FISHING_TIMEOUT_FLEE = 89; + public static final int EVENT_ROGUE_CELL_STATE_CHANGE = 90; + public static final int EVENT_ROGUE_CELL_CONSTRUCT = 91; + public static final int EVENT_ROGUE_CELL_FINISH_SELECT_CARD = 92; + public static final int EVENT_ANY_MONSTER_CAPTURE = 93; + public static final int EVENT_ACTIVITY_INTERACT_GADGET = 94; + public static final int EVENT_CHALLENGE_PAUSE = 95; + public static final int EVENT_LEVEL_TAG_CHANGE = 96; + public static final int EVENT_CUSTOM_DUNGEON_START = 97; + public static final int EVENT_CUSTOM_DUNGEON_RESTART = 98; + public static final int EVENT_CUSTOM_DUNGEON_REACTIVE = 99; + public static final int EVENT_CUSTOM_DUNGEON_OUT_STUCK = 100; + public static final int EVENT_CUSTOM_DUNGEON_EXIT_TRY = 101; + public static final int EVENT_CUSTOM_DUNGEON_OFFICIAL_RESTART = 102; + public static final int EVENT_ANY_MONSTER_CAPTURE_AND_DISAPPEAR = 103; + public static final int EVENT_MICHIAE_INTERACT = 104; + public static final int EVENT_SELECT_UIINTERACT = 105; + public static final int EVENT_LUA_NOTIFY = 106; + public static final int EVENT_PHOTO_FINISH = 107; + public static final int EVENT_IRODORI_MASTER_READY = 108; + public static final int EVENT_ROGUE_START_FIGHT = 109; + public static final int EVENT_ROGUE_CREAGE_FIGHT_GADGET = 110; + public static final int EVENT_ROGUE_CREAGE_REPAIR_GADGET = 111; + public static final int EVENT_ROGUE_OPEN_ACCESS = 112; + public static final int EVENT_GADGET_GIVING_FINISHED = 113; + public static final int EVENT_OBSERVATION_POINT_NOTIFY = 114; + public static final int EVENT_GADGET_GIVING_TAKEBACK = 115; + public static final int EVENT_ECHO_SHELL_INTERACT = 116; + public static final int EVENT_PLATFORM_ARRIVAL = 2701; + public static final int EVENT_PLAYER_BACK_GALLERY_REVIVE_POINT = 2800; + public static final int EVENT_GALLERY_CANNOT_START_AFTER_COUNTDOWN = 2801; +} diff --git a/src/main/java/emu/grasscutter/scripts/constants/ScriptGadgetState.java b/src/main/java/emu/grasscutter/scripts/constants/ScriptGadgetState.java index 043278643..187299a01 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/ScriptGadgetState.java +++ b/src/main/java/emu/grasscutter/scripts/constants/ScriptGadgetState.java @@ -1,24 +1,24 @@ -package emu.grasscutter.scripts.constants; - -public class ScriptGadgetState { - public static final int Default = 0; - public static final int GatherDrop = 1; - public static final int ChestLocked = 101; - public static final int ChestOpened = 102; - public static final int ChestTrap = 103; - public static final int ChestBramble = 104; - public static final int ChestFrozen = 105; - public static final int ChestRock = 106; - public static final int GearStart = 201; - public static final int GearStop = 202; - public static final int GearAction1 = 203; - public static final int GearAction2 = 204; - public static final int CrystalResonate1 = 301; - public static final int CrystalResonate2 = 302; - public static final int CrystalExplode = 303; - public static final int CrystalDrain = 304; - public static final int StatueActive = 401; - public static final int Action01 = 901; - public static final int Action02 = 902; - public static final int Action03 = 903; -} +package emu.grasscutter.scripts.constants; + +public class ScriptGadgetState { + public static final int Default = 0; + public static final int GatherDrop = 1; + public static final int ChestLocked = 101; + public static final int ChestOpened = 102; + public static final int ChestTrap = 103; + public static final int ChestBramble = 104; + public static final int ChestFrozen = 105; + public static final int ChestRock = 106; + public static final int GearStart = 201; + public static final int GearStop = 202; + public static final int GearAction1 = 203; + public static final int GearAction2 = 204; + public static final int CrystalResonate1 = 301; + public static final int CrystalResonate2 = 302; + public static final int CrystalExplode = 303; + public static final int CrystalDrain = 304; + public static final int StatueActive = 401; + public static final int Action01 = 901; + public static final int Action02 = 902; + public static final int Action03 = 903; +} diff --git a/src/main/java/emu/grasscutter/scripts/constants/ScriptRegionShape.java b/src/main/java/emu/grasscutter/scripts/constants/ScriptRegionShape.java index eb983df97..31e1f7f63 100644 --- a/src/main/java/emu/grasscutter/scripts/constants/ScriptRegionShape.java +++ b/src/main/java/emu/grasscutter/scripts/constants/ScriptRegionShape.java @@ -1,9 +1,9 @@ -package emu.grasscutter.scripts.constants; - -public class ScriptRegionShape { - public static final int NONE = 0; - public static final int SPHERE = 1; - public static final int CUBIC = 2; - public static final int CYLINDER = 3; - public static final int POLYGON = 4; -} +package emu.grasscutter.scripts.constants; + +public class ScriptRegionShape { + public static final int NONE = 0; + public static final int SPHERE = 1; + public static final int CUBIC = 2; + public static final int CYLINDER = 3; + public static final int POLYGON = 4; +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneBusiness.java b/src/main/java/emu/grasscutter/scripts/data/SceneBusiness.java index e5a61e5dd..2609f9b5d 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneBusiness.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneBusiness.java @@ -1,10 +1,10 @@ -package emu.grasscutter.scripts.data; - -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneBusiness { - public int type; -} +package emu.grasscutter.scripts.data; + +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneBusiness { + public int type; +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java b/src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java index edefd1253..2bb99f59d 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneGarbage.java @@ -1,11 +1,11 @@ -package emu.grasscutter.scripts.data; - -import java.util.List; -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneGarbage { - public List gadgets; -} +package emu.grasscutter.scripts.data; + +import java.util.List; +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneGarbage { + public List gadgets; +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java index 668cf627a..6b73e7c53 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneMeta.java @@ -1,74 +1,74 @@ -package emu.grasscutter.scripts.data; - -import com.github.davidmoten.rtreemulti.RTree; -import com.github.davidmoten.rtreemulti.geometry.Geometry; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.scripts.SceneIndexManager; -import emu.grasscutter.scripts.ScriptLoader; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.script.Bindings; -import javax.script.CompiledScript; -import javax.script.ScriptException; -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneMeta { - - public SceneConfig config; - public Map blocks; - - public Bindings context; - - public RTree sceneBlockIndex; - - public static SceneMeta of(int sceneId) { - return new SceneMeta().load(sceneId); - } - - public SceneMeta load(int sceneId) { - // Get compiled script if cached - CompiledScript cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + ".lua"); - - if (cs == null) { - Grasscutter.getLogger().warn("No script found for scene " + sceneId); - return null; - } - - // Create bindings - this.context = ScriptLoader.getEngine().createBindings(); - - // Eval script - try { - cs.eval(this.context); - - this.config = - ScriptLoader.getSerializer() - .toObject(SceneConfig.class, this.context.get("scene_config")); - - // TODO optimize later - // Create blocks - List blockIds = - ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks")); - List blocks = - ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects")); - - for (int i = 0; i < blocks.size(); i++) { - SceneBlock block = blocks.get(i); - block.id = blockIds.get(i); - } - - this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b, (a, b) -> a)); - this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle); - - } catch (ScriptException exception) { - Grasscutter.getLogger().error("An error occurred while running a script.", exception); - return null; - } - Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId); - return this; - } -} +package emu.grasscutter.scripts.data; + +import com.github.davidmoten.rtreemulti.RTree; +import com.github.davidmoten.rtreemulti.geometry.Geometry; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.scripts.SceneIndexManager; +import emu.grasscutter.scripts.ScriptLoader; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.script.Bindings; +import javax.script.CompiledScript; +import javax.script.ScriptException; +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneMeta { + + public SceneConfig config; + public Map blocks; + + public Bindings context; + + public RTree sceneBlockIndex; + + public static SceneMeta of(int sceneId) { + return new SceneMeta().load(sceneId); + } + + public SceneMeta load(int sceneId) { + // Get compiled script if cached + CompiledScript cs = ScriptLoader.getScript("Scene/" + sceneId + "/scene" + sceneId + ".lua"); + + if (cs == null) { + Grasscutter.getLogger().warn("No script found for scene " + sceneId); + return null; + } + + // Create bindings + this.context = ScriptLoader.getEngine().createBindings(); + + // Eval script + try { + cs.eval(this.context); + + this.config = + ScriptLoader.getSerializer() + .toObject(SceneConfig.class, this.context.get("scene_config")); + + // TODO optimize later + // Create blocks + List blockIds = + ScriptLoader.getSerializer().toList(Integer.class, this.context.get("blocks")); + List blocks = + ScriptLoader.getSerializer().toList(SceneBlock.class, this.context.get("block_rects")); + + for (int i = 0; i < blocks.size(); i++) { + SceneBlock block = blocks.get(i); + block.id = blockIds.get(i); + } + + this.blocks = blocks.stream().collect(Collectors.toMap(b -> b.id, b -> b, (a, b) -> a)); + this.sceneBlockIndex = SceneIndexManager.buildIndex(2, blocks, SceneBlock::toRectangle); + + } catch (ScriptException exception) { + Grasscutter.getLogger().error("An error occurred while running a script.", exception); + return null; + } + Grasscutter.getLogger().debug("Successfully loaded metadata in scene {}.", sceneId); + return this; + } +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneNPC.java b/src/main/java/emu/grasscutter/scripts/data/SceneNPC.java index 00edef640..1dfb44211 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneNPC.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneNPC.java @@ -1,10 +1,10 @@ -package emu.grasscutter.scripts.data; - -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneNPC extends SceneObject { - public int npc_id; -} +package emu.grasscutter.scripts.data; + +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneNPC extends SceneObject { + public int npc_id; +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneRegion.java b/src/main/java/emu/grasscutter/scripts/data/SceneRegion.java index f0d2bfd57..3c43037ed 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneRegion.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneRegion.java @@ -1,38 +1,38 @@ -package emu.grasscutter.scripts.data; - -import emu.grasscutter.scripts.constants.ScriptRegionShape; -import emu.grasscutter.utils.Position; -import java.util.List; -import lombok.Setter; - -@Setter -public class SceneRegion { - public int config_id; - public int shape; - public Position pos; - // for CUBIC - public Position size; - // for SPHERE - public int radius; - public int area_id; - public float height; - public List point_array; - - public transient SceneGroup group; - - public boolean contains(Position position) { - switch (shape) { - case ScriptRegionShape.CUBIC: - return (Math.abs(pos.getX() - position.getX()) <= size.getX()) - && (Math.abs(pos.getY() - position.getY()) <= size.getY()) - && (Math.abs(pos.getZ() - position.getZ()) <= size.getZ()); - case ScriptRegionShape.SPHERE: - var x = Math.pow(pos.getX() - position.getX(), 2); - var y = Math.pow(pos.getY() - position.getY(), 2); - var z = Math.pow(pos.getZ() - position.getZ(), 2); - // ^ means XOR in java! - return x + y + z <= (radius * radius); - } - return false; - } -} +package emu.grasscutter.scripts.data; + +import emu.grasscutter.scripts.constants.ScriptRegionShape; +import emu.grasscutter.utils.Position; +import java.util.List; +import lombok.Setter; + +@Setter +public class SceneRegion { + public int config_id; + public int shape; + public Position pos; + // for CUBIC + public Position size; + // for SPHERE + public int radius; + public int area_id; + public float height; + public List point_array; + + public transient SceneGroup group; + + public boolean contains(Position position) { + switch (shape) { + case ScriptRegionShape.CUBIC: + return (Math.abs(pos.getX() - position.getX()) <= size.getX()) + && (Math.abs(pos.getY() - position.getY()) <= size.getY()) + && (Math.abs(pos.getZ() - position.getZ()) <= size.getZ()); + case ScriptRegionShape.SPHERE: + var x = Math.pow(pos.getX() - position.getX(), 2); + var y = Math.pow(pos.getY() - position.getY(), 2); + var z = Math.pow(pos.getZ() - position.getZ(), 2); + // ^ means XOR in java! + return x + y + z <= (radius * radius); + } + return false; + } +} diff --git a/src/main/java/emu/grasscutter/scripts/data/SceneVar.java b/src/main/java/emu/grasscutter/scripts/data/SceneVar.java index c0664f234..5e9fb4d4c 100644 --- a/src/main/java/emu/grasscutter/scripts/data/SceneVar.java +++ b/src/main/java/emu/grasscutter/scripts/data/SceneVar.java @@ -1,13 +1,13 @@ -package emu.grasscutter.scripts.data; - -import lombok.Setter; -import lombok.ToString; - -@ToString -@Setter -public class SceneVar { - public String name; - public int value; - public boolean no_refresh; - public int configId; -} +package emu.grasscutter.scripts.data; + +import lombok.Setter; +import lombok.ToString; + +@ToString +@Setter +public class SceneVar { + public String name; + public int value; + public boolean no_refresh; + public int configId; +} diff --git a/src/main/java/emu/grasscutter/scripts/serializer/LuaTableJacksonSerializer.java b/src/main/java/emu/grasscutter/scripts/serializer/LuaTableJacksonSerializer.java index 1fcd4e4d1..42c0ce4fc 100644 --- a/src/main/java/emu/grasscutter/scripts/serializer/LuaTableJacksonSerializer.java +++ b/src/main/java/emu/grasscutter/scripts/serializer/LuaTableJacksonSerializer.java @@ -1,195 +1,195 @@ -package emu.grasscutter.scripts.serializer; - -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.type.CollectionType; -import com.fasterxml.jackson.databind.type.MapType; -import emu.grasscutter.Grasscutter; -import java.io.IOException; -import java.util.*; -import org.luaj.vm2.LuaTable; -import org.luaj.vm2.LuaValue; - -public class LuaTableJacksonSerializer extends JsonSerializer implements Serializer { - - private static ObjectMapper objectMapper; - - public LuaTableJacksonSerializer() { - if (objectMapper == null) { - objectMapper = new ObjectMapper(); - objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true); - // Some properties in Lua table but not in java field - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper - .configOverride(List.class) - .setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY)); - SimpleModule luaSerializeModule = new SimpleModule(); - luaSerializeModule.addSerializer(LuaTable.class, this); - objectMapper.registerModule(luaSerializeModule); - } - } - - @Override - public void serialize(LuaTable value, JsonGenerator gen, SerializerProvider serializers) - throws IOException { - if (value == null || value.isnil()) { - gen.writeNull(); - return; - } - - // Detect table type - boolean isArray = false; - LuaValue[] keys = value.keys(); - if (keys.length == 0) { - gen.writeNull(); - return; - } - - int count = 0; - for (int i = 0; i < keys.length; i++) { - if (!keys[i].isint() || (i + 1) != keys[i].toint()) { - break; - } else { - count++; - } - } - - if (count == keys.length) { - isArray = true; - } - - if (isArray) { - gen.writeStartArray(); - for (LuaValue key : keys) { - LuaValue luaValue = value.get(key); - if (luaValue.isnil()) { - gen.writeNull(); - } else if (luaValue.isboolean()) { - gen.writeBoolean(luaValue.toboolean()); - } else if (luaValue.isint()) { - gen.writeNumber(luaValue.toint()); - } else if (luaValue.islong()) { - gen.writeNumber(luaValue.tolong()); - } else if (luaValue.isnumber()) { - gen.writeNumber(luaValue.tofloat()); - } else if (luaValue.isstring()) { - gen.writeString(luaValue.tojstring()); - } else if (luaValue.istable()) { - serialize(luaValue.checktable(), gen, serializers); - } - } - gen.writeEndArray(); - } else { - gen.writeStartObject(); - for (LuaValue key : keys) { - String keyStr = key.toString(); - LuaValue luaValue = value.get(key); - if (luaValue.isnil()) { - gen.writeNullField(keyStr); - } else if (luaValue.isboolean()) { - gen.writeBooleanField(keyStr, luaValue.toboolean()); - } else if (luaValue.isint()) { - gen.writeNumberField(keyStr, luaValue.toint()); - } else if (luaValue.islong()) { - gen.writeNumberField(keyStr, luaValue.tolong()); - } else if (luaValue.isnumber()) { - gen.writeNumberField(keyStr, luaValue.tofloat()); - } else if (luaValue.isstring()) { - gen.writeStringField(keyStr, luaValue.tojstring()); - } else if (luaValue.istable()) { - gen.writeFieldName(keyStr); - serialize(luaValue.checktable(), gen, serializers); - } - } - gen.writeEndObject(); - } - - gen.flush(); - gen.close(); - } - - @Override - public List toList(Class type, Object obj) { - List list = new ArrayList<>(); - if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { - return list; - } - - CollectionType collectionType = - objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, type); - JsonNode jsonNode = objectMapper.valueToTree(luaTable); - Grasscutter.getLogger() - .trace( - "[LuaTableToList] className={},data={}", type.getCanonicalName(), jsonNode.toString()); - if (jsonNode.isEmpty()) { - return list; - } - if (jsonNode.isArray()) { - try { - Object o = objectMapper.treeToValue(jsonNode, collectionType); - if (o != null) { - list = (ArrayList) o; - } - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - } else if (jsonNode.isObject()) { - Iterator> fields = jsonNode.fields(); - List nodes = new ArrayList<>(); - while (fields.hasNext()) { - Map.Entry next = fields.next(); - nodes.add(next.getValue()); - } - list = objectMapper.convertValue(nodes, collectionType); - } - return list; - } - - @Override - public T toObject(Class type, Object obj) { - if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { - return null; - } - - JsonNode jsonNode = objectMapper.valueToTree(luaTable); - Grasscutter.getLogger() - .trace( - "[LuaTableToObject] className={},data={}", - type.getCanonicalName(), - jsonNode.toString()); - try { - return objectMapper.treeToValue(jsonNode, type); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public Map toMap(Class type, Object obj) { - HashMap map = new HashMap<>(); - if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { - return map; - } - - MapType mapStringType = - objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, type); - JsonNode jsonNode = objectMapper.valueToTree(luaTable); - Grasscutter.getLogger() - .trace( - "[LuaTableToMap] className={},data={}", type.getCanonicalName(), jsonNode.toString()); - try { - Object o = objectMapper.treeToValue(jsonNode, mapStringType); - if (o != null) { - return (HashMap) o; - } - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - return map; - } -} +package emu.grasscutter.scripts.serializer; + +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.fasterxml.jackson.databind.type.MapType; +import emu.grasscutter.Grasscutter; +import java.io.IOException; +import java.util.*; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; + +public class LuaTableJacksonSerializer extends JsonSerializer implements Serializer { + + private static ObjectMapper objectMapper; + + public LuaTableJacksonSerializer() { + if (objectMapper == null) { + objectMapper = new ObjectMapper(); + objectMapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true); + // Some properties in Lua table but not in java field + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper + .configOverride(List.class) + .setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY)); + SimpleModule luaSerializeModule = new SimpleModule(); + luaSerializeModule.addSerializer(LuaTable.class, this); + objectMapper.registerModule(luaSerializeModule); + } + } + + @Override + public void serialize(LuaTable value, JsonGenerator gen, SerializerProvider serializers) + throws IOException { + if (value == null || value.isnil()) { + gen.writeNull(); + return; + } + + // Detect table type + boolean isArray = false; + LuaValue[] keys = value.keys(); + if (keys.length == 0) { + gen.writeNull(); + return; + } + + int count = 0; + for (int i = 0; i < keys.length; i++) { + if (!keys[i].isint() || (i + 1) != keys[i].toint()) { + break; + } else { + count++; + } + } + + if (count == keys.length) { + isArray = true; + } + + if (isArray) { + gen.writeStartArray(); + for (LuaValue key : keys) { + LuaValue luaValue = value.get(key); + if (luaValue.isnil()) { + gen.writeNull(); + } else if (luaValue.isboolean()) { + gen.writeBoolean(luaValue.toboolean()); + } else if (luaValue.isint()) { + gen.writeNumber(luaValue.toint()); + } else if (luaValue.islong()) { + gen.writeNumber(luaValue.tolong()); + } else if (luaValue.isnumber()) { + gen.writeNumber(luaValue.tofloat()); + } else if (luaValue.isstring()) { + gen.writeString(luaValue.tojstring()); + } else if (luaValue.istable()) { + serialize(luaValue.checktable(), gen, serializers); + } + } + gen.writeEndArray(); + } else { + gen.writeStartObject(); + for (LuaValue key : keys) { + String keyStr = key.toString(); + LuaValue luaValue = value.get(key); + if (luaValue.isnil()) { + gen.writeNullField(keyStr); + } else if (luaValue.isboolean()) { + gen.writeBooleanField(keyStr, luaValue.toboolean()); + } else if (luaValue.isint()) { + gen.writeNumberField(keyStr, luaValue.toint()); + } else if (luaValue.islong()) { + gen.writeNumberField(keyStr, luaValue.tolong()); + } else if (luaValue.isnumber()) { + gen.writeNumberField(keyStr, luaValue.tofloat()); + } else if (luaValue.isstring()) { + gen.writeStringField(keyStr, luaValue.tojstring()); + } else if (luaValue.istable()) { + gen.writeFieldName(keyStr); + serialize(luaValue.checktable(), gen, serializers); + } + } + gen.writeEndObject(); + } + + gen.flush(); + gen.close(); + } + + @Override + public List toList(Class type, Object obj) { + List list = new ArrayList<>(); + if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { + return list; + } + + CollectionType collectionType = + objectMapper.getTypeFactory().constructCollectionType(ArrayList.class, type); + JsonNode jsonNode = objectMapper.valueToTree(luaTable); + Grasscutter.getLogger() + .trace( + "[LuaTableToList] className={},data={}", type.getCanonicalName(), jsonNode.toString()); + if (jsonNode.isEmpty()) { + return list; + } + if (jsonNode.isArray()) { + try { + Object o = objectMapper.treeToValue(jsonNode, collectionType); + if (o != null) { + list = (ArrayList) o; + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } else if (jsonNode.isObject()) { + Iterator> fields = jsonNode.fields(); + List nodes = new ArrayList<>(); + while (fields.hasNext()) { + Map.Entry next = fields.next(); + nodes.add(next.getValue()); + } + list = objectMapper.convertValue(nodes, collectionType); + } + return list; + } + + @Override + public T toObject(Class type, Object obj) { + if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { + return null; + } + + JsonNode jsonNode = objectMapper.valueToTree(luaTable); + Grasscutter.getLogger() + .trace( + "[LuaTableToObject] className={},data={}", + type.getCanonicalName(), + jsonNode.toString()); + try { + return objectMapper.treeToValue(jsonNode, type); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public Map toMap(Class type, Object obj) { + HashMap map = new HashMap<>(); + if (!(obj instanceof LuaTable luaTable) || luaTable.isnil()) { + return map; + } + + MapType mapStringType = + objectMapper.getTypeFactory().constructMapType(HashMap.class, String.class, type); + JsonNode jsonNode = objectMapper.valueToTree(luaTable); + Grasscutter.getLogger() + .trace( + "[LuaTableToMap] className={},data={}", type.getCanonicalName(), jsonNode.toString()); + try { + Object o = objectMapper.treeToValue(jsonNode, mapStringType); + if (o != null) { + return (HashMap) o; + } + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return map; + } +} diff --git a/src/main/java/emu/grasscutter/scripts/serializer/Serializer.java b/src/main/java/emu/grasscutter/scripts/serializer/Serializer.java index f67b926f2..8251b53f8 100644 --- a/src/main/java/emu/grasscutter/scripts/serializer/Serializer.java +++ b/src/main/java/emu/grasscutter/scripts/serializer/Serializer.java @@ -1,13 +1,13 @@ -package emu.grasscutter.scripts.serializer; - -import java.util.List; -import java.util.Map; - -public interface Serializer { - - List toList(Class type, Object obj); - - T toObject(Class type, Object obj); - - Map toMap(Class type, Object obj); -} +package emu.grasscutter.scripts.serializer; + +import java.util.List; +import java.util.Map; + +public interface Serializer { + + List toList(Class type, Object obj); + + T toObject(Class type, Object obj); + + Map toMap(Class type, Object obj); +} diff --git a/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterSpawnService.java b/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterSpawnService.java index 1708149ac..9ffd2c663 100644 --- a/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterSpawnService.java +++ b/src/main/java/emu/grasscutter/scripts/service/ScriptMonsterSpawnService.java @@ -1,38 +1,38 @@ -package emu.grasscutter.scripts.service; - -import emu.grasscutter.game.entity.EntityMonster; -import emu.grasscutter.scripts.SceneScriptManager; -import emu.grasscutter.scripts.listener.ScriptMonsterListener; -import java.util.ArrayList; -import java.util.List; - -public class ScriptMonsterSpawnService { - - public final List onMonsterCreatedListener = new ArrayList<>(); - public final List onMonsterDeadListener = new ArrayList<>(); - private final SceneScriptManager sceneScriptManager; - - public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager) { - this.sceneScriptManager = sceneScriptManager; - } - - public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) { - onMonsterCreatedListener.add(scriptMonsterListener); - } - - public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) { - onMonsterDeadListener.add(scriptMonsterListener); - } - - public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) { - onMonsterCreatedListener.remove(scriptMonsterListener); - } - - public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) { - onMonsterDeadListener.remove(scriptMonsterListener); - } - - public void onMonsterDead(EntityMonster entityMonster) { - onMonsterDeadListener.forEach(l -> l.onNotify(entityMonster)); - } -} +package emu.grasscutter.scripts.service; + +import emu.grasscutter.game.entity.EntityMonster; +import emu.grasscutter.scripts.SceneScriptManager; +import emu.grasscutter.scripts.listener.ScriptMonsterListener; +import java.util.ArrayList; +import java.util.List; + +public class ScriptMonsterSpawnService { + + public final List onMonsterCreatedListener = new ArrayList<>(); + public final List onMonsterDeadListener = new ArrayList<>(); + private final SceneScriptManager sceneScriptManager; + + public ScriptMonsterSpawnService(SceneScriptManager sceneScriptManager) { + this.sceneScriptManager = sceneScriptManager; + } + + public void addMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) { + onMonsterCreatedListener.add(scriptMonsterListener); + } + + public void addMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) { + onMonsterDeadListener.add(scriptMonsterListener); + } + + public void removeMonsterCreatedListener(ScriptMonsterListener scriptMonsterListener) { + onMonsterCreatedListener.remove(scriptMonsterListener); + } + + public void removeMonsterDeadListener(ScriptMonsterListener scriptMonsterListener) { + onMonsterDeadListener.remove(scriptMonsterListener); + } + + public void onMonsterDead(EntityMonster entityMonster) { + onMonsterDeadListener.forEach(l -> l.onNotify(entityMonster)); + } +} diff --git a/src/main/java/emu/grasscutter/server/event/Cancellable.java b/src/main/java/emu/grasscutter/server/event/Cancellable.java index 462db7e00..8fcc7c7d4 100644 --- a/src/main/java/emu/grasscutter/server/event/Cancellable.java +++ b/src/main/java/emu/grasscutter/server/event/Cancellable.java @@ -1,6 +1,6 @@ -package emu.grasscutter.server.event; - -/** Implementing this interface marks an event as cancellable. */ -public interface Cancellable { - void cancel(); -} +package emu.grasscutter.server.event; + +/** Implementing this interface marks an event as cancellable. */ +public interface Cancellable { + void cancel(); +} diff --git a/src/main/java/emu/grasscutter/server/event/Event.java b/src/main/java/emu/grasscutter/server/event/Event.java index a5f4827e3..4392b133b 100644 --- a/src/main/java/emu/grasscutter/server/event/Event.java +++ b/src/main/java/emu/grasscutter/server/event/Event.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.event; - -import emu.grasscutter.Grasscutter; - -/** A generic server event. */ -public abstract class Event { - private boolean cancelled = false; - - /** Return the cancelled state of the event. */ - public boolean isCanceled() { - return this.cancelled; - } - - /** Cancels the event if possible. */ - public void cancel() { - if (this instanceof Cancellable) this.cancelled = true; - } - - /** Pushes this event to all listeners. */ - public void call() { - Grasscutter.getPluginManager().invokeEvent(this); - } -} +package emu.grasscutter.server.event; + +import emu.grasscutter.Grasscutter; + +/** A generic server event. */ +public abstract class Event { + private boolean cancelled = false; + + /** Return the cancelled state of the event. */ + public boolean isCanceled() { + return this.cancelled; + } + + /** Cancels the event if possible. */ + public void cancel() { + if (this instanceof Cancellable) this.cancelled = true; + } + + /** Pushes this event to all listeners. */ + public void call() { + Grasscutter.getPluginManager().invokeEvent(this); + } +} diff --git a/src/main/java/emu/grasscutter/server/event/EventHandler.java b/src/main/java/emu/grasscutter/server/event/EventHandler.java index 373a5074e..5587e33b9 100644 --- a/src/main/java/emu/grasscutter/server/event/EventHandler.java +++ b/src/main/java/emu/grasscutter/server/event/EventHandler.java @@ -1,90 +1,90 @@ -package emu.grasscutter.server.event; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.plugin.Plugin; -import emu.grasscutter.utils.EventConsumer; - -public final class EventHandler { - private final Class eventClass; - private EventConsumer listener; - private HandlerPriority priority; - private boolean handleCanceled; - - public EventHandler(Class eventClass) { - this.eventClass = eventClass; - } - - /** - * Gets which event this handler is handling. - * - * @return An event class. - */ - public Class handles() { - return this.eventClass; - } - - /** - * Returns the callback for the handler. - * - * @return A consumer callback. - */ - public EventConsumer getCallback() { - return this.listener; - } - - /** - * Returns the handler's priority. - * - * @return The priority of the handler. - */ - public HandlerPriority getPriority() { - return this.priority; - } - - /** - * Returns if the handler will ignore cancelled events. - * - * @return The ignore cancelled state. - */ - public boolean ignoresCanceled() { - return this.handleCanceled; - } - - /** - * Sets the callback method for when the event is invoked. - * - * @param listener An event handler method. - * @return Method chaining. - */ - public EventHandler listener(EventConsumer listener) { - this.listener = listener; - return this; - } - - /** - * Changes the handler's priority in handling events. - * - * @param priority The priority of the handler. - * @return Method chaining. - */ - public EventHandler priority(HandlerPriority priority) { - this.priority = priority; - return this; - } - - /** - * Sets if the handler will ignore cancelled events. - * - * @param ignore If the handler should ignore cancelled events. - * @return Method chaining. - */ - public EventHandler ignore(boolean ignore) { - this.handleCanceled = ignore; - return this; - } - - /** Registers the handler into the PluginManager. */ - public void register(Plugin plugin) { - Grasscutter.getPluginManager().registerListener(plugin, this); - } -} +package emu.grasscutter.server.event; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.plugin.Plugin; +import emu.grasscutter.utils.EventConsumer; + +public final class EventHandler { + private final Class eventClass; + private EventConsumer listener; + private HandlerPriority priority; + private boolean handleCanceled; + + public EventHandler(Class eventClass) { + this.eventClass = eventClass; + } + + /** + * Gets which event this handler is handling. + * + * @return An event class. + */ + public Class handles() { + return this.eventClass; + } + + /** + * Returns the callback for the handler. + * + * @return A consumer callback. + */ + public EventConsumer getCallback() { + return this.listener; + } + + /** + * Returns the handler's priority. + * + * @return The priority of the handler. + */ + public HandlerPriority getPriority() { + return this.priority; + } + + /** + * Returns if the handler will ignore cancelled events. + * + * @return The ignore cancelled state. + */ + public boolean ignoresCanceled() { + return this.handleCanceled; + } + + /** + * Sets the callback method for when the event is invoked. + * + * @param listener An event handler method. + * @return Method chaining. + */ + public EventHandler listener(EventConsumer listener) { + this.listener = listener; + return this; + } + + /** + * Changes the handler's priority in handling events. + * + * @param priority The priority of the handler. + * @return Method chaining. + */ + public EventHandler priority(HandlerPriority priority) { + this.priority = priority; + return this; + } + + /** + * Sets if the handler will ignore cancelled events. + * + * @param ignore If the handler should ignore cancelled events. + * @return Method chaining. + */ + public EventHandler ignore(boolean ignore) { + this.handleCanceled = ignore; + return this; + } + + /** Registers the handler into the PluginManager. */ + public void register(Plugin plugin) { + Grasscutter.getPluginManager().registerListener(plugin, this); + } +} diff --git a/src/main/java/emu/grasscutter/server/event/HandlerPriority.java b/src/main/java/emu/grasscutter/server/event/HandlerPriority.java index 29e252851..bd2dfc476 100644 --- a/src/main/java/emu/grasscutter/server/event/HandlerPriority.java +++ b/src/main/java/emu/grasscutter/server/event/HandlerPriority.java @@ -1,12 +1,12 @@ -package emu.grasscutter.server.event; - -public enum HandlerPriority { - /** The handler will be called before every other handler. */ - HIGH, - - /** The handler will be called the same time as other handlers. */ - NORMAL, - - /** The handler will be called after every other handler. */ - LOW -} +package emu.grasscutter.server.event; + +public enum HandlerPriority { + /** The handler will be called before every other handler. */ + HIGH, + + /** The handler will be called the same time as other handlers. */ + NORMAL, + + /** The handler will be called after every other handler. */ + LOW +} diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java index e231e32ca..937f9f8f7 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryAllRegionsEvent.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.event.dispatch; - -import emu.grasscutter.server.event.types.ServerEvent; - -public final class QueryAllRegionsEvent extends ServerEvent { - private String regionList; - - public QueryAllRegionsEvent(String regionList) { - super(Type.DISPATCH); - - this.regionList = regionList; - } - - public String getRegionList() { - return this.regionList; - } - - public void setRegionList(String regionList) { - this.regionList = regionList; - } -} +package emu.grasscutter.server.event.dispatch; + +import emu.grasscutter.server.event.types.ServerEvent; + +public final class QueryAllRegionsEvent extends ServerEvent { + private String regionList; + + public QueryAllRegionsEvent(String regionList) { + super(Type.DISPATCH); + + this.regionList = regionList; + } + + public String getRegionList() { + return this.regionList; + } + + public void setRegionList(String regionList) { + this.regionList = regionList; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java index 7adb29900..6ae59362d 100644 --- a/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java +++ b/src/main/java/emu/grasscutter/server/event/dispatch/QueryCurrentRegionEvent.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.event.dispatch; - -import emu.grasscutter.server.event.types.ServerEvent; - -public final class QueryCurrentRegionEvent extends ServerEvent { - private String regionInfo; - - public QueryCurrentRegionEvent(String regionInfo) { - super(Type.DISPATCH); - - this.regionInfo = regionInfo; - } - - public String getRegionInfo() { - return this.regionInfo; - } - - public void setRegionInfo(String regionInfo) { - this.regionInfo = regionInfo; - } -} +package emu.grasscutter.server.event.dispatch; + +import emu.grasscutter.server.event.types.ServerEvent; + +public final class QueryCurrentRegionEvent extends ServerEvent { + private String regionInfo; + + public QueryCurrentRegionEvent(String regionInfo) { + super(Type.DISPATCH); + + this.regionInfo = regionInfo; + } + + public String getRegionInfo() { + return this.regionInfo; + } + + public void setRegionInfo(String regionInfo) { + this.regionInfo = regionInfo; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java index d25dda588..6da7414c6 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.event.entity; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.server.event.types.EntityEvent; -import emu.grasscutter.utils.Location; -import javax.annotation.Nullable; -import lombok.Getter; - -public final class EntityDeathEvent extends EntityEvent { - @Getter private final Location deathLocation; - @Getter @Nullable private final GameEntity killer; - - public EntityDeathEvent(GameEntity entity, int killerId) { - super(entity); - - this.deathLocation = new Location(entity.getScene(), entity.getPosition()); - this.killer = entity.getScene().getEntityById(killerId); - } -} +package emu.grasscutter.server.event.entity; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.server.event.types.EntityEvent; +import emu.grasscutter.utils.Location; +import javax.annotation.Nullable; +import lombok.Getter; + +public final class EntityDeathEvent extends EntityEvent { + @Getter private final Location deathLocation; + @Getter @Nullable private final GameEntity killer; + + public EntityDeathEvent(GameEntity entity, int killerId) { + super(entity); + + this.deathLocation = new Location(entity.getScene(), entity.getPosition()); + this.killer = entity.getScene().getEntityById(killerId); + } +} diff --git a/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java b/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java index 2049d1440..9c4eff060 100644 --- a/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java +++ b/src/main/java/emu/grasscutter/server/event/entity/EntityMoveEvent.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.event.entity; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; -import emu.grasscutter.server.event.types.EntityEvent; -import emu.grasscutter.utils.Position; - -public final class EntityMoveEvent extends EntityEvent { - private final Position position, rotation; - private final MotionState motionState; - - public EntityMoveEvent( - GameEntity entity, Position position, Position rotation, MotionState motionState) { - super(entity); - - this.position = position; - this.rotation = rotation; - this.motionState = motionState; - } - - public Position getPosition() { - return this.position; - } - - public Position getRotation() { - return this.rotation; - } - - public MotionState getMotionState() { - return this.motionState; - } -} +package emu.grasscutter.server.event.entity; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; +import emu.grasscutter.server.event.types.EntityEvent; +import emu.grasscutter.utils.Position; + +public final class EntityMoveEvent extends EntityEvent { + private final Position position, rotation; + private final MotionState motionState; + + public EntityMoveEvent( + GameEntity entity, Position position, Position rotation, MotionState motionState) { + super(entity); + + this.position = position; + this.rotation = rotation; + this.motionState = motionState; + } + + public Position getPosition() { + return this.position; + } + + public Position getRotation() { + return this.rotation; + } + + public MotionState getMotionState() { + return this.motionState; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java b/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java index e6a3b8482..24cf09235 100644 --- a/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/PlayerCreationEvent.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.event.game; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.types.GameEvent; -import emu.grasscutter.server.game.GameSession; - -public final class PlayerCreationEvent extends GameEvent { - private final GameSession session; - private Class playerClass; - - public PlayerCreationEvent(GameSession session, Class playerClass) { - this.session = session; - this.playerClass = playerClass; - } - - public GameSession getSession() { - return this.session; - } - - public Class getPlayerClass() { - return this.playerClass; - } - - public void setPlayerClass(Class playerClass) { - this.playerClass = playerClass; - } -} +package emu.grasscutter.server.event.game; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.GameEvent; +import emu.grasscutter.server.game.GameSession; + +public final class PlayerCreationEvent extends GameEvent { + private final GameSession session; + private Class playerClass; + + public PlayerCreationEvent(GameSession session, Class playerClass) { + this.session = session; + this.playerClass = playerClass; + } + + public GameSession getSession() { + return this.session; + } + + public Class getPlayerClass() { + return this.playerClass; + } + + public void setPlayerClass(Class playerClass) { + this.playerClass = playerClass; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java index 61c3bb395..b0c14e2f0 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ReceiveCommandFeedbackEvent.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.event.game; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.types.ServerEvent; -import javax.annotation.Nullable; - -public final class ReceiveCommandFeedbackEvent extends ServerEvent implements Cancellable { - @Nullable private final Player player; - private String message; - - public ReceiveCommandFeedbackEvent(@Nullable Player player, String message) { - super(Type.GAME); - - this.player = player; - this.message = message; - } - - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Nullable public Player getPlayer() { - return this.player; - } -} +package emu.grasscutter.server.event.game; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.ServerEvent; +import javax.annotation.Nullable; + +public final class ReceiveCommandFeedbackEvent extends ServerEvent implements Cancellable { + @Nullable private final Player player; + private String message; + + public ReceiveCommandFeedbackEvent(@Nullable Player player, String message) { + super(Type.GAME); + + this.player = player; + this.message = message; + } + + public String getMessage() { + return this.message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Nullable public Player getPlayer() { + return this.player; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java index db8003ce1..4f21297cf 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ReceivePacketEvent.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.event.game; - -import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.types.ServerEvent; -import emu.grasscutter.server.game.GameSession; - -public final class ReceivePacketEvent extends ServerEvent implements Cancellable { - private final GameSession gameSession; - private final int packetId; - private byte[] packetData; - - public ReceivePacketEvent(GameSession gameSession, int packetId, byte[] packetData) { - super(Type.GAME); - - this.gameSession = gameSession; - this.packetId = packetId; - this.packetData = packetData; - } - - public GameSession getGameSession() { - return this.gameSession; - } - - public int getPacketId() { - return this.packetId; - } - - public byte[] getPacketData() { - return this.packetData; - } - - public void setPacketData(byte[] packetData) { - this.packetData = packetData; - } -} +package emu.grasscutter.server.event.game; + +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.ServerEvent; +import emu.grasscutter.server.game.GameSession; + +public final class ReceivePacketEvent extends ServerEvent implements Cancellable { + private final GameSession gameSession; + private final int packetId; + private byte[] packetData; + + public ReceivePacketEvent(GameSession gameSession, int packetId, byte[] packetData) { + super(Type.GAME); + + this.gameSession = gameSession; + this.packetId = packetId; + this.packetData = packetData; + } + + public GameSession getGameSession() { + return this.gameSession; + } + + public int getPacketId() { + return this.packetId; + } + + public byte[] getPacketData() { + return this.packetData; + } + + public void setPacketData(byte[] packetData) { + this.packetData = packetData; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java b/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java index 111daef57..7a6125ba7 100644 --- a/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/SendPacketEvent.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.event.game; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.types.ServerEvent; -import emu.grasscutter.server.game.GameSession; - -public final class SendPacketEvent extends ServerEvent implements Cancellable { - private final GameSession gameSession; - private BasePacket packet; - - public SendPacketEvent(GameSession gameSession, BasePacket packet) { - super(Type.GAME); - - this.gameSession = gameSession; - this.packet = packet; - } - - public GameSession getGameSession() { - return this.gameSession; - } - - public BasePacket getPacket() { - return this.packet; - } - - public void setPacket(BasePacket packet) { - this.packet = packet; - } -} +package emu.grasscutter.server.event.game; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.ServerEvent; +import emu.grasscutter.server.game.GameSession; + +public final class SendPacketEvent extends ServerEvent implements Cancellable { + private final GameSession gameSession; + private BasePacket packet; + + public SendPacketEvent(GameSession gameSession, BasePacket packet) { + super(Type.GAME); + + this.gameSession = gameSession; + this.packet = packet; + } + + public GameSession getGameSession() { + return this.gameSession; + } + + public BasePacket getPacket() { + return this.packet; + } + + public void setPacket(BasePacket packet) { + this.packet = packet; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/game/ServerTickEvent.java b/src/main/java/emu/grasscutter/server/event/game/ServerTickEvent.java index 8ca3b1298..2c60d9fb6 100644 --- a/src/main/java/emu/grasscutter/server/event/game/ServerTickEvent.java +++ b/src/main/java/emu/grasscutter/server/event/game/ServerTickEvent.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.event.game; - -import emu.grasscutter.server.event.types.ServerEvent; -import java.time.Instant; - -public final class ServerTickEvent extends ServerEvent { - private final Instant start, end; - - public ServerTickEvent(Instant start, Instant end) { - super(Type.GAME); - - this.start = start; - this.end = end; - } - - public Instant getTickStart() { - return this.start; - } - - public Instant getTickEnd() { - return this.end; - } -} +package emu.grasscutter.server.event.game; + +import emu.grasscutter.server.event.types.ServerEvent; +import java.time.Instant; + +public final class ServerTickEvent extends ServerEvent { + private final Instant start, end; + + public ServerTickEvent(Instant start, Instant end) { + super(Type.GAME); + + this.start = start; + this.end = end; + } + + public Instant getTickStart() { + return this.start; + } + + public Instant getTickEnd() { + return this.end; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java b/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java index 943c0cf24..a5e60d7e4 100644 --- a/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java +++ b/src/main/java/emu/grasscutter/server/event/internal/ServerStartEvent.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.event.internal; - -import emu.grasscutter.server.event.types.ServerEvent; -import java.time.OffsetDateTime; - -public final class ServerStartEvent extends ServerEvent { - private final OffsetDateTime startTime; - - public ServerStartEvent(Type type, OffsetDateTime startTime) { - super(type); - - this.startTime = startTime; - } - - public OffsetDateTime getStartTime() { - return this.startTime; - } -} +package emu.grasscutter.server.event.internal; + +import emu.grasscutter.server.event.types.ServerEvent; +import java.time.OffsetDateTime; + +public final class ServerStartEvent extends ServerEvent { + private final OffsetDateTime startTime; + + public ServerStartEvent(Type type, OffsetDateTime startTime) { + super(type); + + this.startTime = startTime; + } + + public OffsetDateTime getStartTime() { + return this.startTime; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java b/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java index 2fdb1bfb9..2fc6bc6a4 100644 --- a/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java +++ b/src/main/java/emu/grasscutter/server/event/internal/ServerStopEvent.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.event.internal; - -import emu.grasscutter.server.event.types.ServerEvent; -import java.time.OffsetDateTime; - -public final class ServerStopEvent extends ServerEvent { - private final OffsetDateTime stopTime; - - public ServerStopEvent(Type type, OffsetDateTime stopTime) { - super(type); - - this.stopTime = stopTime; - } - - public OffsetDateTime getStopTime() { - return this.stopTime; - } -} +package emu.grasscutter.server.event.internal; + +import emu.grasscutter.server.event.types.ServerEvent; +import java.time.OffsetDateTime; + +public final class ServerStopEvent extends ServerEvent { + private final OffsetDateTime stopTime; + + public ServerStopEvent(Type type, OffsetDateTime stopTime) { + super(type); + + this.stopTime = stopTime; + } + + public OffsetDateTime getStopTime() { + return this.stopTime; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerMoveEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerMoveEvent.java index 595162624..a0dfdb5d7 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerMoveEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerMoveEvent.java @@ -1,40 +1,40 @@ -package emu.grasscutter.server.event.player; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.types.PlayerEvent; -import emu.grasscutter.utils.Position; - -/** TODO: Allow plugins to change the position of the player. */ -public final class PlayerMoveEvent extends PlayerEvent { - private final MoveType type; - private final Position from; - private final Position to; - - public PlayerMoveEvent(Player player, MoveType type, Position from, Position to) { - super(player); - - this.type = type; - this.from = from; - this.to = to; - } - - public MoveType getMoveType() { - return this.type; - } - - public Position getSource() { - return this.from; - } - - public Position getDestination() { - return this.to; - } - - public enum MoveType { - /** The player has sent a combat invocation to move. */ - PLAYER, - - /** The server has requested that the player moves. */ - SERVER - } -} +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; +import emu.grasscutter.utils.Position; + +/** TODO: Allow plugins to change the position of the player. */ +public final class PlayerMoveEvent extends PlayerEvent { + private final MoveType type; + private final Position from; + private final Position to; + + public PlayerMoveEvent(Player player, MoveType type, Position from, Position to) { + super(player); + + this.type = type; + this.from = from; + this.to = to; + } + + public MoveType getMoveType() { + return this.type; + } + + public Position getSource() { + return this.from; + } + + public Position getDestination() { + return this.to; + } + + public enum MoveType { + /** The player has sent a combat invocation to move. */ + PLAYER, + + /** The server has requested that the player moves. */ + SERVER + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerQuitEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerQuitEvent.java index b3cbf4bd4..b2d4b382a 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerQuitEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerQuitEvent.java @@ -1,10 +1,10 @@ -package emu.grasscutter.server.event.player; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.types.PlayerEvent; - -public final class PlayerQuitEvent extends PlayerEvent { - public PlayerQuitEvent(Player player) { - super(player); - } -} +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; + +public final class PlayerQuitEvent extends PlayerEvent { + public PlayerQuitEvent(Player player) { + super(player); + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java index deaea0707..c008a9783 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerReceiveMailEvent.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.event.player; - -import emu.grasscutter.game.mail.Mail; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.types.PlayerEvent; - -public final class PlayerReceiveMailEvent extends PlayerEvent implements Cancellable { - private Mail message; - - public PlayerReceiveMailEvent(Player player, Mail message) { - super(player); - - this.message = message; - } - - public Mail getMessage() { - return this.message; - } - - public void setMessage(Mail message) { - this.message = message; - } -} +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.PlayerEvent; + +public final class PlayerReceiveMailEvent extends PlayerEvent implements Cancellable { + private Mail message; + + public PlayerReceiveMailEvent(Player player, Mail message) { + super(player); + + this.message = message; + } + + public Mail getMessage() { + return this.message; + } + + public void setMessage(Mail message) { + this.message = message; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java index c7258ad28..524d27078 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerTeamDeathEvent.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.event.player; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.types.PlayerEvent; -import lombok.Getter; - -/** - * This event is invoked when the ENTIRE TEAM dies. To listen for one player death, use {@link - * emu.grasscutter.server.event.entity.EntityDeathEvent}. - */ -public final class PlayerTeamDeathEvent extends PlayerEvent { - @Getter private final EntityAvatar selectedAvatar; - - public PlayerTeamDeathEvent(Player player, EntityAvatar selectedAvatar) { - super(player); - - this.selectedAvatar = selectedAvatar; - } -} +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; + +/** + * This event is invoked when the ENTIRE TEAM dies. To listen for one player death, use {@link + * emu.grasscutter.server.event.entity.EntityDeathEvent}. + */ +public final class PlayerTeamDeathEvent extends PlayerEvent { + @Getter private final EntityAvatar selectedAvatar; + + public PlayerTeamDeathEvent(Player player, EntityAvatar selectedAvatar) { + super(player); + + this.selectedAvatar = selectedAvatar; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java index c70c63b58..dfe3022d6 100644 --- a/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerUseFoodEvent.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.event.player; - -import emu.grasscutter.data.excels.ItemData; -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.Cancellable; -import emu.grasscutter.server.event.types.PlayerEvent; -import lombok.Getter; -import lombok.Setter; - -/** This event is invoked when the player uses food on an avatar. */ -public final class PlayerUseFoodEvent extends PlayerEvent implements Cancellable { - @Getter private final EntityAvatar selectedAvatar; - @Getter @Setter private ItemData foodUsed; - - public PlayerUseFoodEvent(Player player, ItemData foodUsed, EntityAvatar selectedAvatar) { - super(player); - - this.foodUsed = foodUsed; - this.selectedAvatar = selectedAvatar; - } -} +package emu.grasscutter.server.event.player; + +import emu.grasscutter.data.excels.ItemData; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; +import lombok.Setter; + +/** This event is invoked when the player uses food on an avatar. */ +public final class PlayerUseFoodEvent extends PlayerEvent implements Cancellable { + @Getter private final EntityAvatar selectedAvatar; + @Getter @Setter private ItemData foodUsed; + + public PlayerUseFoodEvent(Player player, ItemData foodUsed, EntityAvatar selectedAvatar) { + super(player); + + this.foodUsed = foodUsed; + this.selectedAvatar = selectedAvatar; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java b/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java index a42fd8a94..3530ebd57 100644 --- a/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/EntityEvent.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.event.types; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.server.event.Event; - -/** An event that is related to entity interactions. */ -public abstract class EntityEvent extends Event { - protected final GameEntity entity; - - public EntityEvent(GameEntity player) { - this.entity = player; - } - - public GameEntity getEntity() { - return this.entity; - } -} +package emu.grasscutter.server.event.types; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.server.event.Event; + +/** An event that is related to entity interactions. */ +public abstract class EntityEvent extends Event { + protected final GameEntity entity; + + public EntityEvent(GameEntity player) { + this.entity = player; + } + + public GameEntity getEntity() { + return this.entity; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/types/GameEvent.java b/src/main/java/emu/grasscutter/server/event/types/GameEvent.java index 3e2501f11..ad7839f21 100644 --- a/src/main/java/emu/grasscutter/server/event/types/GameEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/GameEvent.java @@ -1,6 +1,6 @@ -package emu.grasscutter.server.event.types; - -import emu.grasscutter.server.event.Event; - -/** An event that is related to the game. */ -public abstract class GameEvent extends Event {} +package emu.grasscutter.server.event.types; + +import emu.grasscutter.server.event.Event; + +/** An event that is related to the game. */ +public abstract class GameEvent extends Event {} diff --git a/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java index 6e5f99a12..2d1a77492 100644 --- a/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/PlayerEvent.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.event.types; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.event.Event; - -/** An event that is related to player interactions. */ -public abstract class PlayerEvent extends Event { - protected final Player player; - - public PlayerEvent(Player player) { - this.player = player; - } - - public Player getPlayer() { - return this.player; - } -} +package emu.grasscutter.server.event.types; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.Event; + +/** An event that is related to player interactions. */ +public abstract class PlayerEvent extends Event { + protected final Player player; + + public PlayerEvent(Player player) { + this.player = player; + } + + public Player getPlayer() { + return this.player; + } +} diff --git a/src/main/java/emu/grasscutter/server/event/types/ServerEvent.java b/src/main/java/emu/grasscutter/server/event/types/ServerEvent.java index aeba37ab1..31d392fc9 100644 --- a/src/main/java/emu/grasscutter/server/event/types/ServerEvent.java +++ b/src/main/java/emu/grasscutter/server/event/types/ServerEvent.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.event.types; - -import emu.grasscutter.server.event.Event; - -/** An event that is related to the internals of the server. */ -public abstract class ServerEvent extends Event { - protected final Type type; - - public ServerEvent(Type type) { - this.type = type; - } - - public Type getServerType() { - return this.type; - } - - public enum Type { - DISPATCH, - GAME - } -} +package emu.grasscutter.server.event.types; + +import emu.grasscutter.server.event.Event; + +/** An event that is related to the internals of the server. */ +public abstract class ServerEvent extends Event { + protected final Type type; + + public ServerEvent(Type type) { + this.type = type; + } + + public Type getServerType() { + return this.type; + } + + public enum Type { + DISPATCH, + GAME + } +} diff --git a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java index ffab7b525..d40b3d33d 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java +++ b/src/main/java/emu/grasscutter/server/game/GameServerPacketHandler.java @@ -1,110 +1,110 @@ -package emu.grasscutter.server.game; - -import static emu.grasscutter.config.Configuration.GAME_INFO; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.Grasscutter.ServerDebugMode; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.event.game.ReceivePacketEvent; -import emu.grasscutter.server.game.GameSession.SessionState; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import java.util.Set; -import org.reflections.Reflections; - -@SuppressWarnings("unchecked") -public class GameServerPacketHandler { - private final Int2ObjectMap handlers; - - public GameServerPacketHandler(Class handlerClass) { - this.handlers = new Int2ObjectOpenHashMap<>(); - - this.registerHandlers(handlerClass); - } - - public void registerPacketHandler(Class handlerClass) { - try { - Opcodes opcode = handlerClass.getAnnotation(Opcodes.class); - - if (opcode == null || opcode.disabled() || opcode.value() <= 0) { - return; - } - - PacketHandler packetHandler = handlerClass.getDeclaredConstructor().newInstance(); - - this.handlers.put(opcode.value(), packetHandler); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void registerHandlers(Class handlerClass) { - Reflections reflections = new Reflections("emu.grasscutter.server.packet"); - Set handlerClasses = reflections.getSubTypesOf(handlerClass); - - for (Object obj : handlerClasses) { - this.registerPacketHandler((Class) obj); - } - - // Debug - Grasscutter.getLogger() - .debug("Registered " + this.handlers.size() + " " + handlerClass.getSimpleName() + "s"); - } - - public void handle(GameSession session, int opcode, byte[] header, byte[] payload) { - PacketHandler handler = this.handlers.get(opcode); - - if (handler != null) { - try { - // Make sure session is ready for packets - SessionState state = session.getState(); - - if (opcode == PacketOpcodes.PingReq) { - // Always continue if packet is ping request - } else if (opcode == PacketOpcodes.GetPlayerTokenReq) { - if (state != SessionState.WAITING_FOR_TOKEN) { - return; - } - } else if (state == SessionState.ACCOUNT_BANNED) { - session.close(); - return; - } else if (opcode == PacketOpcodes.PlayerLoginReq) { - if (state != SessionState.WAITING_FOR_LOGIN) { - return; - } - } else if (opcode == PacketOpcodes.SetPlayerBornDataReq) { - if (state != SessionState.PICKING_CHARACTER) { - return; - } - } else { - if (state != SessionState.ACTIVE) { - return; - } - } - - // Invoke event. - ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); - event.call(); - if (!event.isCanceled()) // If event is not canceled, continue. - handler.handle(session, header, event.getPacketData()); - } catch (Exception ex) { - // TODO Remove this when no more needed - ex.printStackTrace(); - } - return; // Packet successfully handled - } - - // Log unhandled packets - if (GAME_INFO.logPackets == ServerDebugMode.MISSING - || GAME_INFO.logPackets == ServerDebugMode.ALL) { - Grasscutter.getLogger() - .info( - "Unhandled packet (" - + opcode - + "): " - + emu.grasscutter.net.packet.PacketOpcodesUtils.getOpcodeName(opcode)); - } - } -} +package emu.grasscutter.server.game; + +import static emu.grasscutter.config.Configuration.GAME_INFO; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.Grasscutter.ServerDebugMode; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.event.game.ReceivePacketEvent; +import emu.grasscutter.server.game.GameSession.SessionState; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import java.util.Set; +import org.reflections.Reflections; + +@SuppressWarnings("unchecked") +public class GameServerPacketHandler { + private final Int2ObjectMap handlers; + + public GameServerPacketHandler(Class handlerClass) { + this.handlers = new Int2ObjectOpenHashMap<>(); + + this.registerHandlers(handlerClass); + } + + public void registerPacketHandler(Class handlerClass) { + try { + Opcodes opcode = handlerClass.getAnnotation(Opcodes.class); + + if (opcode == null || opcode.disabled() || opcode.value() <= 0) { + return; + } + + PacketHandler packetHandler = handlerClass.getDeclaredConstructor().newInstance(); + + this.handlers.put(opcode.value(), packetHandler); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void registerHandlers(Class handlerClass) { + Reflections reflections = new Reflections("emu.grasscutter.server.packet"); + Set handlerClasses = reflections.getSubTypesOf(handlerClass); + + for (Object obj : handlerClasses) { + this.registerPacketHandler((Class) obj); + } + + // Debug + Grasscutter.getLogger() + .debug("Registered " + this.handlers.size() + " " + handlerClass.getSimpleName() + "s"); + } + + public void handle(GameSession session, int opcode, byte[] header, byte[] payload) { + PacketHandler handler = this.handlers.get(opcode); + + if (handler != null) { + try { + // Make sure session is ready for packets + SessionState state = session.getState(); + + if (opcode == PacketOpcodes.PingReq) { + // Always continue if packet is ping request + } else if (opcode == PacketOpcodes.GetPlayerTokenReq) { + if (state != SessionState.WAITING_FOR_TOKEN) { + return; + } + } else if (state == SessionState.ACCOUNT_BANNED) { + session.close(); + return; + } else if (opcode == PacketOpcodes.PlayerLoginReq) { + if (state != SessionState.WAITING_FOR_LOGIN) { + return; + } + } else if (opcode == PacketOpcodes.SetPlayerBornDataReq) { + if (state != SessionState.PICKING_CHARACTER) { + return; + } + } else { + if (state != SessionState.ACTIVE) { + return; + } + } + + // Invoke event. + ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload); + event.call(); + if (!event.isCanceled()) // If event is not canceled, continue. + handler.handle(session, header, event.getPacketData()); + } catch (Exception ex) { + // TODO Remove this when no more needed + ex.printStackTrace(); + } + return; // Packet successfully handled + } + + // Log unhandled packets + if (GAME_INFO.logPackets == ServerDebugMode.MISSING + || GAME_INFO.logPackets == ServerDebugMode.ALL) { + Grasscutter.getLogger() + .info( + "Unhandled packet (" + + opcode + + "): " + + emu.grasscutter.net.packet.PacketOpcodesUtils.getOpcodeName(opcode)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index 98a2f4256..307991e48 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -1,270 +1,270 @@ -package emu.grasscutter.server.game; - -import static emu.grasscutter.config.Configuration.GAME_INFO; -import static emu.grasscutter.config.Configuration.SERVER; -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.Grasscutter.ServerDebugMode; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.packet.PacketOpcodesUtils; -import emu.grasscutter.server.event.game.SendPacketEvent; -import emu.grasscutter.utils.Crypto; -import emu.grasscutter.utils.FileUtils; -import emu.grasscutter.utils.Utils; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import java.io.File; -import java.net.InetSocketAddress; -import java.nio.file.Path; -import lombok.Getter; -import lombok.Setter; - -public class GameSession implements GameSessionManager.KcpChannel { - private final GameServer server; - private GameSessionManager.KcpTunnel tunnel; - - @Getter @Setter private Account account; - @Getter private Player player; - - @Setter private boolean useSecretKey; - @Getter @Setter private SessionState state; - - @Getter private int clientTime; - @Getter private long lastPingTime; - private int lastClientSeq = 10; - - public GameSession(GameServer server) { - this.server = server; - this.state = SessionState.WAITING_FOR_TOKEN; - this.lastPingTime = System.currentTimeMillis(); - } - - public GameServer getServer() { - return server; - } - - public InetSocketAddress getAddress() { - try { - return tunnel.getAddress(); - } catch (Throwable ignore) { - return null; - } - } - - public boolean useSecretKey() { - return useSecretKey; - } - - public String getAccountId() { - return this.getAccount().getId(); - } - - public synchronized void setPlayer(Player player) { - this.player = player; - this.player.setSession(this); - this.player.setAccount(this.getAccount()); - } - - public boolean isLoggedIn() { - return this.getPlayer() != null; - } - - public void updateLastPingTime(int clientTime) { - this.clientTime = clientTime; - this.lastPingTime = System.currentTimeMillis(); - } - - public int getNextClientSequence() { - return ++lastClientSeq; - } - - public void replayPacket(int opcode, String name) { - Path filePath = FileUtils.getPluginPath(name); - File p = filePath.toFile(); - - if (!p.exists()) return; - - byte[] packet = FileUtils.read(p); - - BasePacket basePacket = new BasePacket(opcode); - basePacket.setData(packet); - - send(basePacket); - } - - public void logPacket(String sendOrRecv, int opcode, byte[] payload) { - Grasscutter.getLogger() - .info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")"); - if (GAME_INFO.isShowPacketPayload) System.out.println(Utils.bytesToHex(payload)); - } - - public void send(BasePacket packet) { - // Test - if (packet.getOpcode() <= 0) { - Grasscutter.getLogger().warn("Tried to send packet with missing cmd id!"); - return; - } - - // DO NOT REMOVE (unless we find a way to validate code before sending to client which I don't - // think we can) - // Stop WindSeedClientNotify from being sent for security purposes. - if (PacketOpcodesUtils.BANNED_PACKETS.contains(packet.getOpcode())) { - return; - } - - // Header - if (packet.shouldBuildHeader()) { - packet.buildHeader(this.getNextClientSequence()); - } - - // Log - switch (GAME_INFO.logPackets) { - case ALL -> { - if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode()) - || GAME_INFO.isShowLoopPackets) { - logPacket("SEND", packet.getOpcode(), packet.getData()); - } - } - case WHITELIST -> { - if (SERVER.debugWhitelist.contains(packet.getOpcode())) { - logPacket("SEND", packet.getOpcode(), packet.getData()); - } - } - case BLACKLIST -> { - if (!SERVER.debugBlacklist.contains(packet.getOpcode())) { - logPacket("SEND", packet.getOpcode(), packet.getData()); - } - } - default -> {} - } - - // Invoke event. - SendPacketEvent event = new SendPacketEvent(this, packet); - event.call(); - if (!event.isCanceled()) { // If event is not cancelled, continue. - tunnel.writeData(event.getPacket().build()); - } - } - - @Override - public void onConnected(GameSessionManager.KcpTunnel tunnel) { - this.tunnel = tunnel; - Grasscutter.getLogger().info(translate("messages.game.connect", this.getAddress().toString())); - } - - @Override - public void handleReceive(byte[] bytes) { - // Decrypt and turn back into a packet - Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY); - ByteBuf packet = Unpooled.wrappedBuffer(bytes); - - // Log - // logPacket(packet); - // Handle - try { - boolean allDebug = GAME_INFO.logPackets == ServerDebugMode.ALL; - while (packet.readableBytes() > 0) { - // Length - if (packet.readableBytes() < 12) { - return; - } - // Packet sanity check - int const1 = packet.readShort(); - if (const1 != 17767) { - if (allDebug) { - Grasscutter.getLogger() - .error("Bad Data Package Received: got {} ,expect 17767", const1); - } - return; // Bad packet - } - // Data - int opcode = packet.readShort(); - int headerLength = packet.readShort(); - int payloadLength = packet.readInt(); - byte[] header = new byte[headerLength]; - byte[] payload = new byte[payloadLength]; - - packet.readBytes(header); - packet.readBytes(payload); - // Sanity check #2 - int const2 = packet.readShort(); - if (const2 != -30293) { - if (allDebug) { - Grasscutter.getLogger() - .error("Bad Data Package Received: got {} ,expect -30293", const2); - } - return; // Bad packet - } - - // Log packet - switch (GAME_INFO.logPackets) { - case ALL -> { - if (!PacketOpcodesUtils.LOOP_PACKETS.contains(opcode) || GAME_INFO.isShowLoopPackets) { - logPacket("RECV", opcode, payload); - } - } - case WHITELIST -> { - if (SERVER.debugWhitelist.contains(opcode)) { - logPacket("RECV", opcode, payload); - } - } - case BLACKLIST -> { - if (!(SERVER.debugBlacklist.contains(opcode))) { - logPacket("RECV", opcode, payload); - } - } - default -> {} - } - - // Handle - getServer().getPacketHandler().handle(this, opcode, header, payload); - } - } catch (Exception e) { - e.printStackTrace(); - } finally { - // byteBuf.release(); //Needn't - packet.release(); - } - } - - @Override - public void handleClose() { - setState(SessionState.INACTIVE); - // send disconnection pack in case of reconnection - Grasscutter.getLogger() - .info(translate("messages.game.disconnect", this.getAddress().toString())); - // Save after disconnecting - if (this.isLoggedIn()) { - Player player = getPlayer(); - // Call logout event. - player.onLogout(); - } - try { - send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify)); - } catch (Throwable ignore) { - Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress()); - } - tunnel = null; - } - - public void close() { - tunnel.close(); - } - - public boolean isActive() { - return getState() == SessionState.ACTIVE; - } - - public enum SessionState { - INACTIVE, - WAITING_FOR_TOKEN, - WAITING_FOR_LOGIN, - PICKING_CHARACTER, - ACTIVE, - ACCOUNT_BANNED - } -} +package emu.grasscutter.server.game; + +import static emu.grasscutter.config.Configuration.GAME_INFO; +import static emu.grasscutter.config.Configuration.SERVER; +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.Grasscutter.ServerDebugMode; +import emu.grasscutter.game.Account; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.packet.PacketOpcodesUtils; +import emu.grasscutter.server.event.game.SendPacketEvent; +import emu.grasscutter.utils.Crypto; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.Utils; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.io.File; +import java.net.InetSocketAddress; +import java.nio.file.Path; +import lombok.Getter; +import lombok.Setter; + +public class GameSession implements GameSessionManager.KcpChannel { + private final GameServer server; + private GameSessionManager.KcpTunnel tunnel; + + @Getter @Setter private Account account; + @Getter private Player player; + + @Setter private boolean useSecretKey; + @Getter @Setter private SessionState state; + + @Getter private int clientTime; + @Getter private long lastPingTime; + private int lastClientSeq = 10; + + public GameSession(GameServer server) { + this.server = server; + this.state = SessionState.WAITING_FOR_TOKEN; + this.lastPingTime = System.currentTimeMillis(); + } + + public GameServer getServer() { + return server; + } + + public InetSocketAddress getAddress() { + try { + return tunnel.getAddress(); + } catch (Throwable ignore) { + return null; + } + } + + public boolean useSecretKey() { + return useSecretKey; + } + + public String getAccountId() { + return this.getAccount().getId(); + } + + public synchronized void setPlayer(Player player) { + this.player = player; + this.player.setSession(this); + this.player.setAccount(this.getAccount()); + } + + public boolean isLoggedIn() { + return this.getPlayer() != null; + } + + public void updateLastPingTime(int clientTime) { + this.clientTime = clientTime; + this.lastPingTime = System.currentTimeMillis(); + } + + public int getNextClientSequence() { + return ++lastClientSeq; + } + + public void replayPacket(int opcode, String name) { + Path filePath = FileUtils.getPluginPath(name); + File p = filePath.toFile(); + + if (!p.exists()) return; + + byte[] packet = FileUtils.read(p); + + BasePacket basePacket = new BasePacket(opcode); + basePacket.setData(packet); + + send(basePacket); + } + + public void logPacket(String sendOrRecv, int opcode, byte[] payload) { + Grasscutter.getLogger() + .info(sendOrRecv + ": " + PacketOpcodesUtils.getOpcodeName(opcode) + " (" + opcode + ")"); + if (GAME_INFO.isShowPacketPayload) System.out.println(Utils.bytesToHex(payload)); + } + + public void send(BasePacket packet) { + // Test + if (packet.getOpcode() <= 0) { + Grasscutter.getLogger().warn("Tried to send packet with missing cmd id!"); + return; + } + + // DO NOT REMOVE (unless we find a way to validate code before sending to client which I don't + // think we can) + // Stop WindSeedClientNotify from being sent for security purposes. + if (PacketOpcodesUtils.BANNED_PACKETS.contains(packet.getOpcode())) { + return; + } + + // Header + if (packet.shouldBuildHeader()) { + packet.buildHeader(this.getNextClientSequence()); + } + + // Log + switch (GAME_INFO.logPackets) { + case ALL -> { + if (!PacketOpcodesUtils.LOOP_PACKETS.contains(packet.getOpcode()) + || GAME_INFO.isShowLoopPackets) { + logPacket("SEND", packet.getOpcode(), packet.getData()); + } + } + case WHITELIST -> { + if (SERVER.debugWhitelist.contains(packet.getOpcode())) { + logPacket("SEND", packet.getOpcode(), packet.getData()); + } + } + case BLACKLIST -> { + if (!SERVER.debugBlacklist.contains(packet.getOpcode())) { + logPacket("SEND", packet.getOpcode(), packet.getData()); + } + } + default -> {} + } + + // Invoke event. + SendPacketEvent event = new SendPacketEvent(this, packet); + event.call(); + if (!event.isCanceled()) { // If event is not cancelled, continue. + tunnel.writeData(event.getPacket().build()); + } + } + + @Override + public void onConnected(GameSessionManager.KcpTunnel tunnel) { + this.tunnel = tunnel; + Grasscutter.getLogger().info(translate("messages.game.connect", this.getAddress().toString())); + } + + @Override + public void handleReceive(byte[] bytes) { + // Decrypt and turn back into a packet + Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY); + ByteBuf packet = Unpooled.wrappedBuffer(bytes); + + // Log + // logPacket(packet); + // Handle + try { + boolean allDebug = GAME_INFO.logPackets == ServerDebugMode.ALL; + while (packet.readableBytes() > 0) { + // Length + if (packet.readableBytes() < 12) { + return; + } + // Packet sanity check + int const1 = packet.readShort(); + if (const1 != 17767) { + if (allDebug) { + Grasscutter.getLogger() + .error("Bad Data Package Received: got {} ,expect 17767", const1); + } + return; // Bad packet + } + // Data + int opcode = packet.readShort(); + int headerLength = packet.readShort(); + int payloadLength = packet.readInt(); + byte[] header = new byte[headerLength]; + byte[] payload = new byte[payloadLength]; + + packet.readBytes(header); + packet.readBytes(payload); + // Sanity check #2 + int const2 = packet.readShort(); + if (const2 != -30293) { + if (allDebug) { + Grasscutter.getLogger() + .error("Bad Data Package Received: got {} ,expect -30293", const2); + } + return; // Bad packet + } + + // Log packet + switch (GAME_INFO.logPackets) { + case ALL -> { + if (!PacketOpcodesUtils.LOOP_PACKETS.contains(opcode) || GAME_INFO.isShowLoopPackets) { + logPacket("RECV", opcode, payload); + } + } + case WHITELIST -> { + if (SERVER.debugWhitelist.contains(opcode)) { + logPacket("RECV", opcode, payload); + } + } + case BLACKLIST -> { + if (!(SERVER.debugBlacklist.contains(opcode))) { + logPacket("RECV", opcode, payload); + } + } + default -> {} + } + + // Handle + getServer().getPacketHandler().handle(this, opcode, header, payload); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + // byteBuf.release(); //Needn't + packet.release(); + } + } + + @Override + public void handleClose() { + setState(SessionState.INACTIVE); + // send disconnection pack in case of reconnection + Grasscutter.getLogger() + .info(translate("messages.game.disconnect", this.getAddress().toString())); + // Save after disconnecting + if (this.isLoggedIn()) { + Player player = getPlayer(); + // Call logout event. + player.onLogout(); + } + try { + send(new BasePacket(PacketOpcodes.ServerDisconnectClientNotify)); + } catch (Throwable ignore) { + Grasscutter.getLogger().warn("closing {} error", getAddress().getAddress().getHostAddress()); + } + tunnel = null; + } + + public void close() { + tunnel.close(); + } + + public boolean isActive() { + return getState() == SessionState.ACTIVE; + } + + public enum SessionState { + INACTIVE, + WAITING_FOR_TOKEN, + WAITING_FOR_LOGIN, + PICKING_CHARACTER, + ACTIVE, + ACCOUNT_BANNED + } +} diff --git a/src/main/java/emu/grasscutter/server/game/GameSessionManager.java b/src/main/java/emu/grasscutter/server/game/GameSessionManager.java index 185ad2c0a..26146b81f 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSessionManager.java +++ b/src/main/java/emu/grasscutter/server/game/GameSessionManager.java @@ -1,115 +1,115 @@ -package emu.grasscutter.server.game; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.utils.Utils; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.DefaultEventLoop; -import java.net.InetSocketAddress; -import java.util.concurrent.ConcurrentHashMap; -import kcp.highway.KcpListener; -import kcp.highway.Ukcp; - -public class GameSessionManager { - private static final DefaultEventLoop logicThread = new DefaultEventLoop(); - private static final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); - private static final KcpListener listener = - new KcpListener() { - @Override - public void onConnected(Ukcp ukcp) { - int times = 0; - GameServer server = Grasscutter.getGameServer(); - while (server == null) { // Waiting server to establish - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - ukcp.close(); - return; - } - if (times++ > 5) { - Grasscutter.getLogger().error("Service is not available!"); - ukcp.close(); - return; - } - server = Grasscutter.getGameServer(); - } - GameSession conversation = new GameSession(server); - conversation.onConnected( - new KcpTunnel() { - @Override - public InetSocketAddress getAddress() { - return ukcp.user().getRemoteAddress(); - } - - @Override - public void writeData(byte[] bytes) { - ByteBuf buf = Unpooled.wrappedBuffer(bytes); - ukcp.write(buf); - buf.release(); - } - - @Override - public void close() { - ukcp.close(); - } - - @Override - public int getSrtt() { - return ukcp.srtt(); - } - }); - sessions.put(ukcp, conversation); - } - - @Override - public void handleReceive(ByteBuf buf, Ukcp kcp) { - byte[] byteData = Utils.byteBufToArray(buf); - logicThread.execute( - () -> { - try { - GameSession conversation = sessions.get(kcp); - if (conversation != null) { - conversation.handleReceive(byteData); - } - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - - @Override - public void handleException(Throwable ex, Ukcp ukcp) {} - - @Override - public void handleClose(Ukcp ukcp) { - GameSession conversation = sessions.get(ukcp); - if (conversation != null) { - conversation.handleClose(); - sessions.remove(ukcp); - } - } - }; - - public static KcpListener getListener() { - return listener; - } - - interface KcpTunnel { - InetSocketAddress getAddress(); - - void writeData(byte[] bytes); - - void close(); - - int getSrtt(); - } - - interface KcpChannel { - void onConnected(KcpTunnel tunnel); - - void handleClose(); - - void handleReceive(byte[] bytes); - } -} +package emu.grasscutter.server.game; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.utils.Utils; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.DefaultEventLoop; +import java.net.InetSocketAddress; +import java.util.concurrent.ConcurrentHashMap; +import kcp.highway.KcpListener; +import kcp.highway.Ukcp; + +public class GameSessionManager { + private static final DefaultEventLoop logicThread = new DefaultEventLoop(); + private static final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); + private static final KcpListener listener = + new KcpListener() { + @Override + public void onConnected(Ukcp ukcp) { + int times = 0; + GameServer server = Grasscutter.getGameServer(); + while (server == null) { // Waiting server to establish + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + ukcp.close(); + return; + } + if (times++ > 5) { + Grasscutter.getLogger().error("Service is not available!"); + ukcp.close(); + return; + } + server = Grasscutter.getGameServer(); + } + GameSession conversation = new GameSession(server); + conversation.onConnected( + new KcpTunnel() { + @Override + public InetSocketAddress getAddress() { + return ukcp.user().getRemoteAddress(); + } + + @Override + public void writeData(byte[] bytes) { + ByteBuf buf = Unpooled.wrappedBuffer(bytes); + ukcp.write(buf); + buf.release(); + } + + @Override + public void close() { + ukcp.close(); + } + + @Override + public int getSrtt() { + return ukcp.srtt(); + } + }); + sessions.put(ukcp, conversation); + } + + @Override + public void handleReceive(ByteBuf buf, Ukcp kcp) { + byte[] byteData = Utils.byteBufToArray(buf); + logicThread.execute( + () -> { + try { + GameSession conversation = sessions.get(kcp); + if (conversation != null) { + conversation.handleReceive(byteData); + } + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + + @Override + public void handleException(Throwable ex, Ukcp ukcp) {} + + @Override + public void handleClose(Ukcp ukcp) { + GameSession conversation = sessions.get(ukcp); + if (conversation != null) { + conversation.handleClose(); + sessions.remove(ukcp); + } + } + }; + + public static KcpListener getListener() { + return listener; + } + + interface KcpTunnel { + InetSocketAddress getAddress(); + + void writeData(byte[] bytes); + + void close(); + + int getSrtt(); + } + + interface KcpChannel { + void onConnected(KcpTunnel tunnel); + + void handleClose(); + + void handleReceive(byte[] bytes); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/Router.java b/src/main/java/emu/grasscutter/server/http/Router.java index 3aedb39e3..5c7aa9a68 100644 --- a/src/main/java/emu/grasscutter/server/http/Router.java +++ b/src/main/java/emu/grasscutter/server/http/Router.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.http; - -import io.javalin.Javalin; -import io.javalin.http.Handler; - -/** Defines routes for an {@link Javalin} instance. */ -public interface Router { - - /** - * Called when the router is initialized by Express. - * - * @param javalin A Javalin instance. - */ - void applyRoutes(Javalin javalin); - - /** - * Applies this handler to all endpoint types - * - * @param javalin A Javalin instance. - * @param path - * @param ctx - * @return The Javalin instance. - */ - default Javalin allRoutes(Javalin javalin, String path, Handler ctx) { - javalin.get(path, ctx); - javalin.post(path, ctx); - javalin.put(path, ctx); - javalin.patch(path, ctx); - javalin.delete(path, ctx); - - return javalin; - } -} +package emu.grasscutter.server.http; + +import io.javalin.Javalin; +import io.javalin.http.Handler; + +/** Defines routes for an {@link Javalin} instance. */ +public interface Router { + + /** + * Called when the router is initialized by Express. + * + * @param javalin A Javalin instance. + */ + void applyRoutes(Javalin javalin); + + /** + * Applies this handler to all endpoint types + * + * @param javalin A Javalin instance. + * @param path + * @param ctx + * @return The Javalin instance. + */ + default Javalin allRoutes(Javalin javalin, String path, Handler ctx) { + javalin.get(path, ctx); + javalin.post(path, ctx); + javalin.put(path, ctx); + javalin.patch(path, ctx); + javalin.delete(path, ctx); + + return javalin; + } +} diff --git a/src/main/java/emu/grasscutter/server/http/dispatch/DispatchHandler.java b/src/main/java/emu/grasscutter/server/http/dispatch/DispatchHandler.java index 23b512eed..17b907117 100644 --- a/src/main/java/emu/grasscutter/server/http/dispatch/DispatchHandler.java +++ b/src/main/java/emu/grasscutter/server/http/dispatch/DispatchHandler.java @@ -1,160 +1,160 @@ -package emu.grasscutter.server.http.dispatch; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.auth.AuthenticationSystem; -import emu.grasscutter.auth.OAuthAuthenticator.ClientType; -import emu.grasscutter.server.http.Router; -import emu.grasscutter.server.http.objects.ComboTokenReqJson; -import emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData; -import emu.grasscutter.server.http.objects.LoginAccountRequestJson; -import emu.grasscutter.server.http.objects.LoginTokenRequestJson; -import emu.grasscutter.utils.JsonUtils; -import io.javalin.Javalin; -import io.javalin.http.Context; - -/** Handles requests related to authentication. (aka dispatch) */ -public final class DispatchHandler implements Router { - /** - * @route /hk4e_global/mdk/shield/api/login - */ - private static void clientLogin(Context ctx) { - // Parse body data. - String rawBodyData = ctx.body(); - var bodyData = JsonUtils.decode(rawBodyData, LoginAccountRequestJson.class); - - // Validate body data. - if (bodyData == null) return; - - // Pass data to authentication handler. - var responseData = - Grasscutter.getAuthenticationSystem() - .getPasswordAuthenticator() - .authenticate(AuthenticationSystem.fromPasswordRequest(ctx, bodyData)); - // Send response. - ctx.json(responseData); - - // Log to console. - Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); - } - - /** - * @route /hk4e_global/mdk/shield/api/verify - */ - private static void tokenLogin(Context ctx) { - // Parse body data. - String rawBodyData = ctx.body(); - var bodyData = JsonUtils.decode(rawBodyData, LoginTokenRequestJson.class); - - // Validate body data. - if (bodyData == null) return; - - // Pass data to authentication handler. - var responseData = - Grasscutter.getAuthenticationSystem() - .getTokenAuthenticator() - .authenticate(AuthenticationSystem.fromTokenRequest(ctx, bodyData)); - // Send response. - ctx.json(responseData); - - // Log to console. - Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); - } - - /** - * @route /hk4e_global/combo/granter/login/v2/login - */ - private static void sessionKeyLogin(Context ctx) { - // Parse body data. - String rawBodyData = ctx.body(); - var bodyData = JsonUtils.decode(rawBodyData, ComboTokenReqJson.class); - - // Validate body data. - if (bodyData == null || bodyData.data == null) return; - - // Decode additional body data. - var tokenData = JsonUtils.decode(bodyData.data, LoginTokenData.class); - - // Pass data to authentication handler. - var responseData = - Grasscutter.getAuthenticationSystem() - .getSessionKeyAuthenticator() - .authenticate(AuthenticationSystem.fromComboTokenRequest(ctx, bodyData, tokenData)); - // Send response. - ctx.json(responseData); - - // Log to console. - Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); - } - - @Override - public void applyRoutes(Javalin javalin) { - // OS - // Username & Password login (from client). - javalin.post("/hk4e_global/mdk/shield/api/login", DispatchHandler::clientLogin); - // Cached token login (from registry). - javalin.post("/hk4e_global/mdk/shield/api/verify", DispatchHandler::tokenLogin); - // Combo token login (from session key). - javalin.post("/hk4e_global/combo/granter/login/v2/login", DispatchHandler::sessionKeyLogin); - - // CN - // Username & Password login (from client). - javalin.post("/hk4e_cn/mdk/shield/api/login", DispatchHandler::clientLogin); - // Cached token login (from registry). - javalin.post("/hk4e_cn/mdk/shield/api/verify", DispatchHandler::tokenLogin); - // Combo token login (from session key). - javalin.post("/hk4e_cn/combo/granter/login/v2/login", DispatchHandler::sessionKeyLogin); - - // External login (from other clients). - javalin.get( - "/authentication/type", - ctx -> ctx.result(Grasscutter.getAuthenticationSystem().getClass().getSimpleName())); - javalin.post( - "/authentication/login", - ctx -> - Grasscutter.getAuthenticationSystem() - .getExternalAuthenticator() - .handleLogin(AuthenticationSystem.fromExternalRequest(ctx))); - javalin.post( - "/authentication/register", - ctx -> - Grasscutter.getAuthenticationSystem() - .getExternalAuthenticator() - .handleAccountCreation(AuthenticationSystem.fromExternalRequest(ctx))); - javalin.post( - "/authentication/change_password", - ctx -> - Grasscutter.getAuthenticationSystem() - .getExternalAuthenticator() - .handlePasswordReset(AuthenticationSystem.fromExternalRequest(ctx))); - - // External login (from OAuth2). - javalin.post( - "/hk4e_global/mdk/shield/api/loginByThirdparty", - ctx -> - Grasscutter.getAuthenticationSystem() - .getOAuthAuthenticator() - .handleLogin(AuthenticationSystem.fromExternalRequest(ctx))); - javalin.get( - "/authentication/openid/redirect", - ctx -> - Grasscutter.getAuthenticationSystem() - .getOAuthAuthenticator() - .handleTokenProcess(AuthenticationSystem.fromExternalRequest(ctx))); - javalin.get( - "/Api/twitter_login", - ctx -> - Grasscutter.getAuthenticationSystem() - .getOAuthAuthenticator() - .handleRedirection( - AuthenticationSystem.fromExternalRequest(ctx), ClientType.DESKTOP)); - javalin.get( - "/sdkTwitterLogin.html", - ctx -> - Grasscutter.getAuthenticationSystem() - .getOAuthAuthenticator() - .handleRedirection( - AuthenticationSystem.fromExternalRequest(ctx), ClientType.MOBILE)); - } -} +package emu.grasscutter.server.http.dispatch; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.auth.AuthenticationSystem; +import emu.grasscutter.auth.OAuthAuthenticator.ClientType; +import emu.grasscutter.server.http.Router; +import emu.grasscutter.server.http.objects.ComboTokenReqJson; +import emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData; +import emu.grasscutter.server.http.objects.LoginAccountRequestJson; +import emu.grasscutter.server.http.objects.LoginTokenRequestJson; +import emu.grasscutter.utils.JsonUtils; +import io.javalin.Javalin; +import io.javalin.http.Context; + +/** Handles requests related to authentication. (aka dispatch) */ +public final class DispatchHandler implements Router { + /** + * @route /hk4e_global/mdk/shield/api/login + */ + private static void clientLogin(Context ctx) { + // Parse body data. + String rawBodyData = ctx.body(); + var bodyData = JsonUtils.decode(rawBodyData, LoginAccountRequestJson.class); + + // Validate body data. + if (bodyData == null) return; + + // Pass data to authentication handler. + var responseData = + Grasscutter.getAuthenticationSystem() + .getPasswordAuthenticator() + .authenticate(AuthenticationSystem.fromPasswordRequest(ctx, bodyData)); + // Send response. + ctx.json(responseData); + + // Log to console. + Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); + } + + /** + * @route /hk4e_global/mdk/shield/api/verify + */ + private static void tokenLogin(Context ctx) { + // Parse body data. + String rawBodyData = ctx.body(); + var bodyData = JsonUtils.decode(rawBodyData, LoginTokenRequestJson.class); + + // Validate body data. + if (bodyData == null) return; + + // Pass data to authentication handler. + var responseData = + Grasscutter.getAuthenticationSystem() + .getTokenAuthenticator() + .authenticate(AuthenticationSystem.fromTokenRequest(ctx, bodyData)); + // Send response. + ctx.json(responseData); + + // Log to console. + Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); + } + + /** + * @route /hk4e_global/combo/granter/login/v2/login + */ + private static void sessionKeyLogin(Context ctx) { + // Parse body data. + String rawBodyData = ctx.body(); + var bodyData = JsonUtils.decode(rawBodyData, ComboTokenReqJson.class); + + // Validate body data. + if (bodyData == null || bodyData.data == null) return; + + // Decode additional body data. + var tokenData = JsonUtils.decode(bodyData.data, LoginTokenData.class); + + // Pass data to authentication handler. + var responseData = + Grasscutter.getAuthenticationSystem() + .getSessionKeyAuthenticator() + .authenticate(AuthenticationSystem.fromComboTokenRequest(ctx, bodyData, tokenData)); + // Send response. + ctx.json(responseData); + + // Log to console. + Grasscutter.getLogger().info(translate("messages.dispatch.account.login_attempt", ctx.ip())); + } + + @Override + public void applyRoutes(Javalin javalin) { + // OS + // Username & Password login (from client). + javalin.post("/hk4e_global/mdk/shield/api/login", DispatchHandler::clientLogin); + // Cached token login (from registry). + javalin.post("/hk4e_global/mdk/shield/api/verify", DispatchHandler::tokenLogin); + // Combo token login (from session key). + javalin.post("/hk4e_global/combo/granter/login/v2/login", DispatchHandler::sessionKeyLogin); + + // CN + // Username & Password login (from client). + javalin.post("/hk4e_cn/mdk/shield/api/login", DispatchHandler::clientLogin); + // Cached token login (from registry). + javalin.post("/hk4e_cn/mdk/shield/api/verify", DispatchHandler::tokenLogin); + // Combo token login (from session key). + javalin.post("/hk4e_cn/combo/granter/login/v2/login", DispatchHandler::sessionKeyLogin); + + // External login (from other clients). + javalin.get( + "/authentication/type", + ctx -> ctx.result(Grasscutter.getAuthenticationSystem().getClass().getSimpleName())); + javalin.post( + "/authentication/login", + ctx -> + Grasscutter.getAuthenticationSystem() + .getExternalAuthenticator() + .handleLogin(AuthenticationSystem.fromExternalRequest(ctx))); + javalin.post( + "/authentication/register", + ctx -> + Grasscutter.getAuthenticationSystem() + .getExternalAuthenticator() + .handleAccountCreation(AuthenticationSystem.fromExternalRequest(ctx))); + javalin.post( + "/authentication/change_password", + ctx -> + Grasscutter.getAuthenticationSystem() + .getExternalAuthenticator() + .handlePasswordReset(AuthenticationSystem.fromExternalRequest(ctx))); + + // External login (from OAuth2). + javalin.post( + "/hk4e_global/mdk/shield/api/loginByThirdparty", + ctx -> + Grasscutter.getAuthenticationSystem() + .getOAuthAuthenticator() + .handleLogin(AuthenticationSystem.fromExternalRequest(ctx))); + javalin.get( + "/authentication/openid/redirect", + ctx -> + Grasscutter.getAuthenticationSystem() + .getOAuthAuthenticator() + .handleTokenProcess(AuthenticationSystem.fromExternalRequest(ctx))); + javalin.get( + "/Api/twitter_login", + ctx -> + Grasscutter.getAuthenticationSystem() + .getOAuthAuthenticator() + .handleRedirection( + AuthenticationSystem.fromExternalRequest(ctx), ClientType.DESKTOP)); + javalin.get( + "/sdkTwitterLogin.html", + ctx -> + Grasscutter.getAuthenticationSystem() + .getOAuthAuthenticator() + .handleRedirection( + AuthenticationSystem.fromExternalRequest(ctx), ClientType.MOBILE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/documentation/DocumentationServerHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/DocumentationServerHandler.java index c34cfaaa0..1d38fbfc6 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/DocumentationServerHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/DocumentationServerHandler.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.http.documentation; - -import emu.grasscutter.server.http.Router; -import io.javalin.Javalin; - -public final class DocumentationServerHandler implements Router { - - @Override - public void applyRoutes(Javalin javalin) { - final RootRequestHandler root = new RootRequestHandler(); - final HandbookRequestHandler handbook = new HandbookRequestHandler(); - final GachaMappingRequestHandler gachaMapping = new GachaMappingRequestHandler(); - - // TODO: Removal - // TODO: Forward /documentation requests to https://grasscutter.io/wiki - javalin.get("/documentation/handbook", handbook::handle); - javalin.get("/documentation/gachamapping", gachaMapping::handle); - javalin.get("/documentation", root::handle); - } -} +package emu.grasscutter.server.http.documentation; + +import emu.grasscutter.server.http.Router; +import io.javalin.Javalin; + +public final class DocumentationServerHandler implements Router { + + @Override + public void applyRoutes(Javalin javalin) { + final RootRequestHandler root = new RootRequestHandler(); + final HandbookRequestHandler handbook = new HandbookRequestHandler(); + final GachaMappingRequestHandler gachaMapping = new GachaMappingRequestHandler(); + + // TODO: Removal + // TODO: Forward /documentation requests to https://grasscutter.io/wiki + javalin.get("/documentation/handbook", handbook::handle); + javalin.get("/documentation/gachamapping", gachaMapping::handle); + javalin.get("/documentation", root::handle); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java index 29a49f562..98fddda5f 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/HandbookHandler.java @@ -1,5 +1,7 @@ package emu.grasscutter.server.http.documentation; +import static emu.grasscutter.config.Configuration.HANDBOOK; + import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerRunMode; import emu.grasscutter.data.GameData; @@ -12,16 +14,14 @@ import emu.grasscutter.utils.objects.HandbookBody; import io.javalin.Javalin; import io.javalin.http.Context; -import static emu.grasscutter.config.Configuration.HANDBOOK; - /** Handles requests for the new GM Handbook. */ public final class HandbookHandler implements Router { private final byte[] handbook; private final boolean serve; /** - * Constructor for the handbook router. - * Enables serving the handbook if the handbook file is found. + * Constructor for the handbook router. Enables serving the handbook if the handbook file is + * found. */ public HandbookHandler() { this.handbook = FileUtils.readResource("/handbook.html"); @@ -44,8 +44,7 @@ public final class HandbookHandler implements Router { * @return True if the server can execute handbook commands. */ private boolean controlSupported() { - return HANDBOOK.enable && - Grasscutter.getRunMode() == ServerRunMode.HYBRID; + return HANDBOOK.enable && Grasscutter.getRunMode() == ServerRunMode.HYBRID; } /** @@ -101,16 +100,16 @@ public final class HandbookHandler implements Router { var avatar = new Avatar(avatarData); avatar.setLevel(request.getLevel()); avatar.setPromoteLevel(Avatar.getMinPromoteLevel(avatar.getLevel())); - avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> - avatar.setSkillLevel(id, request.getTalentLevels())); + avatar + .getSkillDepot() + .getSkillsAndEnergySkill() + .forEach(id -> avatar.setSkillLevel(id, request.getTalentLevels())); avatar.forceConstellationLevel(request.getConstellations()); - avatar.recalcStats(true); avatar.save(); + avatar.recalcStats(true); + avatar.save(); player.addAvatar(avatar); // Add the avatar. - ctx.json(HandbookBody.Response.builder() - .status(200) - .message("Avatar granted.") - .build()); + ctx.json(HandbookBody.Response.builder().status(200).message("Avatar granted.").build()); } catch (NumberFormatException ignored) { ctx.status(500).result("Invalid player UID or avatar ID."); } catch (Exception exception) { @@ -159,10 +158,7 @@ public final class HandbookHandler implements Router { // Add the item to the inventory. player.getInventory().addItem(itemStack, ActionReason.Gm); - ctx.json(HandbookBody.Response.builder() - .status(200) - .message("Item granted.") - .build()); + ctx.json(HandbookBody.Response.builder().status(200).message("Item granted.").build()); } catch (NumberFormatException ignored) { ctx.status(500).result("Invalid player UID or item ID."); } catch (Exception exception) { diff --git a/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java b/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java index 19515387e..0330cb443 100644 --- a/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java +++ b/src/main/java/emu/grasscutter/server/http/documentation/RootRequestHandler.java @@ -1,42 +1,42 @@ -package emu.grasscutter.server.http.documentation; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.utils.FileUtils; -import io.javalin.http.ContentType; -import io.javalin.http.Context; -import java.io.IOException; -import java.nio.file.Files; - -final class RootRequestHandler implements DocumentationHandler { - - private final String template; - - public RootRequestHandler() { - var templatePath = FileUtils.getDataPath("documentation/index.html"); - String t = null; - try { - t = Files.readString(templatePath); - } catch (IOException ignored) { - Grasscutter.getLogger().warn("File does not exist: " + templatePath); - } - this.template = t; - } - - @Override - public void handle(Context ctx) { - if (template == null) { - ctx.status(500); - return; - } - - String content = - template - .replace("{{TITLE}}", translate("documentation.index.title")) - .replace("{{ITEM_HANDBOOK}}", translate("documentation.index.handbook")) - .replace("{{ITEM_GACHA_MAPPING}}", translate("documentation.index.gacha_mapping")); - ctx.contentType(ContentType.TEXT_HTML); - ctx.result(content); - } -} +package emu.grasscutter.server.http.documentation; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.utils.FileUtils; +import io.javalin.http.ContentType; +import io.javalin.http.Context; +import java.io.IOException; +import java.nio.file.Files; + +final class RootRequestHandler implements DocumentationHandler { + + private final String template; + + public RootRequestHandler() { + var templatePath = FileUtils.getDataPath("documentation/index.html"); + String t = null; + try { + t = Files.readString(templatePath); + } catch (IOException ignored) { + Grasscutter.getLogger().warn("File does not exist: " + templatePath); + } + this.template = t; + } + + @Override + public void handle(Context ctx) { + if (template == null) { + ctx.status(500); + return; + } + + String content = + template + .replace("{{TITLE}}", translate("documentation.index.title")) + .replace("{{ITEM_HANDBOOK}}", translate("documentation.index.handbook")) + .replace("{{ITEM_GACHA_MAPPING}}", translate("documentation.index.gacha_mapping")); + ctx.contentType(ContentType.TEXT_HTML); + ctx.result(content); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java index 40ea55bd6..f57bade8b 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/AnnouncementsHandler.java @@ -1,121 +1,121 @@ -package emu.grasscutter.server.http.handlers; - -import static emu.grasscutter.config.Configuration.*; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.data.DataLoader; -import emu.grasscutter.server.http.Router; -import emu.grasscutter.server.http.objects.HttpJsonResponse; -import emu.grasscutter.utils.FileUtils; -import io.javalin.Javalin; -import io.javalin.http.ContentType; -import io.javalin.http.Context; -import java.io.IOException; -import java.io.InputStream; -import java.util.Objects; -import java.util.StringJoiner; - -/** Handles requests related to the announcements page. */ -public final class AnnouncementsHandler implements Router { - private static void getAnnouncement(Context ctx) { - String data = ""; - if (Objects.equals( - ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnContent")) { - try { - data = FileUtils.readToString(DataLoader.load("GameAnnouncement.json")); - } catch (Exception e) { - if (e.getClass() == IOException.class) { - Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); - } - } - } else if (Objects.equals( - ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnList")) { - try { - data = FileUtils.readToString(DataLoader.load("GameAnnouncementList.json")); - } catch (Exception e) { - if (e.getClass() == IOException.class) { - Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); - } - } - } else { - ctx.result("{\"retcode\":404,\"message\":\"Unknown request path\"}"); - } - - if (data.isEmpty()) { - ctx.result("{\"retcode\":500,\"message\":\"Unable to fetch requsted content\"}"); - return; - } - - String dispatchDomain = - "http" - + (HTTP_ENCRYPTION.useInRouting ? "s" : "") - + "://" - + lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) - + ":" - + lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort); - - data = - data.replace("{{DISPATCH_PUBLIC}}", dispatchDomain) - .replace("{{SYSTEM_TIME}}", String.valueOf(System.currentTimeMillis())); - ctx.result("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}"); - } - - private static void getPageResources(Context ctx) { - // Re-process the path - remove the first slash and prevent directory traversal - // (the first slash will act as root path when resolving local path) - String[] path = ctx.path().split("/"); - StringJoiner stringJoiner = new StringJoiner("/"); - for (String pathName : path) { - // Filter the illegal payload to prevent directory traversal - if (!pathName.isEmpty() && !pathName.equals("..") && !pathName.contains("\\")) { - stringJoiner.add(pathName); - } - } - try (InputStream filestream = DataLoader.load(stringJoiner.toString())) { - String possibleFilename = ctx.path(); - - ContentType fromExtension = - ContentType.getContentTypeByExtension( - possibleFilename.substring(possibleFilename.lastIndexOf(".") + 1)); - ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM); - ctx.result(filestream.readAllBytes()); - } catch (Exception e) { - Grasscutter.getLogger().warn("File does not exist: " + ctx.path()); - ctx.status(404); - } - } - - @Override - public void applyRoutes(Javalin javalin) { - // hk4e-api-os.hoyoverse.com - this.allRoutes( - javalin, - "/common/hk4e_global/announcement/api/getAlertPic", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}")); - // hk4e-api-os.hoyoverse.com - this.allRoutes( - javalin, - "/common/hk4e_global/announcement/api/getAlertAnn", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}")); - // hk4e-api-os.hoyoverse.com - this.allRoutes( - javalin, - "/common/hk4e_global/announcement/api/getAnnList", - AnnouncementsHandler::getAnnouncement); - // hk4e-api-os-static.hoyoverse.com - this.allRoutes( - javalin, - "/common/hk4e_global/announcement/api/getAnnContent", - AnnouncementsHandler::getAnnouncement); - // hk4e-sdk-os.hoyoverse.com - this.allRoutes( - javalin, - "/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}")); - - javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources); - } -} +package emu.grasscutter.server.http.handlers; + +import static emu.grasscutter.config.Configuration.*; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.data.DataLoader; +import emu.grasscutter.server.http.Router; +import emu.grasscutter.server.http.objects.HttpJsonResponse; +import emu.grasscutter.utils.FileUtils; +import io.javalin.Javalin; +import io.javalin.http.ContentType; +import io.javalin.http.Context; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import java.util.StringJoiner; + +/** Handles requests related to the announcements page. */ +public final class AnnouncementsHandler implements Router { + private static void getAnnouncement(Context ctx) { + String data = ""; + if (Objects.equals( + ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnContent")) { + try { + data = FileUtils.readToString(DataLoader.load("GameAnnouncement.json")); + } catch (Exception e) { + if (e.getClass() == IOException.class) { + Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); + } + } + } else if (Objects.equals( + ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnList")) { + try { + data = FileUtils.readToString(DataLoader.load("GameAnnouncementList.json")); + } catch (Exception e) { + if (e.getClass() == IOException.class) { + Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e); + } + } + } else { + ctx.result("{\"retcode\":404,\"message\":\"Unknown request path\"}"); + } + + if (data.isEmpty()) { + ctx.result("{\"retcode\":500,\"message\":\"Unable to fetch requsted content\"}"); + return; + } + + String dispatchDomain = + "http" + + (HTTP_ENCRYPTION.useInRouting ? "s" : "") + + "://" + + lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress) + + ":" + + lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort); + + data = + data.replace("{{DISPATCH_PUBLIC}}", dispatchDomain) + .replace("{{SYSTEM_TIME}}", String.valueOf(System.currentTimeMillis())); + ctx.result("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}"); + } + + private static void getPageResources(Context ctx) { + // Re-process the path - remove the first slash and prevent directory traversal + // (the first slash will act as root path when resolving local path) + String[] path = ctx.path().split("/"); + StringJoiner stringJoiner = new StringJoiner("/"); + for (String pathName : path) { + // Filter the illegal payload to prevent directory traversal + if (!pathName.isEmpty() && !pathName.equals("..") && !pathName.contains("\\")) { + stringJoiner.add(pathName); + } + } + try (InputStream filestream = DataLoader.load(stringJoiner.toString())) { + String possibleFilename = ctx.path(); + + ContentType fromExtension = + ContentType.getContentTypeByExtension( + possibleFilename.substring(possibleFilename.lastIndexOf(".") + 1)); + ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM); + ctx.result(filestream.readAllBytes()); + } catch (Exception e) { + Grasscutter.getLogger().warn("File does not exist: " + ctx.path()); + ctx.status(404); + } + } + + @Override + public void applyRoutes(Javalin javalin) { + // hk4e-api-os.hoyoverse.com + this.allRoutes( + javalin, + "/common/hk4e_global/announcement/api/getAlertPic", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}")); + // hk4e-api-os.hoyoverse.com + this.allRoutes( + javalin, + "/common/hk4e_global/announcement/api/getAlertAnn", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}")); + // hk4e-api-os.hoyoverse.com + this.allRoutes( + javalin, + "/common/hk4e_global/announcement/api/getAnnList", + AnnouncementsHandler::getAnnouncement); + // hk4e-api-os-static.hoyoverse.com + this.allRoutes( + javalin, + "/common/hk4e_global/announcement/api/getAnnContent", + AnnouncementsHandler::getAnnouncement); + // hk4e-sdk-os.hoyoverse.com + this.allRoutes( + javalin, + "/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}")); + + javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java index dbef3a852..66300e7b6 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/GachaHandler.java @@ -1,153 +1,153 @@ -package emu.grasscutter.server.http.handlers; - -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.gacha.GachaBanner; -import emu.grasscutter.game.gacha.GachaSystem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.server.http.Router; -import emu.grasscutter.utils.FileUtils; -import emu.grasscutter.utils.Utils; -import io.javalin.Javalin; -import io.javalin.http.ContentType; -import io.javalin.http.Context; -import io.javalin.http.staticfiles.Location; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.Set; -import lombok.Getter; - -/** Handles all gacha-related HTTP requests. */ -public final class GachaHandler implements Router { - @Getter - private static final Path gachaMappingsPath = FileUtils.getDataUserPath("gacha/mappings.js"); - - @Deprecated(forRemoval = true) - public static final String gachaMappings = gachaMappingsPath.toString(); - - private static void gachaRecords(Context ctx) { - String sessionKey = ctx.queryParam("s"); - Account account = DatabaseHelper.getAccountBySessionKey(sessionKey); - if (account == null) { - ctx.status(403).result("Requested account was not found"); - return; - } - Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); - if (player == null) { - ctx.status(403).result("No player associated with requested account"); - return; - } - - int page = 0, gachaType = 0; - if (ctx.queryParam("p") != null) page = Integer.parseInt(ctx.queryParam("p")); - if (ctx.queryParam("gachaType") != null) - gachaType = Integer.parseInt(ctx.queryParam("gachaType")); - - String records = DatabaseHelper.getGachaRecords(player.getUid(), page, gachaType).toString(); - long maxPage = DatabaseHelper.getGachaRecordsMaxPage(player.getUid(), page, gachaType); - - String template = - new String( - FileUtils.read(FileUtils.getDataPath("gacha/records.html")), StandardCharsets.UTF_8) - .replace("{{REPLACE_RECORDS}}", records) - .replace("{{REPLACE_MAXPAGE}}", String.valueOf(maxPage)) - .replace("{{TITLE}}", translate(player, "gacha.records.title")) - .replace("{{DATE}}", translate(player, "gacha.records.date")) - .replace("{{ITEM}}", translate(player, "gacha.records.item")) - .replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale())); - ctx.contentType(ContentType.TEXT_HTML); - ctx.result(template); - } - - private static void gachaDetails(Context ctx) { - Path detailsTemplate = FileUtils.getDataPath("gacha/details.html"); - String sessionKey = ctx.queryParam("s"); - Account account = DatabaseHelper.getAccountBySessionKey(sessionKey); - if (account == null) { - ctx.status(403).result("Requested account was not found"); - return; - } - Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); - if (player == null) { - ctx.status(403).result("No player associated with requested account"); - return; - } - - String template; - try { - template = Files.readString(detailsTemplate); - } catch (IOException e) { - Grasscutter.getLogger().warn("Failed to read data/gacha/details.html"); - ctx.status(500); - return; - } - - // Add translated title etc. to the page. - template = - template - .replace("{{TITLE}}", translate(player, "gacha.details.title")) - .replace( - "{{AVAILABLE_FIVE_STARS}}", translate(player, "gacha.details.available_five_stars")) - .replace( - "{{AVAILABLE_FOUR_STARS}}", translate(player, "gacha.details.available_four_stars")) - .replace( - "{{AVAILABLE_THREE_STARS}}", - translate(player, "gacha.details.available_three_stars")) - .replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale())); - - // Get the banner info for the banner we want. - int scheduleId = Integer.parseInt(ctx.queryParam("scheduleId")); - GachaSystem manager = Grasscutter.getGameServer().getGachaSystem(); - GachaBanner banner = manager.getGachaBanners().get(scheduleId); - - // Add 5-star items. - Set fiveStarItems = new LinkedHashSet<>(); - - Arrays.stream(banner.getRateUpItems5()).forEach(i -> fiveStarItems.add(Integer.toString(i))); - Arrays.stream(banner.getFallbackItems5Pool1()) - .forEach(i -> fiveStarItems.add(Integer.toString(i))); - Arrays.stream(banner.getFallbackItems5Pool2()) - .forEach(i -> fiveStarItems.add(Integer.toString(i))); - - template = template.replace("{{FIVE_STARS}}", "[" + String.join(",", fiveStarItems) + "]"); - - // Add 4-star items. - Set fourStarItems = new LinkedHashSet<>(); - - Arrays.stream(banner.getRateUpItems4()).forEach(i -> fourStarItems.add(Integer.toString(i))); - Arrays.stream(banner.getFallbackItems4Pool1()) - .forEach(i -> fourStarItems.add(Integer.toString(i))); - Arrays.stream(banner.getFallbackItems4Pool2()) - .forEach(i -> fourStarItems.add(Integer.toString(i))); - - template = template.replace("{{FOUR_STARS}}", "[" + String.join(",", fourStarItems) + "]"); - - // Add 3-star items. - Set threeStarItems = new LinkedHashSet<>(); - Arrays.stream(banner.getFallbackItems3()).forEach(i -> threeStarItems.add(Integer.toString(i))); - template = template.replace("{{THREE_STARS}}", "[" + String.join(",", threeStarItems) + "]"); - - // Done. - ctx.contentType(ContentType.TEXT_HTML); - ctx.result(template); - } - - @Override - public void applyRoutes(Javalin javalin) { - javalin.get("/gacha", GachaHandler::gachaRecords); - javalin.get("/gacha/details", GachaHandler::gachaDetails); - - javalin._conf.addSinglePageRoot( - "/gacha/mappings", - gachaMappingsPath.toString(), - Location.EXTERNAL); // TODO: This ***must*** be changed to take the Path not a String. This - // might involve upgrading Javalin. - } -} +package emu.grasscutter.server.http.handlers; + +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.Account; +import emu.grasscutter.game.gacha.GachaBanner; +import emu.grasscutter.game.gacha.GachaSystem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.http.Router; +import emu.grasscutter.utils.FileUtils; +import emu.grasscutter.utils.Utils; +import io.javalin.Javalin; +import io.javalin.http.ContentType; +import io.javalin.http.Context; +import io.javalin.http.staticfiles.Location; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.Set; +import lombok.Getter; + +/** Handles all gacha-related HTTP requests. */ +public final class GachaHandler implements Router { + @Getter + private static final Path gachaMappingsPath = FileUtils.getDataUserPath("gacha/mappings.js"); + + @Deprecated(forRemoval = true) + public static final String gachaMappings = gachaMappingsPath.toString(); + + private static void gachaRecords(Context ctx) { + String sessionKey = ctx.queryParam("s"); + Account account = DatabaseHelper.getAccountBySessionKey(sessionKey); + if (account == null) { + ctx.status(403).result("Requested account was not found"); + return; + } + Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); + if (player == null) { + ctx.status(403).result("No player associated with requested account"); + return; + } + + int page = 0, gachaType = 0; + if (ctx.queryParam("p") != null) page = Integer.parseInt(ctx.queryParam("p")); + if (ctx.queryParam("gachaType") != null) + gachaType = Integer.parseInt(ctx.queryParam("gachaType")); + + String records = DatabaseHelper.getGachaRecords(player.getUid(), page, gachaType).toString(); + long maxPage = DatabaseHelper.getGachaRecordsMaxPage(player.getUid(), page, gachaType); + + String template = + new String( + FileUtils.read(FileUtils.getDataPath("gacha/records.html")), StandardCharsets.UTF_8) + .replace("{{REPLACE_RECORDS}}", records) + .replace("{{REPLACE_MAXPAGE}}", String.valueOf(maxPage)) + .replace("{{TITLE}}", translate(player, "gacha.records.title")) + .replace("{{DATE}}", translate(player, "gacha.records.date")) + .replace("{{ITEM}}", translate(player, "gacha.records.item")) + .replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale())); + ctx.contentType(ContentType.TEXT_HTML); + ctx.result(template); + } + + private static void gachaDetails(Context ctx) { + Path detailsTemplate = FileUtils.getDataPath("gacha/details.html"); + String sessionKey = ctx.queryParam("s"); + Account account = DatabaseHelper.getAccountBySessionKey(sessionKey); + if (account == null) { + ctx.status(403).result("Requested account was not found"); + return; + } + Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); + if (player == null) { + ctx.status(403).result("No player associated with requested account"); + return; + } + + String template; + try { + template = Files.readString(detailsTemplate); + } catch (IOException e) { + Grasscutter.getLogger().warn("Failed to read data/gacha/details.html"); + ctx.status(500); + return; + } + + // Add translated title etc. to the page. + template = + template + .replace("{{TITLE}}", translate(player, "gacha.details.title")) + .replace( + "{{AVAILABLE_FIVE_STARS}}", translate(player, "gacha.details.available_five_stars")) + .replace( + "{{AVAILABLE_FOUR_STARS}}", translate(player, "gacha.details.available_four_stars")) + .replace( + "{{AVAILABLE_THREE_STARS}}", + translate(player, "gacha.details.available_three_stars")) + .replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale())); + + // Get the banner info for the banner we want. + int scheduleId = Integer.parseInt(ctx.queryParam("scheduleId")); + GachaSystem manager = Grasscutter.getGameServer().getGachaSystem(); + GachaBanner banner = manager.getGachaBanners().get(scheduleId); + + // Add 5-star items. + Set fiveStarItems = new LinkedHashSet<>(); + + Arrays.stream(banner.getRateUpItems5()).forEach(i -> fiveStarItems.add(Integer.toString(i))); + Arrays.stream(banner.getFallbackItems5Pool1()) + .forEach(i -> fiveStarItems.add(Integer.toString(i))); + Arrays.stream(banner.getFallbackItems5Pool2()) + .forEach(i -> fiveStarItems.add(Integer.toString(i))); + + template = template.replace("{{FIVE_STARS}}", "[" + String.join(",", fiveStarItems) + "]"); + + // Add 4-star items. + Set fourStarItems = new LinkedHashSet<>(); + + Arrays.stream(banner.getRateUpItems4()).forEach(i -> fourStarItems.add(Integer.toString(i))); + Arrays.stream(banner.getFallbackItems4Pool1()) + .forEach(i -> fourStarItems.add(Integer.toString(i))); + Arrays.stream(banner.getFallbackItems4Pool2()) + .forEach(i -> fourStarItems.add(Integer.toString(i))); + + template = template.replace("{{FOUR_STARS}}", "[" + String.join(",", fourStarItems) + "]"); + + // Add 3-star items. + Set threeStarItems = new LinkedHashSet<>(); + Arrays.stream(banner.getFallbackItems3()).forEach(i -> threeStarItems.add(Integer.toString(i))); + template = template.replace("{{THREE_STARS}}", "[" + String.join(",", threeStarItems) + "]"); + + // Done. + ctx.contentType(ContentType.TEXT_HTML); + ctx.result(template); + } + + @Override + public void applyRoutes(Javalin javalin) { + javalin.get("/gacha", GachaHandler::gachaRecords); + javalin.get("/gacha/details", GachaHandler::gachaDetails); + + javalin._conf.addSinglePageRoot( + "/gacha/mappings", + gachaMappingsPath.toString(), + Location.EXTERNAL); // TODO: This ***must*** be changed to take the Path not a String. This + // might involve upgrading Javalin. + } +} diff --git a/src/main/java/emu/grasscutter/server/http/handlers/GenericHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/GenericHandler.java index 6ea0d7154..d29480142 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/GenericHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/GenericHandler.java @@ -1,85 +1,85 @@ -package emu.grasscutter.server.http.handlers; - -import static emu.grasscutter.config.Configuration.ACCOUNT; - -import emu.grasscutter.GameConstants; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.server.http.Router; -import emu.grasscutter.server.http.objects.HttpJsonResponse; -import emu.grasscutter.server.http.objects.WebStaticVersionResponse; -import io.javalin.Javalin; -import io.javalin.http.Context; - -/** Handles all generic, hard-coded responses. */ -public final class GenericHandler implements Router { - private static void serverStatus(Context ctx) { - int playerCount = Grasscutter.getGameServer().getPlayers().size(); - int maxPlayer = ACCOUNT.maxPlayer; - String version = GameConstants.VERSION; - - ctx.result( - "{\"retcode\":0,\"status\":{\"playerCount\":" - + playerCount - + ",\"maxPlayer\":" - + maxPlayer - + ",\"version\":\"" - + version - + "\"}}"); - } - - @Override - public void applyRoutes(Javalin javalin) { - // hk4e-sdk-os.hoyoverse.com - javalin.get( - "/hk4e_global/mdk/agreement/api/getAgreementInfos", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}")); - // hk4e-sdk-os.hoyoverse.com (this could be either GET or POST based on the observation of - // different clients) - this.allRoutes( - javalin, - "/hk4e_global/combo/granter/api/compareProtocolVersion", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}")); - - // api-account-os.hoyoverse.com - javalin.post( - "/account/risky/api/check", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}")); - - // sdk-os-static.hoyoverse.com - javalin.get( - "/combo/box/api/config/sdk/combo", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"disable_email_bind_skip\":\"false\",\"email_bind_remind_interval\":\"7\",\"email_bind_remind\":\"true\"}}}")); - // hk4e-sdk-os-static.hoyoverse.com - javalin.get( - "/hk4e_global/combo/granter/api/getConfig", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"https://webstatic-sea.hoyoverse.com/hk4e/announcement/index.html?sdk_presentation_style=fullscreen\\u0026sdk_screen_transparent=true\\u0026game_biz=hk4e_global\\u0026auth_appid=announcement\\u0026game=hk4e#/\",\"push_alias_type\":2,\"disable_ysdk_guard\":false,\"enable_announce_pic_popup\":true}}")); - // hk4e-sdk-os-static.hoyoverse.com - javalin.get( - "/hk4e_global/mdk/shield/api/loadConfig", - new HttpJsonResponse( - "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":6,\"game_key\":\"hk4e_global\",\"client\":\"PC\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"原神海外\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[\"fb\",\"tw\"],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{\"tw\":\"\",\"fb\":\"\"},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{\"tw\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800},\"fb\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800}}}}")); - // Test api? - // abtest-api-data-sg.hoyoverse.com - javalin.post( - "/data_abtest_api/config/experiment/list", - new HttpJsonResponse( - "{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}")); - - // log-upload-os.mihoyo.com - this.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}")); - this.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}")); - javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}")); - // /perf/config/verify?device_id=xxx&platform=x&name=xxx - this.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}")); - - // webstatic-sea.hoyoverse.com - javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse()); - - javalin.get("/status/server", GenericHandler::serverStatus); - } -} +package emu.grasscutter.server.http.handlers; + +import static emu.grasscutter.config.Configuration.ACCOUNT; + +import emu.grasscutter.GameConstants; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.server.http.Router; +import emu.grasscutter.server.http.objects.HttpJsonResponse; +import emu.grasscutter.server.http.objects.WebStaticVersionResponse; +import io.javalin.Javalin; +import io.javalin.http.Context; + +/** Handles all generic, hard-coded responses. */ +public final class GenericHandler implements Router { + private static void serverStatus(Context ctx) { + int playerCount = Grasscutter.getGameServer().getPlayers().size(); + int maxPlayer = ACCOUNT.maxPlayer; + String version = GameConstants.VERSION; + + ctx.result( + "{\"retcode\":0,\"status\":{\"playerCount\":" + + playerCount + + ",\"maxPlayer\":" + + maxPlayer + + ",\"version\":\"" + + version + + "\"}}"); + } + + @Override + public void applyRoutes(Javalin javalin) { + // hk4e-sdk-os.hoyoverse.com + javalin.get( + "/hk4e_global/mdk/agreement/api/getAgreementInfos", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}")); + // hk4e-sdk-os.hoyoverse.com (this could be either GET or POST based on the observation of + // different clients) + this.allRoutes( + javalin, + "/hk4e_global/combo/granter/api/compareProtocolVersion", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}")); + + // api-account-os.hoyoverse.com + javalin.post( + "/account/risky/api/check", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}")); + + // sdk-os-static.hoyoverse.com + javalin.get( + "/combo/box/api/config/sdk/combo", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"disable_email_bind_skip\":\"false\",\"email_bind_remind_interval\":\"7\",\"email_bind_remind\":\"true\"}}}")); + // hk4e-sdk-os-static.hoyoverse.com + javalin.get( + "/hk4e_global/combo/granter/api/getConfig", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"https://webstatic-sea.hoyoverse.com/hk4e/announcement/index.html?sdk_presentation_style=fullscreen\\u0026sdk_screen_transparent=true\\u0026game_biz=hk4e_global\\u0026auth_appid=announcement\\u0026game=hk4e#/\",\"push_alias_type\":2,\"disable_ysdk_guard\":false,\"enable_announce_pic_popup\":true}}")); + // hk4e-sdk-os-static.hoyoverse.com + javalin.get( + "/hk4e_global/mdk/shield/api/loadConfig", + new HttpJsonResponse( + "{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":6,\"game_key\":\"hk4e_global\",\"client\":\"PC\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"原神海外\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[\"fb\",\"tw\"],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{\"tw\":\"\",\"fb\":\"\"},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{\"tw\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800},\"fb\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800}}}}")); + // Test api? + // abtest-api-data-sg.hoyoverse.com + javalin.post( + "/data_abtest_api/config/experiment/list", + new HttpJsonResponse( + "{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}")); + + // log-upload-os.mihoyo.com + this.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}")); + this.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}")); + javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}")); + // /perf/config/verify?device_id=xxx&platform=x&name=xxx + this.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}")); + + // webstatic-sea.hoyoverse.com + javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse()); + + javalin.get("/status/server", GenericHandler::serverStatus); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/handlers/LogHandler.java b/src/main/java/emu/grasscutter/server/http/handlers/LogHandler.java index ab4c5b125..57e3a8fb8 100644 --- a/src/main/java/emu/grasscutter/server/http/handlers/LogHandler.java +++ b/src/main/java/emu/grasscutter/server/http/handlers/LogHandler.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.http.handlers; - -import emu.grasscutter.server.http.Router; -import io.javalin.Javalin; -import io.javalin.http.Context; - -/** Handles logging requests made to the server. */ -public final class LogHandler implements Router { - private static void log(Context ctx) { - // TODO: Figure out how to dump request body and log to file. - ctx.result("{\"code\":0}"); - } - - @Override - public void applyRoutes(Javalin javalin) { - // overseauspider.yuanshen.com - javalin.post("/log", LogHandler::log); - // log-upload-os.mihoyo.com - javalin.post("/crash/dataUpload", LogHandler::log); - } -} +package emu.grasscutter.server.http.handlers; + +import emu.grasscutter.server.http.Router; +import io.javalin.Javalin; +import io.javalin.http.Context; + +/** Handles logging requests made to the server. */ +public final class LogHandler implements Router { + private static void log(Context ctx) { + // TODO: Figure out how to dump request body and log to file. + ctx.result("{\"code\":0}"); + } + + @Override + public void applyRoutes(Javalin javalin) { + // overseauspider.yuanshen.com + javalin.post("/log", LogHandler::log); + // log-upload-os.mihoyo.com + javalin.post("/crash/dataUpload", LogHandler::log); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenReqJson.java b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenReqJson.java index 4f371c2da..07cde5906 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenReqJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenReqJson.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.http.objects; - -public class ComboTokenReqJson { - public int app_id; - public int channel_id; - public String data; - public String device; - public String sign; - - public static class LoginTokenData { - public String uid; - public String token; - public boolean guest; - } -} +package emu.grasscutter.server.http.objects; + +public class ComboTokenReqJson { + public int app_id; + public int channel_id; + public String data; + public String device; + public String sign; + + public static class LoginTokenData { + public String uid; + public String token; + public boolean guest; + } +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java index 03dad809e..c229a1e19 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/ComboTokenResJson.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.http.objects; - -public class ComboTokenResJson { - public String message; - public int retcode; - public LoginData data = new LoginData(); - - public static class LoginData { - public int account_type = 1; - public boolean heartbeat; - public String combo_id; - public String combo_token; - public String open_id; - public String data = "{\"guest\":false}"; - public String fatigue_remind = null; // ? - } -} +package emu.grasscutter.server.http.objects; + +public class ComboTokenResJson { + public String message; + public int retcode; + public LoginData data = new LoginData(); + + public static class LoginData { + public int account_type = 1; + public boolean heartbeat; + public String combo_id; + public String combo_token; + public String open_id; + public String data = "{\"guest\":false}"; + public String fatigue_remind = null; // ? + } +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java b/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java index 757f34b7c..e0dd7ad92 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java +++ b/src/main/java/emu/grasscutter/server/http/objects/HttpJsonResponse.java @@ -1,52 +1,52 @@ -package emu.grasscutter.server.http.objects; - -import static emu.grasscutter.config.Configuration.DISPATCH_INFO; -import static emu.grasscutter.utils.Language.translate; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.Grasscutter.ServerDebugMode; -import io.javalin.http.Context; -import io.javalin.http.Handler; -import java.util.Arrays; -import java.util.Objects; -import org.jetbrains.annotations.NotNull; - -public final class HttpJsonResponse implements Handler { - private final String response; - private final String[] - missingRoutes = { // TODO: When http requests for theses routes are found please remove it - // from this list and update the route request type in the DispatchServer - "/common/hk4e_global/announcement/api/getAlertPic", - "/common/hk4e_global/announcement/api/getAlertAnn", - "/common/hk4e_global/announcement/api/getAnnList", - "/common/hk4e_global/announcement/api/getAnnContent", - "/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", - "/log/sdk/upload", - "/sdk/upload", - "/perf/config/verify", - "/log", - "/crash/dataUpload" - }; - - public HttpJsonResponse(String response) { - this.response = response; - } - - @Override - public void handle(@NotNull Context ctx) throws Exception { - // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled - if (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING - && Arrays.stream(missingRoutes) - .anyMatch(x -> Objects.equals(x, ctx.endpointHandlerPath()))) { - Grasscutter.getLogger() - .info( - translate( - "messages.dispatch.request", - ctx.ip(), - ctx.method(), - ctx.endpointHandlerPath()) - + (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING ? "(MISSING)" : "")); - } - ctx.result(response); - } -} +package emu.grasscutter.server.http.objects; + +import static emu.grasscutter.config.Configuration.DISPATCH_INFO; +import static emu.grasscutter.utils.Language.translate; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.Grasscutter.ServerDebugMode; +import io.javalin.http.Context; +import io.javalin.http.Handler; +import java.util.Arrays; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; + +public final class HttpJsonResponse implements Handler { + private final String response; + private final String[] + missingRoutes = { // TODO: When http requests for theses routes are found please remove it + // from this list and update the route request type in the DispatchServer + "/common/hk4e_global/announcement/api/getAlertPic", + "/common/hk4e_global/announcement/api/getAlertAnn", + "/common/hk4e_global/announcement/api/getAnnList", + "/common/hk4e_global/announcement/api/getAnnContent", + "/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier", + "/log/sdk/upload", + "/sdk/upload", + "/perf/config/verify", + "/log", + "/crash/dataUpload" + }; + + public HttpJsonResponse(String response) { + this.response = response; + } + + @Override + public void handle(@NotNull Context ctx) throws Exception { + // Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled + if (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING + && Arrays.stream(missingRoutes) + .anyMatch(x -> Objects.equals(x, ctx.endpointHandlerPath()))) { + Grasscutter.getLogger() + .info( + translate( + "messages.dispatch.request", + ctx.ip(), + ctx.method(), + ctx.endpointHandlerPath()) + + (DISPATCH_INFO.logRequests == ServerDebugMode.MISSING ? "(MISSING)" : "")); + } + ctx.result(response); + } +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/LoginAccountRequestJson.java b/src/main/java/emu/grasscutter/server/http/objects/LoginAccountRequestJson.java index 8e71cf02a..d0bd1c143 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/LoginAccountRequestJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/LoginAccountRequestJson.java @@ -1,7 +1,7 @@ -package emu.grasscutter.server.http.objects; - -public class LoginAccountRequestJson { - public String account; - public String password; - public boolean is_crypto; -} +package emu.grasscutter.server.http.objects; + +public class LoginAccountRequestJson { + public String account; + public String password; + public boolean is_crypto; +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java b/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java index dd6fdd1cf..0557c9c05 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/LoginResultJson.java @@ -1,38 +1,38 @@ -package emu.grasscutter.server.http.objects; - -public class LoginResultJson { - public String message; - public int retcode; - public VerifyData data = new VerifyData(); - - public static class VerifyData { - public VerifyAccountData account = new VerifyAccountData(); - public boolean device_grant_required = false; - public String realname_operation = "NONE"; - public boolean realperson_required = false; - public boolean safe_mobile_required = false; - } - - public static class VerifyAccountData { - public String uid; - public String name = ""; - public String email = ""; - public String mobile = ""; - public String is_email_verify = "0"; - public String realname = ""; - public String identity_card = ""; - public String token; - public String safe_mobile = ""; - public String facebook_name = ""; - public String twitter_name = ""; - public String game_center_name = ""; - public String google_name = ""; - public String apple_name = ""; - public String sony_name = ""; - public String tap_name = ""; - public String country = "US"; - public String reactivate_ticket = ""; - public String area_code = "**"; - public String device_grant_ticket = ""; - } -} +package emu.grasscutter.server.http.objects; + +public class LoginResultJson { + public String message; + public int retcode; + public VerifyData data = new VerifyData(); + + public static class VerifyData { + public VerifyAccountData account = new VerifyAccountData(); + public boolean device_grant_required = false; + public String realname_operation = "NONE"; + public boolean realperson_required = false; + public boolean safe_mobile_required = false; + } + + public static class VerifyAccountData { + public String uid; + public String name = ""; + public String email = ""; + public String mobile = ""; + public String is_email_verify = "0"; + public String realname = ""; + public String identity_card = ""; + public String token; + public String safe_mobile = ""; + public String facebook_name = ""; + public String twitter_name = ""; + public String game_center_name = ""; + public String google_name = ""; + public String apple_name = ""; + public String sony_name = ""; + public String tap_name = ""; + public String country = "US"; + public String reactivate_ticket = ""; + public String area_code = "**"; + public String device_grant_ticket = ""; + } +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/LoginTokenRequestJson.java b/src/main/java/emu/grasscutter/server/http/objects/LoginTokenRequestJson.java index 216c86bfe..2ab624d9e 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/LoginTokenRequestJson.java +++ b/src/main/java/emu/grasscutter/server/http/objects/LoginTokenRequestJson.java @@ -1,6 +1,6 @@ -package emu.grasscutter.server.http.objects; - -public class LoginTokenRequestJson { - public String uid; - public String token; -} +package emu.grasscutter.server.http.objects; + +public class LoginTokenRequestJson { + public String uid; + public String token; +} diff --git a/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java b/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java index 4ef451c50..9195affdd 100644 --- a/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java +++ b/src/main/java/emu/grasscutter/server/http/objects/WebStaticVersionResponse.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.http.objects; - -import static emu.grasscutter.config.Configuration.DISPATCH_INFO; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.utils.FileUtils; -import io.javalin.http.ContentType; -import io.javalin.http.Context; -import io.javalin.http.Handler; -import java.io.IOException; -import java.io.InputStream; - -public class WebStaticVersionResponse implements Handler { - - private static void getPageResources(String path, Context ctx) { - try (InputStream filestream = FileUtils.readResourceAsStream(path)) { - ContentType fromExtension = - ContentType.getContentTypeByExtension(path.substring(path.lastIndexOf(".") + 1)); - ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM); - ctx.result(filestream.readAllBytes()); - } catch (Exception e) { - if (DISPATCH_INFO.logRequests == Grasscutter.ServerDebugMode.MISSING) { - Grasscutter.getLogger().warn("Webstatic File Missing: " + path); - } - ctx.status(404); - } - } - - @Override - public void handle(Context ctx) throws IOException { - String requestFor = ctx.path().substring(ctx.path().lastIndexOf("-") + 1); - - getPageResources("/webstatic/" + requestFor, ctx); - } -} +package emu.grasscutter.server.http.objects; + +import static emu.grasscutter.config.Configuration.DISPATCH_INFO; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.utils.FileUtils; +import io.javalin.http.ContentType; +import io.javalin.http.Context; +import io.javalin.http.Handler; +import java.io.IOException; +import java.io.InputStream; + +public class WebStaticVersionResponse implements Handler { + + private static void getPageResources(String path, Context ctx) { + try (InputStream filestream = FileUtils.readResourceAsStream(path)) { + ContentType fromExtension = + ContentType.getContentTypeByExtension(path.substring(path.lastIndexOf(".") + 1)); + ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM); + ctx.result(filestream.readAllBytes()); + } catch (Exception e) { + if (DISPATCH_INFO.logRequests == Grasscutter.ServerDebugMode.MISSING) { + Grasscutter.getLogger().warn("Webstatic File Missing: " + path); + } + ctx.status(404); + } + } + + @Override + public void handle(Context ctx) throws IOException { + String requestFor = ctx.path().substring(ctx.path().lastIndexOf("-") + 1); + + getPageResources("/webstatic/" + requestFor, ctx); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/Handler.java b/src/main/java/emu/grasscutter/server/packet/recv/Handler.java index 2ed64a1aa..a269e01cd 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/Handler.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/Handler.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.NONE) -public class Handler extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.NONE) +public class Handler extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAbilityInvocationsNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAbilityInvocationsNotify.java index ada634c55..29581d41b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAbilityInvocationsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAbilityInvocationsNotify.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityInvocationsNotifyOuterClass.AbilityInvocationsNotify; -import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AbilityInvocationsNotify) -public class HandlerAbilityInvocationsNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AbilityInvocationsNotify notif = AbilityInvocationsNotify.parseFrom(payload); - - Player player = session.getPlayer(); - for (AbilityInvokeEntry entry : notif.getInvokesList()) { - player.getAbilityManager().onAbilityInvoke(entry); - player.getAbilityInvokeHandler().addEntry(entry.getForwardType(), entry); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityInvocationsNotifyOuterClass.AbilityInvocationsNotify; +import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AbilityInvocationsNotify) +public class HandlerAbilityInvocationsNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AbilityInvocationsNotify notif = AbilityInvocationsNotify.parseFrom(payload); + + Player player = session.getPlayer(); + for (AbilityInvokeEntry entry : notif.getInvokesList()) { + player.getAbilityManager().onAbilityInvoke(entry); + player.getAbilityInvokeHandler().addEntry(entry.getForwardType(), entry); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerActivityTakeWatcherRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerActivityTakeWatcherRewardReq.java index 8bc92ee45..ddc9ebded 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerActivityTakeWatcherRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerActivityTakeWatcherRewardReq.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityTakeWatcherRewardReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketActivityTakeWatcherRewardRsp; -import java.util.Optional; - -@Opcodes(PacketOpcodes.ActivityTakeWatcherRewardReq) -public class HandlerActivityTakeWatcherRewardReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - ActivityTakeWatcherRewardReqOuterClass.ActivityTakeWatcherRewardReq.parseFrom(payload); - - Optional.ofNullable( - session - .getPlayer() - .getActivityManager() - .getPlayerActivityDataMap() - .get(req.getActivityId())) - .ifPresent(x -> x.takeWatcherReward(req.getWatcherId())); - - session.send(new PacketActivityTakeWatcherRewardRsp(req.getActivityId(), req.getWatcherId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityTakeWatcherRewardReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketActivityTakeWatcherRewardRsp; +import java.util.Optional; + +@Opcodes(PacketOpcodes.ActivityTakeWatcherRewardReq) +public class HandlerActivityTakeWatcherRewardReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + ActivityTakeWatcherRewardReqOuterClass.ActivityTakeWatcherRewardReq.parseFrom(payload); + + Optional.ofNullable( + session + .getPlayer() + .getActivityManager() + .getPlayerActivityDataMap() + .get(req.getActivityId())) + .ifPresent(x -> x.takeWatcherReward(req.getWatcherId())); + + session.send(new PacketActivityTakeWatcherRewardRsp(req.getActivityId(), req.getWatcherId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddBackupAvatarTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddBackupAvatarTeamReq.java index cae92aca0..ca481971c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddBackupAvatarTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAddBackupAvatarTeamReq.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AddBackupAvatarTeamReq) -public class HandlerAddBackupAvatarTeamReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getTeamManager().addNewCustomTeam(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AddBackupAvatarTeamReq) +public class HandlerAddBackupAvatarTeamReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getTeamManager().addNewCustomTeam(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAskAddFriendReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAskAddFriendReq.java index 4354d57d7..8a5989c88 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAskAddFriendReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAskAddFriendReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AskAddFriendReqOuterClass.AskAddFriendReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AskAddFriendReq) -public class HandlerAskAddFriendReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AskAddFriendReq req = AskAddFriendReq.parseFrom(payload); - - session.getPlayer().getFriendsList().sendFriendRequest(req.getTargetUid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AskAddFriendReqOuterClass.AskAddFriendReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AskAddFriendReq) +public class HandlerAskAddFriendReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AskAddFriendReq req = AskAddFriendReq.parseFrom(payload); + + session.getPlayer().getFriendsList().sendFriendRequest(req.getTargetUid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeCostumeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeCostumeReq.java index 89530ba85..d0f3d00ac 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeCostumeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarChangeCostumeReq.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarChangeCostumeReqOuterClass.AvatarChangeCostumeReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeRsp; - -@Opcodes(PacketOpcodes.AvatarChangeCostumeReq) -public class HandlerAvatarChangeCostumeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarChangeCostumeReq req = AvatarChangeCostumeReq.parseFrom(payload); - - boolean success = - session.getPlayer().getAvatars().changeCostume(req.getAvatarGuid(), req.getCostumeId()); - - if (success) { - session - .getPlayer() - .sendPacket(new PacketAvatarChangeCostumeRsp(req.getAvatarGuid(), req.getCostumeId())); - } else { - session.getPlayer().sendPacket(new PacketAvatarChangeCostumeRsp()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarChangeCostumeReqOuterClass.AvatarChangeCostumeReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeRsp; + +@Opcodes(PacketOpcodes.AvatarChangeCostumeReq) +public class HandlerAvatarChangeCostumeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarChangeCostumeReq req = AvatarChangeCostumeReq.parseFrom(payload); + + boolean success = + session.getPlayer().getAvatars().changeCostume(req.getAvatarGuid(), req.getCostumeId()); + + if (success) { + session + .getPlayer() + .sendPacket(new PacketAvatarChangeCostumeRsp(req.getAvatarGuid(), req.getCostumeId())); + } else { + session.getPlayer().sendPacket(new PacketAvatarChangeCostumeRsp()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarDieAnimationEndReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarDieAnimationEndReq.java index 19a972aad..bfa4f0538 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarDieAnimationEndReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarDieAnimationEndReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarDieAnimationEndReqOuterClass.AvatarDieAnimationEndReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AvatarDieAnimationEndReq) -public class HandlerAvatarDieAnimationEndReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarDieAnimationEndReq req = AvatarDieAnimationEndReq.parseFrom(payload); - - session.getPlayer().getTeamManager().onAvatarDie(req.getDieGuid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarDieAnimationEndReqOuterClass.AvatarDieAnimationEndReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AvatarDieAnimationEndReq) +public class HandlerAvatarDieAnimationEndReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarDieAnimationEndReq req = AvatarDieAnimationEndReq.parseFrom(payload); + + session.getPlayer().getTeamManager().onAvatarDie(req.getDieGuid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java index ee01a564b..1b3ce6789 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionAllDataReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarExpeditionAllDataRsp; - -@Opcodes(PacketOpcodes.AvatarExpeditionAllDataReq) -public class HandlerAvatarExpeditionAllDataReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var player = session.getPlayer(); - session.send( - new PacketAvatarExpeditionAllDataRsp( - player.getExpeditionInfo(), player.getExpeditionLimit())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionAllDataRsp; + +@Opcodes(PacketOpcodes.AvatarExpeditionAllDataReq) +public class HandlerAvatarExpeditionAllDataReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var player = session.getPlayer(); + session.send( + new PacketAvatarExpeditionAllDataRsp( + player.getExpeditionInfo(), player.getExpeditionLimit())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java index e6df45fa4..521cbd251 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarExpeditionGetRewardReq.java @@ -1,47 +1,47 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.game.expedition.ExpeditionRewardDataList; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionGetRewardReqOuterClass.AvatarExpeditionGetRewardReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarExpeditionGetRewardRsp; -import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; -import java.util.ArrayList; -import java.util.List; - -@Opcodes(PacketOpcodes.AvatarExpeditionGetRewardReq) -public class HandlerAvatarExpeditionGetRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarExpeditionGetRewardReq req = AvatarExpeditionGetRewardReq.parseFrom(payload); - var player = session.getPlayer(); - - ExpeditionInfo expInfo = player.getExpeditionInfo(req.getAvatarGuid()); - List items = new ArrayList<>(); - List expeditionRewardDataLists = - session - .getServer() - .getExpeditionSystem() - .getExpeditionRewardDataList() - .get(expInfo.getExpId()); - - if (expeditionRewardDataLists != null) { - expeditionRewardDataLists.stream() - .filter(r -> r.getHourTime() == expInfo.getHourTime()) - .map(ExpeditionRewardDataList::getRewards) - .forEach(items::addAll); - } - - player.getInventory().addItems(items); - player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward)); - - player.removeExpeditionInfo(req.getAvatarGuid()); - player.save(); - session.send(new PacketAvatarExpeditionGetRewardRsp(player.getExpeditionInfo(), items)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.expedition.ExpeditionRewardDataList; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionGetRewardReqOuterClass.AvatarExpeditionGetRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarExpeditionGetRewardRsp; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; +import java.util.ArrayList; +import java.util.List; + +@Opcodes(PacketOpcodes.AvatarExpeditionGetRewardReq) +public class HandlerAvatarExpeditionGetRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarExpeditionGetRewardReq req = AvatarExpeditionGetRewardReq.parseFrom(payload); + var player = session.getPlayer(); + + ExpeditionInfo expInfo = player.getExpeditionInfo(req.getAvatarGuid()); + List items = new ArrayList<>(); + List expeditionRewardDataLists = + session + .getServer() + .getExpeditionSystem() + .getExpeditionRewardDataList() + .get(expInfo.getExpId()); + + if (expeditionRewardDataLists != null) { + expeditionRewardDataLists.stream() + .filter(r -> r.getHourTime() == expInfo.getHourTime()) + .map(ExpeditionRewardDataList::getRewards) + .forEach(items::addAll); + } + + player.getInventory().addItems(items); + player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.ExpeditionReward)); + + player.removeExpeditionInfo(req.getAvatarGuid()); + player.save(); + session.send(new PacketAvatarExpeditionGetRewardRsp(player.getExpeditionInfo(), items)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java index 34237acc9..8243f8b26 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java @@ -1,55 +1,55 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.RewardData; -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarDataNotify; -import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; -import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; -import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; - -@Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) -public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarFetterLevelRewardReq req = AvatarFetterLevelRewardReq.parseFrom(payload); - if (req.getFetterLevel() < 10) { - // You don't have a full level of fetter level, why do you want to get a divorce certificate? - session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); - } else { - long avatarGuid = req.getAvatarGuid(); - - Avatar avatar = session.getPlayer().getAvatars().getAvatarByGuid(avatarGuid); - - int rewardId = avatar.getNameCardRewardId(); - - RewardData card = GameData.getRewardDataMap().get(rewardId); - int cardId = card.getRewardItemList().get(0).getItemId(); - - if (session.getPlayer().getNameCardList().contains(cardId)) { - // Already got divorce certificate. - session - .getPlayer() - .sendPacket( - new PacketAvatarFetterLevelRewardRsp( - req.getAvatarGuid(), req.getFetterLevel(), rewardId)); - return; - } - - GameItem item = new GameItem(cardId); - session.getPlayer().getInventory().addItem(item, ActionReason.FetterLevelReward); - session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); - session.send(new PacketAvatarFetterDataNotify(avatar)); - session.send(new PacketAvatarDataNotify(avatar.getPlayer())); - session.send( - new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.excels.RewardData; +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardReqOuterClass.AvatarFetterLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarDataNotify; +import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; +import emu.grasscutter.server.packet.send.PacketAvatarFetterLevelRewardRsp; +import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify; + +@Opcodes(PacketOpcodes.AvatarFetterLevelRewardReq) +public class HandlerAvatarFetterLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarFetterLevelRewardReq req = AvatarFetterLevelRewardReq.parseFrom(payload); + if (req.getFetterLevel() < 10) { + // You don't have a full level of fetter level, why do you want to get a divorce certificate? + session.send(new PacketAvatarFetterLevelRewardRsp(req.getAvatarGuid(), req.getFetterLevel())); + } else { + long avatarGuid = req.getAvatarGuid(); + + Avatar avatar = session.getPlayer().getAvatars().getAvatarByGuid(avatarGuid); + + int rewardId = avatar.getNameCardRewardId(); + + RewardData card = GameData.getRewardDataMap().get(rewardId); + int cardId = card.getRewardItemList().get(0).getItemId(); + + if (session.getPlayer().getNameCardList().contains(cardId)) { + // Already got divorce certificate. + session + .getPlayer() + .sendPacket( + new PacketAvatarFetterLevelRewardRsp( + req.getAvatarGuid(), req.getFetterLevel(), rewardId)); + return; + } + + GameItem item = new GameItem(cardId); + session.getPlayer().getInventory().addItem(item, ActionReason.FetterLevelReward); + session.getPlayer().sendPacket(new PacketUnlockNameCardNotify(cardId)); + session.send(new PacketAvatarFetterDataNotify(avatar)); + session.send(new PacketAvatarDataNotify(avatar.getPlayer())); + session.send( + new PacketAvatarFetterLevelRewardRsp(avatarGuid, req.getFetterLevel(), rewardId)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarPromoteReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarPromoteReq.java index 1cb3d9df3..6d0f38c2c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarPromoteReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarPromoteReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarPromoteReqOuterClass.AvatarPromoteReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AvatarPromoteReq) -public class HandlerAvatarPromoteReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarPromoteReq req = AvatarPromoteReq.parseFrom(payload); - - // Ascend avatar - session.getServer().getInventorySystem().promoteAvatar(session.getPlayer(), req.getGuid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarPromoteReqOuterClass.AvatarPromoteReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AvatarPromoteReq) +public class HandlerAvatarPromoteReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarPromoteReq req = AvatarPromoteReq.parseFrom(payload); + + // Ascend avatar + session.getServer().getInventorySystem().promoteAvatar(session.getPlayer(), req.getGuid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarSkillUpgradeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarSkillUpgradeReq.java index c0655b980..9cc09e771 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarSkillUpgradeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarSkillUpgradeReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillUpgradeReqOuterClass.AvatarSkillUpgradeReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AvatarSkillUpgradeReq) -public class HandlerAvatarSkillUpgradeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarSkillUpgradeReq req = AvatarSkillUpgradeReq.parseFrom(payload); - - // Sanity checks - var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid()); - if (avatar == null) return; - // Level up avatar talent - avatar.upgradeSkill(req.getAvatarSkillId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillUpgradeReqOuterClass.AvatarSkillUpgradeReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AvatarSkillUpgradeReq) +public class HandlerAvatarSkillUpgradeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarSkillUpgradeReq req = AvatarSkillUpgradeReq.parseFrom(payload); + + // Sanity checks + var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid()); + if (avatar == null) return; + // Level up avatar talent + avatar.upgradeSkill(req.getAvatarSkillId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarUpgradeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarUpgradeReq.java index 7e509a00a..f8fa2596e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarUpgradeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarUpgradeReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarUpgradeReqOuterClass.AvatarUpgradeReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.AvatarUpgradeReq) -public class HandlerAvatarUpgradeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarUpgradeReq req = AvatarUpgradeReq.parseFrom(payload); - - // Level up avatar - session - .getServer() - .getInventorySystem() - .upgradeAvatar(session.getPlayer(), req.getAvatarGuid(), req.getItemId(), req.getCount()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarUpgradeReqOuterClass.AvatarUpgradeReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.AvatarUpgradeReq) +public class HandlerAvatarUpgradeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarUpgradeReq req = AvatarUpgradeReq.parseFrom(payload); + + // Level up avatar + session + .getServer() + .getInventorySystem() + .upgradeAvatar(session.getPlayer(), req.getAvatarGuid(), req.getItemId(), req.getCount()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarWearFlycloakReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarWearFlycloakReq.java index cb02e4b83..794dd06d8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarWearFlycloakReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarWearFlycloakReq.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarWearFlycloakReqOuterClass.AvatarWearFlycloakReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarWearFlycloakRsp; - -@Opcodes(PacketOpcodes.AvatarWearFlycloakReq) -public class HandlerAvatarWearFlycloakReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - AvatarWearFlycloakReq req = AvatarWearFlycloakReq.parseFrom(payload); - - boolean success = - session.getPlayer().getAvatars().wearFlycloak(req.getAvatarGuid(), req.getFlycloakId()); - - if (success) { - session - .getPlayer() - .sendPacket(new PacketAvatarWearFlycloakRsp(req.getAvatarGuid(), req.getFlycloakId())); - } else { - session.getPlayer().sendPacket(new PacketAvatarWearFlycloakRsp()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarWearFlycloakReqOuterClass.AvatarWearFlycloakReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarWearFlycloakRsp; + +@Opcodes(PacketOpcodes.AvatarWearFlycloakReq) +public class HandlerAvatarWearFlycloakReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + AvatarWearFlycloakReq req = AvatarWearFlycloakReq.parseFrom(payload); + + boolean success = + session.getPlayer().getAvatars().wearFlycloak(req.getAvatarGuid(), req.getFlycloakId()); + + if (success) { + session + .getPlayer() + .sendPacket(new PacketAvatarWearFlycloakRsp(req.getAvatarGuid(), req.getFlycloakId())); + } else { + session.getPlayer().sendPacket(new PacketAvatarWearFlycloakRsp()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBackMyWorldReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBackMyWorldReq.java index 8ce17741e..6b1b7c58a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBackMyWorldReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBackMyWorldReq.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketBackMyWorldRsp; - -@Opcodes(PacketOpcodes.BackMyWorldReq) -public class HandlerBackMyWorldReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - Scene scene = session.getPlayer().getScene(); - int prevScene = scene.getPrevScene(); - - // Sanity check for switching between teapot realms - if (prevScene >= 2000 && prevScene <= 2400) { - prevScene = 3; - } - - session - .getPlayer() - .getWorld() - .transferPlayerToScene( - session.getPlayer(), - prevScene, - TeleportType.WAYPOINT, - session.getPlayer().getPrevPos()); - - session.send(new PacketBackMyWorldRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketBackMyWorldRsp; + +@Opcodes(PacketOpcodes.BackMyWorldReq) +public class HandlerBackMyWorldReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + Scene scene = session.getPlayer().getScene(); + int prevScene = scene.getPrevScene(); + + // Sanity check for switching between teapot realms + if (prevScene >= 2000 && prevScene <= 2400) { + prevScene = 3; + } + + session + .getPlayer() + .getWorld() + .transferPlayerToScene( + session.getPlayer(), + prevScene, + TeleportType.WAYPOINT, + session.getPlayer().getPrevPos()); + + session.send(new PacketBackMyWorldRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyBattlePassLevelReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyBattlePassLevelReq.java index cc8240fe3..c57315a9b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyBattlePassLevelReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyBattlePassLevelReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BuyBattlePassLevelReqOuterClass.BuyBattlePassLevelReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketBuyBattlePassLevelRsp; - -@Opcodes(PacketOpcodes.BuyBattlePassLevelReq) -public class HandlerBuyBattlePassLevelReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - BuyBattlePassLevelReq req = BuyBattlePassLevelReq.parseFrom(payload); - - int buyLevel = session.getPlayer().getBattlePassManager().buyLevels(req.getBuyLevel()); - - session.send(new PacketBuyBattlePassLevelRsp(buyLevel)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BuyBattlePassLevelReqOuterClass.BuyBattlePassLevelReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketBuyBattlePassLevelRsp; + +@Opcodes(PacketOpcodes.BuyBattlePassLevelReq) +public class HandlerBuyBattlePassLevelReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + BuyBattlePassLevelReq req = BuyBattlePassLevelReq.parseFrom(payload); + + int buyLevel = session.getPlayer().getBattlePassManager().buyLevels(req.getBuyLevel()); + + session.send(new PacketBuyBattlePassLevelRsp(buyLevel)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java index 4a177a642..ed056d037 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java @@ -1,87 +1,87 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.game.shop.ShopInfo; -import emu.grasscutter.game.shop.ShopLimit; -import emu.grasscutter.game.shop.ShopSystem; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BuyGoodsReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp; -import emu.grasscutter.utils.Utils; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -@Opcodes(PacketOpcodes.BuyGoodsReq) -public class HandlerBuyGoodsReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - BuyGoodsReqOuterClass.BuyGoodsReq buyGoodsReq = - BuyGoodsReqOuterClass.BuyGoodsReq.parseFrom(payload); - List configShop = - session.getServer().getShopSystem().getShopData().get(buyGoodsReq.getShopType()); - if (configShop == null) return; - - // Don't trust your users' input - var player = session.getPlayer(); - List targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId()); - for (int goodsId : targetShopGoodsId) { - Optional sg2 = - configShop.stream().filter(x -> x.getGoodsId() == goodsId).findFirst(); - if (sg2.isEmpty()) continue; - ShopInfo sg = sg2.get(); - - int currentTs = Utils.getCurrentSeconds(); - ShopLimit shopLimit = player.getGoodsLimit(sg.getGoodsId()); - int bought = 0; - if (shopLimit != null) { - if (currentTs > shopLimit.getNextRefreshTime()) { - shopLimit.setNextRefreshTime(ShopSystem.getShopNextRefreshTime(sg)); - } else { - bought = shopLimit.getHasBoughtInPeriod(); - } - player.save(); - } - - if ((bought + buyGoodsReq.getBuyCount() > sg.getBuyLimit()) && sg.getBuyLimit() != 0) { - return; - } - - List costs = - new ArrayList(sg.getCostItemList()); // Can this even be null? - costs.add(new ItemParamData(202, sg.getScoin())); - costs.add(new ItemParamData(201, sg.getHcoin())); - costs.add(new ItemParamData(203, sg.getMcoin())); - if (!player.getInventory().payItems(costs, buyGoodsReq.getBuyCount())) { - return; - } - - player.addShopLimit( - sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg)); - GameItem item = - new GameItem( - sg.getGoodsItem().getId(), buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount()); - player - .getInventory() - .addItem( - item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop - session.send( - new PacketBuyGoodsRsp( - buyGoodsReq.getShopType(), - player.getGoodsLimit(sg.getGoodsId()).getHasBoughtInPeriod(), - Stream.of(buyGoodsReq.getGoods()) - .filter(x -> x.getGoodsId() == goodsId) - .findFirst() - .get())); - } - - player.save(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.shop.ShopInfo; +import emu.grasscutter.game.shop.ShopLimit; +import emu.grasscutter.game.shop.ShopSystem; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BuyGoodsReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp; +import emu.grasscutter.utils.Utils; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +@Opcodes(PacketOpcodes.BuyGoodsReq) +public class HandlerBuyGoodsReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + BuyGoodsReqOuterClass.BuyGoodsReq buyGoodsReq = + BuyGoodsReqOuterClass.BuyGoodsReq.parseFrom(payload); + List configShop = + session.getServer().getShopSystem().getShopData().get(buyGoodsReq.getShopType()); + if (configShop == null) return; + + // Don't trust your users' input + var player = session.getPlayer(); + List targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId()); + for (int goodsId : targetShopGoodsId) { + Optional sg2 = + configShop.stream().filter(x -> x.getGoodsId() == goodsId).findFirst(); + if (sg2.isEmpty()) continue; + ShopInfo sg = sg2.get(); + + int currentTs = Utils.getCurrentSeconds(); + ShopLimit shopLimit = player.getGoodsLimit(sg.getGoodsId()); + int bought = 0; + if (shopLimit != null) { + if (currentTs > shopLimit.getNextRefreshTime()) { + shopLimit.setNextRefreshTime(ShopSystem.getShopNextRefreshTime(sg)); + } else { + bought = shopLimit.getHasBoughtInPeriod(); + } + player.save(); + } + + if ((bought + buyGoodsReq.getBuyCount() > sg.getBuyLimit()) && sg.getBuyLimit() != 0) { + return; + } + + List costs = + new ArrayList(sg.getCostItemList()); // Can this even be null? + costs.add(new ItemParamData(202, sg.getScoin())); + costs.add(new ItemParamData(201, sg.getHcoin())); + costs.add(new ItemParamData(203, sg.getMcoin())); + if (!player.getInventory().payItems(costs, buyGoodsReq.getBuyCount())) { + return; + } + + player.addShopLimit( + sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg)); + GameItem item = + new GameItem( + sg.getGoodsItem().getId(), buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount()); + player + .getInventory() + .addItem( + item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop + session.send( + new PacketBuyGoodsRsp( + buyGoodsReq.getShopType(), + player.getGoodsLimit(sg.getGoodsId()).getHasBoughtInPeriod(), + Stream.of(buyGoodsReq.getGoods()) + .filter(x -> x.getGoodsId() == goodsId) + .findFirst() + .get())); + } + + player.save(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCalcWeaponUpgradeReturnItemsReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCalcWeaponUpgradeReturnItemsReq.java index 531cea93f..8bccf2341 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCalcWeaponUpgradeReturnItemsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCalcWeaponUpgradeReturnItemsReq.java @@ -1,36 +1,36 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CalcWeaponUpgradeReturnItemsReqOuterClass.CalcWeaponUpgradeReturnItemsReq; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketCalcWeaponUpgradeReturnItemsRsp; -import java.util.List; - -@Opcodes(PacketOpcodes.CalcWeaponUpgradeReturnItemsReq) -public class HandlerCalcWeaponUpgradeReturnItemsReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - CalcWeaponUpgradeReturnItemsReq req = CalcWeaponUpgradeReturnItemsReq.parseFrom(payload); - - List returnOres = - session - .getServer() - .getInventorySystem() - .calcWeaponUpgradeReturnItems( - session.getPlayer(), - req.getTargetWeaponGuid(), - req.getFoodWeaponGuidListList(), - req.getItemParamListList()); - - if (returnOres != null) { - session.send( - new PacketCalcWeaponUpgradeReturnItemsRsp(req.getTargetWeaponGuid(), returnOres)); - } else { - session.send(new PacketCalcWeaponUpgradeReturnItemsRsp()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CalcWeaponUpgradeReturnItemsReqOuterClass.CalcWeaponUpgradeReturnItemsReq; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketCalcWeaponUpgradeReturnItemsRsp; +import java.util.List; + +@Opcodes(PacketOpcodes.CalcWeaponUpgradeReturnItemsReq) +public class HandlerCalcWeaponUpgradeReturnItemsReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + CalcWeaponUpgradeReturnItemsReq req = CalcWeaponUpgradeReturnItemsReq.parseFrom(payload); + + List returnOres = + session + .getServer() + .getInventorySystem() + .calcWeaponUpgradeReturnItems( + session.getPlayer(), + req.getTargetWeaponGuid(), + req.getFoodWeaponGuidListList(), + req.getItemParamListList()); + + if (returnOres != null) { + session.send( + new PacketCalcWeaponUpgradeReturnItemsRsp(req.getTargetWeaponGuid(), returnOres)); + } else { + session.send(new PacketCalcWeaponUpgradeReturnItemsRsp()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeAvatarReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeAvatarReq.java index 059630e9d..ff32a17b0 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeAvatarReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeAvatarReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeAvatarReqOuterClass.ChangeAvatarReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ChangeAvatarReq) -public class HandlerChangeAvatarReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChangeAvatarReq req = ChangeAvatarReq.parseFrom(payload); - - session.getPlayer().getTeamManager().changeAvatar(req.getGuid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeAvatarReqOuterClass.ChangeAvatarReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ChangeAvatarReq) +public class HandlerChangeAvatarReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChangeAvatarReq req = ChangeAvatarReq.parseFrom(payload); + + session.getPlayer().getTeamManager().changeAvatar(req.getGuid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java index 56e66f4c9..51264d738 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMailStarNotify.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.mail.Mail; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeMailStarNotifyOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketMailChangeNotify; -import java.util.ArrayList; -import java.util.List; - -@Opcodes(PacketOpcodes.ChangeMailStarNotify) -public class HandlerChangeMailStarNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChangeMailStarNotifyOuterClass.ChangeMailStarNotify req = - ChangeMailStarNotifyOuterClass.ChangeMailStarNotify.parseFrom(payload); - - List updatedMail = new ArrayList<>(); - - for (int mailId : req.getMailIdListList()) { - Mail message = session.getPlayer().getMail(mailId); - - message.importance = req.getIsStar() ? 1 : 0; - - session.getPlayer().replaceMailByIndex(mailId, message); - updatedMail.add(message); - } - - session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeMailStarNotifyOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMailChangeNotify; +import java.util.ArrayList; +import java.util.List; + +@Opcodes(PacketOpcodes.ChangeMailStarNotify) +public class HandlerChangeMailStarNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChangeMailStarNotifyOuterClass.ChangeMailStarNotify req = + ChangeMailStarNotifyOuterClass.ChangeMailStarNotify.parseFrom(payload); + + List updatedMail = new ArrayList<>(); + + for (int mailId : req.getMailIdListList()) { + Mail message = session.getPlayer().getMail(mailId); + + message.importance = req.getIsStar() ? 1 : 0; + + session.getPlayer().replaceMailByIndex(mailId, message); + updatedMail.add(message); + } + + session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMpTeamAvatarReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMpTeamAvatarReq.java index 99c3d1981..d5d18c1b1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMpTeamAvatarReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeMpTeamAvatarReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeMpTeamAvatarReqOuterClass.ChangeMpTeamAvatarReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ChangeMpTeamAvatarReq) -public class HandlerChangeMpTeamAvatarReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChangeMpTeamAvatarReq req = ChangeMpTeamAvatarReq.parseFrom(payload); - - session.getPlayer().getTeamManager().setupMpTeam(req.getAvatarGuidListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeMpTeamAvatarReqOuterClass.ChangeMpTeamAvatarReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ChangeMpTeamAvatarReq) +public class HandlerChangeMpTeamAvatarReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChangeMpTeamAvatarReq req = ChangeMpTeamAvatarReq.parseFrom(payload); + + session.getPlayer().getTeamManager().setupMpTeam(req.getAvatarGuidListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeTeamNameReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeTeamNameReq.java index 281a02ff0..186a55f60 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeTeamNameReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChangeTeamNameReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeTeamNameReqOuterClass.ChangeTeamNameReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ChangeTeamNameReq) -public class HandlerChangeTeamNameReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChangeTeamNameReq req = ChangeTeamNameReq.parseFrom(payload); - - session.getPlayer().getTeamManager().setTeamName(req.getTeamId(), req.getTeamName()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeTeamNameReqOuterClass.ChangeTeamNameReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ChangeTeamNameReq) +public class HandlerChangeTeamNameReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChangeTeamNameReq req = ChangeTeamNameReq.parseFrom(payload); + + session.getPlayer().getTeamManager().setTeamName(req.getTeamId(), req.getTeamName()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChooseCurAvatarTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChooseCurAvatarTeamReq.java index 264425554..2370f81ab 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerChooseCurAvatarTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerChooseCurAvatarTeamReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChooseCurAvatarTeamReqOuterClass.ChooseCurAvatarTeamReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ChooseCurAvatarTeamReq) -public class HandlerChooseCurAvatarTeamReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ChooseCurAvatarTeamReq req = ChooseCurAvatarTeamReq.parseFrom(payload); - - session.getPlayer().getTeamManager().setCurrentTeam(req.getTeamId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChooseCurAvatarTeamReqOuterClass.ChooseCurAvatarTeamReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ChooseCurAvatarTeamReq) +public class HandlerChooseCurAvatarTeamReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ChooseCurAvatarTeamReq req = ChooseCurAvatarTeamReq.parseFrom(payload); + + session.getPlayer().getTeamManager().setCurrentTeam(req.getTeamId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java index 23c5ab6da..fa534ac23 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerClientAbilityInitFinishNotify.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; -import emu.grasscutter.net.proto.ClientAbilityInitFinishNotifyOuterClass.ClientAbilityInitFinishNotify; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ClientAbilityInitFinishNotify) -public class HandlerClientAbilityInitFinishNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ClientAbilityInitFinishNotify notif = ClientAbilityInitFinishNotify.parseFrom(payload); - - Player player = session.getPlayer(); - - // Call skill end in the player's ability manager. - player.getAbilityManager().onSkillEnd(player); - - for (AbilityInvokeEntry entry : notif.getInvokesList()) { - player.getAbilityManager().onAbilityInvoke(entry); - player.getClientAbilityInitFinishHandler().addEntry(entry.getForwardType(), entry); - } - - if (notif.getInvokesList().size() > 0) { - session.getPlayer().getClientAbilityInitFinishHandler().update(session.getPlayer()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; +import emu.grasscutter.net.proto.ClientAbilityInitFinishNotifyOuterClass.ClientAbilityInitFinishNotify; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ClientAbilityInitFinishNotify) +public class HandlerClientAbilityInitFinishNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ClientAbilityInitFinishNotify notif = ClientAbilityInitFinishNotify.parseFrom(payload); + + Player player = session.getPlayer(); + + // Call skill end in the player's ability manager. + player.getAbilityManager().onSkillEnd(player); + + for (AbilityInvokeEntry entry : notif.getInvokesList()) { + player.getAbilityManager().onAbilityInvoke(entry); + player.getClientAbilityInitFinishHandler().addEntry(entry.getForwardType(), entry); + } + + if (notif.getInvokesList().size() > 0) { + session.getPlayer().getClientAbilityInitFinishHandler().update(session.getPlayer()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombineReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombineReq.java index 803c918eb..fa8bd96d3 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombineReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCombineReq.java @@ -1,52 +1,52 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CombineReqOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketCombineRsp; -import java.util.List; -import java.util.stream.Collectors; - -@Opcodes(PacketOpcodes.CombineReq) -public class HandlerCombineReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - CombineReqOuterClass.CombineReq req = CombineReqOuterClass.CombineReq.parseFrom(payload); - - var result = - session - .getServer() - .getCombineSystem() - .combineItem(session.getPlayer(), req.getCombineId(), req.getCombineCount()); - - if (result == null) { - return; - } - - session.send( - new PacketCombineRsp( - req, - toItemParamList(result.getMaterial()), - toItemParamList(result.getResult()), - toItemParamList(result.getExtra()), - toItemParamList(result.getBack()), - toItemParamList(result.getBack()))); - } - - private List toItemParamList(List list) { - return list.stream() - .map( - item -> - ItemParamOuterClass.ItemParam.newBuilder() - .setItemId(item.getId()) - .setCount(item.getCount()) - .build()) - .collect(Collectors.toList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CombineReqOuterClass; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketCombineRsp; +import java.util.List; +import java.util.stream.Collectors; + +@Opcodes(PacketOpcodes.CombineReq) +public class HandlerCombineReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + CombineReqOuterClass.CombineReq req = CombineReqOuterClass.CombineReq.parseFrom(payload); + + var result = + session + .getServer() + .getCombineSystem() + .combineItem(session.getPlayer(), req.getCombineId(), req.getCombineCount()); + + if (result == null) { + return; + } + + session.send( + new PacketCombineRsp( + req, + toItemParamList(result.getMaterial()), + toItemParamList(result.getResult()), + toItemParamList(result.getExtra()), + toItemParamList(result.getBack()), + toItemParamList(result.getBack()))); + } + + private List toItemParamList(List list) { + return list.stream() + .map( + item -> + ItemParamOuterClass.ItemParam.newBuilder() + .setItemId(item.getId()) + .setCount(item.getCount()) + .build()) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCreateVehicleReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCreateVehicleReq.java index 609d711cb..4d0c18857 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerCreateVehicleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerCreateVehicleReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CreateVehicleReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketCreateVehicleRsp; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.CreateVehicleReq) -public class HandlerCreateVehicleReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - CreateVehicleReqOuterClass.CreateVehicleReq req = - CreateVehicleReqOuterClass.CreateVehicleReq.parseFrom(payload); - session.send( - new PacketCreateVehicleRsp( - session.getPlayer(), - req.getVehicleId(), - req.getScenePointId(), - new Position(req.getPos()), - new Position(req.getRot()))); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CreateVehicleReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketCreateVehicleRsp; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.CreateVehicleReq) +public class HandlerCreateVehicleReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + CreateVehicleReqOuterClass.CreateVehicleReq req = + CreateVehicleReqOuterClass.CreateVehicleReq.parseFrom(payload); + session.send( + new PacketCreateVehicleRsp( + session.getPlayer(), + req.getVehicleId(), + req.getScenePointId(), + new Position(req.getPos()), + new Position(req.getRot()))); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDealAddFriendReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDealAddFriendReq.java index 0419f8167..393f85d06 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDealAddFriendReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDealAddFriendReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DealAddFriendReqOuterClass.DealAddFriendReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DealAddFriendReq) -public class HandlerDealAddFriendReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DealAddFriendReq req = DealAddFriendReq.parseFrom(payload); - - session - .getPlayer() - .getFriendsList() - .handleFriendRequest(req.getTargetUid(), req.getDealAddFriendResult()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DealAddFriendReqOuterClass.DealAddFriendReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DealAddFriendReq) +public class HandlerDealAddFriendReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DealAddFriendReq req = DealAddFriendReq.parseFrom(payload); + + session + .getPlayer() + .getFriendsList() + .handleFriendRequest(req.getTargetUid(), req.getDealAddFriendResult()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelBackupAvatarTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelBackupAvatarTeamReq.java index e4d1af26b..63362a1a2 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelBackupAvatarTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelBackupAvatarTeamReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DelBackupAvatarTeamReqOuterClass.DelBackupAvatarTeamReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DelBackupAvatarTeamReq) -public class HandlerDelBackupAvatarTeamReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DelBackupAvatarTeamReq req = DelBackupAvatarTeamReq.parseFrom(payload); - session.getPlayer().getTeamManager().removeCustomTeam(req.getBackupAvatarTeamId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DelBackupAvatarTeamReqOuterClass.DelBackupAvatarTeamReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DelBackupAvatarTeamReq) +public class HandlerDelBackupAvatarTeamReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DelBackupAvatarTeamReq req = DelBackupAvatarTeamReq.parseFrom(payload); + session.getPlayer().getTeamManager().removeCustomTeam(req.getBackupAvatarTeamId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelMailReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelMailReq.java index 3162e16a7..8843a9f93 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelMailReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDelMailReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DelMailReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DelMailReq) -public class HandlerDelMailReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DelMailReqOuterClass.DelMailReq req = DelMailReqOuterClass.DelMailReq.parseFrom(payload); - - session.getPlayer().getMailHandler().deleteMail(req.getMailIdListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DelMailReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DelMailReq) +public class HandlerDelMailReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DelMailReqOuterClass.DelMailReq req = DelMailReqOuterClass.DelMailReq.parseFrom(payload); + + session.getPlayer().getMailHandler().deleteMail(req.getMailIdListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDeleteFriendReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDeleteFriendReq.java index 84c960979..4b539ab34 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDeleteFriendReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDeleteFriendReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DeleteFriendReqOuterClass.DeleteFriendReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DeleteFriendReq) -public class HandlerDeleteFriendReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DeleteFriendReq req = DeleteFriendReq.parseFrom(payload); - - session.getPlayer().getFriendsList().deleteFriend(req.getTargetUid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DeleteFriendReqOuterClass.DeleteFriendReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DeleteFriendReq) +public class HandlerDeleteFriendReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DeleteFriendReq req = DeleteFriendReq.parseFrom(payload); + + session.getPlayer().getFriendsList().deleteFriend(req.getTargetUid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDestroyMaterialReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDestroyMaterialReq.java index 7089b5981..de89c5861 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDestroyMaterialReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDestroyMaterialReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DestroyMaterialReqOuterClass.DestroyMaterialReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DestroyMaterialReq) -public class HandlerDestroyMaterialReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DestroyMaterialReq req = DestroyMaterialReq.parseFrom(payload); - - // Delete items - session - .getServer() - .getInventorySystem() - .destroyMaterial(session.getPlayer(), req.getMaterialListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DestroyMaterialReqOuterClass.DestroyMaterialReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DestroyMaterialReq) +public class HandlerDestroyMaterialReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DestroyMaterialReq req = DestroyMaterialReq.parseFrom(payload); + + // Delete items + session + .getServer() + .getInventorySystem() + .destroyMaterial(session.getPlayer(), req.getMaterialListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDoGachaReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDoGachaReq.java index 7d4630201..d41599ddf 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerDoGachaReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerDoGachaReq.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DoGachaReqOuterClass.DoGachaReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.DoGachaReq) -public class HandlerDoGachaReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - DoGachaReq req = DoGachaReq.parseFrom(payload); - - session - .getServer() - .getGachaSystem() - .doPulls(session.getPlayer(), req.getGachaScheduleId(), req.getGachaTimes()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DoGachaReqOuterClass.DoGachaReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.DoGachaReq) +public class HandlerDoGachaReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + DoGachaReq req = DoGachaReq.parseFrom(payload); + + session + .getServer() + .getGachaSystem() + .doPulls(session.getPlayer(), req.getGachaScheduleId(), req.getGachaTimes()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java index 9e0156e1c..a1c82eaf1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java @@ -1,54 +1,54 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.player.Player.SceneLoadState; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.*; - -@Opcodes(PacketOpcodes.EnterSceneDoneReq) -public class HandlerEnterSceneDoneReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Finished loading - session.getPlayer().setSceneLoadState(SceneLoadState.LOADED); - - // Done - - session.send(new PacketPlayerTimeNotify(session.getPlayer())); // Probably not the right place - - // Spawn player in world - session.getPlayer().getScene().spawnPlayer(session.getPlayer()); - - // Spawn other entites already in world - session.getPlayer().getScene().showOtherEntities(session.getPlayer()); - - // Locations - session.send(new PacketWorldPlayerLocationNotify(session.getPlayer().getWorld())); - session.send(new PacketScenePlayerLocationNotify(session.getPlayer().getScene())); - session.send(new PacketWorldPlayerRTTNotify(session.getPlayer().getWorld())); - - // spawn NPC - session.getPlayer().getScene().loadNpcForPlayerEnter(session.getPlayer()); - - // notify client to load the npc for quest - var questGroupSuites = - session.getPlayer().getQuestManager().getSceneGroupSuite(session.getPlayer().getSceneId()); - - session.getPlayer().getScene().loadGroupForQuest(questGroupSuites); - Grasscutter.getLogger() - .debug( - "Loaded Scene {} Quest(s) Groupsuite(s): {}", - session.getPlayer().getSceneId(), - questGroupSuites); - session.send(new PacketGroupSuiteNotify(questGroupSuites)); - - // Reset timer for sending player locations - session.getPlayer().resetSendPlayerLocTime(); - // Rsp - session.send(new PacketEnterSceneDoneRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.player.Player.SceneLoadState; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.*; + +@Opcodes(PacketOpcodes.EnterSceneDoneReq) +public class HandlerEnterSceneDoneReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Finished loading + session.getPlayer().setSceneLoadState(SceneLoadState.LOADED); + + // Done + + session.send(new PacketPlayerTimeNotify(session.getPlayer())); // Probably not the right place + + // Spawn player in world + session.getPlayer().getScene().spawnPlayer(session.getPlayer()); + + // Spawn other entites already in world + session.getPlayer().getScene().showOtherEntities(session.getPlayer()); + + // Locations + session.send(new PacketWorldPlayerLocationNotify(session.getPlayer().getWorld())); + session.send(new PacketScenePlayerLocationNotify(session.getPlayer().getScene())); + session.send(new PacketWorldPlayerRTTNotify(session.getPlayer().getWorld())); + + // spawn NPC + session.getPlayer().getScene().loadNpcForPlayerEnter(session.getPlayer()); + + // notify client to load the npc for quest + var questGroupSuites = + session.getPlayer().getQuestManager().getSceneGroupSuite(session.getPlayer().getSceneId()); + + session.getPlayer().getScene().loadGroupForQuest(questGroupSuites); + Grasscutter.getLogger() + .debug( + "Loaded Scene {} Quest(s) Groupsuite(s): {}", + session.getPlayer().getSceneId(), + questGroupSuites); + session.send(new PacketGroupSuiteNotify(questGroupSuites)); + + // Reset timer for sending player locations + session.getPlayer().resetSendPlayerLocTime(); + // Rsp + session.send(new PacketEnterSceneDoneRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneReadyReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneReadyReq.java index 534c44a8a..412263846 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneReadyReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneReadyReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEnterScenePeerNotify; -import emu.grasscutter.server.packet.send.PacketEnterSceneReadyRsp; - -@Opcodes(PacketOpcodes.EnterSceneReadyReq) -public class HandlerEnterSceneReadyReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) { - session.send(new PacketEnterScenePeerNotify(session.getPlayer())); - session.send(new PacketEnterSceneReadyRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEnterScenePeerNotify; +import emu.grasscutter.server.packet.send.PacketEnterSceneReadyRsp; + +@Opcodes(PacketOpcodes.EnterSceneReadyReq) +public class HandlerEnterSceneReadyReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) { + session.send(new PacketEnterScenePeerNotify(session.getPlayer())); + session.send(new PacketEnterSceneReadyRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTransPointRegionNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTransPointRegionNotify.java index 1875ac20f..5d60c3b99 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTransPointRegionNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterTransPointRegionNotify.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EnterTransPointRegionNotify) -public class HandlerEnterTransPointRegionNotify extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getSotsManager().handleEnterTransPointRegionNotify(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EnterTransPointRegionNotify) +public class HandlerEnterTransPointRegionNotify extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getSotsManager().handleEnterTransPointRegionNotify(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java index 3ccbb62ea..def3d4e1d 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterWorldAreaReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterWorldAreaReqOuterClass.EnterWorldAreaReq; -import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEnterWorldAreaRsp; - -@Opcodes(PacketOpcodes.EnterWorldAreaReq) -public class HandlerEnterWorldAreaReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PacketHead head = PacketHead.parseFrom(header); - EnterWorldAreaReq enterWorld = EnterWorldAreaReq.parseFrom(payload); - - session.send(new PacketEnterWorldAreaRsp(head.getClientSequenceId(), enterWorld)); - // session.send(new PacketScenePlayerLocationNotify(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterWorldAreaReqOuterClass.EnterWorldAreaReq; +import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEnterWorldAreaRsp; + +@Opcodes(PacketOpcodes.EnterWorldAreaReq) +public class HandlerEnterWorldAreaReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PacketHead head = PacketHead.parseFrom(header); + EnterWorldAreaReq enterWorld = EnterWorldAreaReq.parseFrom(payload); + + session.send(new PacketEnterWorldAreaRsp(head.getClientSequenceId(), enterWorld)); + // session.send(new PacketScenePlayerLocationNotify(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEntityAiSyncNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEntityAiSyncNotify.java index d5c88579c..ac61309b9 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEntityAiSyncNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEntityAiSyncNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EntityAiSyncNotifyOuterClass.EntityAiSyncNotify; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEntityAiSyncNotify; - -@Opcodes(PacketOpcodes.EntityAiSyncNotify) -public class HandlerEntityAiSyncNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EntityAiSyncNotify notify = EntityAiSyncNotify.parseFrom(payload); - - if (notify.getLocalAvatarAlertedMonsterListCount() > 0) { - session.getPlayer().getScene().broadcastPacket(new PacketEntityAiSyncNotify(notify)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EntityAiSyncNotifyOuterClass.EntityAiSyncNotify; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEntityAiSyncNotify; + +@Opcodes(PacketOpcodes.EntityAiSyncNotify) +public class HandlerEntityAiSyncNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EntityAiSyncNotify notify = EntityAiSyncNotify.parseFrom(payload); + + if (notify.getLocalAvatarAlertedMonsterListCount() > 0) { + session.getPlayer().getScene().broadcastPacket(new PacketEntityAiSyncNotify(notify)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncCombatThreatInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncCombatThreatInfoNotify.java index 194bc99fd..b59ddc0d3 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncCombatThreatInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncCombatThreatInfoNotify.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EvtAiSyncCombatThreatInfoNotify) -public class HandlerEvtAiSyncCombatThreatInfoNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EvtAiSyncCombatThreatInfoNotify) +public class HandlerEvtAiSyncCombatThreatInfoNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncSkillCdNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncSkillCdNotify.java index 369e58177..09b6649b4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncSkillCdNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAiSyncSkillCdNotify.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EvtAiSyncSkillCdNotify) -public class HandlerEvtAiSyncSkillCdNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EvtAiSyncSkillCdNotify) +public class HandlerEvtAiSyncSkillCdNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarLockChairReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarLockChairReq.java index 77ee78fd6..b6decd7f3 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarLockChairReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarLockChairReq.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarLockChairReqOuterClass.EvtAvatarLockChairReq; -import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEvtAvatarLockChairRsp; - -@Opcodes(PacketOpcodes.EvtAvatarLockChairReq) -public class HandlerEvtAvatarLockChairReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PacketHead head = PacketHead.parseFrom(header); - EvtAvatarLockChairReq lockChairReq = EvtAvatarLockChairReq.parseFrom(payload); - - EntityAvatar entityAvatar = session.getPlayer().getTeamManager().getCurrentAvatarEntity(); - - session.send( - new PacketEvtAvatarLockChairRsp(head.getClientSequenceId(), entityAvatar, lockChairReq)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarLockChairReqOuterClass.EvtAvatarLockChairReq; +import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEvtAvatarLockChairRsp; + +@Opcodes(PacketOpcodes.EvtAvatarLockChairReq) +public class HandlerEvtAvatarLockChairReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PacketHead head = PacketHead.parseFrom(header); + EvtAvatarLockChairReq lockChairReq = EvtAvatarLockChairReq.parseFrom(payload); + + EntityAvatar entityAvatar = session.getPlayer().getTeamManager().getCurrentAvatarEntity(); + + session.send( + new PacketEvtAvatarLockChairRsp(head.getClientSequenceId(), entityAvatar, lockChairReq)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarSitDownNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarSitDownNotify.java index cfae90de8..27aed700b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarSitDownNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarSitDownNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEvtAvatarSitDownNotify; - -@Opcodes(PacketOpcodes.EvtAvatarSitDownNotify) -public class HandlerEvtAvatarSitDownNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtAvatarSitDownNotify notify = EvtAvatarSitDownNotify.parseFrom(payload); - - session.getPlayer().getScene().broadcastPacket(new PacketEvtAvatarSitDownNotify(notify)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEvtAvatarSitDownNotify; + +@Opcodes(PacketOpcodes.EvtAvatarSitDownNotify) +public class HandlerEvtAvatarSitDownNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtAvatarSitDownNotify notify = EvtAvatarSitDownNotify.parseFrom(payload); + + session.getPlayer().getScene().broadcastPacket(new PacketEvtAvatarSitDownNotify(notify)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarStandUpNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarStandUpNotify.java index 4cab5406f..9ad133f0b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarStandUpNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtAvatarStandUpNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarStandUpNotifyOuterClass.EvtAvatarStandUpNotify; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEvtAvatarStandUpNotify; - -@Opcodes(PacketOpcodes.EvtAvatarStandUpNotify) -public class HandlerEvtAvatarStandUpNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtAvatarStandUpNotify notify = EvtAvatarStandUpNotify.parseFrom(payload); - - session.getPlayer().getScene().broadcastPacket(new PacketEvtAvatarStandUpNotify(notify)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarStandUpNotifyOuterClass.EvtAvatarStandUpNotify; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEvtAvatarStandUpNotify; + +@Opcodes(PacketOpcodes.EvtAvatarStandUpNotify) +public class HandlerEvtAvatarStandUpNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtAvatarStandUpNotify notify = EvtAvatarStandUpNotify.parseFrom(payload); + + session.getPlayer().getScene().broadcastPacket(new PacketEvtAvatarStandUpNotify(notify)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java index d8b38c08b..dc1b60015 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java @@ -1,38 +1,38 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.entity.EntityClientGadget; -import emu.grasscutter.game.entity.EntitySolarIsotomaClientGadget; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EvtCreateGadgetNotify) -public class HandlerEvtCreateGadgetNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload); - - // Sanity check - dont add duplicate entities - if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) { - return; - } - - // Create entity and summon in world - var gadgetId = notify.getConfigId(); - EntityClientGadget gadget = - switch (gadgetId) { - // Solar Isotoma. - case EntitySolarIsotomaClientGadget.GADGET_ID -> new EntitySolarIsotomaClientGadget( - session.getPlayer().getScene(), session.getPlayer(), notify); - - // Default. - default -> new EntityClientGadget( - session.getPlayer().getScene(), session.getPlayer(), notify); - }; - - session.getPlayer().getScene().onPlayerCreateGadget(gadget); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.EntityClientGadget; +import emu.grasscutter.game.entity.EntitySolarIsotomaClientGadget; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EvtCreateGadgetNotify) +public class HandlerEvtCreateGadgetNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtCreateGadgetNotify notify = EvtCreateGadgetNotify.parseFrom(payload); + + // Sanity check - dont add duplicate entities + if (session.getPlayer().getScene().getEntityById(notify.getEntityId()) != null) { + return; + } + + // Create entity and summon in world + var gadgetId = notify.getConfigId(); + EntityClientGadget gadget = + switch (gadgetId) { + // Solar Isotoma. + case EntitySolarIsotomaClientGadget.GADGET_ID -> new EntitySolarIsotomaClientGadget( + session.getPlayer().getScene(), session.getPlayer(), notify); + + // Default. + default -> new EntityClientGadget( + session.getPlayer().getScene(), session.getPlayer(), notify); + }; + + session.getPlayer().getScene().onPlayerCreateGadget(gadget); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDestroyGadgetNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDestroyGadgetNotify.java index bafc30dc6..71d1502b8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDestroyGadgetNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtDestroyGadgetNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtDestroyGadgetNotifyOuterClass.EvtDestroyGadgetNotify; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.EvtDestroyGadgetNotify) -public class HandlerEvtDestroyGadgetNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - EvtDestroyGadgetNotify notify = EvtDestroyGadgetNotify.parseFrom(payload); - - session.getPlayer().getScene().onPlayerDestroyGadget(notify.getEntityId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtDestroyGadgetNotifyOuterClass.EvtDestroyGadgetNotify; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.EvtDestroyGadgetNotify) +public class HandlerEvtDestroyGadgetNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtDestroyGadgetNotify notify = EvtDestroyGadgetNotify.parseFrom(payload); + + session.getPlayer().getScene().onPlayerDestroyGadget(notify.getEntityId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtEntityRenderersChangedNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtEntityRenderersChangedNotify.java index 91b08a599..68cad064a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtEntityRenderersChangedNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtEntityRenderersChangedNotify.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtEntityRenderersChangedNotifyOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketEvtEntityRenderersChangedNotify; - -@Opcodes(PacketOpcodes.EvtEntityRenderersChangedNotify) -public class HandlerEvtEntityRenderersChangedNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - EvtEntityRenderersChangedNotifyOuterClass.EvtEntityRenderersChangedNotify.parseFrom( - payload); - - switch (req.getForwardType()) { - case FORWARD_TYPE_TO_ALL -> session - .getPlayer() - .getScene() - .broadcastPacket(new PacketEvtEntityRenderersChangedNotify(req)); - case FORWARD_TYPE_TO_ALL_EXCEPT_CUR -> session - .getPlayer() - .getScene() - .broadcastPacketToOthers( - session.getPlayer(), new PacketEvtEntityRenderersChangedNotify(req)); - case FORWARD_TYPE_TO_HOST -> session - .getPlayer() - .getScene() - .getWorld() - .getHost() - .sendPacket(new PacketEvtEntityRenderersChangedNotify(req)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtEntityRenderersChangedNotifyOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEvtEntityRenderersChangedNotify; + +@Opcodes(PacketOpcodes.EvtEntityRenderersChangedNotify) +public class HandlerEvtEntityRenderersChangedNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + EvtEntityRenderersChangedNotifyOuterClass.EvtEntityRenderersChangedNotify.parseFrom( + payload); + + switch (req.getForwardType()) { + case FORWARD_TYPE_TO_ALL -> session + .getPlayer() + .getScene() + .broadcastPacket(new PacketEvtEntityRenderersChangedNotify(req)); + case FORWARD_TYPE_TO_ALL_EXCEPT_CUR -> session + .getPlayer() + .getScene() + .broadcastPacketToOthers( + session.getPlayer(), new PacketEvtEntityRenderersChangedNotify(req)); + case FORWARD_TYPE_TO_HOST -> session + .getPlayer() + .getScene() + .getWorld() + .getHost() + .sendPacket(new PacketEvtEntityRenderersChangedNotify(req)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerExitTransPointRegionNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerExitTransPointRegionNotify.java index 8814f1fcc..ecb41bdd5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerExitTransPointRegionNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerExitTransPointRegionNotify.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ExitTransPointRegionNotify) -public class HandlerExitTransPointRegionNotify extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getSotsManager().handleExitTransPointRegionNotify(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ExitTransPointRegionNotify) +public class HandlerExitTransPointRegionNotify extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getSotsManager().handleExitTransPointRegionNotify(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeGetQueueDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeGetQueueDataReq.java index d0291d3ba..1be6a8b2e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeGetQueueDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeGetQueueDataReq.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ForgeGetQueueDataReq) -public class HandlerForgeGetQueueDataReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getForgingManager().handleForgeGetQueueDataReq(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ForgeGetQueueDataReq) +public class HandlerForgeGetQueueDataReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getForgingManager().handleForgeGetQueueDataReq(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeQueueManipulateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeQueueManipulateReq.java index 2006dbf8a..b6891613c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeQueueManipulateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeQueueManipulateReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ForgeQueueManipulateReq) -public class HandlerForgeQueueManipulateReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ForgeQueueManipulateReq req = ForgeQueueManipulateReq.parseFrom(payload); - session.getPlayer().getForgingManager().handleForgeQueueManipulateReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ForgeQueueManipulateReq) +public class HandlerForgeQueueManipulateReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ForgeQueueManipulateReq req = ForgeQueueManipulateReq.parseFrom(payload); + session.getPlayer().getForgingManager().handleForgeQueueManipulateReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java index 5e11866d2..33a89aba4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeStartReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ForgeStartReq) -public class HandlerForgeStartReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ForgeStartReqOuterClass.ForgeStartReq req = - ForgeStartReqOuterClass.ForgeStartReq.parseFrom(payload); - session.getPlayer().getForgingManager().handleForgeStartReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeStartReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ForgeStartReq) +public class HandlerForgeStartReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ForgeStartReqOuterClass.ForgeStartReq req = + ForgeStartReqOuterClass.ForgeStartReq.parseFrom(payload); + session.getPlayer().getForgingManager().handleForgeStartReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeReq.java index f996c8424..f1dd234f7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeReq.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.FurnitureMakeReq) -public class HandlerFurnitureMakeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getFurnitureManager().queryStatus(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.FurnitureMakeReq) +public class HandlerFurnitureMakeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getFurnitureManager().queryStatus(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeStartReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeStartReq.java index 08041c893..2fe0ce9f8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeStartReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerFurnitureMakeStartReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FurnitureMakeStartReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.FurnitureMakeStartReq) -public class HandlerFurnitureMakeStartReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = FurnitureMakeStartReqOuterClass.FurnitureMakeStartReq.parseFrom(payload); - - session.getPlayer().getFurnitureManager().startMake(req.getMakeId(), req.getAvatarId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FurnitureMakeStartReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.FurnitureMakeStartReq) +public class HandlerFurnitureMakeStartReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = FurnitureMakeStartReqOuterClass.FurnitureMakeStartReq.parseFrom(payload); + + session.getPlayer().getFurnitureManager().startMake(req.getMakeId(), req.getAvatarId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGachaWishReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGachaWishReq.java index 45b913f43..bc6fa5694 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGachaWishReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGachaWishReq.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.gacha.GachaBanner; -import emu.grasscutter.game.gacha.PlayerGachaBannerInfo; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GachaWishReqOuterClass.GachaWishReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGachaWishRsp; - -@Opcodes(PacketOpcodes.GachaWishReq) -public class HandlerGachaWishReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GachaWishReq req = GachaWishReq.parseFrom(payload); - - GachaBanner banner = - session.getServer().getGachaSystem().getGachaBanners().get(req.getGachaScheduleId()); - PlayerGachaBannerInfo gachaInfo = session.getPlayer().getGachaInfo().getBannerInfo(banner); - - gachaInfo.setFailedChosenItemPulls(0); - gachaInfo.setWishItemId(req.getItemId()); - - session.send( - new PacketGachaWishRsp( - req.getGachaType(), - req.getGachaScheduleId(), - req.getItemId(), - 0, - banner.getWishMaxProgress())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.gacha.GachaBanner; +import emu.grasscutter.game.gacha.PlayerGachaBannerInfo; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GachaWishReqOuterClass.GachaWishReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGachaWishRsp; + +@Opcodes(PacketOpcodes.GachaWishReq) +public class HandlerGachaWishReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GachaWishReq req = GachaWishReq.parseFrom(payload); + + GachaBanner banner = + session.getServer().getGachaSystem().getGachaBanners().get(req.getGachaScheduleId()); + PlayerGachaBannerInfo gachaInfo = session.getPlayer().getGachaInfo().getBannerInfo(banner); + + gachaInfo.setFailedChosenItemPulls(0); + gachaInfo.setWishItemId(req.getItemId()); + + session.send( + new PacketGachaWishRsp( + req.getGachaType(), + req.getGachaScheduleId(), + req.getItemId(), + 0, + banner.getWishMaxProgress())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityInfoReq.java index 7c93b8d35..bfd90684d 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityInfoReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetActivityInfoReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetActivityInfoRsp; -import java.util.HashSet; - -@Opcodes(PacketOpcodes.GetActivityInfoReq) -public class HandlerGetActivityInfoReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = GetActivityInfoReqOuterClass.GetActivityInfoReq.parseFrom(payload); - - session.send( - new PacketGetActivityInfoRsp( - new HashSet<>(req.getActivityIdListList()), session.getPlayer().getActivityManager())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetActivityInfoReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetActivityInfoRsp; +import java.util.HashSet; + +@Opcodes(PacketOpcodes.GetActivityInfoReq) +public class HandlerGetActivityInfoReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = GetActivityInfoReqOuterClass.GetActivityInfoReq.parseFrom(payload); + + session.send( + new PacketGetActivityInfoRsp( + new HashSet<>(req.getActivityIdListList()), session.getPlayer().getActivityManager())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityShopSheetInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityShopSheetInfoReq.java index 459a6a6c9..8c7f8ce6f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityShopSheetInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetActivityShopSheetInfoReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetActivityShopSheetInfoReqOuterClass.GetActivityShopSheetInfoReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetActivityShopSheetInfoRsp; - -@Opcodes(PacketOpcodes.GetActivityShopSheetInfoReq) -public class HandlerGetActivityShopSheetInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetActivityShopSheetInfoReq req = GetActivityShopSheetInfoReq.parseFrom(payload); - session.getPlayer().sendPacket(new PacketGetActivityShopSheetInfoRsp(req.getShopType())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetActivityShopSheetInfoReqOuterClass.GetActivityShopSheetInfoReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetActivityShopSheetInfoRsp; + +@Opcodes(PacketOpcodes.GetActivityShopSheetInfoReq) +public class HandlerGetActivityShopSheetInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetActivityShopSheetInfoReq req = GetActivityShopSheetInfoReq.parseFrom(payload); + session.getPlayer().sendPacket(new PacketGetActivityShopSheetInfoRsp(req.getShopType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllH5ActivityInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllH5ActivityInfoReq.java index 068b341fd..fcf0ff080 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllH5ActivityInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllH5ActivityInfoReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketH5ActivityIdsNotify; - -@Opcodes(PacketOpcodes.GetAllH5ActivityInfoReq) -public class HandlerGetAllH5ActivityInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketH5ActivityIdsNotify()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketH5ActivityIdsNotify; + +@Opcodes(PacketOpcodes.GetAllH5ActivityInfoReq) +public class HandlerGetAllH5ActivityInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketH5ActivityIdsNotify()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllUnlockNameCardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllUnlockNameCardReq.java index 7b401636c..effa02ea3 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllUnlockNameCardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllUnlockNameCardReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetAllUnlockNameCardRsp; - -@Opcodes(PacketOpcodes.GetAllUnlockNameCardReq) -public class HandlerGetAllUnlockNameCardReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketGetAllUnlockNameCardRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetAllUnlockNameCardRsp; + +@Opcodes(PacketOpcodes.GetAllUnlockNameCardReq) +public class HandlerGetAllUnlockNameCardReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketGetAllUnlockNameCardRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAuthkeyReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAuthkeyReq.java index 605410817..732a973f6 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAuthkeyReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAuthkeyReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetAuthkeyRsp; - -@Opcodes(PacketOpcodes.GetAuthkeyReq) -public class HandlerGetAuthkeyReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketGetAuthkeyRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetAuthkeyRsp; + +@Opcodes(PacketOpcodes.GetAuthkeyReq) +public class HandlerGetAuthkeyReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketGetAuthkeyRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetDailyDungeonEntryInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetDailyDungeonEntryInfoReq.java index e4405ac55..c38eb253e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetDailyDungeonEntryInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetDailyDungeonEntryInfoReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetDailyDungeonEntryInfoReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetDailyDungeonEntryInfoRsp; - -@Opcodes(PacketOpcodes.GetDailyDungeonEntryInfoReq) -public class HandlerGetDailyDungeonEntryInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = GetDailyDungeonEntryInfoReqOuterClass.GetDailyDungeonEntryInfoReq.parseFrom(payload); - - session.send(new PacketGetDailyDungeonEntryInfoRsp(req.getSceneId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetDailyDungeonEntryInfoReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetDailyDungeonEntryInfoRsp; + +@Opcodes(PacketOpcodes.GetDailyDungeonEntryInfoReq) +public class HandlerGetDailyDungeonEntryInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = GetDailyDungeonEntryInfoReqOuterClass.GetDailyDungeonEntryInfoReq.parseFrom(payload); + + session.send(new PacketGetDailyDungeonEntryInfoRsp(req.getSceneId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowAvatarInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowAvatarInfoReq.java index f2db90c87..7141e8a06 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowAvatarInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowAvatarInfoReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetFriendShowAvatarInfoReqOuterClass.GetFriendShowAvatarInfoReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetFriendShowAvatarInfoRsp; - -@Opcodes(PacketOpcodes.GetFriendShowAvatarInfoReq) -public class HandlerGetFriendShowAvatarInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetFriendShowAvatarInfoReq req = GetFriendShowAvatarInfoReq.parseFrom(payload); - - int targetUid = req.getUid(); - Player targetPlayer = session.getServer().getPlayerByUid(targetUid, true); - - if (targetPlayer.isShowAvatars()) { - session.send( - new PacketGetFriendShowAvatarInfoRsp(targetUid, targetPlayer.getShowAvatarInfoList())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetFriendShowAvatarInfoReqOuterClass.GetFriendShowAvatarInfoReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetFriendShowAvatarInfoRsp; + +@Opcodes(PacketOpcodes.GetFriendShowAvatarInfoReq) +public class HandlerGetFriendShowAvatarInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetFriendShowAvatarInfoReq req = GetFriendShowAvatarInfoReq.parseFrom(payload); + + int targetUid = req.getUid(); + Player targetPlayer = session.getServer().getPlayerByUid(targetUid, true); + + if (targetPlayer.isShowAvatars()) { + session.send( + new PacketGetFriendShowAvatarInfoRsp(targetUid, targetPlayer.getShowAvatarInfoList())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowNameCardInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowNameCardInfoReq.java index 93d5645b6..d52e63db9 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowNameCardInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFriendShowNameCardInfoReq.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetFriendShowNameCardInfoReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetFriendShowNameCardInfoRsp; - -@Opcodes(PacketOpcodes.GetFriendShowNameCardInfoReq) -public class HandlerGetFriendShowNameCardInfoReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - GetFriendShowNameCardInfoReqOuterClass.GetFriendShowNameCardInfoReq.parseFrom(payload); - - int targetUid = req.getUid(); - Player target = session.getServer().getPlayerByUid(targetUid, true); - - session.send( - new PacketGetFriendShowNameCardInfoRsp(targetUid, target.getShowNameCardInfoList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetFriendShowNameCardInfoReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetFriendShowNameCardInfoRsp; + +@Opcodes(PacketOpcodes.GetFriendShowNameCardInfoReq) +public class HandlerGetFriendShowNameCardInfoReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + GetFriendShowNameCardInfoReqOuterClass.GetFriendShowNameCardInfoReq.parseFrom(payload); + + int targetUid = req.getUid(); + Player target = session.getServer().getPlayerByUid(targetUid, true); + + session.send( + new PacketGetFriendShowNameCardInfoRsp(targetUid, target.getShowNameCardInfoList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFurnitureCurModuleArrangeCountReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFurnitureCurModuleArrangeCountReq.java index 6ca662014..05f6477a7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFurnitureCurModuleArrangeCountReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetFurnitureCurModuleArrangeCountReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketFurnitureCurModuleArrangeCountNotify; - -@Opcodes(PacketOpcodes.GetFurnitureCurModuleArrangeCountReq) -public class HandlerGetFurnitureCurModuleArrangeCountReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketFurnitureCurModuleArrangeCountNotify()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketFurnitureCurModuleArrangeCountNotify; + +@Opcodes(PacketOpcodes.GetFurnitureCurModuleArrangeCountReq) +public class HandlerGetFurnitureCurModuleArrangeCountReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketFurnitureCurModuleArrangeCountNotify()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetGachaInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetGachaInfoReq.java index e1262c28e..8cfa62bdb 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetGachaInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetGachaInfoReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetGachaInfoRsp; - -@Opcodes(PacketOpcodes.GetGachaInfoReq) -public class HandlerGetGachaInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send( - new PacketGetGachaInfoRsp(session.getServer().getGachaSystem(), session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetGachaInfoRsp; + +@Opcodes(PacketOpcodes.GetGachaInfoReq) +public class HandlerGetGachaInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send( + new PacketGetGachaInfoRsp(session.getServer().getGachaSystem(), session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetHomeLevelUpRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetHomeLevelUpRewardReq.java index 0bcd1fac4..54c651af6 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetHomeLevelUpRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetHomeLevelUpRewardReq.java @@ -1,41 +1,41 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetHomeLevelUpRewardReqOuterClass.GetHomeLevelUpRewardReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetHomeLevelUpRewardRsp; -import java.util.List; -import java.util.Set; - -@Opcodes(PacketOpcodes.GetHomeLevelUpRewardReq) -public class HandlerGetHomeLevelUpRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Replica of TakePlayerLevelReward for adv rank rewards - Player pl = session.getPlayer(); - synchronized (pl) { - GetHomeLevelUpRewardReq req = GetHomeLevelUpRewardReq.parseFrom(payload); - int level = req.getLevel(); - Set homeRewardedLevels = session.getPlayer().getHomeRewardedLevels(); - if (!homeRewardedLevels.contains(level)) { // No duplicated reward - int rewardId = GameData.getHomeWorldLevelDataMap().get(level).getRewardId(); - if (rewardId != 0) { - List rewardItems = - GameData.getRewardDataMap().get(rewardId).getRewardItemList(); - pl.getInventory().addItemParamDatas(rewardItems, ActionReason.GetHomeLevelupReward); - homeRewardedLevels.add(level); - pl.setHomeRewardedLevels(homeRewardedLevels); - pl.save(); - pl.getHome().onClaimReward(pl); - session.send(new PacketGetHomeLevelUpRewardRsp(level, rewardId)); - } - } - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetHomeLevelUpRewardReqOuterClass.GetHomeLevelUpRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetHomeLevelUpRewardRsp; +import java.util.List; +import java.util.Set; + +@Opcodes(PacketOpcodes.GetHomeLevelUpRewardReq) +public class HandlerGetHomeLevelUpRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Replica of TakePlayerLevelReward for adv rank rewards + Player pl = session.getPlayer(); + synchronized (pl) { + GetHomeLevelUpRewardReq req = GetHomeLevelUpRewardReq.parseFrom(payload); + int level = req.getLevel(); + Set homeRewardedLevels = session.getPlayer().getHomeRewardedLevels(); + if (!homeRewardedLevels.contains(level)) { // No duplicated reward + int rewardId = GameData.getHomeWorldLevelDataMap().get(level).getRewardId(); + if (rewardId != 0) { + List rewardItems = + GameData.getRewardDataMap().get(rewardId).getRewardItemList(); + pl.getInventory().addItemParamDatas(rewardItems, ActionReason.GetHomeLevelupReward); + homeRewardedLevels.add(level); + pl.setHomeRewardedLevels(homeRewardedLevels); + pl.save(); + pl.getHome().onClaimReward(pl); + session.send(new PacketGetHomeLevelUpRewardRsp(level, rewardId)); + } + } + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetInvestigationMonsterReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetInvestigationMonsterReq.java index 015420850..1f9a7167e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetInvestigationMonsterReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetInvestigationMonsterReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetInvestigationMonsterReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetInvestigationMonsterRsp; - -@Opcodes(PacketOpcodes.GetInvestigationMonsterReq) -public class HandlerGetInvestigationMonsterReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = GetInvestigationMonsterReqOuterClass.GetInvestigationMonsterReq.parseFrom(payload); - - session.send( - new PacketGetInvestigationMonsterRsp( - session.getPlayer(), - session.getServer().getWorldDataSystem(), - req.getCityIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetInvestigationMonsterReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetInvestigationMonsterRsp; + +@Opcodes(PacketOpcodes.GetInvestigationMonsterReq) +public class HandlerGetInvestigationMonsterReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = GetInvestigationMonsterReqOuterClass.GetInvestigationMonsterReq.parseFrom(payload); + + session.send( + new PacketGetInvestigationMonsterRsp( + session.getPlayer(), + session.getServer().getWorldDataSystem(), + req.getCityIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java index 1eed668ef..580973d43 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetMailItemReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetMailItemRsp; - -@Opcodes(PacketOpcodes.GetMailItemReq) -public class HandlerGetMailItemReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetMailItemReqOuterClass.GetMailItemReq req = - GetMailItemReqOuterClass.GetMailItemReq.parseFrom(payload); - session.send(new PacketGetMailItemRsp(session.getPlayer(), req.getMailIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetMailItemReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetMailItemRsp; + +@Opcodes(PacketOpcodes.GetMailItemReq) +public class HandlerGetMailItemReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetMailItemReqOuterClass.GetMailItemReq req = + GetMailItemReqOuterClass.GetMailItemReq.parseFrom(payload); + session.send(new PacketGetMailItemRsp(session.getPlayer(), req.getMailIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerAskFriendListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerAskFriendListReq.java index f19c84070..26eb5f7bd 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerAskFriendListReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerAskFriendListReq.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetPlayerAskFriendListRsp; - -@Opcodes(PacketOpcodes.GetPlayerAskFriendListReq) -public class HandlerGetPlayerAskFriendListReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketGetPlayerAskFriendListRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetPlayerAskFriendListRsp; + +@Opcodes(PacketOpcodes.GetPlayerAskFriendListReq) +public class HandlerGetPlayerAskFriendListReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketGetPlayerAskFriendListRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerBlacklistReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerBlacklistReq.java index fee70dd9d..9dc676f73 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerBlacklistReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerBlacklistReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.GetPlayerBlacklistReq) -public class HandlerGetPlayerBlacklistReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new BasePacket(PacketOpcodes.GetPlayerBlacklistRsp).buildHeader(3)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.GetPlayerBlacklistReq) +public class HandlerGetPlayerBlacklistReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new BasePacket(PacketOpcodes.GetPlayerBlacklistRsp).buildHeader(3)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerFriendListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerFriendListReq.java index 6d4fc40f1..8dec66a7d 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerFriendListReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerFriendListReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetPlayerFriendListRsp; - -@Opcodes(PacketOpcodes.GetPlayerFriendListReq) -public class HandlerGetPlayerFriendListReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // session.send(new PacketGetPlayerAskFriendListRsp(session.getPlayer())); - session.send(new PacketGetPlayerFriendListRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetPlayerFriendListRsp; + +@Opcodes(PacketOpcodes.GetPlayerFriendListReq) +public class HandlerGetPlayerFriendListReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // session.send(new PacketGetPlayerAskFriendListRsp(session.getPlayer())); + session.send(new PacketGetPlayerFriendListRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerHomeCompInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerHomeCompInfoReq.java index d7cb0ddb3..c36f8e789 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerHomeCompInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerHomeCompInfoReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; - -@Opcodes(PacketOpcodes.GetPlayerHomeCompInfoReq) -public class HandlerGetPlayerHomeCompInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; + +@Opcodes(PacketOpcodes.GetPlayerHomeCompInfoReq) +public class HandlerGetPlayerHomeCompInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerSocialDetailReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerSocialDetailReq.java index c2832f3df..0655d95f2 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerSocialDetailReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerSocialDetailReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetPlayerSocialDetailReqOuterClass.GetPlayerSocialDetailReq; -import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp; - -@Opcodes(PacketOpcodes.GetPlayerSocialDetailReq) -public class HandlerGetPlayerSocialDetailReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetPlayerSocialDetailReq req = GetPlayerSocialDetailReq.parseFrom(payload); - - SocialDetail.Builder detail = session.getServer().getSocialDetailByUid(req.getUid()); - - if (detail != null) { - detail.setIsFriend(session.getPlayer().getFriendsList().isFriendsWith(req.getUid())); - } - - session.send(new PacketGetPlayerSocialDetailRsp(detail)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetPlayerSocialDetailReqOuterClass.GetPlayerSocialDetailReq; +import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp; + +@Opcodes(PacketOpcodes.GetPlayerSocialDetailReq) +public class HandlerGetPlayerSocialDetailReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetPlayerSocialDetailReq req = GetPlayerSocialDetailReq.parseFrom(payload); + + SocialDetail.Builder detail = session.getServer().getSocialDetailByUid(req.getUid()); + + if (detail != null) { + detail.setIsFriend(session.getPlayer().getFriendsList().isFriendsWith(req.getUid())); + } + + session.send(new PacketGetPlayerSocialDetailRsp(detail)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java index 496a8e95d..730c38e6f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetPlayerTokenReq.java @@ -1,146 +1,146 @@ -package emu.grasscutter.server.packet.recv; - -import static emu.grasscutter.config.Configuration.ACCOUNT; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq; -import emu.grasscutter.server.event.game.PlayerCreationEvent; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.game.GameSession.SessionState; -import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp; -import emu.grasscutter.utils.ByteHelper; -import emu.grasscutter.utils.Crypto; -import emu.grasscutter.utils.Utils; -import java.nio.ByteBuffer; -import java.security.Signature; -import javax.crypto.Cipher; - -@Opcodes(PacketOpcodes.GetPlayerTokenReq) -public class HandlerGetPlayerTokenReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetPlayerTokenReq req = GetPlayerTokenReq.parseFrom(payload); - - // Authenticate - Account account = DatabaseHelper.getAccountById(req.getAccountUid()); - if (account == null || !account.getToken().equals(req.getAccountToken())) { - return; - } - - // Set account - session.setAccount(account); - - // Check if player object exists in server - // NOTE: CHECKING MUST SITUATED HERE (BEFORE getPlayerByUid)! because to save firstly ,to load - // secondly !!! - // TODO - optimize - boolean kicked = false; - Player exists = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); - if (exists != null) { - GameSession existsSession = exists.getSession(); - if (existsSession != session) { // No self-kicking - exists.onLogout(); // must save immediately , or the below will load old data - existsSession.close(); - Grasscutter.getLogger() - .warn("Player {} was kicked due to duplicated login", account.getUsername()); - kicked = true; - } - } - - // NOTE: If there are 5 online players, max count of player is 5, - // a new client want to login by kicking one of them , - // I think it should be allowed - if (!kicked) { - // Max players limit - if (ACCOUNT.maxPlayer > -1 - && Grasscutter.getGameServer().getPlayers().size() >= ACCOUNT.maxPlayer) { - session.close(); - return; - } - } - - // Call creation event. - PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); - event.call(); - - // Get player. - Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass()); - - if (player == null) { - int nextPlayerUid = - DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid()); - - // Create player instance from event. - player = - event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session); - - // Save to db - DatabaseHelper.generatePlayerUid(player, nextPlayerUid); - } - - // Set player object for session - session.setPlayer(player); - - // Checks if the player is banned - if (session.getAccount().isBanned()) { - session.setState(SessionState.ACCOUNT_BANNED); - session.send( - new PacketGetPlayerTokenRsp( - session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime())); - return; - } - - // Load player from database - player.loadFromDatabase(); - - // Set session state - session.setUseSecretKey(true); - session.setState(SessionState.WAITING_FOR_LOGIN); - - // Only >= 2.7.50 has this - if (req.getKeyId() > 0) { - try { - Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); - cipher.init(Cipher.DECRYPT_MODE, Crypto.CUR_SIGNING_KEY); - - var client_seed_encrypted = Utils.base64Decode(req.getClientRandKey()); - var client_seed = ByteBuffer.wrap(cipher.doFinal(client_seed_encrypted)).getLong(); - - byte[] seed_bytes = - ByteBuffer.wrap(new byte[8]).putLong(Crypto.ENCRYPT_SEED ^ client_seed).array(); - - cipher.init(Cipher.ENCRYPT_MODE, Crypto.EncryptionKeys.get(req.getKeyId())); - var seed_encrypted = cipher.doFinal(seed_bytes); - - Signature privateSignature = Signature.getInstance("SHA256withRSA"); - privateSignature.initSign(Crypto.CUR_SIGNING_KEY); - privateSignature.update(seed_bytes); - - session.send( - new PacketGetPlayerTokenRsp( - session, - Utils.base64Encode(seed_encrypted), - Utils.base64Encode(privateSignature.sign()))); - } catch (Exception ignore) { - // Only UA Patch users will have exception - byte[] clientBytes = Utils.base64Decode(req.getClientRandKey()); - byte[] seed = ByteHelper.longToBytes(Crypto.ENCRYPT_SEED); - Crypto.xor(clientBytes, seed); - - String base64str = Utils.base64Encode(clientBytes); - - session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl")); - } - } else { - // Send packet - session.send(new PacketGetPlayerTokenRsp(session)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import static emu.grasscutter.config.Configuration.ACCOUNT; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.Account; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetPlayerTokenReqOuterClass.GetPlayerTokenReq; +import emu.grasscutter.server.event.game.PlayerCreationEvent; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.game.GameSession.SessionState; +import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp; +import emu.grasscutter.utils.ByteHelper; +import emu.grasscutter.utils.Crypto; +import emu.grasscutter.utils.Utils; +import java.nio.ByteBuffer; +import java.security.Signature; +import javax.crypto.Cipher; + +@Opcodes(PacketOpcodes.GetPlayerTokenReq) +public class HandlerGetPlayerTokenReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetPlayerTokenReq req = GetPlayerTokenReq.parseFrom(payload); + + // Authenticate + Account account = DatabaseHelper.getAccountById(req.getAccountUid()); + if (account == null || !account.getToken().equals(req.getAccountToken())) { + return; + } + + // Set account + session.setAccount(account); + + // Check if player object exists in server + // NOTE: CHECKING MUST SITUATED HERE (BEFORE getPlayerByUid)! because to save firstly ,to load + // secondly !!! + // TODO - optimize + boolean kicked = false; + Player exists = Grasscutter.getGameServer().getPlayerByAccountId(account.getId()); + if (exists != null) { + GameSession existsSession = exists.getSession(); + if (existsSession != session) { // No self-kicking + exists.onLogout(); // must save immediately , or the below will load old data + existsSession.close(); + Grasscutter.getLogger() + .warn("Player {} was kicked due to duplicated login", account.getUsername()); + kicked = true; + } + } + + // NOTE: If there are 5 online players, max count of player is 5, + // a new client want to login by kicking one of them , + // I think it should be allowed + if (!kicked) { + // Max players limit + if (ACCOUNT.maxPlayer > -1 + && Grasscutter.getGameServer().getPlayers().size() >= ACCOUNT.maxPlayer) { + session.close(); + return; + } + } + + // Call creation event. + PlayerCreationEvent event = new PlayerCreationEvent(session, Player.class); + event.call(); + + // Get player. + Player player = DatabaseHelper.getPlayerByAccount(account, event.getPlayerClass()); + + if (player == null) { + int nextPlayerUid = + DatabaseHelper.getNextPlayerId(session.getAccount().getReservedPlayerUid()); + + // Create player instance from event. + player = + event.getPlayerClass().getDeclaredConstructor(GameSession.class).newInstance(session); + + // Save to db + DatabaseHelper.generatePlayerUid(player, nextPlayerUid); + } + + // Set player object for session + session.setPlayer(player); + + // Checks if the player is banned + if (session.getAccount().isBanned()) { + session.setState(SessionState.ACCOUNT_BANNED); + session.send( + new PacketGetPlayerTokenRsp( + session, 21, "FORBID_CHEATING_PLUGINS", session.getAccount().getBanEndTime())); + return; + } + + // Load player from database + player.loadFromDatabase(); + + // Set session state + session.setUseSecretKey(true); + session.setState(SessionState.WAITING_FOR_LOGIN); + + // Only >= 2.7.50 has this + if (req.getKeyId() > 0) { + try { + Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); + cipher.init(Cipher.DECRYPT_MODE, Crypto.CUR_SIGNING_KEY); + + var client_seed_encrypted = Utils.base64Decode(req.getClientRandKey()); + var client_seed = ByteBuffer.wrap(cipher.doFinal(client_seed_encrypted)).getLong(); + + byte[] seed_bytes = + ByteBuffer.wrap(new byte[8]).putLong(Crypto.ENCRYPT_SEED ^ client_seed).array(); + + cipher.init(Cipher.ENCRYPT_MODE, Crypto.EncryptionKeys.get(req.getKeyId())); + var seed_encrypted = cipher.doFinal(seed_bytes); + + Signature privateSignature = Signature.getInstance("SHA256withRSA"); + privateSignature.initSign(Crypto.CUR_SIGNING_KEY); + privateSignature.update(seed_bytes); + + session.send( + new PacketGetPlayerTokenRsp( + session, + Utils.base64Encode(seed_encrypted), + Utils.base64Encode(privateSignature.sign()))); + } catch (Exception ignore) { + // Only UA Patch users will have exception + byte[] clientBytes = Utils.base64Decode(req.getClientRandKey()); + byte[] seed = ByteHelper.longToBytes(Crypto.ENCRYPT_SEED); + Crypto.xor(clientBytes, seed); + + String base64str = Utils.base64Encode(clientBytes); + + session.send(new PacketGetPlayerTokenRsp(session, base64str, "bm90aGluZyBoZXJl")); + } + } else { + // Send packet + session.send(new PacketGetPlayerTokenRsp(session)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetRegionSearchReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetRegionSearchReq.java index d87e3462f..509ea5b57 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetRegionSearchReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetRegionSearchReq.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.GetRegionSearchReq) -public class HandlerGetRegionSearchReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.GetRegionSearchReq) +public class HandlerGetRegionSearchReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetSceneAreaReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetSceneAreaReq.java index 9524a73e8..179f13eef 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetSceneAreaReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetSceneAreaReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetSceneAreaReqOuterClass.GetSceneAreaReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetSceneAreaRsp; - -@Opcodes(PacketOpcodes.GetSceneAreaReq) -public class HandlerGetSceneAreaReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetSceneAreaReq req = GetSceneAreaReq.parseFrom(payload); - - session.send(new PacketGetSceneAreaRsp(session.getPlayer(), req.getSceneId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetSceneAreaReqOuterClass.GetSceneAreaReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetSceneAreaRsp; + +@Opcodes(PacketOpcodes.GetSceneAreaReq) +public class HandlerGetSceneAreaReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetSceneAreaReq req = GetSceneAreaReq.parseFrom(payload); + + session.send(new PacketGetSceneAreaRsp(session.getPlayer(), req.getSceneId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetScenePointReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetScenePointReq.java index fcb395aa9..ac7dec203 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetScenePointReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetScenePointReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetScenePointReqOuterClass.GetScenePointReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetScenePointRsp; - -@Opcodes(PacketOpcodes.GetScenePointReq) -public class HandlerGetScenePointReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetScenePointReq req = GetScenePointReq.parseFrom(payload); - - session.send(new PacketGetScenePointRsp(session.getPlayer(), req.getSceneId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetScenePointReqOuterClass.GetScenePointReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetScenePointRsp; + +@Opcodes(PacketOpcodes.GetScenePointReq) +public class HandlerGetScenePointReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetScenePointReq req = GetScenePointReq.parseFrom(payload); + + session.send(new PacketGetScenePointRsp(session.getPlayer(), req.getSceneId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopReq.java index 2be1381bc..c0accac1b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetShopReqOuterClass.GetShopReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetShopRsp; - -@Opcodes(PacketOpcodes.GetShopReq) -public class HandlerGetShopReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - GetShopReq req = GetShopReq.parseFrom(payload); - - session.send(new PacketGetShopRsp(session.getPlayer(), req.getShopType())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetShopReqOuterClass.GetShopReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetShopRsp; + +@Opcodes(PacketOpcodes.GetShopReq) +public class HandlerGetShopReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + GetShopReq req = GetShopReq.parseFrom(payload); + + session.send(new PacketGetShopRsp(session.getPlayer(), req.getShopType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopmallDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopmallDataReq.java index 5d4362c86..cd595fb29 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopmallDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetShopmallDataReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetShopmallDataRsp; - -@Opcodes(PacketOpcodes.GetShopmallDataReq) -public class HandlerGetShopmallDataReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // TODO add the correct shops - session.send(new PacketGetShopmallDataRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetShopmallDataRsp; + +@Opcodes(PacketOpcodes.GetShopmallDataReq) +public class HandlerGetShopmallDataReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // TODO add the correct shops + session.send(new PacketGetShopmallDataRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWidgetSlotReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWidgetSlotReq.java index a9e145cd8..674ae9c96 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWidgetSlotReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWidgetSlotReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetWidgetSlotRsp; - -@Opcodes(PacketOpcodes.GetWidgetSlotReq) -public class HandlerGetWidgetSlotReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - Player player = session.getPlayer(); - session.send(new PacketGetWidgetSlotRsp(player)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetWidgetSlotRsp; + +@Opcodes(PacketOpcodes.GetWidgetSlotReq) +public class HandlerGetWidgetSlotReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + Player player = session.getPlayer(); + session.send(new PacketGetWidgetSlotRsp(player)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWorldMpInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWorldMpInfoReq.java index 780fb4559..c6a09826a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWorldMpInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetWorldMpInfoReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetWorldMpInfoRsp; - -@Opcodes(PacketOpcodes.GetWorldMpInfoReq) -public class HandlerGetWorldMpInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketGetWorldMpInfoRsp(session.getPlayer().getWorld())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetWorldMpInfoRsp; + +@Opcodes(PacketOpcodes.GetWorldMpInfoReq) +public class HandlerGetWorldMpInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketGetWorldMpInfoRsp(session.getPlayer().getWorld())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHitTreeNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHitTreeNotify.java index b9e665541..3735fb53c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHitTreeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHitTreeNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HitTreeNotifyOuterClass.HitTreeNotify; -import emu.grasscutter.server.game.GameSession; - -/** Implement Deforestation Function */ -@Opcodes(PacketOpcodes.HitTreeNotify) -public class HandlerHitTreeNotify extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - HitTreeNotify hit = HitTreeNotify.parseFrom(payload); - session.getPlayer().getDeforestationManager().onDeforestationInvoke(hit); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HitTreeNotifyOuterClass.HitTreeNotify; +import emu.grasscutter.server.game.GameSession; + +/** Implement Deforestation Function */ +@Opcodes(PacketOpcodes.HitTreeNotify) +public class HandlerHitTreeNotify extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + HitTreeNotify hit = HitTreeNotify.parseFrom(payload); + session.getPlayer().getDeforestationManager().onDeforestationInvoke(hit); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeEditModeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeEditModeReq.java index c18bb3b5d..6e3b7ad31 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeEditModeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeEditModeReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeEditModeReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeBasicInfoNotify; -import emu.grasscutter.server.packet.send.PacketHomeChangeEditModeRsp; -import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; -import emu.grasscutter.server.packet.send.PacketHomePreChangeEditModeNotify; - -@Opcodes(PacketOpcodes.HomeChangeEditModeReq) -public class HandlerHomeChangeEditModeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = HomeChangeEditModeReqOuterClass.HomeChangeEditModeReq.parseFrom(payload); - - session.send(new PacketHomePreChangeEditModeNotify(req.getIsEnterEditMode())); - session.send(new PacketHomeBasicInfoNotify(session.getPlayer(), req.getIsEnterEditMode())); - session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); - - session.send(new PacketHomeChangeEditModeRsp(req.getIsEnterEditMode())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeEditModeReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeBasicInfoNotify; +import emu.grasscutter.server.packet.send.PacketHomeChangeEditModeRsp; +import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; +import emu.grasscutter.server.packet.send.PacketHomePreChangeEditModeNotify; + +@Opcodes(PacketOpcodes.HomeChangeEditModeReq) +public class HandlerHomeChangeEditModeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = HomeChangeEditModeReqOuterClass.HomeChangeEditModeReq.parseFrom(payload); + + session.send(new PacketHomePreChangeEditModeNotify(req.getIsEnterEditMode())); + session.send(new PacketHomeBasicInfoNotify(session.getPlayer(), req.getIsEnterEditMode())); + session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); + + session.send(new PacketHomeChangeEditModeRsp(req.getIsEnterEditMode())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java index 24d8e7a6d..66780449c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChangeModuleReq.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeModuleReqOuterClass; -import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeChangeModuleRsp; -import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; -import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.HomeChangeModuleReq) -public class HandlerHomeChangeModuleReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - HomeChangeModuleReqOuterClass.HomeChangeModuleReq req = - HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); - session.getPlayer().setCurrentRealmId(req.getTargetModuleId()); - session.send(new PacketHomeChangeModuleRsp(req.getTargetModuleId())); - session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); - session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); - - int realmId = 2000 + req.getTargetModuleId(); - - Scene scene = session.getPlayer().getWorld().getSceneById(realmId); - Position pos = scene.getScriptManager().getConfig().born_pos; - - session - .getPlayer() - .getWorld() - .transferPlayerToScene(session.getPlayer(), realmId, TeleportType.WAYPOINT, pos); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeModuleReqOuterClass; +import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeChangeModuleRsp; +import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; +import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.HomeChangeModuleReq) +public class HandlerHomeChangeModuleReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + HomeChangeModuleReqOuterClass.HomeChangeModuleReq req = + HomeChangeModuleReqOuterClass.HomeChangeModuleReq.parseFrom(payload); + session.getPlayer().setCurrentRealmId(req.getTargetModuleId()); + session.send(new PacketHomeChangeModuleRsp(req.getTargetModuleId())); + session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); + session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); + + int realmId = 2000 + req.getTargetModuleId(); + + Scene scene = session.getPlayer().getWorld().getSceneById(realmId); + Position pos = scene.getScriptManager().getConfig().born_pos; + + session + .getPlayer() + .getWorld() + .transferPlayerToScene(session.getPlayer(), realmId, TeleportType.WAYPOINT, pos); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChooseModuleReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChooseModuleReq.java index 9d25e4e2c..ae0d2e574 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChooseModuleReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeChooseModuleReq.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChooseModuleReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeChooseModuleRsp; -import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; -import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; - -@Opcodes(PacketOpcodes.HomeChooseModuleReq) -public class HandlerHomeChooseModuleReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - HomeChooseModuleReqOuterClass.HomeChooseModuleReq req = - HomeChooseModuleReqOuterClass.HomeChooseModuleReq.parseFrom(payload); - session.getPlayer().addRealmList(req.getModuleId()); - session.getPlayer().setCurrentRealmId(req.getModuleId()); - session.send(new PacketHomeChooseModuleRsp(req.getModuleId())); - session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); - session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChooseModuleReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeChooseModuleRsp; +import emu.grasscutter.server.packet.send.PacketHomeComfortInfoNotify; +import emu.grasscutter.server.packet.send.PacketPlayerHomeCompInfoNotify; + +@Opcodes(PacketOpcodes.HomeChooseModuleReq) +public class HandlerHomeChooseModuleReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + HomeChooseModuleReqOuterClass.HomeChooseModuleReq req = + HomeChooseModuleReqOuterClass.HomeChooseModuleReq.parseFrom(payload); + session.getPlayer().addRealmList(req.getModuleId()); + session.getPlayer().setCurrentRealmId(req.getModuleId()); + session.send(new PacketHomeChooseModuleRsp(req.getModuleId())); + session.send(new PacketPlayerHomeCompInfoNotify(session.getPlayer())); + session.send(new PacketHomeComfortInfoNotify(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeEnterEditModeFinishReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeEnterEditModeFinishReq.java index f6b26ae6c..8b347fbfe 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeEnterEditModeFinishReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeEnterEditModeFinishReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeEnterEditModeFinishRsp; - -@Opcodes(PacketOpcodes.HomeEnterEditModeFinishReq) -public class HandlerHomeEnterEditModeFinishReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - /* - * This packet is about the edit mode - */ - session.send(new PacketHomeEnterEditModeFinishRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeEnterEditModeFinishRsp; + +@Opcodes(PacketOpcodes.HomeEnterEditModeFinishReq) +public class HandlerHomeEnterEditModeFinishReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + /* + * This packet is about the edit mode + */ + session.send(new PacketHomeEnterEditModeFinishRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetArrangementInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetArrangementInfoReq.java index b2d3574c7..e2e4512d0 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetArrangementInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetArrangementInfoReq.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeGetArrangementInfoReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeGetArrangementInfoRsp; - -@Opcodes(PacketOpcodes.HomeGetArrangementInfoReq) -public class HandlerHomeGetArrangementInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = HomeGetArrangementInfoReqOuterClass.HomeGetArrangementInfoReq.parseFrom(payload); - - session.send( - new PacketHomeGetArrangementInfoRsp(session.getPlayer(), req.getSceneIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeGetArrangementInfoReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeGetArrangementInfoRsp; + +@Opcodes(PacketOpcodes.HomeGetArrangementInfoReq) +public class HandlerHomeGetArrangementInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = HomeGetArrangementInfoReqOuterClass.HomeGetArrangementInfoReq.parseFrom(payload); + + session.send( + new PacketHomeGetArrangementInfoRsp(session.getPlayer(), req.getSceneIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetBasicInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetBasicInfoReq.java index 6f6ac91b2..c4ea0ae47 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetBasicInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeGetBasicInfoReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeBasicInfoNotify; - -@Opcodes(PacketOpcodes.HomeGetBasicInfoReq) -public class HandlerHomeGetBasicInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - session.send(new PacketHomeBasicInfoNotify(session.getPlayer(), false)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeBasicInfoNotify; + +@Opcodes(PacketOpcodes.HomeGetBasicInfoReq) +public class HandlerHomeGetBasicInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + session.send(new PacketHomeBasicInfoNotify(session.getPlayer(), false)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeFetterExpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeFetterExpReq.java index b9d00bec2..18eeac3fd 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeFetterExpReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeFetterExpReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeResourceTakeFetterExpRsp; - -@Opcodes(PacketOpcodes.HomeResourceTakeFetterExpReq) -public class HandlerHomeResourceTakeFetterExpReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - session.send(new PacketHomeResourceTakeFetterExpRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeResourceTakeFetterExpRsp; + +@Opcodes(PacketOpcodes.HomeResourceTakeFetterExpReq) +public class HandlerHomeResourceTakeFetterExpReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + session.send(new PacketHomeResourceTakeFetterExpRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeHomeCoinReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeHomeCoinReq.java index 6562169ea..2d2b11741 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeHomeCoinReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeResourceTakeHomeCoinReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeResourceTakeHomeCoinRsp; - -@Opcodes(PacketOpcodes.HomeResourceTakeHomeCoinReq) -public class HandlerHomeResourceTakeHomeCoinReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - session.send(new PacketHomeResourceTakeHomeCoinRsp(session.getPlayer())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeResourceTakeHomeCoinRsp; + +@Opcodes(PacketOpcodes.HomeResourceTakeHomeCoinReq) +public class HandlerHomeResourceTakeHomeCoinReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + session.send(new PacketHomeResourceTakeHomeCoinRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java index 23ee974cb..e71debf64 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneInitFinishReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeSceneInitFinishRsp; - -@Opcodes(PacketOpcodes.HomeSceneInitFinishReq) -public class HandlerHomeSceneInitFinishReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send(new PacketHomeSceneInitFinishRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeSceneInitFinishRsp; + +@Opcodes(PacketOpcodes.HomeSceneInitFinishReq) +public class HandlerHomeSceneInitFinishReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketHomeSceneInitFinishRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java index a34f04766..c4ca0b4dd 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeSceneJumpReq.java @@ -1,51 +1,51 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeSceneJumpReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeSceneJumpRsp; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.HomeSceneJumpReq) -public class HandlerHomeSceneJumpReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = HomeSceneJumpReqOuterClass.HomeSceneJumpReq.parseFrom(payload); - - int realmId = 2000 + session.getPlayer().getCurrentRealmId(); - - var home = session.getPlayer().getHome(); - var homeScene = home.getHomeSceneItem(realmId); - home.save(); - - Scene scene = - session - .getPlayer() - .getWorld() - .getSceneById(req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId); - Position pos = scene.getScriptManager().getConfig().born_pos; - Position rot = home.getSceneMap().get(scene.getId()).getBornRot(); - - // Make player face correct direction when entering or exiting - session.getPlayer().getRotation().set(rot); - - // Make player exit to front of main house - if (!req.getIsEnterRoomScene()) { - pos = home.getSceneMap().get(realmId).getBornPos(); - } - - session - .getPlayer() - .getWorld() - .transferPlayerToScene( - session.getPlayer(), - req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId, - pos); - - session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeSceneJumpReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeSceneJumpRsp; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.HomeSceneJumpReq) +public class HandlerHomeSceneJumpReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = HomeSceneJumpReqOuterClass.HomeSceneJumpReq.parseFrom(payload); + + int realmId = 2000 + session.getPlayer().getCurrentRealmId(); + + var home = session.getPlayer().getHome(); + var homeScene = home.getHomeSceneItem(realmId); + home.save(); + + Scene scene = + session + .getPlayer() + .getWorld() + .getSceneById(req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId); + Position pos = scene.getScriptManager().getConfig().born_pos; + Position rot = home.getSceneMap().get(scene.getId()).getBornRot(); + + // Make player face correct direction when entering or exiting + session.getPlayer().getRotation().set(rot); + + // Make player exit to front of main house + if (!req.getIsEnterRoomScene()) { + pos = home.getSceneMap().get(realmId).getBornPos(); + } + + session + .getPlayer() + .getWorld() + .transferPlayerToScene( + session.getPlayer(), + req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId, + pos); + + session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java index a3f6833f0..d94065d81 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerHomeUpdateArrangementInfoReq.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeUpdateArrangementInfoReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketHomeUpdateArrangementInfoRsp; - -@Opcodes(PacketOpcodes.HomeUpdateArrangementInfoReq) -public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - HomeUpdateArrangementInfoReqOuterClass.HomeUpdateArrangementInfoReq.parseFrom(payload); - - var homeScene = - session.getPlayer().getHome().getHomeSceneItem(session.getPlayer().getSceneId()); - - homeScene.update(req.getSceneArrangementInfo()); - - session.getPlayer().getHome().save(); - - session.send(new PacketHomeUpdateArrangementInfoRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeUpdateArrangementInfoReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketHomeUpdateArrangementInfoRsp; + +@Opcodes(PacketOpcodes.HomeUpdateArrangementInfoReq) +public class HandlerHomeUpdateArrangementInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + HomeUpdateArrangementInfoReqOuterClass.HomeUpdateArrangementInfoReq.parseFrom(payload); + + var homeScene = + session.getPlayer().getHome().getHomeSceneItem(session.getPlayer().getSceneId()); + + homeScene.update(req.getSceneArrangementInfo()); + + session.getPlayer().getHome().save(); + + session.send(new PacketHomeUpdateArrangementInfoRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java index 82d8e2471..65551d759 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.MarkMapReq) -public class HandlerMarkMapReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - MarkMapReq req = MarkMapReq.parseFrom(payload); - session.getPlayer().getMapMarksManager().handleMapMarkReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.MarkMapReqOuterClass.MarkMapReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.MarkMapReq) +public class HandlerMarkMapReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + MarkMapReq req = MarkMapReq.parseFrom(payload); + session.getPlayer().getMapMarksManager().handleMapMarkReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMcoinExchangeHcoinReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMcoinExchangeHcoinReq.java index 83fe33315..0e3b5d8d4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMcoinExchangeHcoinReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMcoinExchangeHcoinReq.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.McoinExchangeHcoinReqOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketMcoinExchangeHcoinRsp; - -@Opcodes(PacketOpcodes.McoinExchangeHcoinReq) -public class HandlerMcoinExchangeHcoinReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq exchangeReq = - McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq.parseFrom(payload); - - if (session.getPlayer().getCrystals() < exchangeReq.getMcoinCost() - && exchangeReq.getMcoinCost() == exchangeReq.getHcoin()) { - session.send( - new PacketMcoinExchangeHcoinRsp(RetcodeOuterClass.Retcode.RET_UNKNOWN_ERROR_VALUE)); - return; - } - - session.getPlayer().setCrystals(session.getPlayer().getCrystals() - exchangeReq.getMcoinCost()); - session.getPlayer().setPrimogems(session.getPlayer().getPrimogems() + exchangeReq.getHcoin()); - session.getPlayer().save(); - session.send(new PacketMcoinExchangeHcoinRsp(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.McoinExchangeHcoinReqOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMcoinExchangeHcoinRsp; + +@Opcodes(PacketOpcodes.McoinExchangeHcoinReq) +public class HandlerMcoinExchangeHcoinReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq exchangeReq = + McoinExchangeHcoinReqOuterClass.McoinExchangeHcoinReq.parseFrom(payload); + + if (session.getPlayer().getCrystals() < exchangeReq.getMcoinCost() + && exchangeReq.getMcoinCost() == exchangeReq.getHcoin()) { + session.send( + new PacketMcoinExchangeHcoinRsp(RetcodeOuterClass.Retcode.RET_UNKNOWN_ERROR_VALUE)); + return; + } + + session.getPlayer().setCrystals(session.getPlayer().getCrystals() - exchangeReq.getMcoinCost()); + session.getPlayer().setPrimogems(session.getPlayer().getPrimogems() + exchangeReq.getHcoin()); + session.getPlayer().save(); + session.send(new PacketMcoinExchangeHcoinRsp(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMonsterAIConfigHashNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMonsterAIConfigHashNotify.java index 702df8640..c2f105a27 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMonsterAIConfigHashNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMonsterAIConfigHashNotify.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.MonsterAIConfigHashNotify) -public class HandlerMonsterAIConfigHashNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.MonsterAIConfigHashNotify) +public class HandlerMonsterAIConfigHashNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameCreateBeatmapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameCreateBeatmapReq.java index 83f9aba6b..c7231ca6a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameCreateBeatmapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameCreateBeatmapReq.java @@ -1,68 +1,68 @@ -// package emu.grasscutter.server.packet.recv; -// -// import emu.grasscutter.database.DatabaseHelper; -// import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler; -// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -// import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData; -// import emu.grasscutter.game.props.ActivityType; -// import emu.grasscutter.net.packet.Opcodes; -// import emu.grasscutter.net.packet.PacketHandler; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameCreateBeatmapReqOuterClass; -// import emu.grasscutter.server.game.GameSession; -// import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; -// import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp; -// import emu.grasscutter.utils.Utils; -// -// import java.util.Objects; -// -// @Opcodes(PacketOpcodes.MusicGameCreateBeatmapReq) -// public class HandlerMusicGameCreateBeatmapReq extends PacketHandler { -// -// @Override -// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { -// var req = MusicGameCreateBeatmapReqOuterClass.MusicGameCreateBeatmapReq.parseFrom(payload); -// -// var musicGameBeatmap = MusicGameBeatmap.of() -// .musicId(req.getMusicBriefInfo().getMusicId()) -// .musicNoteCount(req.getMusicBriefInfo().getMusicNoteCount()) -// .savePosition(req.getMusicBriefInfo().getPosition()) -// .maxScore(req.getMusicBriefInfo().getMaxScore()) -// .authorUid(session.getPlayer().getUid()) -// .beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getBeatmapItemListList())) -// .createTime(Utils.getCurrentSeconds()) -// .build(); -// -// musicGameBeatmap.save(); -// -// var playerData = -// session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME); -// if(playerData.isEmpty()){ -// return; -// } -// -// var handler = (MusicGameActivityHandler) playerData.get().getActivityHandler(); -// var musicGamePlayerData = handler.getMusicGamePlayerData(playerData.get()); -// -// var oldBeatmap = musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream() -// .map(MusicGamePlayerData.CustomBeatmapRecord::getMusicShareId) -// .map(DatabaseHelper::getMusicGameBeatmap) -// .filter(Objects::nonNull) -// .filter(item -> item.getAuthorUid() == session.getPlayer().getUid()) -// .filter(item -> item.getMusicId() == req.getMusicBriefInfo().getMusicId()) -// .filter(item -> item.getSavePosition() == req.getMusicBriefInfo().getPosition()) -// .findFirst(); -// -// // delete old beatmap for player -// // the old beatmap is still in database so that others can still play. -// oldBeatmap.ifPresent(i -> handler.removePersonalBeatmap(playerData.get(), i)); -// -// // link this beatmap to player's personal data -// handler.addPersonalBeatmap(playerData.get(), musicGameBeatmap); -// -// session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get()))); -// session.send(new PacketMusicGameCreateBeatmapRsp(musicGameBeatmap.getMusicShareId(), -// req.getUnknownEnum1())); -// } -// -// } +// package emu.grasscutter.server.packet.recv; +// +// import emu.grasscutter.database.DatabaseHelper; +// import emu.grasscutter.game.activity.musicgame.MusicGameActivityHandler; +// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +// import emu.grasscutter.game.activity.musicgame.MusicGamePlayerData; +// import emu.grasscutter.game.props.ActivityType; +// import emu.grasscutter.net.packet.Opcodes; +// import emu.grasscutter.net.packet.PacketHandler; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameCreateBeatmapReqOuterClass; +// import emu.grasscutter.server.game.GameSession; +// import emu.grasscutter.server.packet.send.PacketActivityInfoNotify; +// import emu.grasscutter.server.packet.send.PacketMusicGameCreateBeatmapRsp; +// import emu.grasscutter.utils.Utils; +// +// import java.util.Objects; +// +// @Opcodes(PacketOpcodes.MusicGameCreateBeatmapReq) +// public class HandlerMusicGameCreateBeatmapReq extends PacketHandler { +// +// @Override +// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { +// var req = MusicGameCreateBeatmapReqOuterClass.MusicGameCreateBeatmapReq.parseFrom(payload); +// +// var musicGameBeatmap = MusicGameBeatmap.of() +// .musicId(req.getMusicBriefInfo().getMusicId()) +// .musicNoteCount(req.getMusicBriefInfo().getMusicNoteCount()) +// .savePosition(req.getMusicBriefInfo().getPosition()) +// .maxScore(req.getMusicBriefInfo().getMaxScore()) +// .authorUid(session.getPlayer().getUid()) +// .beatmap(MusicGameBeatmap.parse(req.getMusicRecord().getBeatmapItemListList())) +// .createTime(Utils.getCurrentSeconds()) +// .build(); +// +// musicGameBeatmap.save(); +// +// var playerData = +// session.getPlayer().getActivityManager().getPlayerActivityDataByActivityType(ActivityType.NEW_ACTIVITY_MUSIC_GAME); +// if(playerData.isEmpty()){ +// return; +// } +// +// var handler = (MusicGameActivityHandler) playerData.get().getActivityHandler(); +// var musicGamePlayerData = handler.getMusicGamePlayerData(playerData.get()); +// +// var oldBeatmap = musicGamePlayerData.getPersonalCustomBeatmapRecord().values().stream() +// .map(MusicGamePlayerData.CustomBeatmapRecord::getMusicShareId) +// .map(DatabaseHelper::getMusicGameBeatmap) +// .filter(Objects::nonNull) +// .filter(item -> item.getAuthorUid() == session.getPlayer().getUid()) +// .filter(item -> item.getMusicId() == req.getMusicBriefInfo().getMusicId()) +// .filter(item -> item.getSavePosition() == req.getMusicBriefInfo().getPosition()) +// .findFirst(); +// +// // delete old beatmap for player +// // the old beatmap is still in database so that others can still play. +// oldBeatmap.ifPresent(i -> handler.removePersonalBeatmap(playerData.get(), i)); +// +// // link this beatmap to player's personal data +// handler.addPersonalBeatmap(playerData.get(), musicGameBeatmap); +// +// session.send(new PacketActivityInfoNotify(handler.toProto(playerData.get()))); +// session.send(new PacketMusicGameCreateBeatmapRsp(musicGameBeatmap.getMusicShareId(), +// req.getUnknownEnum1())); +// } +// +// } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameGetBeatmapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameGetBeatmapReq.java index 77a05e808..b316688f0 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameGetBeatmapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameGetBeatmapReq.java @@ -1,31 +1,31 @@ -// package emu.grasscutter.server.packet.recv; -// -// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -// import emu.grasscutter.net.packet.Opcodes; -// import emu.grasscutter.net.packet.PacketHandler; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass; -// import emu.grasscutter.server.game.GameSession; -// import emu.grasscutter.server.packet.send.PacketMusicGameGetBeatmapRsp; -// -// @Opcodes(PacketOpcodes.MusicGameGetBeatmapReq) -// public class HandlerMusicGameGetBeatmapReq extends PacketHandler { -// -// @Override -// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { -// var req = MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq.parseFrom(payload); -// -// var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId()); -// -// if(musicGameBeatmap == null){ -// return; -// } -// -// session.send(new PacketMusicGameGetBeatmapRsp( -// musicGameBeatmap.toBriefProto().build(), -// musicGameBeatmap.toProto(), -// req -// )); -// } -// -// } +// package emu.grasscutter.server.packet.recv; +// +// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +// import emu.grasscutter.net.packet.Opcodes; +// import emu.grasscutter.net.packet.PacketHandler; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass; +// import emu.grasscutter.server.game.GameSession; +// import emu.grasscutter.server.packet.send.PacketMusicGameGetBeatmapRsp; +// +// @Opcodes(PacketOpcodes.MusicGameGetBeatmapReq) +// public class HandlerMusicGameGetBeatmapReq extends PacketHandler { +// +// @Override +// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { +// var req = MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq.parseFrom(payload); +// +// var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId()); +// +// if(musicGameBeatmap == null){ +// return; +// } +// +// session.send(new PacketMusicGameGetBeatmapRsp( +// musicGameBeatmap.toBriefProto().build(), +// musicGameBeatmap.toProto(), +// req +// )); +// } +// +// } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameSearchBeatmapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameSearchBeatmapReq.java index 70366e42b..42593a779 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameSearchBeatmapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameSearchBeatmapReq.java @@ -1,29 +1,29 @@ -// package emu.grasscutter.server.packet.recv; -// -// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; -// import emu.grasscutter.net.packet.Opcodes; -// import emu.grasscutter.net.packet.PacketHandler; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameSearchBeatmapReqOuterClass; -// import emu.grasscutter.server.game.GameSession; -// import emu.grasscutter.server.packet.send.PacketMusicGameSearchBeatmapRsp; -// -// @Opcodes(PacketOpcodes.MusicGameSearchBeatmapReq) -// public class HandlerMusicGameSearchBeatmapReq extends PacketHandler { -// -// @Override -// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { -// var req = MusicGameSearchBeatmapReqOuterClass.MusicGameSearchBeatmapReq.parseFrom(payload); -// -// var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId()); -// -// if(musicGameBeatmap == null){ -// session.send(new PacketMusicGameSearchBeatmapRsp(11153, req.getUnknownEnum1())); -// return; -// } -// -// session.send(new PacketMusicGameSearchBeatmapRsp(musicGameBeatmap.toBriefProto().build(), -// req.getUnknownEnum1())); -// } -// -// } +// package emu.grasscutter.server.packet.recv; +// +// import emu.grasscutter.game.activity.musicgame.MusicGameBeatmap; +// import emu.grasscutter.net.packet.Opcodes; +// import emu.grasscutter.net.packet.PacketHandler; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameSearchBeatmapReqOuterClass; +// import emu.grasscutter.server.game.GameSession; +// import emu.grasscutter.server.packet.send.PacketMusicGameSearchBeatmapRsp; +// +// @Opcodes(PacketOpcodes.MusicGameSearchBeatmapReq) +// public class HandlerMusicGameSearchBeatmapReq extends PacketHandler { +// +// @Override +// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { +// var req = MusicGameSearchBeatmapReqOuterClass.MusicGameSearchBeatmapReq.parseFrom(payload); +// +// var musicGameBeatmap = MusicGameBeatmap.getByShareId(req.getMusicShareId()); +// +// if(musicGameBeatmap == null){ +// session.send(new PacketMusicGameSearchBeatmapRsp(11153, req.getUnknownEnum1())); +// return; +// } +// +// session.send(new PacketMusicGameSearchBeatmapRsp(musicGameBeatmap.toBriefProto().build(), +// req.getUnknownEnum1())); +// } +// +// } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartReq.java index 6a800d267..23bf26243 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.MusicGameStartReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketMusicGameStartRsp; - -@Opcodes(PacketOpcodes.MusicGameStartReq) -public class HandlerMusicGameStartReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = MusicGameStartReqOuterClass.MusicGameStartReq.parseFrom(payload); - - session.send(new PacketMusicGameStartRsp(req.getMusicBasicId(), req.getUgcGuid())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.MusicGameStartReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMusicGameStartRsp; + +@Opcodes(PacketOpcodes.MusicGameStartReq) +public class HandlerMusicGameStartReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = MusicGameStartReqOuterClass.MusicGameStartReq.parseFrom(payload); + + session.send(new PacketMusicGameStartRsp(req.getMusicBasicId(), req.getUgcGuid())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartToPlayOthersBeatmapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartToPlayOthersBeatmapReq.java index d003307b8..a87c619d1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartToPlayOthersBeatmapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMusicGameStartToPlayOthersBeatmapReq.java @@ -1,21 +1,21 @@ -// package emu.grasscutter.server.packet.recv; -// -// import emu.grasscutter.net.packet.Opcodes; -// import emu.grasscutter.net.packet.PacketHandler; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapReqOuterClass; -// import emu.grasscutter.server.game.GameSession; -// import emu.grasscutter.server.packet.send.PacketMusicGameStartToPlayOthersBeatmapRsp; -// -// @Opcodes(PacketOpcodes.MusicGameStartToPlayOthersBeatmapReq) -// public class HandlerMusicGameStartToPlayOthersBeatmapReq extends PacketHandler { -// -// @Override -// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { -// var req = -// MusicGameStartToPlayOthersBeatmapReqOuterClass.MusicGameStartToPlayOthersBeatmapReq.parseFrom(payload); -// -// session.send(new PacketMusicGameStartToPlayOthersBeatmapRsp(req.getUnknownEnum1())); -// } -// -// } +// package emu.grasscutter.server.packet.recv; +// +// import emu.grasscutter.net.packet.Opcodes; +// import emu.grasscutter.net.packet.PacketHandler; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapReqOuterClass; +// import emu.grasscutter.server.game.GameSession; +// import emu.grasscutter.server.packet.send.PacketMusicGameStartToPlayOthersBeatmapRsp; +// +// @Opcodes(PacketOpcodes.MusicGameStartToPlayOthersBeatmapReq) +// public class HandlerMusicGameStartToPlayOthersBeatmapReq extends PacketHandler { +// +// @Override +// public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { +// var req = +// MusicGameStartToPlayOthersBeatmapReqOuterClass.MusicGameStartToPlayOthersBeatmapReq.parseFrom(payload); +// +// session.send(new PacketMusicGameStartToPlayOthersBeatmapRsp(req.getUnknownEnum1())); +// } +// +// } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerObstacleModifyNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerObstacleModifyNotify.java index 74dbbf729..4bbb853de 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerObstacleModifyNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerObstacleModifyNotify.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ObstacleModifyNotify) -public class HandlerObstacleModifyNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ObstacleModifyNotify) +public class HandlerObstacleModifyNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPathfindingEnterSceneReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPathfindingEnterSceneReq.java index c0d59e708..9f68fd7b8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPathfindingEnterSceneReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPathfindingEnterSceneReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPathfindingEnterSceneRsp; - -@Opcodes(PacketOpcodes.PathfindingEnterSceneReq) -public class HandlerPathfindingEnterSceneReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PacketHead head = PacketHead.parseFrom(header); - session.send(new PacketPathfindingEnterSceneRsp(head.getClientSequenceId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPathfindingEnterSceneRsp; + +@Opcodes(PacketOpcodes.PathfindingEnterSceneReq) +public class HandlerPathfindingEnterSceneReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PacketHead head = PacketHead.parseFrom(header); + session.send(new PacketPathfindingEnterSceneRsp(head.getClientSequenceId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalLineAllDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalLineAllDataReq.java index 2ffdd93bd..3d2751c9a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalLineAllDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalLineAllDataReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPersonalLineAllDataRsp; - -@Opcodes(PacketOpcodes.PersonalLineAllDataReq) -public class HandlerPersonalLineAllDataReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send( - new PacketPersonalLineAllDataRsp( - session.getPlayer().getQuestManager().getMainQuests().values())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPersonalLineAllDataRsp; + +@Opcodes(PacketOpcodes.PersonalLineAllDataReq) +public class HandlerPersonalLineAllDataReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send( + new PacketPersonalLineAllDataRsp( + session.getPlayer().getQuestManager().getMainQuests().values())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java index a46ced9cd..282098ad7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPersonalSceneJumpReq.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.binout.ScenePointEntry; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PersonalSceneJumpReqOuterClass.PersonalSceneJumpReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPersonalSceneJumpRsp; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.PersonalSceneJumpReq) -public class HandlerPersonalSceneJumpReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PersonalSceneJumpReq req = PersonalSceneJumpReq.parseFrom(payload); - var player = session.getPlayer(); - - // get the scene point - ScenePointEntry scenePointEntry = - GameData.getScenePointEntryById(player.getSceneId(), req.getPointId()); - - if (scenePointEntry != null) { - Position pos = - scenePointEntry.getPointData().getTranPos().clone(); // This might not need cloning - int sceneId = scenePointEntry.getPointData().getTranSceneId(); - - player.getWorld().transferPlayerToScene(player, sceneId, pos); - session.send(new PacketPersonalSceneJumpRsp(sceneId, pos)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.binout.ScenePointEntry; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PersonalSceneJumpReqOuterClass.PersonalSceneJumpReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPersonalSceneJumpRsp; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.PersonalSceneJumpReq) +public class HandlerPersonalSceneJumpReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PersonalSceneJumpReq req = PersonalSceneJumpReq.parseFrom(payload); + var player = session.getPlayer(); + + // get the scene point + ScenePointEntry scenePointEntry = + GameData.getScenePointEntryById(player.getSceneId(), req.getPointId()); + + if (scenePointEntry != null) { + Position pos = + scenePointEntry.getPointData().getTranPos().clone(); // This might not need cloning + int sceneId = scenePointEntry.getPointData().getTranSceneId(); + + player.getWorld().transferPlayerToScene(player, sceneId, pos); + session.send(new PacketPersonalSceneJumpRsp(sceneId, pos)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPingReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPingReq.java index 6fbb63124..21c9dc51c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPingReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPingReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; -import emu.grasscutter.net.proto.PingReqOuterClass.PingReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPingRsp; - -@Opcodes(PacketOpcodes.PingReq) -public class HandlerPingReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PacketHead head = PacketHead.parseFrom(header); - PingReq ping = PingReq.parseFrom(payload); - - session.updateLastPingTime(ping.getClientTime()); - - session.send(new PacketPingRsp(head.getClientSequenceId(), ping.getClientTime())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PacketHeadOuterClass.PacketHead; +import emu.grasscutter.net.proto.PingReqOuterClass.PingReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPingRsp; + +@Opcodes(PacketOpcodes.PingReq) +public class HandlerPingReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PacketHead head = PacketHead.parseFrom(header); + PingReq ping = PingReq.parseFrom(payload); + + session.updateLastPingTime(ping.getClientTime()); + + session.send(new PacketPingRsp(head.getClientSequenceId(), ping.getClientTime())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpReq.java index b5f74e50a..3874d6e6f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpReqOuterClass.PlayerApplyEnterMpReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpRsp; - -@Opcodes(PacketOpcodes.PlayerApplyEnterMpReq) -public class HandlerPlayerApplyEnterMpReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PlayerApplyEnterMpReq req = PlayerApplyEnterMpReq.parseFrom(payload); - - session - .getServer() - .getMultiplayerSystem() - .applyEnterMp(session.getPlayer(), req.getTargetUid()); - session.send(new PacketPlayerApplyEnterMpRsp(req.getTargetUid())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpReqOuterClass.PlayerApplyEnterMpReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpRsp; + +@Opcodes(PacketOpcodes.PlayerApplyEnterMpReq) +public class HandlerPlayerApplyEnterMpReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PlayerApplyEnterMpReq req = PlayerApplyEnterMpReq.parseFrom(payload); + + session + .getServer() + .getMultiplayerSystem() + .applyEnterMp(session.getPlayer(), req.getTargetUid()); + session.send(new PacketPlayerApplyEnterMpRsp(req.getTargetUid())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpResultReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpResultReq.java index 8750e4b6e..d1c5d3d40 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpResultReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerApplyEnterMpResultReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpResultReqOuterClass.PlayerApplyEnterMpResultReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpResultRsp; - -@Opcodes(PacketOpcodes.PlayerApplyEnterMpResultReq) -public class HandlerPlayerApplyEnterMpResultReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PlayerApplyEnterMpResultReq req = PlayerApplyEnterMpResultReq.parseFrom(payload); - - session - .getServer() - .getMultiplayerSystem() - .applyEnterMpReply(session.getPlayer(), req.getApplyUid(), req.getIsAgreed()); - session.send(new PacketPlayerApplyEnterMpResultRsp(req.getApplyUid(), req.getIsAgreed())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpResultReqOuterClass.PlayerApplyEnterMpResultReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpResultRsp; + +@Opcodes(PacketOpcodes.PlayerApplyEnterMpResultReq) +public class HandlerPlayerApplyEnterMpResultReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PlayerApplyEnterMpResultReq req = PlayerApplyEnterMpResultReq.parseFrom(payload); + + session + .getServer() + .getMultiplayerSystem() + .applyEnterMpReply(session.getPlayer(), req.getApplyUid(), req.getIsAgreed()); + session.send(new PacketPlayerApplyEnterMpResultRsp(req.getApplyUid(), req.getIsAgreed())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerChatReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerChatReq.java index fd17f7996..3cabd5cb9 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerChatReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerChatReq.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; -import emu.grasscutter.net.proto.PlayerChatReqOuterClass.PlayerChatReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPlayerChatRsp; - -@Opcodes(PacketOpcodes.PlayerChatReq) -public class HandlerPlayerChatReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PlayerChatReq req = PlayerChatReq.parseFrom(payload); - ChatInfo.ContentCase content = req.getChatInfo().getContentCase(); - - if (content == ChatInfo.ContentCase.TEXT) { - session - .getServer() - .getChatSystem() - .sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getText()); - } else if (content == ChatInfo.ContentCase.ICON) { - session - .getServer() - .getChatSystem() - .sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getIcon()); - } - - session.send(new PacketPlayerChatRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; +import emu.grasscutter.net.proto.PlayerChatReqOuterClass.PlayerChatReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPlayerChatRsp; + +@Opcodes(PacketOpcodes.PlayerChatReq) +public class HandlerPlayerChatReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PlayerChatReq req = PlayerChatReq.parseFrom(payload); + ChatInfo.ContentCase content = req.getChatInfo().getContentCase(); + + if (content == ChatInfo.ContentCase.TEXT) { + session + .getServer() + .getChatSystem() + .sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getText()); + } else if (content == ChatInfo.ContentCase.ICON) { + session + .getServer() + .getChatSystem() + .sendTeamMessage(session.getPlayer(), req.getChannelId(), req.getChatInfo().getIcon()); + } + + session.send(new PacketPlayerChatRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCompoundMaterialReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCompoundMaterialReq.java index 14441a0d5..0558dca11 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCompoundMaterialReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCompoundMaterialReq.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PlayerCompoundMaterialReq) -public class HandlerPlayerCompoundMaterialReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq.parseFrom(payload); - session.getPlayer().getCookingCompoundManager().handlePlayerCompoundMaterialReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerCompoundMaterialReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PlayerCompoundMaterialReq) +public class HandlerPlayerCompoundMaterialReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = PlayerCompoundMaterialReqOuterClass.PlayerCompoundMaterialReq.parseFrom(payload); + session.getPlayer().getCookingCompoundManager().handlePlayerCompoundMaterialReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookArgsReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookArgsReq.java index 5cced6396..1e44d7d75 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookArgsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookArgsReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerCookArgsReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PlayerCookArgsReq) -public class HandlerPlayerCookArgsReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PlayerCookArgsReqOuterClass.PlayerCookArgsReq req = - PlayerCookArgsReqOuterClass.PlayerCookArgsReq.parseFrom(payload); - session.getPlayer().getCookingManager().handleCookArgsReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerCookArgsReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PlayerCookArgsReq) +public class HandlerPlayerCookArgsReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PlayerCookArgsReqOuterClass.PlayerCookArgsReq req = + PlayerCookArgsReqOuterClass.PlayerCookArgsReq.parseFrom(payload); + session.getPlayer().getCookingManager().handleCookArgsReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookReq.java index ac92bbdb2..7445657da 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerCookReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerCookReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PlayerCookReq) -public class HandlerPlayerCookReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PlayerCookReqOuterClass.PlayerCookReq req = - PlayerCookReqOuterClass.PlayerCookReq.parseFrom(payload); - session.getPlayer().getCookingManager().handlePlayerCookReq(req); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerCookReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PlayerCookReq) +public class HandlerPlayerCookReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PlayerCookReqOuterClass.PlayerCookReq req = + PlayerCookReqOuterClass.PlayerCookReq.parseFrom(payload); + session.getPlayer().getCookingManager().handlePlayerCookReq(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerForceExitReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerForceExitReq.java index 3a53b0a8a..a975ff5ae 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerForceExitReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerForceExitReq.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PlayerForceExitReq) -public class HandlerPlayerForceExitReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Client should auto disconnect right now - session.send(new BasePacket(PacketOpcodes.PlayerForceExitRsp)); - new Thread() { - @Override - public void run() { - try { - Thread.sleep(1000); // disconnect after 1 seconds - } catch (InterruptedException e) { - e.printStackTrace(); - } - session.close(); - super.run(); - } - }.start(); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PlayerForceExitReq) +public class HandlerPlayerForceExitReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Client should auto disconnect right now + session.send(new BasePacket(PacketOpcodes.PlayerForceExitRsp)); + new Thread() { + @Override + public void run() { + try { + Thread.sleep(1000); // disconnect after 1 seconds + } catch (InterruptedException e) { + e.printStackTrace(); + } + session.close(); + super.run(); + } + }.start(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerGetForceQuitBanInfoReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerGetForceQuitBanInfoReq.java index 1931ec03a..78f931484 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerGetForceQuitBanInfoReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerGetForceQuitBanInfoReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketPlayerGetForceQuitBanInfoRsp; - -@Opcodes(PacketOpcodes.PlayerGetForceQuitBanInfoReq) -public class HandlerPlayerGetForceQuitBanInfoReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - - if (session.getServer().getMultiplayerSystem().leaveCoop(session.getPlayer())) { - // Success - session.send( - new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)); - } else { - // Fail - session.send( - new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPlayerGetForceQuitBanInfoRsp; + +@Opcodes(PacketOpcodes.PlayerGetForceQuitBanInfoReq) +public class HandlerPlayerGetForceQuitBanInfoReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + + if (session.getServer().getMultiplayerSystem().leaveCoop(session.getPlayer())) { + // Success + session.send( + new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SUCC_VALUE)); + } else { + // Fail + session.send( + new PacketPlayerGetForceQuitBanInfoRsp(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java index f5d90172b..ff9495636 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPlayerLoginReq.java @@ -1,51 +1,51 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerLoginReqOuterClass.PlayerLoginReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.game.GameSession.SessionState; -import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp; -import emu.grasscutter.server.packet.send.PacketTakeAchievementRewardReq; - -@Opcodes(PacketOpcodes.PlayerLoginReq) // Sends initial data packets -public class HandlerPlayerLoginReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Check - if (session.getAccount() == null) { - session.close(); - return; - } - - // Parse request - PlayerLoginReq req = PlayerLoginReq.parseFrom(payload); - - // Authenticate session - if (!req.getToken().equals(session.getAccount().getToken())) { - session.close(); - return; - } - - // Load character from db - Player player = session.getPlayer(); - - // Show opening cutscene if player has no avatars - if (player.getAvatars().getAvatarCount() == 0) { - // Pick character - session.setState(SessionState.PICKING_CHARACTER); - session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify)); - } else { - // Login done - session.getPlayer().onLogin(); - } - - // Final packet to tell client logging in is done - session.send(new PacketPlayerLoginRsp(session)); - session.send(new PacketTakeAchievementRewardReq(session)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerLoginReqOuterClass.PlayerLoginReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.game.GameSession.SessionState; +import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp; +import emu.grasscutter.server.packet.send.PacketTakeAchievementRewardReq; + +@Opcodes(PacketOpcodes.PlayerLoginReq) // Sends initial data packets +public class HandlerPlayerLoginReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Check + if (session.getAccount() == null) { + session.close(); + return; + } + + // Parse request + PlayerLoginReq req = PlayerLoginReq.parseFrom(payload); + + // Authenticate session + if (!req.getToken().equals(session.getAccount().getToken())) { + session.close(); + return; + } + + // Load character from db + Player player = session.getPlayer(); + + // Show opening cutscene if player has no avatars + if (player.getAvatars().getAvatarCount() == 0) { + // Pick character + session.setState(SessionState.PICKING_CHARACTER); + session.send(new BasePacket(PacketOpcodes.DoSetPlayerBornDataNotify)); + } else { + // Login done + session.getPlayer().onLogin(); + } + + // Final packet to tell client logging in is done + session.send(new PacketPlayerLoginRsp(session)); + session.send(new PacketTakeAchievementRewardReq(session)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPrivateChatReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPrivateChatReq.java index 47ab5ee09..af7c10057 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPrivateChatReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPrivateChatReq.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PrivateChatReqOuterClass.PrivateChatReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PrivateChatReq) -public class HandlerPrivateChatReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PrivateChatReq req = PrivateChatReq.parseFrom(payload); - PrivateChatReq.ContentCase content = req.getContentCase(); - - if (content == PrivateChatReq.ContentCase.TEXT) { - session - .getServer() - .getChatSystem() - .sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getText()); - } else if (content == PrivateChatReq.ContentCase.ICON) { - session - .getServer() - .getChatSystem() - .sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getIcon()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PrivateChatReqOuterClass.PrivateChatReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PrivateChatReq) +public class HandlerPrivateChatReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PrivateChatReq req = PrivateChatReq.parseFrom(payload); + PrivateChatReq.ContentCase content = req.getContentCase(); + + if (content == PrivateChatReq.ContentCase.TEXT) { + session + .getServer() + .getChatSystem() + .sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getText()); + } else if (content == PrivateChatReq.ContentCase.ICON) { + session + .getServer() + .getChatSystem() + .sendPrivateMessage(session.getPlayer(), req.getTargetUid(), req.getIcon()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullPrivateChatReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullPrivateChatReq.java index 75282bb96..3afa2f8d4 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullPrivateChatReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullPrivateChatReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PullPrivateChatReqOuterClass.PullPrivateChatReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PullPrivateChatReq) -public class HandlerPullPrivateChatReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - PullPrivateChatReq req = PullPrivateChatReq.parseFrom(payload); - - session - .getServer() - .getChatSystem() - .handlePullPrivateChatReq(session.getPlayer(), req.getTargetUid()); - - // session.send(new PacketPullPrivateChatRsp(req.getTargetUid())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PullPrivateChatReqOuterClass.PullPrivateChatReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PullPrivateChatReq) +public class HandlerPullPrivateChatReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + PullPrivateChatReq req = PullPrivateChatReq.parseFrom(payload); + + session + .getServer() + .getChatSystem() + .handlePullPrivateChatReq(session.getPlayer(), req.getTargetUid()); + + // session.send(new PacketPullPrivateChatRsp(req.getTargetUid())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullRecentChatReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullRecentChatReq.java index 1af88edd1..8e7ee378b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullRecentChatReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerPullRecentChatReq.java @@ -1,14 +1,14 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.PullRecentChatReq) -public class HandlerPullRecentChatReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getServer().getChatSystem().handlePullRecentChatReq(session.getPlayer()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.PullRecentChatReq) +public class HandlerPullRecentChatReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getServer().getChatSystem().handlePullRecentChatReq(session.getPlayer()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryCodexMonsterBeKilledNumReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryCodexMonsterBeKilledNumReq.java index f8035ac9e..314821cf1 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryCodexMonsterBeKilledNumReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryCodexMonsterBeKilledNumReq.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QueryCodexMonsterBeKilledNumReqOuterClass.QueryCodexMonsterBeKilledNumReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQueryCodexMonsterBeKilledNumRsp; - -@Opcodes(PacketOpcodes.QueryCodexMonsterBeKilledNumReq) -public class HandlerQueryCodexMonsterBeKilledNumReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - QueryCodexMonsterBeKilledNumReq req = QueryCodexMonsterBeKilledNumReq.parseFrom(payload); - session.send( - new PacketQueryCodexMonsterBeKilledNumRsp(session.getPlayer(), req.getCodexIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QueryCodexMonsterBeKilledNumReqOuterClass.QueryCodexMonsterBeKilledNumReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQueryCodexMonsterBeKilledNumRsp; + +@Opcodes(PacketOpcodes.QueryCodexMonsterBeKilledNumReq) +public class HandlerQueryCodexMonsterBeKilledNumReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + QueryCodexMonsterBeKilledNumReq req = QueryCodexMonsterBeKilledNumReq.parseFrom(payload); + session.send( + new PacketQueryCodexMonsterBeKilledNumRsp(session.getPlayer(), req.getCodexIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java index b7ebf298c..85dcbc251 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQueryPathReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QueryPathReqOuterClass.QueryPathReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketQueryPathRsp; - -@Opcodes(PacketOpcodes.QueryPathReq) -public class HandlerQueryPathReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = QueryPathReq.parseFrom(payload); - - /** It is not the actual work */ - if (req.getDestinationPosList().size() > 0) { - session.send(new PacketQueryPathRsp(req)); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QueryPathReqOuterClass.QueryPathReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketQueryPathRsp; + +@Opcodes(PacketOpcodes.QueryPathReq) +public class HandlerQueryPathReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = QueryPathReq.parseFrom(payload); + + /** It is not the actual work */ + if (req.getDestinationPosList().size() > 0) { + session.send(new PacketQueryPathRsp(req)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java index 2d4ae0790..b9be2b956 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java @@ -1,53 +1,53 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.inventory.Inventory; -import emu.grasscutter.game.inventory.InventoryTab; -import emu.grasscutter.game.inventory.ItemType; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuickUseWidgetRspOuterClass.QuickUseWidgetRsp; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.QuickUseWidgetReq) -public class HandlerQuickUseWidgetReq extends PacketHandler { - /* - * WARNING: with the consuming of material widget ( Example: bomb ), - * this is just a implement designed to the decreasing of count - * - * ### Known Bug: No effects after using item but decrease. ### - * - * If you know which Packet could make the effects, feel free to contribute! - * */ - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - QuickUseWidgetRsp.Builder proto = QuickUseWidgetRsp.newBuilder(); - Player pl = session.getPlayer(); - synchronized (pl) { - int materialId = pl.getWidgetId(); - Inventory inventory = session.getPlayer().getInventory(); - InventoryTab inventoryTab = inventory.getInventoryTab(ItemType.ITEM_MATERIAL); - GameItem item = inventoryTab.getItemById(materialId); - int remain = item.getCount(); - if (remain > 0) { - remain--; - if (remain <= 0) { - proto.setRetcode(1); - } else { - proto.setRetcode(0); - } - proto.setMaterialId(materialId); - inventory.removeItem(item, 1); // decrease count - BasePacket rsp = new BasePacket(PacketOpcodes.QuickUseWidgetRsp); - rsp.setData(proto); - session.send(rsp); - Grasscutter.getLogger().warn("class has no effects in the game, feel free to implement it"); - // but no effects in the game, feel free to implement it! - } - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.inventory.InventoryTab; +import emu.grasscutter.game.inventory.ItemType; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuickUseWidgetRspOuterClass.QuickUseWidgetRsp; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.QuickUseWidgetReq) +public class HandlerQuickUseWidgetReq extends PacketHandler { + /* + * WARNING: with the consuming of material widget ( Example: bomb ), + * this is just a implement designed to the decreasing of count + * + * ### Known Bug: No effects after using item but decrease. ### + * + * If you know which Packet could make the effects, feel free to contribute! + * */ + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + QuickUseWidgetRsp.Builder proto = QuickUseWidgetRsp.newBuilder(); + Player pl = session.getPlayer(); + synchronized (pl) { + int materialId = pl.getWidgetId(); + Inventory inventory = session.getPlayer().getInventory(); + InventoryTab inventoryTab = inventory.getInventoryTab(ItemType.ITEM_MATERIAL); + GameItem item = inventoryTab.getItemById(materialId); + int remain = item.getCount(); + if (remain > 0) { + remain--; + if (remain <= 0) { + proto.setRetcode(1); + } else { + proto.setRetcode(0); + } + proto.setMaterialId(materialId); + inventory.removeItem(item, 1); // decrease count + BasePacket rsp = new BasePacket(PacketOpcodes.QuickUseWidgetRsp); + rsp.setData(proto); + session.send(rsp); + Grasscutter.getLogger().warn("class has no effects in the game, feel free to implement it"); + // but no effects in the game, feel free to implement it! + } + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java index 8b863b470..e70fa22b5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReadMailNotify.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.mail.Mail; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ReadMailNotifyOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketMailChangeNotify; -import java.util.ArrayList; -import java.util.List; - -@Opcodes(PacketOpcodes.ReadMailNotify) -public class HandlerReadMailNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ReadMailNotifyOuterClass.ReadMailNotify req = - ReadMailNotifyOuterClass.ReadMailNotify.parseFrom(payload); - - List updatedMail = new ArrayList<>(); - - for (int mailId : req.getMailIdListList()) { - Mail message = session.getPlayer().getMail(mailId); - - message.isRead = true; - - session.getPlayer().replaceMailByIndex(mailId, message); - updatedMail.add(message); - } - - session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReadMailNotifyOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketMailChangeNotify; +import java.util.ArrayList; +import java.util.List; + +@Opcodes(PacketOpcodes.ReadMailNotify) +public class HandlerReadMailNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ReadMailNotifyOuterClass.ReadMailNotify req = + ReadMailNotifyOuterClass.ReadMailNotify.parseFrom(payload); + + List updatedMail = new ArrayList<>(); + + for (int mailId : req.getMailIdListList()) { + Mail message = session.getPlayer().getMail(mailId); + + message.isRead = true; + + session.getPlayer().replaceMailByIndex(mailId, message); + updatedMail.add(message); + } + + session.send(new PacketMailChangeNotify(session.getPlayer(), updatedMail)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryDecomposeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryDecomposeReq.java index e56b2e151..6844d011e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryDecomposeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryDecomposeReq.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ReliquaryDecomposeReqOuterClass.ReliquaryDecomposeReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ReliquaryDecomposeReq) -public class HandlerReliquaryDecomposeReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ReliquaryDecomposeReq req = ReliquaryDecomposeReq.parseFrom(payload); - session - .getServer() - .getCombineSystem() - .decomposeReliquaries( - session.getPlayer(), req.getConfigId(), req.getTargetCount(), req.getGuidListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReliquaryDecomposeReqOuterClass.ReliquaryDecomposeReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ReliquaryDecomposeReq) +public class HandlerReliquaryDecomposeReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ReliquaryDecomposeReq req = ReliquaryDecomposeReq.parseFrom(payload); + session + .getServer() + .getCombineSystem() + .decomposeReliquaries( + session.getPlayer(), req.getConfigId(), req.getTargetCount(), req.getGuidListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryUpgradeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryUpgradeReq.java index 17fb15cc3..d9ddc8400 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryUpgradeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerReliquaryUpgradeReq.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ReliquaryUpgradeReqOuterClass.ReliquaryUpgradeReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.ReliquaryUpgradeReq) -public class HandlerReliquaryUpgradeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - ReliquaryUpgradeReq req = ReliquaryUpgradeReq.parseFrom(payload); - - session - .getServer() - .getInventorySystem() - .upgradeRelic( - session.getPlayer(), - req.getTargetReliquaryGuid(), - req.getFoodReliquaryGuidListList(), - req.getItemParamListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReliquaryUpgradeReqOuterClass.ReliquaryUpgradeReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.ReliquaryUpgradeReq) +public class HandlerReliquaryUpgradeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ReliquaryUpgradeReq req = ReliquaryUpgradeReq.parseFrom(payload); + + session + .getServer() + .getInventorySystem() + .upgradeRelic( + session.getPlayer(), + req.getTargetReliquaryGuid(), + req.getFoodReliquaryGuidListList(), + req.getItemParamListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java index 014f666ad..05882f528 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java @@ -1,36 +1,36 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.entity.EntityMonster; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneEntityDrownReqOuterClass.SceneEntityDrownReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSceneEntityDrownRsp; - -@Opcodes(PacketOpcodes.SceneEntityDrownReq) -public class HandlerSceneEntityDrownReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SceneEntityDrownReq req = SceneEntityDrownReq.parseFrom(payload); - - GameEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId()); - - if (entity == null || !(entity instanceof EntityMonster || entity instanceof EntityAvatar)) { - return; - } - - entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0); - - // TODO: make a list somewhere of all entities to remove per tick rather than one by one - session.getPlayer().getScene().killEntity(entity, 0); - session - .getPlayer() - .getScene() - .broadcastPacket(new PacketSceneEntityDrownRsp(req.getEntityId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.entity.EntityMonster; +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityDrownReqOuterClass.SceneEntityDrownReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSceneEntityDrownRsp; + +@Opcodes(PacketOpcodes.SceneEntityDrownReq) +public class HandlerSceneEntityDrownReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SceneEntityDrownReq req = SceneEntityDrownReq.parseFrom(payload); + + GameEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId()); + + if (entity == null || !(entity instanceof EntityMonster || entity instanceof EntityAvatar)) { + return; + } + + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 0); + + // TODO: make a list somewhere of all entities to remove per tick rather than one by one + session.getPlayer().getScene().killEntity(entity, 0); + session + .getPlayer() + .getScene() + .broadcastPacket(new PacketSceneEntityDrownRsp(req.getEntityId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneInitFinishReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneInitFinishReq.java index 0a2bf571d..20a9137ef 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneInitFinishReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneInitFinishReq.java @@ -1,40 +1,40 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player.SceneLoadState; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.*; - -@Opcodes(PacketOpcodes.SceneInitFinishReq) -public class HandlerSceneInitFinishReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Info packets - session.send(new PacketServerTimeNotify()); - session.send(new PacketWorldPlayerInfoNotify(session.getPlayer().getWorld())); - session.send(new PacketWorldDataNotify(session.getPlayer().getWorld())); - session.send(new PacketPlayerWorldSceneInfoListNotify()); - session.send(new BasePacket(PacketOpcodes.SceneForceUnlockNotify)); - session.send(new PacketHostPlayerNotify(session.getPlayer().getWorld())); - - session.send(new PacketSceneTimeNotify(session.getPlayer())); - session.send(new PacketPlayerGameTimeNotify(session.getPlayer())); - session.send(new PacketPlayerEnterSceneInfoNotify(session.getPlayer())); - session.send(new PacketSceneAreaWeatherNotify(session.getPlayer())); - session.send(new PacketScenePlayerInfoNotify(session.getPlayer().getWorld())); - session.send(new PacketSceneTeamUpdateNotify(session.getPlayer())); - - session.send(new PacketSyncTeamEntityNotify(session.getPlayer())); - session.send(new PacketSyncScenePlayTeamEntityNotify(session.getPlayer())); - - // Done Packet - session.send(new PacketSceneInitFinishRsp(session.getPlayer())); - - // Set state - session.getPlayer().setSceneLoadState(SceneLoadState.INIT); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player.SceneLoadState; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.*; + +@Opcodes(PacketOpcodes.SceneInitFinishReq) +public class HandlerSceneInitFinishReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Info packets + session.send(new PacketServerTimeNotify()); + session.send(new PacketWorldPlayerInfoNotify(session.getPlayer().getWorld())); + session.send(new PacketWorldDataNotify(session.getPlayer().getWorld())); + session.send(new PacketPlayerWorldSceneInfoListNotify()); + session.send(new BasePacket(PacketOpcodes.SceneForceUnlockNotify)); + session.send(new PacketHostPlayerNotify(session.getPlayer().getWorld())); + + session.send(new PacketSceneTimeNotify(session.getPlayer())); + session.send(new PacketPlayerGameTimeNotify(session.getPlayer())); + session.send(new PacketPlayerEnterSceneInfoNotify(session.getPlayer())); + session.send(new PacketSceneAreaWeatherNotify(session.getPlayer())); + session.send(new PacketScenePlayerInfoNotify(session.getPlayer().getWorld())); + session.send(new PacketSceneTeamUpdateNotify(session.getPlayer())); + + session.send(new PacketSyncTeamEntityNotify(session.getPlayer())); + session.send(new PacketSyncScenePlayTeamEntityNotify(session.getPlayer())); + + // Done Packet + session.send(new PacketSceneInitFinishRsp(session.getPlayer())); + + // Set state + session.getPlayer().setSceneLoadState(SceneLoadState.INIT); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneKickPlayerReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneKickPlayerReq.java index ea5d8142d..eddeddc09 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneKickPlayerReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneKickPlayerReq.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneKickPlayerReqOuterClass.SceneKickPlayerReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSceneKickPlayerRsp; - -@Opcodes(PacketOpcodes.SceneKickPlayerReq) -public class HandlerSceneKickPlayerReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SceneKickPlayerReq req = SceneKickPlayerReq.parseFrom(payload); - - if (session - .getServer() - .getMultiplayerSystem() - .kickPlayer(session.getPlayer(), req.getTargetUid())) { - // Success - session.send(new PacketSceneKickPlayerRsp(req.getTargetUid())); - } else { - // Fail - session.send(new PacketSceneKickPlayerRsp()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneKickPlayerReqOuterClass.SceneKickPlayerReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSceneKickPlayerRsp; + +@Opcodes(PacketOpcodes.SceneKickPlayerReq) +public class HandlerSceneKickPlayerReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SceneKickPlayerReq req = SceneKickPlayerReq.parseFrom(payload); + + if (session + .getServer() + .getMultiplayerSystem() + .kickPlayer(session.getPlayer(), req.getTargetUid())) { + // Success + session.send(new PacketSceneKickPlayerRsp(req.getTargetUid())); + } else { + // Fail + session.send(new PacketSceneKickPlayerRsp()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java index 90d7a6df2..68ec0d5c5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java @@ -1,39 +1,39 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.binout.ScenePointEntry; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq; -import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp; - -@Opcodes(PacketOpcodes.SceneTransToPointReq) -public class HandlerSceneTransToPointReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload); - var player = session.getPlayer(); - - ScenePointEntry scenePointEntry = - GameData.getScenePointEntryById(req.getSceneId(), req.getPointId()); - - if (scenePointEntry != null) { - if (player - .getWorld() - .transferPlayerToScene( - player, - req.getSceneId(), - TeleportType.WAYPOINT, - scenePointEntry.getPointData().getTranPos().clone())) { - session.send(new PacketSceneTransToPointRsp(player, req.getPointId(), req.getSceneId())); - return; - } - } - - session.send(new PacketSceneTransToPointRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.binout.ScenePointEntry; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq; +import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp; + +@Opcodes(PacketOpcodes.SceneTransToPointReq) +public class HandlerSceneTransToPointReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload); + var player = session.getPlayer(); + + ScenePointEntry scenePointEntry = + GameData.getScenePointEntryById(req.getSceneId(), req.getPointId()); + + if (scenePointEntry != null) { + if (player + .getWorld() + .transferPlayerToScene( + player, + req.getSceneId(), + TeleportType.WAYPOINT, + scenePointEntry.getPointData().getTranPos().clone())) { + session.send(new PacketSceneTransToPointRsp(player, req.getPointId(), req.getSceneId())); + return; + } + } + + session.send(new PacketSceneTransToPointRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEntityClientDataNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEntityClientDataNotify.java index 1811c6562..a2fd21952 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEntityClientDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEntityClientDataNotify.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetEntityClientDataNotifyOuterClass.SetEntityClientDataNotify; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.SetEntityClientDataNotify) -public class HandlerSetEntityClientDataNotify extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Skip if there is no one to broadcast it too - if (session.getPlayer().getScene().getPlayerCount() <= 1) { - return; - } - - // Make sure packet is a valid proto before replaying it to the other players - SetEntityClientDataNotify notif = SetEntityClientDataNotify.parseFrom(payload); - - BasePacket packet = new BasePacket(PacketOpcodes.SetEntityClientDataNotify, true); - packet.setData(notif); - - session.getPlayer().getScene().broadcastPacket(packet); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetEntityClientDataNotifyOuterClass.SetEntityClientDataNotify; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.SetEntityClientDataNotify) +public class HandlerSetEntityClientDataNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Skip if there is no one to broadcast it too + if (session.getPlayer().getScene().getPlayerCount() <= 1) { + return; + } + + // Make sure packet is a valid proto before replaying it to the other players + SetEntityClientDataNotify notif = SetEntityClientDataNotify.parseFrom(payload); + + BasePacket packet = new BasePacket(PacketOpcodes.SetEntityClientDataNotify, true); + packet.setData(notif); + + session.getPlayer().getScene().broadcastPacket(packet); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEquipLockStateReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEquipLockStateReq.java index 6434478dc..c4b64f02b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEquipLockStateReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetEquipLockStateReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetEquipLockStateReqOuterClass.SetEquipLockStateReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.SetEquipLockStateReq) -public class HandlerSetEquipLockStateReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetEquipLockStateReq req = SetEquipLockStateReq.parseFrom(payload); - - session - .getServer() - .getInventorySystem() - .lockEquip(session.getPlayer(), req.getTargetEquipGuid(), req.getIsLocked()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetEquipLockStateReqOuterClass.SetEquipLockStateReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.SetEquipLockStateReq) +public class HandlerSetEquipLockStateReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetEquipLockStateReq req = SetEquipLockStateReq.parseFrom(payload); + + session + .getServer() + .getInventorySystem() + .lockEquip(session.getPlayer(), req.getTargetEquipGuid(), req.getIsLocked()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetNameCardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetNameCardReq.java index 4ff035460..d89793f51 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetNameCardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetNameCardReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetNameCardReqOuterClass.SetNameCardReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.SetNameCardReq) -public class HandlerSetNameCardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetNameCardReq req = SetNameCardReq.parseFrom(payload); - - session.getPlayer().setNameCard(req.getNameCardId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetNameCardReqOuterClass.SetNameCardReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.SetNameCardReq) +public class HandlerSetNameCardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetNameCardReq req = SetNameCardReq.parseFrom(payload); + + session.getPlayer().setNameCard(req.getNameCardId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java index a758b29d6..c43d93c44 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java @@ -1,66 +1,66 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerBirthdayReqOuterClass.SetPlayerBirthdayReq; -import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp; -import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp; - -@Opcodes(PacketOpcodes.SetPlayerBirthdayReq) -public class HandlerSetPlayerBirthdayReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload); - - // RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009 - if (session.getPlayer().hasBirthday()) { - session.send(new PacketSetPlayerBirthdayRsp(7009)); - return; - } - - int month = req.getBirthday().getMonth(); - int day = req.getBirthday().getDay(); - - // RET_BIRTHDAY_FORMAT_ERROR = 7022 - if (!isValidBirthday(month, day)) { - session.send(new PacketSetPlayerBirthdayRsp(7022)); - return; - } - - // Update birthday value - session.getPlayer().setBirthday(day, month); - - // Save birthday month and day - session.getPlayer().save(); - SocialDetail.Builder detail = session.getPlayer().getSocialDetail(); - - session.send(new PacketSetPlayerBirthdayRsp(session.getPlayer())); - session.send(new PacketGetPlayerSocialDetailRsp(detail)); - } - - private boolean isValidBirthday(int month, int day) { - - switch (month) { - case 1: - case 3: - case 5: - case 7: - case 8: - case 10: - case 12: - return day > 0 & day <= 31; - case 4: - case 6: - case 9: - case 11: - return day > 0 && day <= 30; - case 2: - return day > 0 & day <= 29; - } - - return false; - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerBirthdayReqOuterClass.SetPlayerBirthdayReq; +import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp; +import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp; + +@Opcodes(PacketOpcodes.SetPlayerBirthdayReq) +public class HandlerSetPlayerBirthdayReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload); + + // RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009 + if (session.getPlayer().hasBirthday()) { + session.send(new PacketSetPlayerBirthdayRsp(7009)); + return; + } + + int month = req.getBirthday().getMonth(); + int day = req.getBirthday().getDay(); + + // RET_BIRTHDAY_FORMAT_ERROR = 7022 + if (!isValidBirthday(month, day)) { + session.send(new PacketSetPlayerBirthdayRsp(7022)); + return; + } + + // Update birthday value + session.getPlayer().setBirthday(day, month); + + // Save birthday month and day + session.getPlayer().save(); + SocialDetail.Builder detail = session.getPlayer().getSocialDetail(); + + session.send(new PacketSetPlayerBirthdayRsp(session.getPlayer())); + session.send(new PacketGetPlayerSocialDetailRsp(detail)); + } + + private boolean isValidBirthday(int month, int day) { + + switch (month) { + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + return day > 0 & day <= 31; + case 4: + case 6: + case 9: + case 11: + return day > 0 && day <= 30; + case 2: + return day > 0 & day <= 29; + } + + return false; + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerHeadImageReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerHeadImageReq.java index 55494dc28..dca919192 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerHeadImageReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerHeadImageReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerHeadImageReqOuterClass.SetPlayerHeadImageReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetPlayerHeadImageRsp; - -@Opcodes(PacketOpcodes.SetPlayerHeadImageReq) -public class HandlerSetPlayerHeadImageReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetPlayerHeadImageReq req = SetPlayerHeadImageReq.parseFrom(payload); - - int id = req.getAvatarId(); - - if (session.getPlayer().getAvatars().hasAvatar(id)) { - session.getPlayer().setHeadImage(id); - session.send(new PacketSetPlayerHeadImageRsp(session.getPlayer())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerHeadImageReqOuterClass.SetPlayerHeadImageReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetPlayerHeadImageRsp; + +@Opcodes(PacketOpcodes.SetPlayerHeadImageReq) +public class HandlerSetPlayerHeadImageReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetPlayerHeadImageReq req = SetPlayerHeadImageReq.parseFrom(payload); + + int id = req.getAvatarId(); + + if (session.getPlayer().getAvatars().hasAvatar(id)) { + session.getPlayer().setHeadImage(id); + session.send(new PacketSetPlayerHeadImageRsp(session.getPlayer())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java index 6b9b316c9..1f79ac0e7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerNameReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerNameReqOuterClass.SetPlayerNameReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetPlayerNameRsp; - -@Opcodes(PacketOpcodes.SetPlayerNameReq) -public class HandlerSetPlayerNameReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - SetPlayerNameReq req = SetPlayerNameReq.parseFrom(payload); - - if (req.getNickName() != null && req.getNickName().length() > 0) { - session.getPlayer().setNickname(req.getNickName()); - session.send(new PacketSetPlayerNameRsp(session.getPlayer())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerNameReqOuterClass.SetPlayerNameReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetPlayerNameRsp; + +@Opcodes(PacketOpcodes.SetPlayerNameReq) +public class HandlerSetPlayerNameReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + SetPlayerNameReq req = SetPlayerNameReq.parseFrom(payload); + + if (req.getNickName() != null && req.getNickName().length() > 0) { + session.getPlayer().setNickname(req.getNickName()); + session.send(new PacketSetPlayerNameRsp(session.getPlayer())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerPropReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerPropReq.java index e39cef120..6753c3e6e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerPropReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerPropReq.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.PlayerProperty; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; -import emu.grasscutter.net.proto.SetPlayerPropReqOuterClass.SetPlayerPropReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetPlayerPropRsp; - -@Opcodes(PacketOpcodes.SetPlayerPropReq) -public class HandlerSetPlayerPropReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - SetPlayerPropReq req = SetPlayerPropReq.parseFrom(payload); - Player player = session.getPlayer(); - for (PropValue p : req.getPropListList()) { - PlayerProperty prop = PlayerProperty.getPropById(p.getType()); - if (prop == PlayerProperty.PROP_IS_MP_MODE_AVAILABLE) { - if (!player.setProperty(prop, (int) p.getVal(), false)) { - session.send(new PacketSetPlayerPropRsp(1)); - return; - } - } - } - player.save(); - session.send(new PacketSetPlayerPropRsp(0)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; +import emu.grasscutter.net.proto.SetPlayerPropReqOuterClass.SetPlayerPropReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetPlayerPropRsp; + +@Opcodes(PacketOpcodes.SetPlayerPropReq) +public class HandlerSetPlayerPropReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + SetPlayerPropReq req = SetPlayerPropReq.parseFrom(payload); + Player player = session.getPlayer(); + for (PropValue p : req.getPropListList()) { + PlayerProperty prop = PlayerProperty.getPropById(p.getType()); + if (prop == PlayerProperty.PROP_IS_MP_MODE_AVAILABLE) { + if (!player.setProperty(prop, (int) p.getVal(), false)) { + session.send(new PacketSetPlayerPropRsp(1)); + return; + } + } + } + player.save(); + session.send(new PacketSetPlayerPropRsp(0)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java index 139dff1c2..a463e1e6f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerSignatureReq.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerSignatureReqOuterClass.SetPlayerSignatureReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetPlayerSignatureRsp; - -@Opcodes(PacketOpcodes.SetPlayerSignatureReq) -public class HandlerSetPlayerSignatureReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - // Auto template - SetPlayerSignatureReq req = SetPlayerSignatureReq.parseFrom(payload); - - if (req.getSignature() != null && req.getSignature().length() > 0) { - session.getPlayer().setSignature(req.getSignature()); - session.send(new PacketSetPlayerSignatureRsp(session.getPlayer())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerSignatureReqOuterClass.SetPlayerSignatureReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetPlayerSignatureRsp; + +@Opcodes(PacketOpcodes.SetPlayerSignatureReq) +public class HandlerSetPlayerSignatureReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + // Auto template + SetPlayerSignatureReq req = SetPlayerSignatureReq.parseFrom(payload); + + if (req.getSignature() != null && req.getSignature().length() > 0) { + session.getPlayer().setSignature(req.getSignature()); + session.send(new PacketSetPlayerSignatureRsp(session.getPlayer())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpAvatarTeamReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpAvatarTeamReq.java index 1b3334674..380edfb54 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpAvatarTeamReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpAvatarTeamReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetUpAvatarTeamReqOuterClass.SetUpAvatarTeamReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.SetUpAvatarTeamReq) -public class HandlerSetUpAvatarTeamReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetUpAvatarTeamReq req = SetUpAvatarTeamReq.parseFrom(payload); - - session - .getPlayer() - .getTeamManager() - .setupAvatarTeam(req.getTeamId(), req.getAvatarTeamGuidListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetUpAvatarTeamReqOuterClass.SetUpAvatarTeamReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.SetUpAvatarTeamReq) +public class HandlerSetUpAvatarTeamReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetUpAvatarTeamReq req = SetUpAvatarTeamReq.parseFrom(payload); + + session + .getPlayer() + .getTeamManager() + .setupAvatarTeam(req.getTeamId(), req.getAvatarTeamGuidListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpLunchBoxWidgetReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpLunchBoxWidgetReq.java index 37d95e5e3..e127831aa 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpLunchBoxWidgetReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetUpLunchBoxWidgetReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetUpLunchBoxWidgetReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetUpLunchBoxWidgetRsp; - -@Opcodes(PacketOpcodes.SetUpLunchBoxWidgetReq) -public class HandlerSetUpLunchBoxWidgetReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = SetUpLunchBoxWidgetReqOuterClass.SetUpLunchBoxWidgetReq.parseFrom(payload); - - session.send(new PacketSetUpLunchBoxWidgetRsp(req.getLunchBoxData())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetUpLunchBoxWidgetReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetUpLunchBoxWidgetRsp; + +@Opcodes(PacketOpcodes.SetUpLunchBoxWidgetReq) +public class HandlerSetUpLunchBoxWidgetReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = SetUpLunchBoxWidgetReqOuterClass.SetUpLunchBoxWidgetReq.parseFrom(payload); + + session.send(new PacketSetUpLunchBoxWidgetRsp(req.getLunchBoxData())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetWidgetSlotReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetWidgetSlotReq.java index 401e7f192..290de2990 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetWidgetSlotReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetWidgetSlotReq.java @@ -1,38 +1,38 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetWidgetSlotReqOuterClass; -import emu.grasscutter.net.proto.WidgetSlotOpOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketSetWidgetSlotRsp; -import emu.grasscutter.server.packet.send.PacketWidgetSlotChangeNotify; - -@Opcodes(PacketOpcodes.SetWidgetSlotReq) -public class HandlerSetWidgetSlotReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - SetWidgetSlotReqOuterClass.SetWidgetSlotReq req = - SetWidgetSlotReqOuterClass.SetWidgetSlotReq.parseFrom(payload); - - Player player = session.getPlayer(); - player.setWidgetId(req.getMaterialId()); - - // WidgetSlotChangeNotify op & slot key - session.send( - new PacketWidgetSlotChangeNotify( - WidgetSlotOpOuterClass.WidgetSlotOp.WIDGET_SLOT_OP_DETACH)); - - // only attaching the widget can set it - if (req.getOp() == WidgetSlotOpOuterClass.WidgetSlotOp.WIDGET_SLOT_OP_ATTACH) { - // WidgetSlotChangeNotify slot - session.send(new PacketWidgetSlotChangeNotify(req.getMaterialId())); - } - - // SetWidgetSlotRsp - session.send(new PacketSetWidgetSlotRsp(req.getMaterialId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetWidgetSlotReqOuterClass; +import emu.grasscutter.net.proto.WidgetSlotOpOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSetWidgetSlotRsp; +import emu.grasscutter.server.packet.send.PacketWidgetSlotChangeNotify; + +@Opcodes(PacketOpcodes.SetWidgetSlotReq) +public class HandlerSetWidgetSlotReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SetWidgetSlotReqOuterClass.SetWidgetSlotReq req = + SetWidgetSlotReqOuterClass.SetWidgetSlotReq.parseFrom(payload); + + Player player = session.getPlayer(); + player.setWidgetId(req.getMaterialId()); + + // WidgetSlotChangeNotify op & slot key + session.send( + new PacketWidgetSlotChangeNotify( + WidgetSlotOpOuterClass.WidgetSlotOp.WIDGET_SLOT_OP_DETACH)); + + // only attaching the widget can set it + if (req.getOp() == WidgetSlotOpOuterClass.WidgetSlotOp.WIDGET_SLOT_OP_ATTACH) { + // WidgetSlotChangeNotify slot + session.send(new PacketWidgetSlotChangeNotify(req.getMaterialId())); + } + + // SetWidgetSlotRsp + session.send(new PacketSetWidgetSlotRsp(req.getMaterialId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeAchievementGoalRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeAchievementGoalRewardReq.java index d20ef4ba4..bb023f245 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeAchievementGoalRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeAchievementGoalRewardReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeAchievementGoalRewardReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.TakeAchievementGoalRewardReq) -public class HandlerTakeAchievementGoalRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - TakeAchievementGoalRewardReqOuterClass.TakeAchievementGoalRewardReq.parseFrom(payload); - session.getPlayer().getAchievements().takeGoalReward(req.getIdListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeAchievementGoalRewardReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.TakeAchievementGoalRewardReq) +public class HandlerTakeAchievementGoalRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + TakeAchievementGoalRewardReqOuterClass.TakeAchievementGoalRewardReq.parseFrom(payload); + session.getPlayer().getAchievements().takeGoalReward(req.getIdListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeBattlePassRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeBattlePassRewardReq.java index e1b290547..b201f6570 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeBattlePassRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeBattlePassRewardReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeBattlePassRewardReqOuterClass.TakeBattlePassRewardReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.TakeBattlePassRewardReq) -public class HandlerTakeBattlePassRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = TakeBattlePassRewardReq.parseFrom(payload); - - session.getPlayer().getBattlePassManager().takeReward(req.getTakeOptionListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeBattlePassRewardReqOuterClass.TakeBattlePassRewardReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.TakeBattlePassRewardReq) +public class HandlerTakeBattlePassRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = TakeBattlePassRewardReq.parseFrom(payload); + + session.getPlayer().getBattlePassManager().takeReward(req.getTakeOptionListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeFurnitureMakeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeFurnitureMakeReq.java index 8706bff1d..bec9366db 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeFurnitureMakeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeFurnitureMakeReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeFurnitureMakeReqOuterClass; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.TakeFurnitureMakeReq) -public class HandlerTakeFurnitureMakeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = TakeFurnitureMakeReqOuterClass.TakeFurnitureMakeReq.parseFrom(payload); - - session - .getPlayer() - .getFurnitureManager() - .take(req.getIndex(), req.getMakeId(), req.getIsFastFinish()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeFurnitureMakeReqOuterClass; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.TakeFurnitureMakeReq) +public class HandlerTakeFurnitureMakeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = TakeFurnitureMakeReqOuterClass.TakeFurnitureMakeReq.parseFrom(payload); + + session + .getPlayer() + .getFurnitureManager() + .take(req.getIndex(), req.getMakeId(), req.getIsFastFinish()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java index eafa180f2..2f68d5791 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java @@ -1,39 +1,39 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp; -import java.util.List; -import java.util.Set; - -@Opcodes(PacketOpcodes.TakePlayerLevelRewardReq) -public class HandlerTakePlayerLevelRewardReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - Player pl = session.getPlayer(); - synchronized (pl) { - TakePlayerLevelRewardReq req = TakePlayerLevelRewardReq.parseFrom(payload); - int level = req.getLevel(); - Set rewardedLevels = session.getPlayer().getRewardedLevels(); - if (!rewardedLevels.contains(level)) { // No duplicated reward - int rewardId = GameData.getPlayerLevelDataMap().get(level).getRewardId(); - if (rewardId != 0) { - List rewardItems = - GameData.getRewardDataMap().get(rewardId).getRewardItemList(); - pl.getInventory().addItemParamDatas(rewardItems, ActionReason.PlayerUpgradeReward); - rewardedLevels.add(level); - pl.setRewardedLevels(rewardedLevels); - pl.save(); - session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); - } - } - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp; +import java.util.List; +import java.util.Set; + +@Opcodes(PacketOpcodes.TakePlayerLevelRewardReq) +public class HandlerTakePlayerLevelRewardReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + Player pl = session.getPlayer(); + synchronized (pl) { + TakePlayerLevelRewardReq req = TakePlayerLevelRewardReq.parseFrom(payload); + int level = req.getLevel(); + Set rewardedLevels = session.getPlayer().getRewardedLevels(); + if (!rewardedLevels.contains(level)) { // No duplicated reward + int rewardId = GameData.getPlayerLevelDataMap().get(level).getRewardId(); + if (rewardId != 0) { + List rewardItems = + GameData.getRewardDataMap().get(rewardId).getRewardItemList(); + pl.getInventory().addItemParamDatas(rewardItems, ActionReason.PlayerUpgradeReward); + rewardedLevels.add(level); + pl.setRewardedLevels(rewardedLevels); + pl.save(); + session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId)); + } + } + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeoffEquipReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeoffEquipReq.java index ebc052b13..56b5b1be5 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeoffEquipReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTakeoffEquipReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeoffEquipReqOuterClass.TakeoffEquipReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketTakeoffEquipRsp; - -@Opcodes(PacketOpcodes.TakeoffEquipReq) -public class HandlerTakeoffEquipReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - TakeoffEquipReq req = TakeoffEquipReq.parseFrom(payload); - - if (session.getPlayer().getInventory().unequipItem(req.getAvatarGuid(), req.getSlot())) { - session.send(new PacketTakeoffEquipRsp(req.getAvatarGuid(), req.getSlot())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeoffEquipReqOuterClass.TakeoffEquipReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketTakeoffEquipRsp; + +@Opcodes(PacketOpcodes.TakeoffEquipReq) +public class HandlerTakeoffEquipReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + TakeoffEquipReq req = TakeoffEquipReq.parseFrom(payload); + + if (session.getPlayer().getInventory().unequipItem(req.getAvatarGuid(), req.getSlot())) { + session.send(new PacketTakeoffEquipRsp(req.getAvatarGuid(), req.getSlot())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerAllDataReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerAllDataReq.java index 0e4d3cb87..e5dbe0b1a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerAllDataReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerAllDataReq.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketTowerAllDataRsp; - -@Opcodes(PacketOpcodes.TowerAllDataReq) -public class HandlerTowerAllDataReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.send( - new PacketTowerAllDataRsp( - session.getServer().getTowerSystem(), session.getPlayer().getTowerManager())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketTowerAllDataRsp; + +@Opcodes(PacketOpcodes.TowerAllDataReq) +public class HandlerTowerAllDataReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send( + new PacketTowerAllDataRsp( + session.getServer().getTowerSystem(), session.getPlayer().getTowerManager())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerEnterLevelReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerEnterLevelReq.java index f39ffc3fe..4e219e72d 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerEnterLevelReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerEnterLevelReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerEnterLevelReqOuterClass.TowerEnterLevelReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.TowerEnterLevelReq) -public class HandlerTowerEnterLevelReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - TowerEnterLevelReq req = TowerEnterLevelReq.parseFrom(payload); - - // session.send(new PacketTowerCurLevelRecordChangeNotify()); - session.getPlayer().getTowerManager().enterLevel(req.getEnterPointId()); - - // session.send(new PacketTowerLevelStarCondNotify()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerEnterLevelReqOuterClass.TowerEnterLevelReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.TowerEnterLevelReq) +public class HandlerTowerEnterLevelReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + TowerEnterLevelReq req = TowerEnterLevelReq.parseFrom(payload); + + // session.send(new PacketTowerCurLevelRecordChangeNotify()); + session.getPlayer().getTowerManager().enterLevel(req.getEnterPointId()); + + // session.send(new PacketTowerLevelStarCondNotify()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerTeamSelectReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerTeamSelectReq.java index ff5c21da8..c745caa10 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerTeamSelectReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTowerTeamSelectReq.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerTeamOuterClass; -import emu.grasscutter.net.proto.TowerTeamSelectReqOuterClass.TowerTeamSelectReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketTowerTeamSelectRsp; - -@Opcodes(PacketOpcodes.TowerTeamSelectReq) -public class HandlerTowerTeamSelectReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - TowerTeamSelectReq req = TowerTeamSelectReq.parseFrom(payload); - - var towerTeams = - req.getTowerTeamListList().stream() - .map(TowerTeamOuterClass.TowerTeam::getAvatarGuidListList) - .toList(); - - session.getPlayer().getTowerManager().teamSelect(req.getFloorId(), towerTeams); - - session.send(new PacketTowerTeamSelectRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerTeamOuterClass; +import emu.grasscutter.net.proto.TowerTeamSelectReqOuterClass.TowerTeamSelectReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketTowerTeamSelectRsp; + +@Opcodes(PacketOpcodes.TowerTeamSelectReq) +public class HandlerTowerTeamSelectReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + TowerTeamSelectReq req = TowerTeamSelectReq.parseFrom(payload); + + var towerTeams = + req.getTowerTeamListList().stream() + .map(TowerTeamOuterClass.TowerTeam::getAvatarGuidListList) + .toList(); + + session.getPlayer().getTowerManager().teamSelect(req.getFloorId(), towerTeams); + + session.send(new PacketTowerTeamSelectRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java index 47e882687..37063550e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerTryEnterHomeReq.java @@ -1,72 +1,72 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.home.GameHome; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FriendEnterHomeOptionOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.TryEnterHomeReqOuterClass; -import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.TryEnterHomeReq) -public class HandlerTryEnterHomeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = TryEnterHomeReqOuterClass.TryEnterHomeReq.parseFrom(payload); - var targetPlayer = session.getServer().getPlayerByUid(req.getTargetUid(), true); - - if (req.getTargetUid() != session.getPlayer().getUid()) { - // I hope that tomorrow there will be a hero who can support multiplayer mode and write code - // like a poem - var targetHome = GameHome.getByUid(req.getTargetUid()); - switch (targetHome.getEnterHomeOption()) { - case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption - .FRIEND_ENTER_HOME_OPTION_NEED_CONFIRM_VALUE: - if (!targetPlayer.isOnline()) { - session.send( - new PacketTryEnterHomeRsp( - RetcodeOuterClass.Retcode.RET_HOME_OWNER_OFFLINE_VALUE, req.getTargetUid())); - return; - } - break; - case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption - .FRIEND_ENTER_HOME_OPTION_REFUSE_VALUE: - session.send( - new PacketTryEnterHomeRsp( - RetcodeOuterClass.Retcode.RET_HOME_HOME_REFUSE_GUEST_ENTER_VALUE, - req.getTargetUid())); - return; - case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption - .FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE: - break; - } - - session.send(new PacketTryEnterHomeRsp()); - return; - } - - int realmId = 2000 + session.getPlayer().getCurrentRealmId(); - - var home = session.getPlayer().getHome(); - - // prepare the default arrangement for first come in - var homeScene = home.getHomeSceneItem(realmId); - home.save(); - - Scene scene = session.getPlayer().getWorld().getSceneById(realmId); - Position pos = scene.getScriptManager().getConfig().born_pos; - - boolean result = - session - .getPlayer() - .getWorld() - .transferPlayerToScene(session.getPlayer(), realmId, TeleportType.WAYPOINT, pos); - if (result) session.send(new PacketTryEnterHomeRsp(req.getTargetUid())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.home.GameHome; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FriendEnterHomeOptionOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.TryEnterHomeReqOuterClass; +import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.TryEnterHomeReq) +public class HandlerTryEnterHomeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = TryEnterHomeReqOuterClass.TryEnterHomeReq.parseFrom(payload); + var targetPlayer = session.getServer().getPlayerByUid(req.getTargetUid(), true); + + if (req.getTargetUid() != session.getPlayer().getUid()) { + // I hope that tomorrow there will be a hero who can support multiplayer mode and write code + // like a poem + var targetHome = GameHome.getByUid(req.getTargetUid()); + switch (targetHome.getEnterHomeOption()) { + case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption + .FRIEND_ENTER_HOME_OPTION_NEED_CONFIRM_VALUE: + if (!targetPlayer.isOnline()) { + session.send( + new PacketTryEnterHomeRsp( + RetcodeOuterClass.Retcode.RET_HOME_OWNER_OFFLINE_VALUE, req.getTargetUid())); + return; + } + break; + case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption + .FRIEND_ENTER_HOME_OPTION_REFUSE_VALUE: + session.send( + new PacketTryEnterHomeRsp( + RetcodeOuterClass.Retcode.RET_HOME_HOME_REFUSE_GUEST_ENTER_VALUE, + req.getTargetUid())); + return; + case FriendEnterHomeOptionOuterClass.FriendEnterHomeOption + .FRIEND_ENTER_HOME_OPTION_DIRECT_VALUE: + break; + } + + session.send(new PacketTryEnterHomeRsp()); + return; + } + + int realmId = 2000 + session.getPlayer().getCurrentRealmId(); + + var home = session.getPlayer().getHome(); + + // prepare the default arrangement for first come in + var homeScene = home.getHomeSceneItem(realmId); + home.save(); + + Scene scene = session.getPlayer().getWorld().getSceneById(realmId); + Position pos = scene.getScriptManager().getConfig().born_pos; + + boolean result = + session + .getPlayer() + .getWorld() + .transferPlayerToScene(session.getPlayer(), realmId, TeleportType.WAYPOINT, pos); + if (result) session.send(new PacketTryEnterHomeRsp(req.getTargetUid())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnionCmdNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnionCmdNotify.java index 9276f712f..80cdaced2 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnionCmdNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnionCmdNotify.java @@ -1,45 +1,45 @@ -package emu.grasscutter.server.packet.recv; - -import static emu.grasscutter.config.Configuration.GAME_INFO; -import static emu.grasscutter.config.Configuration.SERVER; - -import emu.grasscutter.Grasscutter.ServerDebugMode; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnionCmdNotifyOuterClass.UnionCmdNotify; -import emu.grasscutter.net.proto.UnionCmdOuterClass.UnionCmd; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.UnionCmdNotify) -public class HandlerUnionCmdNotify extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - UnionCmdNotify req = UnionCmdNotify.parseFrom(payload); - for (UnionCmd cmd : req.getCmdListList()) { - int cmdOpcode = cmd.getMessageId(); - byte[] cmdPayload = cmd.getBody().toByteArray(); - if (GAME_INFO.logPackets == ServerDebugMode.WHITELIST - && SERVER.debugWhitelist.contains(cmd.getMessageId())) { - session.logPacket("RECV in Union", cmdOpcode, cmdPayload); - } else if (GAME_INFO.logPackets == ServerDebugMode.BLACKLIST - && !SERVER.debugBlacklist.contains(cmd.getMessageId())) { - session.logPacket("RECV in Union", cmdOpcode, cmdPayload); - } - // debugLevel ALL ignores UnionCmdNotify, so we will also ignore the contained opcodes - session - .getServer() - .getPacketHandler() - .handle(session, cmd.getMessageId(), EMPTY_BYTE_ARRAY, cmd.getBody().toByteArray()); - } - - // Update - session.getPlayer().getCombatInvokeHandler().update(session.getPlayer()); - session.getPlayer().getAbilityInvokeHandler().update(session.getPlayer()); - - // Handle attack results last - while (!session.getPlayer().getAttackResults().isEmpty()) { - session.getPlayer().getScene().handleAttack(session.getPlayer().getAttackResults().poll()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import static emu.grasscutter.config.Configuration.GAME_INFO; +import static emu.grasscutter.config.Configuration.SERVER; + +import emu.grasscutter.Grasscutter.ServerDebugMode; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnionCmdNotifyOuterClass.UnionCmdNotify; +import emu.grasscutter.net.proto.UnionCmdOuterClass.UnionCmd; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.UnionCmdNotify) +public class HandlerUnionCmdNotify extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + UnionCmdNotify req = UnionCmdNotify.parseFrom(payload); + for (UnionCmd cmd : req.getCmdListList()) { + int cmdOpcode = cmd.getMessageId(); + byte[] cmdPayload = cmd.getBody().toByteArray(); + if (GAME_INFO.logPackets == ServerDebugMode.WHITELIST + && SERVER.debugWhitelist.contains(cmd.getMessageId())) { + session.logPacket("RECV in Union", cmdOpcode, cmdPayload); + } else if (GAME_INFO.logPackets == ServerDebugMode.BLACKLIST + && !SERVER.debugBlacklist.contains(cmd.getMessageId())) { + session.logPacket("RECV in Union", cmdOpcode, cmdPayload); + } + // debugLevel ALL ignores UnionCmdNotify, so we will also ignore the contained opcodes + session + .getServer() + .getPacketHandler() + .handle(session, cmd.getMessageId(), EMPTY_BYTE_ARRAY, cmd.getBody().toByteArray()); + } + + // Update + session.getPlayer().getCombatInvokeHandler().update(session.getPlayer()); + session.getPlayer().getAbilityInvokeHandler().update(session.getPlayer()); + + // Handle attack results last + while (!session.getPlayer().getAttackResults().isEmpty()) { + session.getPlayer().getScene().handleAttack(session.getPlayer().getAttackResults().poll()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockAvatarTalentReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockAvatarTalentReq.java index ef465bc01..5f21bbc08 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockAvatarTalentReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockAvatarTalentReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnlockAvatarTalentReqOuterClass.UnlockAvatarTalentReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.UnlockAvatarTalentReq) -public class HandlerUnlockAvatarTalentReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - UnlockAvatarTalentReq req = UnlockAvatarTalentReq.parseFrom(payload); - - // Unlock avatar const - var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid()); - if (avatar == null) return; - avatar.unlockConstellation(req.getTalentId()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnlockAvatarTalentReqOuterClass.UnlockAvatarTalentReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.UnlockAvatarTalentReq) +public class HandlerUnlockAvatarTalentReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + UnlockAvatarTalentReq req = UnlockAvatarTalentReq.parseFrom(payload); + + // Unlock avatar const + var avatar = session.getPlayer().getAvatars().getAvatarByGuid(req.getAvatarGuid()); + if (avatar == null) return; + avatar.unlockConstellation(req.getTalentId()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockTransPointReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockTransPointReq.java index 79ba77681..aa6fa6ac2 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockTransPointReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUnlockTransPointReq.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.UnlockTransPointReqOuterClass.UnlockTransPointReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketUnlockTransPointRsp; - -@Opcodes(PacketOpcodes.UnlockTransPointReq) -public class HandlerUnlockTransPointReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - UnlockTransPointReq req = UnlockTransPointReq.parseFrom(payload); - boolean unlocked = - session - .getPlayer() - .getProgressManager() - .unlockTransPoint(req.getSceneId(), req.getPointId(), false); - session - .getPlayer() - .sendPacket( - new PacketUnlockTransPointRsp( - unlocked - ? RetcodeOuterClass.Retcode.RET_SUCC - : RetcodeOuterClass.Retcode.RET_FAIL)); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.UnlockTransPointReqOuterClass.UnlockTransPointReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketUnlockTransPointRsp; + +@Opcodes(PacketOpcodes.UnlockTransPointReq) +public class HandlerUnlockTransPointReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + UnlockTransPointReq req = UnlockTransPointReq.parseFrom(payload); + boolean unlocked = + session + .getPlayer() + .getProgressManager() + .unlockTransPoint(req.getSceneId(), req.getPointId(), false); + session + .getPlayer() + .sendPacket( + new PacketUnlockTransPointRsp( + unlocked + ? RetcodeOuterClass.Retcode.RET_SUCC + : RetcodeOuterClass.Retcode.RET_FAIL)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java index 0dbdf130a..728d34f5c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketUpdatePlayerShowAvatarListRsp; - -@Opcodes(PacketOpcodes.UpdatePlayerShowAvatarListReq) -public class HandlerUpdatePlayerShowAvatarListReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - UpdatePlayerShowAvatarListReqOuterClass.UpdatePlayerShowAvatarListReq req = - UpdatePlayerShowAvatarListReqOuterClass.UpdatePlayerShowAvatarListReq.parseFrom(payload); - - session.getPlayer().setShowAvatars(req.getIsShowAvatar()); - session.getPlayer().setShowAvatarList(req.getShowAvatarIdListList()); - - session.send( - new PacketUpdatePlayerShowAvatarListRsp( - req.getIsShowAvatar(), req.getShowAvatarIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketUpdatePlayerShowAvatarListRsp; + +@Opcodes(PacketOpcodes.UpdatePlayerShowAvatarListReq) +public class HandlerUpdatePlayerShowAvatarListReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + UpdatePlayerShowAvatarListReqOuterClass.UpdatePlayerShowAvatarListReq req = + UpdatePlayerShowAvatarListReqOuterClass.UpdatePlayerShowAvatarListReq.parseFrom(payload); + + session.getPlayer().setShowAvatars(req.getIsShowAvatar()); + session.getPlayer().setShowAvatarList(req.getShowAvatarIdListList()); + + session.send( + new PacketUpdatePlayerShowAvatarListRsp( + req.getIsShowAvatar(), req.getShowAvatarIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowNameCardListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowNameCardListReq.java index 919e1f6ec..8b6e454df 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowNameCardListReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowNameCardListReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UpdatePlayerShowNameCardListReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketUpdatePlayerShowNameCardListRsp; - -@Opcodes(PacketOpcodes.UpdatePlayerShowNameCardListReq) -public class HandlerUpdatePlayerShowNameCardListReq extends PacketHandler { - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - var req = - UpdatePlayerShowNameCardListReqOuterClass.UpdatePlayerShowNameCardListReq.parseFrom( - payload); - - session.getPlayer().setShowNameCardList(req.getShowNameCardIdListList()); - - session.send(new PacketUpdatePlayerShowNameCardListRsp(req.getShowNameCardIdListList())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UpdatePlayerShowNameCardListReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketUpdatePlayerShowNameCardListRsp; + +@Opcodes(PacketOpcodes.UpdatePlayerShowNameCardListReq) +public class HandlerUpdatePlayerShowNameCardListReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + var req = + UpdatePlayerShowNameCardListReqOuterClass.UpdatePlayerShowNameCardListReq.parseFrom( + payload); + + session.getPlayer().setShowNameCardList(req.getShowNameCardIdListList()); + + session.send(new PacketUpdatePlayerShowNameCardListRsp(req.getShowNameCardIdListList())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUseItemReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUseItemReq.java index 3c0fa93a4..d7651e236 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUseItemReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUseItemReq.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UseItemReqOuterClass.UseItemReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketUseItemRsp; - -@Opcodes(PacketOpcodes.UseItemReq) -public class HandlerUseItemReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - UseItemReq req = UseItemReq.parseFrom(payload); - - GameItem useItem = - session - .getServer() - .getInventorySystem() - .useItem( - session.getPlayer(), - req.getTargetGuid(), - req.getGuid(), - req.getCount(), - req.getOptionIdx(), - req.getIsEnterMpDungeonTeam()); - if (useItem != null) { - session.send(new PacketUseItemRsp(req.getTargetGuid(), useItem)); - } else { - session.send(new PacketUseItemRsp()); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UseItemReqOuterClass.UseItemReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketUseItemRsp; + +@Opcodes(PacketOpcodes.UseItemReq) +public class HandlerUseItemReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + UseItemReq req = UseItemReq.parseFrom(payload); + + GameItem useItem = + session + .getServer() + .getInventorySystem() + .useItem( + session.getPlayer(), + req.getTargetGuid(), + req.getGuid(), + req.getCount(), + req.getOptionIdx(), + req.getIsEnterMpDungeonTeam()); + if (useItem != null) { + session.send(new PacketUseItemRsp(req.getTargetGuid(), useItem)); + } else { + session.send(new PacketUseItemRsp()); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerVehicleInteractReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerVehicleInteractReq.java index c8a4e6ba5..a79eeac1a 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerVehicleInteractReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerVehicleInteractReq.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.VehicleInteractReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketVehicleInteractRsp; - -@Opcodes(PacketOpcodes.VehicleInteractReq) -public class HandlerVehicleInteractReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - VehicleInteractReqOuterClass.VehicleInteractReq req = - VehicleInteractReqOuterClass.VehicleInteractReq.parseFrom(payload); - session - .getPlayer() - .getStaminaManager() - .handleVehicleInteractReq(session, req.getEntityId(), req.getInteractType()); - session.send( - new PacketVehicleInteractRsp( - session.getPlayer(), req.getEntityId(), req.getInteractType())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.VehicleInteractReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketVehicleInteractRsp; + +@Opcodes(PacketOpcodes.VehicleInteractReq) +public class HandlerVehicleInteractReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + VehicleInteractReqOuterClass.VehicleInteractReq req = + VehicleInteractReqOuterClass.VehicleInteractReq.parseFrom(payload); + session + .getPlayer() + .getStaminaManager() + .handleVehicleInteractReq(session, req.getEntityId(), req.getInteractType()); + session.send( + new PacketVehicleInteractRsp( + session.getPlayer(), req.getEntityId(), req.getInteractType())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponAwakenReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponAwakenReq.java index 80078bbb3..31a293929 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponAwakenReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponAwakenReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WeaponAwakenReqOuterClass.WeaponAwakenReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.WeaponAwakenReq) -public class HandlerWeaponAwakenReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - WeaponAwakenReq req = WeaponAwakenReq.parseFrom(payload); - - // Weapon refinement - session - .getServer() - .getInventorySystem() - .refineWeapon(session.getPlayer(), req.getTargetWeaponGuid(), req.getItemGuid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WeaponAwakenReqOuterClass.WeaponAwakenReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.WeaponAwakenReq) +public class HandlerWeaponAwakenReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + WeaponAwakenReq req = WeaponAwakenReq.parseFrom(payload); + + // Weapon refinement + session + .getServer() + .getInventorySystem() + .refineWeapon(session.getPlayer(), req.getTargetWeaponGuid(), req.getItemGuid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponPromoteReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponPromoteReq.java index 1c2b5d927..909a0bf8b 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponPromoteReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponPromoteReq.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WeaponPromoteReqOuterClass.WeaponPromoteReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.WeaponPromoteReq) -public class HandlerWeaponPromoteReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - WeaponPromoteReq req = WeaponPromoteReq.parseFrom(payload); - - // Ascend weapon - session - .getServer() - .getInventorySystem() - .promoteWeapon(session.getPlayer(), req.getTargetWeaponGuid()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WeaponPromoteReqOuterClass.WeaponPromoteReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.WeaponPromoteReq) +public class HandlerWeaponPromoteReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + WeaponPromoteReq req = WeaponPromoteReq.parseFrom(payload); + + // Ascend weapon + session + .getServer() + .getInventorySystem() + .promoteWeapon(session.getPlayer(), req.getTargetWeaponGuid()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponUpgradeReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponUpgradeReq.java index cc99dbb5f..560899515 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponUpgradeReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWeaponUpgradeReq.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WeaponUpgradeReqOuterClass.WeaponUpgradeReq; -import emu.grasscutter.server.game.GameSession; - -@Opcodes(PacketOpcodes.WeaponUpgradeReq) -public class HandlerWeaponUpgradeReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - WeaponUpgradeReq req = WeaponUpgradeReq.parseFrom(payload); - - // Level up weapon - session - .getServer() - .getInventorySystem() - .upgradeWeapon( - session.getPlayer(), - req.getTargetWeaponGuid(), - req.getFoodWeaponGuidListList(), - req.getItemParamListList()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WeaponUpgradeReqOuterClass.WeaponUpgradeReq; +import emu.grasscutter.server.game.GameSession; + +@Opcodes(PacketOpcodes.WeaponUpgradeReq) +public class HandlerWeaponUpgradeReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + WeaponUpgradeReq req = WeaponUpgradeReq.parseFrom(payload); + + // Level up weapon + session + .getServer() + .getInventorySystem() + .upgradeWeapon( + session.getPlayer(), + req.getTargetWeaponGuid(), + req.getFoodWeaponGuidListList(), + req.getItemParamListList()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWearEquipReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWearEquipReq.java index 2af2fbe45..e17363df8 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWearEquipReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWearEquipReq.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WearEquipReqOuterClass.WearEquipReq; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketWearEquipRsp; - -@Opcodes(PacketOpcodes.WearEquipReq) -public class HandlerWearEquipReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - WearEquipReq req = WearEquipReq.parseFrom(payload); - - if (session.getPlayer().getInventory().equipItem(req.getAvatarGuid(), req.getEquipGuid())) { - session.send(new PacketWearEquipRsp(req.getAvatarGuid(), req.getEquipGuid())); - } - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WearEquipReqOuterClass.WearEquipReq; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketWearEquipRsp; + +@Opcodes(PacketOpcodes.WearEquipReq) +public class HandlerWearEquipReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + WearEquipReq req = WearEquipReq.parseFrom(payload); + + if (session.getPlayer().getInventory().equipItem(req.getAvatarGuid(), req.getEquipGuid())) { + session.send(new PacketWearEquipRsp(req.getAvatarGuid(), req.getEquipGuid())); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWidgetDoBagReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWidgetDoBagReq.java index 1fe08a42c..ded47db7f 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWidgetDoBagReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWidgetDoBagReq.java @@ -1,44 +1,44 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.game.entity.EntityVehicle; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WidgetDoBagReqOuterClass; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketWidgetCoolDownNotify; -import emu.grasscutter.server.packet.send.PacketWidgetDoBagRsp; -import emu.grasscutter.server.packet.send.PacketWidgetGadgetDataNotify; -import emu.grasscutter.utils.Position; - -@Opcodes(PacketOpcodes.WidgetDoBagReq) -public class HandlerWidgetDoBagReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - WidgetDoBagReqOuterClass.WidgetDoBagReq req = - WidgetDoBagReqOuterClass.WidgetDoBagReq.parseFrom(payload); - var locationInfo = req.getWidgetCreatorInfo().getLocationInfo(); - Position pos = new Position(locationInfo.getPos()); - Position rot = new Position(locationInfo.getRot()); - switch (req.getMaterialId()) { - case 220026 -> { - this.spawnVehicle(session, 70500025, pos, rot); - session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); - session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); - } - case 220047 -> this.spawnVehicle(session, 70800058, pos, rot); - default -> {} - } - session.send(new PacketWidgetDoBagRsp()); - } - - private void spawnVehicle(GameSession session, int gadgetId, Position pos, Position rot) - throws Exception { - var player = session.getPlayer(); - var scene = player.getScene(); - var entity = new EntityVehicle(scene, player, gadgetId, 0, pos, rot); - scene.addEntity(entity); - session.send(new PacketWidgetGadgetDataNotify(gadgetId, entity.getId())); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.EntityVehicle; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WidgetDoBagReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketWidgetCoolDownNotify; +import emu.grasscutter.server.packet.send.PacketWidgetDoBagRsp; +import emu.grasscutter.server.packet.send.PacketWidgetGadgetDataNotify; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.WidgetDoBagReq) +public class HandlerWidgetDoBagReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + WidgetDoBagReqOuterClass.WidgetDoBagReq req = + WidgetDoBagReqOuterClass.WidgetDoBagReq.parseFrom(payload); + var locationInfo = req.getWidgetCreatorInfo().getLocationInfo(); + Position pos = new Position(locationInfo.getPos()); + Position rot = new Position(locationInfo.getRot()); + switch (req.getMaterialId()) { + case 220026 -> { + this.spawnVehicle(session, 70500025, pos, rot); + session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); + session.send(new PacketWidgetCoolDownNotify(15, System.currentTimeMillis() + 5000L, true)); + } + case 220047 -> this.spawnVehicle(session, 70800058, pos, rot); + default -> {} + } + session.send(new PacketWidgetDoBagRsp()); + } + + private void spawnVehicle(GameSession session, int gadgetId, Position pos, Position rot) + throws Exception { + var player = session.getPlayer(); + var scene = player.getScene(); + var entity = new EntityVehicle(scene, player, gadgetId, 0, pos, rot); + scene.addEntity(entity); + session.send(new PacketWidgetGadgetDataNotify(gadgetId, entity.getId())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWorldPlayerReviveReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWorldPlayerReviveReq.java index b5d4f1b01..4924d24e0 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerWorldPlayerReviveReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerWorldPlayerReviveReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.recv; - -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketWorldPlayerReviveRsp; - -@Opcodes(PacketOpcodes.WorldPlayerReviveReq) -public class HandlerWorldPlayerReviveReq extends PacketHandler { - - @Override - public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { - session.getPlayer().getTeamManager().respawnTeam(); - session.send(new PacketWorldPlayerReviveRsp()); - } -} +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketWorldPlayerReviveRsp; + +@Opcodes(PacketOpcodes.WorldPlayerReviveReq) +public class HandlerWorldPlayerReviveReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.getPlayer().getTeamManager().respawnTeam(); + session.send(new PacketWorldPlayerReviveRsp()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PackageTakeCompoundOutputRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PackageTakeCompoundOutputRsp.java index df187ccdd..c97363c60 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PackageTakeCompoundOutputRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PackageTakeCompoundOutputRsp.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.TakeCompoundOutputRspOuterClass.TakeCompoundOutputRsp; - -public class PackageTakeCompoundOutputRsp extends BasePacket { - - public PackageTakeCompoundOutputRsp(Iterable itemList, int retcode) { - super(PacketOpcodes.TakeCompoundOutputRsp); - var builder = TakeCompoundOutputRsp.newBuilder().addAllItemList(itemList).setRetcode(retcode); - setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.TakeCompoundOutputRspOuterClass.TakeCompoundOutputRsp; + +public class PackageTakeCompoundOutputRsp extends BasePacket { + + public PackageTakeCompoundOutputRsp(Iterable itemList, int retcode) { + super(PacketOpcodes.TakeCompoundOutputRsp); + var builder = TakeCompoundOutputRsp.newBuilder().addAllItemList(itemList).setRetcode(retcode); + setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/Packet.java b/src/main/java/emu/grasscutter/server/packet/send/Packet.java index d9007f8a2..b1da86038 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/Packet.java +++ b/src/main/java/emu/grasscutter/server/packet/send/Packet.java @@ -1,11 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class Packet extends BasePacket { - - public Packet() { - super(PacketOpcodes.NONE); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class Packet extends BasePacket { + + public Packet() { + super(PacketOpcodes.NONE); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityChangeNotify.java index b00c0dd67..1de68d8ff 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityChangeNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNotify; - -public class PacketAbilityChangeNotify extends BasePacket { - - public PacketAbilityChangeNotify(EntityAvatar entity) { - super(PacketOpcodes.AbilityChangeNotify, true); - - AbilityChangeNotify proto = - AbilityChangeNotify.newBuilder() - .setEntityId(entity.getId()) - .setAbilityControlBlock(entity.getAbilityControlBlock()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityChangeNotifyOuterClass.AbilityChangeNotify; + +public class PacketAbilityChangeNotify extends BasePacket { + + public PacketAbilityChangeNotify(EntityAvatar entity) { + super(PacketOpcodes.AbilityChangeNotify, true); + + AbilityChangeNotify proto = + AbilityChangeNotify.newBuilder() + .setEntityId(entity.getId()) + .setAbilityControlBlock(entity.getAbilityControlBlock()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityInvocationsNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityInvocationsNotify.java index 3cc4dfe83..7715abac6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityInvocationsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAbilityInvocationsNotify.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityInvocationsNotifyOuterClass.AbilityInvocationsNotify; -import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; -import java.util.List; - -public class PacketAbilityInvocationsNotify extends BasePacket { - - public PacketAbilityInvocationsNotify(AbilityInvokeEntry entry) { - super(PacketOpcodes.AbilityInvocationsNotify, true); - - AbilityInvocationsNotify proto = - AbilityInvocationsNotify.newBuilder().addInvokes(entry).build(); - - this.setData(proto); - } - - public PacketAbilityInvocationsNotify(List entries) { - super(PacketOpcodes.AbilityInvocationsNotify, true); - - AbilityInvocationsNotify proto = - AbilityInvocationsNotify.newBuilder().addAllInvokes(entries).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityInvocationsNotifyOuterClass.AbilityInvocationsNotify; +import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; +import java.util.List; + +public class PacketAbilityInvocationsNotify extends BasePacket { + + public PacketAbilityInvocationsNotify(AbilityInvokeEntry entry) { + super(PacketOpcodes.AbilityInvocationsNotify, true); + + AbilityInvocationsNotify proto = + AbilityInvocationsNotify.newBuilder().addInvokes(entry).build(); + + this.setData(proto); + } + + public PacketAbilityInvocationsNotify(List entries) { + super(PacketOpcodes.AbilityInvocationsNotify, true); + + AbilityInvocationsNotify proto = + AbilityInvocationsNotify.newBuilder().addAllInvokes(entries).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementAllDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementAllDataNotify.java index 422f35e27..474f88dd2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementAllDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementAllDataNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.achievement.Achievement; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AchievementAllDataNotifyOuterClass; - -public class PacketAchievementAllDataNotify extends BasePacket { - public PacketAchievementAllDataNotify(Player player) { - super(PacketOpcodes.AchievementAllDataNotify); - - var achievements = player.getAchievements(); - var notify = - AchievementAllDataNotifyOuterClass.AchievementAllDataNotify.newBuilder() - .addAllAchievementList( - achievements.getAchievementList().values().stream() - .map(Achievement::toProto) - .toList()) - .addAllRewardTakenGoalIdList(achievements.getTakenGoalRewardIdList()) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.achievement.Achievement; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AchievementAllDataNotifyOuterClass; + +public class PacketAchievementAllDataNotify extends BasePacket { + public PacketAchievementAllDataNotify(Player player) { + super(PacketOpcodes.AchievementAllDataNotify); + + var achievements = player.getAchievements(); + var notify = + AchievementAllDataNotifyOuterClass.AchievementAllDataNotify.newBuilder() + .addAllAchievementList( + achievements.getAchievementList().values().stream() + .map(Achievement::toProto) + .toList()) + .addAllRewardTakenGoalIdList(achievements.getTakenGoalRewardIdList()) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementUpdateNotify.java index 8eb02570d..2d85554fc 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAchievementUpdateNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.achievement.Achievement; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AchievementUpdateNotifyOuterClass; -import java.util.List; - -public class PacketAchievementUpdateNotify extends BasePacket { - public PacketAchievementUpdateNotify(List achievements) { - super(PacketOpcodes.AchievementUpdateNotify); - - var notify = - AchievementUpdateNotifyOuterClass.AchievementUpdateNotify.newBuilder() - .addAllAchievementList(achievements.stream().map(Achievement::toProto).toList()) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.achievement.Achievement; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AchievementUpdateNotifyOuterClass; +import java.util.List; + +public class PacketAchievementUpdateNotify extends BasePacket { + public PacketAchievementUpdateNotify(List achievements) { + super(PacketOpcodes.AchievementUpdateNotify); + + var notify = + AchievementUpdateNotifyOuterClass.AchievementUpdateNotify.newBuilder() + .addAllAchievementList(achievements.stream().map(Achievement::toProto).toList()) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityInfoNotify.java index d6b014b5d..a11e6ec51 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityInfoNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityInfoNotifyOuterClass; -import emu.grasscutter.net.proto.ActivityInfoOuterClass; - -public class PacketActivityInfoNotify extends BasePacket { - - public PacketActivityInfoNotify(ActivityInfoOuterClass.ActivityInfo activityInfo) { - super(PacketOpcodes.ActivityInfoNotify); - - var proto = ActivityInfoNotifyOuterClass.ActivityInfoNotify.newBuilder(); - - proto.setActivityInfo(activityInfo); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityInfoNotifyOuterClass; +import emu.grasscutter.net.proto.ActivityInfoOuterClass; + +public class PacketActivityInfoNotify extends BasePacket { + + public PacketActivityInfoNotify(ActivityInfoOuterClass.ActivityInfo activityInfo) { + super(PacketOpcodes.ActivityInfoNotify); + + var proto = ActivityInfoNotifyOuterClass.ActivityInfoNotify.newBuilder(); + + proto.setActivityInfo(activityInfo); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java index 4b78eba53..c7ec0f45f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityScheduleInfoNotify.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityScheduleInfoNotifyOuterClass; -import emu.grasscutter.net.proto.ActivityScheduleInfoOuterClass; -import emu.grasscutter.utils.DateHelper; -import java.util.Collection; - -public class PacketActivityScheduleInfoNotify extends BasePacket { - - public PacketActivityScheduleInfoNotify(Collection activityConfigItemList) { - super(PacketOpcodes.ActivityScheduleInfoNotify); - - var proto = ActivityScheduleInfoNotifyOuterClass.ActivityScheduleInfoNotify.newBuilder(); - - activityConfigItemList.forEach( - item -> { - proto.addActivityScheduleList( - ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder() - .setActivityId(item.getActivityId()) - .setScheduleId(item.getScheduleId()) - .setIsOpen(true) - .setBeginTime(DateHelper.getUnixTime(item.getBeginTime())) - .setEndTime(DateHelper.getUnixTime(item.getEndTime())) - .build()); - }); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityScheduleInfoNotifyOuterClass; +import emu.grasscutter.net.proto.ActivityScheduleInfoOuterClass; +import emu.grasscutter.utils.DateHelper; +import java.util.Collection; + +public class PacketActivityScheduleInfoNotify extends BasePacket { + + public PacketActivityScheduleInfoNotify(Collection activityConfigItemList) { + super(PacketOpcodes.ActivityScheduleInfoNotify); + + var proto = ActivityScheduleInfoNotifyOuterClass.ActivityScheduleInfoNotify.newBuilder(); + + activityConfigItemList.forEach( + item -> { + proto.addActivityScheduleList( + ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder() + .setActivityId(item.getActivityId()) + .setScheduleId(item.getScheduleId()) + .setIsOpen(true) + .setBeginTime(DateHelper.getUnixTime(item.getBeginTime())) + .setEndTime(DateHelper.getUnixTime(item.getEndTime())) + .build()); + }); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityTakeWatcherRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityTakeWatcherRewardRsp.java index e723a225d..a4e4c9471 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityTakeWatcherRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityTakeWatcherRewardRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityTakeWatcherRewardRspOuterClass; - -public class PacketActivityTakeWatcherRewardRsp extends BasePacket { - - public PacketActivityTakeWatcherRewardRsp(int activityId, int watcherId) { - super(PacketOpcodes.ActivityTakeWatcherRewardRsp); - - var proto = ActivityTakeWatcherRewardRspOuterClass.ActivityTakeWatcherRewardRsp.newBuilder(); - - proto.setActivityId(activityId).setWatcherId(watcherId); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityTakeWatcherRewardRspOuterClass; + +public class PacketActivityTakeWatcherRewardRsp extends BasePacket { + + public PacketActivityTakeWatcherRewardRsp(int activityId, int watcherId) { + super(PacketOpcodes.ActivityTakeWatcherRewardRsp); + + var proto = ActivityTakeWatcherRewardRspOuterClass.ActivityTakeWatcherRewardRsp.newBuilder(); + + proto.setActivityId(activityId).setWatcherId(watcherId); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityUpdateWatcherNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityUpdateWatcherNotify.java index 0a5c3b205..9ecafcdce 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketActivityUpdateWatcherNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketActivityUpdateWatcherNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.activity.PlayerActivityData; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityUpdateWatcherNotifyOuterClass; - -public class PacketActivityUpdateWatcherNotify extends BasePacket { - - public PacketActivityUpdateWatcherNotify( - int activityId, PlayerActivityData.WatcherInfo watcherInfo) { - super(PacketOpcodes.ActivityUpdateWatcherNotify); - - var proto = ActivityUpdateWatcherNotifyOuterClass.ActivityUpdateWatcherNotify.newBuilder(); - - proto.setActivityId(activityId).setWatcherInfo(watcherInfo.toProto()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.activity.PlayerActivityData; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityUpdateWatcherNotifyOuterClass; + +public class PacketActivityUpdateWatcherNotify extends BasePacket { + + public PacketActivityUpdateWatcherNotify( + int activityId, PlayerActivityData.WatcherInfo watcherInfo) { + super(PacketOpcodes.ActivityUpdateWatcherNotify); + + var proto = ActivityUpdateWatcherNotifyOuterClass.ActivityUpdateWatcherNotify.newBuilder(); + + proto.setActivityId(activityId).setWatcherInfo(watcherInfo.toProto()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAddBackupAvatarTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAddBackupAvatarTeamRsp.java index 10f3bbd4d..1327703c8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAddBackupAvatarTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAddBackupAvatarTeamRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AddBackupAvatarTeamRspOuterClass.AddBackupAvatarTeamRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; - -public class PacketAddBackupAvatarTeamRsp extends BasePacket { - public PacketAddBackupAvatarTeamRsp(Retcode retcode) { - super(PacketOpcodes.AddBackupAvatarTeamRsp); - - AddBackupAvatarTeamRsp proto = - AddBackupAvatarTeamRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } - - public PacketAddBackupAvatarTeamRsp() { - this(Retcode.RET_SUCC); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AddBackupAvatarTeamRspOuterClass.AddBackupAvatarTeamRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketAddBackupAvatarTeamRsp extends BasePacket { + public PacketAddBackupAvatarTeamRsp(Retcode retcode) { + super(PacketOpcodes.AddBackupAvatarTeamRsp); + + AddBackupAvatarTeamRsp proto = + AddBackupAvatarTeamRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } + + public PacketAddBackupAvatarTeamRsp() { + this(Retcode.RET_SUCC); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAddQuestContentProgressRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAddQuestContentProgressRsp.java index 0405052b1..e4ea5e6b8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAddQuestContentProgressRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAddQuestContentProgressRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AddQuestContentProgressRspOuterClass; - -public class PacketAddQuestContentProgressRsp extends BasePacket { - - public PacketAddQuestContentProgressRsp(int contentType) { - super(PacketOpcodes.AddQuestContentProgressRsp); - - var proto = AddQuestContentProgressRspOuterClass.AddQuestContentProgressRsp.newBuilder(); - - proto.setContentType(contentType); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AddQuestContentProgressRspOuterClass; + +public class PacketAddQuestContentProgressRsp extends BasePacket { + + public PacketAddQuestContentProgressRsp(int contentType) { + super(PacketOpcodes.AddQuestContentProgressRsp); + + var proto = AddQuestContentProgressRspOuterClass.AddQuestContentProgressRsp.newBuilder(); + + proto.setContentType(contentType); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAllWidgetDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAllWidgetDataNotify.java index 0b2466c72..749b21209 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAllWidgetDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAllWidgetDataNotify.java @@ -1,55 +1,55 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AllWidgetDataNotifyOuterClass.AllWidgetDataNotify; -import emu.grasscutter.net.proto.LunchBoxDataOuterClass; -import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; -import emu.grasscutter.net.proto.WidgetSlotTagOuterClass; -import java.util.List; - -public class PacketAllWidgetDataNotify extends BasePacket { - - public PacketAllWidgetDataNotify(Player player) { - super(PacketOpcodes.AllWidgetDataNotify); - - // TODO: Implement this - - AllWidgetDataNotify.Builder proto = - AllWidgetDataNotify.newBuilder() - // If you want to implement this, feel free to do so. :) - .setLunchBoxData(LunchBoxDataOuterClass.LunchBoxData.newBuilder().build()) - // Maybe it's a little difficult, or it makes you upset :( - .addAllOneoffGatherPointDetectorDataList(List.of()) - // So, goodbye, and hopefully sometime in the future o(* ̄▽ ̄*)ブ - .addAllCoolDownGroupDataList(List.of()) - // I'll see your PR with a title that says (・∀・(・∀・(・∀・*) - .addAllAnchorPointList(List.of()) - // "Complete implementation of widget functionality" b( ̄▽ ̄)d - .addAllClientCollectorDataList(List.of()) - // Good luck, my boy. - .addAllNormalCoolDownDataList(List.of()); - - if (player.getWidgetId() - == 0) { // TODO: check this logic later, it was null-checking an int before which made it - // dead code - proto.addAllSlotList(List.of()); - } else { - proto.addSlotList( - WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() - .setIsActive(true) - .setMaterialId(player.getWidgetId()) - .build()); - - proto.addSlotList( - WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() - .setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_TAG_ATTACH_AVATAR) - .build()); - } - - AllWidgetDataNotify protoData = proto.build(); - - this.setData(protoData); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AllWidgetDataNotifyOuterClass.AllWidgetDataNotify; +import emu.grasscutter.net.proto.LunchBoxDataOuterClass; +import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; +import emu.grasscutter.net.proto.WidgetSlotTagOuterClass; +import java.util.List; + +public class PacketAllWidgetDataNotify extends BasePacket { + + public PacketAllWidgetDataNotify(Player player) { + super(PacketOpcodes.AllWidgetDataNotify); + + // TODO: Implement this + + AllWidgetDataNotify.Builder proto = + AllWidgetDataNotify.newBuilder() + // If you want to implement this, feel free to do so. :) + .setLunchBoxData(LunchBoxDataOuterClass.LunchBoxData.newBuilder().build()) + // Maybe it's a little difficult, or it makes you upset :( + .addAllOneoffGatherPointDetectorDataList(List.of()) + // So, goodbye, and hopefully sometime in the future o(* ̄▽ ̄*)ブ + .addAllCoolDownGroupDataList(List.of()) + // I'll see your PR with a title that says (・∀・(・∀・(・∀・*) + .addAllAnchorPointList(List.of()) + // "Complete implementation of widget functionality" b( ̄▽ ̄)d + .addAllClientCollectorDataList(List.of()) + // Good luck, my boy. + .addAllNormalCoolDownDataList(List.of()); + + if (player.getWidgetId() + == 0) { // TODO: check this logic later, it was null-checking an int before which made it + // dead code + proto.addAllSlotList(List.of()); + } else { + proto.addSlotList( + WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() + .setIsActive(true) + .setMaterialId(player.getWidgetId()) + .build()); + + proto.addSlotList( + WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() + .setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_TAG_ATTACH_AVATAR) + .build()); + } + + AllWidgetDataNotify protoData = proto.build(); + + this.setData(protoData); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendNotify.java index bd8b80069..fcb9d1ec5 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.friends.Friendship; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AskAddFriendNotifyOuterClass.AskAddFriendNotify; - -public class PacketAskAddFriendNotify extends BasePacket { - - public PacketAskAddFriendNotify(Friendship friendship) { - super(PacketOpcodes.AskAddFriendNotify); - - AskAddFriendNotify proto = - AskAddFriendNotify.newBuilder() - .setTargetUid(friendship.getFriendId()) - .setTargetFriendBrief(friendship.toProto()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.friends.Friendship; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AskAddFriendNotifyOuterClass.AskAddFriendNotify; + +public class PacketAskAddFriendNotify extends BasePacket { + + public PacketAskAddFriendNotify(Friendship friendship) { + super(PacketOpcodes.AskAddFriendNotify); + + AskAddFriendNotify proto = + AskAddFriendNotify.newBuilder() + .setTargetUid(friendship.getFriendId()) + .setTargetFriendBrief(friendship.toProto()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendRsp.java index 3765baeb6..6d611308c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAskAddFriendRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AskAddFriendRspOuterClass.AskAddFriendRsp; - -public class PacketAskAddFriendRsp extends BasePacket { - - public PacketAskAddFriendRsp(int targetUid) { - super(PacketOpcodes.AskAddFriendRsp); - - AskAddFriendRsp proto = AskAddFriendRsp.newBuilder().setTargetUid(targetUid).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AskAddFriendRspOuterClass.AskAddFriendRsp; + +public class PacketAskAddFriendRsp extends BasePacket { + + public PacketAskAddFriendRsp(int targetUid) { + super(PacketOpcodes.AskAddFriendRsp); + + AskAddFriendRsp proto = AskAddFriendRsp.newBuilder().setTargetUid(targetUid).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarAddNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarAddNotify.java index 83736363f..4de173d8a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarAddNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarAddNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarAddNotifyOuterClass.AvatarAddNotify; - -public class PacketAvatarAddNotify extends BasePacket { - - public PacketAvatarAddNotify(Avatar avatar, boolean addedToTeam) { - super(PacketOpcodes.AvatarAddNotify); - - AvatarAddNotify proto = - AvatarAddNotify.newBuilder().setAvatar(avatar.toProto()).setIsInTeam(addedToTeam).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarAddNotifyOuterClass.AvatarAddNotify; + +public class PacketAvatarAddNotify extends BasePacket { + + public PacketAvatarAddNotify(Avatar avatar, boolean addedToTeam) { + super(PacketOpcodes.AvatarAddNotify); + + AvatarAddNotify proto = + AvatarAddNotify.newBuilder().setAvatar(avatar.toProto()).setIsInTeam(addedToTeam).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeNotify.java index f5ee35b86..56678717c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarChangeCostumeNotifyOuterClass.AvatarChangeCostumeNotify; - -public class PacketAvatarChangeCostumeNotify extends BasePacket { - - public PacketAvatarChangeCostumeNotify(EntityAvatar entity) { - super(PacketOpcodes.AvatarChangeCostumeNotify); - - AvatarChangeCostumeNotify proto = - AvatarChangeCostumeNotify.newBuilder().setEntityInfo(entity.toProto()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarChangeCostumeNotifyOuterClass.AvatarChangeCostumeNotify; + +public class PacketAvatarChangeCostumeNotify extends BasePacket { + + public PacketAvatarChangeCostumeNotify(EntityAvatar entity) { + super(PacketOpcodes.AvatarChangeCostumeNotify); + + AvatarChangeCostumeNotify proto = + AvatarChangeCostumeNotify.newBuilder().setEntityInfo(entity.toProto()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeRsp.java index a4752da07..5f7cecd03 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeCostumeRsp.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarChangeCostumeRspOuterClass.AvatarChangeCostumeRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketAvatarChangeCostumeRsp extends BasePacket { - - public PacketAvatarChangeCostumeRsp(long avatarGuid, int costumeId) { - super(PacketOpcodes.AvatarChangeCostumeRsp); - - AvatarChangeCostumeRsp proto = - AvatarChangeCostumeRsp.newBuilder() - .setAvatarGuid(avatarGuid) - .setCostumeId(costumeId) - .build(); - - this.setData(proto); - } - - public PacketAvatarChangeCostumeRsp() { - super(PacketOpcodes.AvatarChangeCostumeRsp); - - AvatarChangeCostumeRsp proto = - AvatarChangeCostumeRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarChangeCostumeRspOuterClass.AvatarChangeCostumeRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketAvatarChangeCostumeRsp extends BasePacket { + + public PacketAvatarChangeCostumeRsp(long avatarGuid, int costumeId) { + super(PacketOpcodes.AvatarChangeCostumeRsp); + + AvatarChangeCostumeRsp proto = + AvatarChangeCostumeRsp.newBuilder() + .setAvatarGuid(avatarGuid) + .setCostumeId(costumeId) + .build(); + + this.setData(proto); + } + + public PacketAvatarChangeCostumeRsp() { + super(PacketOpcodes.AvatarChangeCostumeRsp); + + AvatarChangeCostumeRsp proto = + AvatarChangeCostumeRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeElementTypeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeElementTypeRsp.java index 6e4af0e82..35ab5c30a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeElementTypeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarChangeElementTypeRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarChangeElementTypeRspOuterClass.AvatarChangeElementTypeRsp; - -public class PacketAvatarChangeElementTypeRsp extends BasePacket { - - public PacketAvatarChangeElementTypeRsp() { - super(PacketOpcodes.AvatarChangeElementTypeRsp); - } - - public PacketAvatarChangeElementTypeRsp(int retcode) { - super(PacketOpcodes.AvatarChangeElementTypeRsp); - - if (retcode > 0) { - AvatarChangeElementTypeRsp proto = - AvatarChangeElementTypeRsp.newBuilder().setRetcode(retcode).build(); - - this.setData(proto); - } - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarChangeElementTypeRspOuterClass.AvatarChangeElementTypeRsp; + +public class PacketAvatarChangeElementTypeRsp extends BasePacket { + + public PacketAvatarChangeElementTypeRsp() { + super(PacketOpcodes.AvatarChangeElementTypeRsp); + } + + public PacketAvatarChangeElementTypeRsp(int retcode) { + super(PacketOpcodes.AvatarChangeElementTypeRsp); + + if (retcode > 0) { + AvatarChangeElementTypeRsp proto = + AvatarChangeElementTypeRsp.newBuilder().setRetcode(retcode).build(); + + this.setData(proto); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDataNotify.java index a7fe8e845..94c069cb7 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDataNotify.java @@ -1,42 +1,42 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarDataNotifyOuterClass.AvatarDataNotify; - -public class PacketAvatarDataNotify extends BasePacket { - - public PacketAvatarDataNotify(Player player) { - super(PacketOpcodes.AvatarDataNotify, true); - - AvatarDataNotify.Builder proto = - AvatarDataNotify.newBuilder() - .setCurAvatarTeamId(player.getTeamManager().getCurrentTeamId()) - .setChooseAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()) - .addAllOwnedFlycloakList(player.getFlyCloakList()) - .addAllOwnedCostumeList(player.getCostumeList()); - - player.getAvatars().forEach(avatar -> proto.addAvatarList(avatar.toProto())); - - player - .getTeamManager() - .getTeams() - .forEach( - (id, teamInfo) -> { - proto.putAvatarTeamMap(id, teamInfo.toProto(player)); - if (id > 4) { // Add the id list for custom teams. - proto.addBackupAvatarTeamOrderList(id); - } - }); - - // Set main character - Avatar mainCharacter = player.getAvatars().getAvatarById(player.getMainCharacterId()); - if (mainCharacter != null) { - proto.setChooseAvatarGuid(mainCharacter.getGuid()); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarDataNotifyOuterClass.AvatarDataNotify; + +public class PacketAvatarDataNotify extends BasePacket { + + public PacketAvatarDataNotify(Player player) { + super(PacketOpcodes.AvatarDataNotify, true); + + AvatarDataNotify.Builder proto = + AvatarDataNotify.newBuilder() + .setCurAvatarTeamId(player.getTeamManager().getCurrentTeamId()) + .setChooseAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()) + .addAllOwnedFlycloakList(player.getFlyCloakList()) + .addAllOwnedCostumeList(player.getCostumeList()); + + player.getAvatars().forEach(avatar -> proto.addAvatarList(avatar.toProto())); + + player + .getTeamManager() + .getTeams() + .forEach( + (id, teamInfo) -> { + proto.putAvatarTeamMap(id, teamInfo.toProto(player)); + if (id > 4) { // Add the id list for custom teams. + proto.addBackupAvatarTeamOrderList(id); + } + }); + + // Set main character + Avatar mainCharacter = player.getAvatars().getAvatarById(player.getMainCharacterId()); + if (mainCharacter != null) { + proto.setChooseAvatarGuid(mainCharacter.getGuid()); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDieAnimationEndRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDieAnimationEndRsp.java index 75f6f0480..2140f6b94 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDieAnimationEndRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarDieAnimationEndRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarDieAnimationEndRspOuterClass.AvatarDieAnimationEndRsp; - -public class PacketAvatarDieAnimationEndRsp extends BasePacket { - - public PacketAvatarDieAnimationEndRsp(long dieGuid, int skillId) { - super(PacketOpcodes.AvatarDieAnimationEndRsp); - - AvatarDieAnimationEndRsp proto = - AvatarDieAnimationEndRsp.newBuilder().setDieGuid(dieGuid).setSkillId(skillId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarDieAnimationEndRspOuterClass.AvatarDieAnimationEndRsp; + +public class PacketAvatarDieAnimationEndRsp extends BasePacket { + + public PacketAvatarDieAnimationEndRsp(long dieGuid, int skillId) { + super(PacketOpcodes.AvatarDieAnimationEndRsp); + + AvatarDieAnimationEndRsp proto = + AvatarDieAnimationEndRsp.newBuilder().setDieGuid(dieGuid).setSkillId(skillId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarEquipChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarEquipChangeNotify.java index 410b8dbff..4c4cbeef0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarEquipChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarEquipChangeNotify.java @@ -1,41 +1,41 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.EquipType; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarEquipChangeNotifyOuterClass.AvatarEquipChangeNotify; - -public class PacketAvatarEquipChangeNotify extends BasePacket { - - public PacketAvatarEquipChangeNotify(Avatar avatar, GameItem item) { - super(PacketOpcodes.AvatarEquipChangeNotify); - - AvatarEquipChangeNotify.Builder proto = - AvatarEquipChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEquipType(item.getEquipSlot()) - .setItemId(item.getItemId()) - .setEquipGuid(item.getGuid()); - - if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) { - proto.setWeapon(item.createSceneWeaponInfo()); - } else { - proto.setReliquary(item.createSceneReliquaryInfo()); - } - - this.setData(proto); - } - - public PacketAvatarEquipChangeNotify(Avatar avatar, EquipType slot) { - super(PacketOpcodes.AvatarEquipChangeNotify); - - AvatarEquipChangeNotify.Builder proto = - AvatarEquipChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEquipType(slot.getValue()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.inventory.EquipType; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarEquipChangeNotifyOuterClass.AvatarEquipChangeNotify; + +public class PacketAvatarEquipChangeNotify extends BasePacket { + + public PacketAvatarEquipChangeNotify(Avatar avatar, GameItem item) { + super(PacketOpcodes.AvatarEquipChangeNotify); + + AvatarEquipChangeNotify.Builder proto = + AvatarEquipChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEquipType(item.getEquipSlot()) + .setItemId(item.getItemId()) + .setEquipGuid(item.getGuid()); + + if (item.getItemData().getEquipType() == EquipType.EQUIP_WEAPON) { + proto.setWeapon(item.createSceneWeaponInfo()); + } else { + proto.setReliquary(item.createSceneReliquaryInfo()); + } + + this.setData(proto); + } + + public PacketAvatarEquipChangeNotify(Avatar avatar, EquipType slot) { + super(PacketOpcodes.AvatarEquipChangeNotify); + + AvatarEquipChangeNotify.Builder proto = + AvatarEquipChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEquipType(slot.getValue()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java index 3f6af6161..452417c64 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionAllDataRspOuterClass.AvatarExpeditionAllDataRsp; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class PacketAvatarExpeditionAllDataRsp extends BasePacket { - public PacketAvatarExpeditionAllDataRsp( - Map expeditionInfo, int expeditionCountLimit) { - super(PacketOpcodes.AvatarExpeditionAllDataRsp); - - var openExpeditionList = - List.of( - 306, 305, 304, 303, 302, 301, 206, 105, 204, 104, 203, 103, 202, 101, 102, 201, 106, - 205, 401, 402, 403, 404, 405, 406); - - this.setData( - AvatarExpeditionAllDataRsp.newBuilder() - .addAllOpenExpeditionList(openExpeditionList) - .setExpeditionCountLimit(expeditionCountLimit) - .putAllExpeditionInfoMap( - expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) - .build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionAllDataRspOuterClass.AvatarExpeditionAllDataRsp; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class PacketAvatarExpeditionAllDataRsp extends BasePacket { + public PacketAvatarExpeditionAllDataRsp( + Map expeditionInfo, int expeditionCountLimit) { + super(PacketOpcodes.AvatarExpeditionAllDataRsp); + + var openExpeditionList = + List.of( + 306, 305, 304, 303, 302, 301, 206, 105, 204, 104, 203, 103, 202, 101, 102, 201, 106, + 205, 401, 402, 403, 404, 405, 406); + + this.setData( + AvatarExpeditionAllDataRsp.newBuilder() + .addAllOpenExpeditionList(openExpeditionList) + .setExpeditionCountLimit(expeditionCountLimit) + .putAllExpeditionInfoMap( + expeditionInfo.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java index 6df6b34b8..a89595314 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionCallBackRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionCallBackRspOuterClass.AvatarExpeditionCallBackRsp; -import java.util.Map; - -public class PacketAvatarExpeditionCallBackRsp extends BasePacket { - public PacketAvatarExpeditionCallBackRsp(Map expeditionInfo) { - super(PacketOpcodes.AvatarExpeditionCallBackRsp); - - AvatarExpeditionCallBackRsp.Builder proto = AvatarExpeditionCallBackRsp.newBuilder(); - expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionCallBackRspOuterClass.AvatarExpeditionCallBackRsp; +import java.util.Map; + +public class PacketAvatarExpeditionCallBackRsp extends BasePacket { + public PacketAvatarExpeditionCallBackRsp(Map expeditionInfo) { + super(PacketOpcodes.AvatarExpeditionCallBackRsp); + + AvatarExpeditionCallBackRsp.Builder proto = AvatarExpeditionCallBackRsp.newBuilder(); + expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java index f437b6114..faefe879e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionDataNotifyOuterClass.AvatarExpeditionDataNotify; -import java.util.Map; -import java.util.stream.Collectors; - -public class PacketAvatarExpeditionDataNotify extends BasePacket { - public PacketAvatarExpeditionDataNotify(Map expeditionInfo) { - super(PacketOpcodes.AvatarExpeditionDataNotify); - - this.setData( - AvatarExpeditionDataNotify.newBuilder() - .putAllExpeditionInfoMap( - expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) - .build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionDataNotifyOuterClass.AvatarExpeditionDataNotify; +import java.util.Map; +import java.util.stream.Collectors; + +public class PacketAvatarExpeditionDataNotify extends BasePacket { + public PacketAvatarExpeditionDataNotify(Map expeditionInfo) { + super(PacketOpcodes.AvatarExpeditionDataNotify); + + this.setData( + AvatarExpeditionDataNotify.newBuilder() + .putAllExpeditionInfoMap( + expeditionInfo.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java index d77f2abd5..9aa6b527a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionGetRewardRsp.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionGetRewardRspOuterClass.AvatarExpeditionGetRewardRsp; -import java.util.Collection; -import java.util.Map; - -public class PacketAvatarExpeditionGetRewardRsp extends BasePacket { - public PacketAvatarExpeditionGetRewardRsp( - Map expeditionInfo, Collection items) { - super(PacketOpcodes.AvatarExpeditionGetRewardRsp); - - AvatarExpeditionGetRewardRsp.Builder proto = AvatarExpeditionGetRewardRsp.newBuilder(); - expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); - items.forEach(item -> proto.addItemList(item.toItemParam())); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionGetRewardRspOuterClass.AvatarExpeditionGetRewardRsp; +import java.util.Collection; +import java.util.Map; + +public class PacketAvatarExpeditionGetRewardRsp extends BasePacket { + public PacketAvatarExpeditionGetRewardRsp( + Map expeditionInfo, Collection items) { + super(PacketOpcodes.AvatarExpeditionGetRewardRsp); + + AvatarExpeditionGetRewardRsp.Builder proto = AvatarExpeditionGetRewardRsp.newBuilder(); + expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); + items.forEach(item -> proto.addItemList(item.toItemParam())); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java index 438ceb5c6..591ec61f6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionStartRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.expedition.ExpeditionInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarExpeditionStartRspOuterClass.AvatarExpeditionStartRsp; -import java.util.Map; - -public class PacketAvatarExpeditionStartRsp extends BasePacket { - public PacketAvatarExpeditionStartRsp(Map expeditionInfo) { - super(PacketOpcodes.AvatarExpeditionStartRsp); - - AvatarExpeditionStartRsp.Builder proto = AvatarExpeditionStartRsp.newBuilder(); - expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.expedition.ExpeditionInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarExpeditionStartRspOuterClass.AvatarExpeditionStartRsp; +import java.util.Map; + +public class PacketAvatarExpeditionStartRsp extends BasePacket { + public PacketAvatarExpeditionStartRsp(Map expeditionInfo) { + super(PacketOpcodes.AvatarExpeditionStartRsp); + + AvatarExpeditionStartRsp.Builder proto = AvatarExpeditionStartRsp.newBuilder(); + expeditionInfo.forEach((key, e) -> proto.putExpeditionInfoMap(key, e.toProto())); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java index f03a99550..a5a18ae18 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterDataNotify.java @@ -1,49 +1,49 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.props.FetterState; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarFetterDataNotifyOuterClass.AvatarFetterDataNotify; -import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; -import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; - -public class PacketAvatarFetterDataNotify extends BasePacket { - - public PacketAvatarFetterDataNotify(Avatar avatar) { - super(PacketOpcodes.AvatarFetterDataNotify); - - int fetterLevel = avatar.getFetterLevel(); - - AvatarFetterInfo.Builder avatarFetter = - AvatarFetterInfo.newBuilder().setExpLevel(avatar.getFetterLevel()); - - if (fetterLevel != 10) { - avatarFetter.setExpNumber(avatar.getFetterExp()); - } - - if (avatar.getFetterList() != null) { - for (int i = 0; i < avatar.getFetterList().size(); i++) { - avatarFetter.addFetterList( - FetterData.newBuilder() - .setFetterId(avatar.getFetterList().get(i)) - .setFetterState(FetterState.FINISH.getValue())); - } - } - - int cardId = avatar.getNameCardId(); - - if (avatar.getPlayer().getNameCardList().contains(cardId)) { - avatarFetter.addRewardedFetterLevelList(10); - } - - AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); - - AvatarFetterDataNotify proto = - AvatarFetterDataNotify.newBuilder() - .putFetterInfoMap(avatar.getGuid(), avatarFetterInfo) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.props.FetterState; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterDataNotifyOuterClass.AvatarFetterDataNotify; +import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo; +import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData; + +public class PacketAvatarFetterDataNotify extends BasePacket { + + public PacketAvatarFetterDataNotify(Avatar avatar) { + super(PacketOpcodes.AvatarFetterDataNotify); + + int fetterLevel = avatar.getFetterLevel(); + + AvatarFetterInfo.Builder avatarFetter = + AvatarFetterInfo.newBuilder().setExpLevel(avatar.getFetterLevel()); + + if (fetterLevel != 10) { + avatarFetter.setExpNumber(avatar.getFetterExp()); + } + + if (avatar.getFetterList() != null) { + for (int i = 0; i < avatar.getFetterList().size(); i++) { + avatarFetter.addFetterList( + FetterData.newBuilder() + .setFetterId(avatar.getFetterList().get(i)) + .setFetterState(FetterState.FINISH.getValue())); + } + } + + int cardId = avatar.getNameCardId(); + + if (avatar.getPlayer().getNameCardList().contains(cardId)) { + avatarFetter.addRewardedFetterLevelList(10); + } + + AvatarFetterInfo avatarFetterInfo = avatarFetter.build(); + + AvatarFetterDataNotify proto = + AvatarFetterDataNotify.newBuilder() + .putFetterInfoMap(avatar.getGuid(), avatarFetterInfo) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java index 91afb0efb..221fe6696 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFetterLevelRewardRsp.java @@ -1,36 +1,36 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarFetterLevelRewardRspOuterClass.AvatarFetterLevelRewardRsp; - -public class PacketAvatarFetterLevelRewardRsp extends BasePacket { - - public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel, int rewardId) { - super(PacketOpcodes.AvatarFetterLevelRewardRsp); - - AvatarFetterLevelRewardRsp proto = - AvatarFetterLevelRewardRsp.newBuilder() - .setAvatarGuid(guid) - .setFetterLevel(fetterLevel) - .setRetcode(0) - .setRewardId(rewardId) - .build(); - - this.setData(proto); - } - - public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel) { - super(PacketOpcodes.AvatarFetterLevelRewardRsp); - - AvatarFetterLevelRewardRsp proto = - AvatarFetterLevelRewardRsp.newBuilder() - .setAvatarGuid(guid) - .setFetterLevel(fetterLevel) - .setRetcode(1) - .setRewardId(0) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFetterLevelRewardRspOuterClass.AvatarFetterLevelRewardRsp; + +public class PacketAvatarFetterLevelRewardRsp extends BasePacket { + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel, int rewardId) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = + AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(0) + .setRewardId(rewardId) + .build(); + + this.setData(proto); + } + + public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel) { + super(PacketOpcodes.AvatarFetterLevelRewardRsp); + + AvatarFetterLevelRewardRsp proto = + AvatarFetterLevelRewardRsp.newBuilder() + .setAvatarGuid(guid) + .setFetterLevel(fetterLevel) + .setRetcode(1) + .setRewardId(0) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropNotify.java index 87b265877..2be1503f6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFightPropNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarFightPropNotifyOuterClass.AvatarFightPropNotify; - -public class PacketAvatarFightPropNotify extends BasePacket { - - public PacketAvatarFightPropNotify(Avatar avatar) { - super(PacketOpcodes.AvatarFightPropNotify); - - AvatarFightPropNotify proto = - AvatarFightPropNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .putAllFightPropMap(avatar.getFightProperties()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFightPropNotifyOuterClass.AvatarFightPropNotify; + +public class PacketAvatarFightPropNotify extends BasePacket { + + public PacketAvatarFightPropNotify(Avatar avatar) { + super(PacketOpcodes.AvatarFightPropNotify); + + AvatarFightPropNotify proto = + AvatarFightPropNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .putAllFightPropMap(avatar.getFightProperties()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFlycloakChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFlycloakChangeNotify.java index 18d18d4ba..f7a67df23 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFlycloakChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarFlycloakChangeNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarFlycloakChangeNotifyOuterClass.AvatarFlycloakChangeNotify; - -public class PacketAvatarFlycloakChangeNotify extends BasePacket { - - public PacketAvatarFlycloakChangeNotify(Avatar avatar) { - super(PacketOpcodes.AvatarFlycloakChangeNotify); - - AvatarFlycloakChangeNotify proto = - AvatarFlycloakChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setFlycloakId(avatar.getFlyCloak()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarFlycloakChangeNotifyOuterClass.AvatarFlycloakChangeNotify; + +public class PacketAvatarFlycloakChangeNotify extends BasePacket { + + public PacketAvatarFlycloakChangeNotify(Avatar avatar) { + super(PacketOpcodes.AvatarFlycloakChangeNotify); + + AvatarFlycloakChangeNotify proto = + AvatarFlycloakChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setFlycloakId(avatar.getFlyCloak()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainCostumeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainCostumeNotify.java index f28718eb3..3b8251542 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainCostumeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainCostumeNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarGainCostumeNotifyOuterClass.AvatarGainCostumeNotify; - -public class PacketAvatarGainCostumeNotify extends BasePacket { - - public PacketAvatarGainCostumeNotify(int costumeId) { - super(PacketOpcodes.AvatarGainCostumeNotify); - - AvatarGainCostumeNotify proto = - AvatarGainCostumeNotify.newBuilder().setCostumeId(costumeId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarGainCostumeNotifyOuterClass.AvatarGainCostumeNotify; + +public class PacketAvatarGainCostumeNotify extends BasePacket { + + public PacketAvatarGainCostumeNotify(int costumeId) { + super(PacketOpcodes.AvatarGainCostumeNotify); + + AvatarGainCostumeNotify proto = + AvatarGainCostumeNotify.newBuilder().setCostumeId(costumeId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainFlycloakNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainFlycloakNotify.java index 2acbde0bc..6a819b1a8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainFlycloakNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarGainFlycloakNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarGainFlycloakNotifyOuterClass.AvatarGainFlycloakNotify; - -public class PacketAvatarGainFlycloakNotify extends BasePacket { - - public PacketAvatarGainFlycloakNotify(int flycloak) { - super(PacketOpcodes.AvatarGainFlycloakNotify); - - AvatarGainFlycloakNotify proto = - AvatarGainFlycloakNotify.newBuilder().setFlycloakId(flycloak).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarGainFlycloakNotifyOuterClass.AvatarGainFlycloakNotify; + +public class PacketAvatarGainFlycloakNotify extends BasePacket { + + public PacketAvatarGainFlycloakNotify(int flycloak) { + super(PacketOpcodes.AvatarGainFlycloakNotify); + + AvatarGainFlycloakNotify proto = + AvatarGainFlycloakNotify.newBuilder().setFlycloakId(flycloak).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarLifeStateChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarLifeStateChangeNotify.java index 8d6e00cc9..2e70ea94f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarLifeStateChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarLifeStateChangeNotify.java @@ -1,67 +1,67 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.game.props.LifeState; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarLifeStateChangeNotifyOuterClass.AvatarLifeStateChangeNotify; -import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; - -public class PacketAvatarLifeStateChangeNotify extends BasePacket { - - public PacketAvatarLifeStateChangeNotify(Avatar avatar) { - super(PacketOpcodes.AvatarLifeStateChangeNotify); - - AvatarLifeStateChangeNotify proto = - AvatarLifeStateChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setLifeState( - avatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) > 0 - ? LifeState.LIFE_ALIVE.getValue() - : LifeState.LIFE_DEAD.getValue()) - .build(); - - this.setData(proto); - } - - public PacketAvatarLifeStateChangeNotify(Avatar avatar, int attackerId, LifeState lifeState) { - super(PacketOpcodes.AvatarLifeStateChangeNotify); - - AvatarLifeStateChangeNotify proto = - AvatarLifeStateChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setLifeState(lifeState.getValue()) - .setMoveReliableSeq(attackerId) - .build(); - - this.setData(proto); - } - - public PacketAvatarLifeStateChangeNotify( - Avatar avatar, LifeState lifeState, PlayerDieType dieType) { - this(avatar, lifeState, null, "", dieType); - } - - public PacketAvatarLifeStateChangeNotify( - Avatar avatar, - LifeState lifeState, - GameEntity sourceEntity, - String attackTag, - PlayerDieType dieType) { - super(PacketOpcodes.AvatarLifeStateChangeNotify); - - AvatarLifeStateChangeNotify.Builder proto = AvatarLifeStateChangeNotify.newBuilder(); - - proto.setAvatarGuid(avatar.getGuid()); - proto.setLifeState(lifeState.getValue()); - if (sourceEntity != null) { - proto.setSourceEntityId(sourceEntity.getId()); - } - proto.setDieType(dieType); - proto.setAttackTag((attackTag)); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.game.props.LifeState; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarLifeStateChangeNotifyOuterClass.AvatarLifeStateChangeNotify; +import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; + +public class PacketAvatarLifeStateChangeNotify extends BasePacket { + + public PacketAvatarLifeStateChangeNotify(Avatar avatar) { + super(PacketOpcodes.AvatarLifeStateChangeNotify); + + AvatarLifeStateChangeNotify proto = + AvatarLifeStateChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setLifeState( + avatar.getFightProperty(FightProperty.FIGHT_PROP_CUR_HP) > 0 + ? LifeState.LIFE_ALIVE.getValue() + : LifeState.LIFE_DEAD.getValue()) + .build(); + + this.setData(proto); + } + + public PacketAvatarLifeStateChangeNotify(Avatar avatar, int attackerId, LifeState lifeState) { + super(PacketOpcodes.AvatarLifeStateChangeNotify); + + AvatarLifeStateChangeNotify proto = + AvatarLifeStateChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setLifeState(lifeState.getValue()) + .setMoveReliableSeq(attackerId) + .build(); + + this.setData(proto); + } + + public PacketAvatarLifeStateChangeNotify( + Avatar avatar, LifeState lifeState, PlayerDieType dieType) { + this(avatar, lifeState, null, "", dieType); + } + + public PacketAvatarLifeStateChangeNotify( + Avatar avatar, + LifeState lifeState, + GameEntity sourceEntity, + String attackTag, + PlayerDieType dieType) { + super(PacketOpcodes.AvatarLifeStateChangeNotify); + + AvatarLifeStateChangeNotify.Builder proto = AvatarLifeStateChangeNotify.newBuilder(); + + proto.setAvatarGuid(avatar.getGuid()); + proto.setLifeState(lifeState.getValue()); + if (sourceEntity != null) { + proto.setSourceEntityId(sourceEntity.getId()); + } + proto.setDieType(dieType); + proto.setAttackTag((attackTag)); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPromoteRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPromoteRsp.java index f962e99d3..eb3a8a0cb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPromoteRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPromoteRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarPromoteRspOuterClass.AvatarPromoteRsp; - -public class PacketAvatarPromoteRsp extends BasePacket { - - public PacketAvatarPromoteRsp(Avatar avatar) { - super(PacketOpcodes.AvatarPromoteRsp); - - AvatarPromoteRsp proto = AvatarPromoteRsp.newBuilder().setGuid(avatar.getGuid()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarPromoteRspOuterClass.AvatarPromoteRsp; + +public class PacketAvatarPromoteRsp extends BasePacket { + + public PacketAvatarPromoteRsp(Avatar avatar) { + super(PacketOpcodes.AvatarPromoteRsp); + + AvatarPromoteRsp proto = AvatarPromoteRsp.newBuilder().setGuid(avatar.getGuid()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPropNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPropNotify.java index 8ef965c65..c60a901fe 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPropNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarPropNotify.java @@ -1,51 +1,51 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.props.PlayerProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarPropNotifyOuterClass.AvatarPropNotify; -import java.util.Map; - -public class PacketAvatarPropNotify extends BasePacket { - public PacketAvatarPropNotify(Avatar avatar) { - super(PacketOpcodes.AvatarPropNotify); - - AvatarPropNotify proto = - AvatarPropNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .putPropMap(PlayerProperty.PROP_LEVEL.getId(), avatar.getLevel()) - .putPropMap(PlayerProperty.PROP_EXP.getId(), avatar.getExp()) - .putPropMap(PlayerProperty.PROP_BREAK_LEVEL.getId(), avatar.getPromoteLevel()) - .putPropMap(PlayerProperty.PROP_SATIATION_VAL.getId(), avatar.getSatiation()) - .putPropMap( - PlayerProperty.PROP_SATIATION_PENALTY_TIME.getId(), avatar.getSatiationPenalty()) - .build(); - - this.setData(proto); - } - - public PacketAvatarPropNotify(Avatar avatar, PlayerProperty prop, int value) { - super(PacketOpcodes.AvatarPropNotify); - - AvatarPropNotify proto = - AvatarPropNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .putPropMap(prop.getId(), value) - .build(); - - this.setData(proto); - } - - public PacketAvatarPropNotify(Avatar avatar, Map propMap) { - super(PacketOpcodes.AvatarPropNotify); - - AvatarPropNotify proto = - AvatarPropNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .putAllPropMap(propMap) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarPropNotifyOuterClass.AvatarPropNotify; +import java.util.Map; + +public class PacketAvatarPropNotify extends BasePacket { + public PacketAvatarPropNotify(Avatar avatar) { + super(PacketOpcodes.AvatarPropNotify); + + AvatarPropNotify proto = + AvatarPropNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .putPropMap(PlayerProperty.PROP_LEVEL.getId(), avatar.getLevel()) + .putPropMap(PlayerProperty.PROP_EXP.getId(), avatar.getExp()) + .putPropMap(PlayerProperty.PROP_BREAK_LEVEL.getId(), avatar.getPromoteLevel()) + .putPropMap(PlayerProperty.PROP_SATIATION_VAL.getId(), avatar.getSatiation()) + .putPropMap( + PlayerProperty.PROP_SATIATION_PENALTY_TIME.getId(), avatar.getSatiationPenalty()) + .build(); + + this.setData(proto); + } + + public PacketAvatarPropNotify(Avatar avatar, PlayerProperty prop, int value) { + super(PacketOpcodes.AvatarPropNotify); + + AvatarPropNotify proto = + AvatarPropNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .putPropMap(prop.getId(), value) + .build(); + + this.setData(proto); + } + + public PacketAvatarPropNotify(Avatar avatar, Map propMap) { + super(PacketOpcodes.AvatarPropNotify); + + AvatarPropNotify proto = + AvatarPropNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .putAllPropMap(propMap) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSatiationDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSatiationDataNotify.java index 8e094ab59..1205279bb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSatiationDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSatiationDataNotify.java @@ -1,46 +1,46 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSatiationDataNotifyOuterClass.AvatarSatiationDataNotify; -import emu.grasscutter.net.proto.AvatarSatiationDataOuterClass.AvatarSatiationData; - -public class PacketAvatarSatiationDataNotify extends BasePacket { - - public PacketAvatarSatiationDataNotify(Avatar avatar, float finishTime, long penaltyTime) { - super(PacketOpcodes.AvatarSatiationDataNotify); - - AvatarSatiationData.Builder avatarSatiation = - AvatarSatiationData.newBuilder().setAvatarGuid(avatar.getGuid()).setFinishTime(finishTime); - - // Penalty for overeating - if (penaltyTime > 0) { - avatarSatiation.setPenaltyFinishTime(penaltyTime); - } - - avatarSatiation.build(); - - AvatarSatiationDataNotify notify = - AvatarSatiationDataNotify.newBuilder().addSatiationDataList(0, avatarSatiation).build(); - - this.setData(notify); - } - - public PacketAvatarSatiationDataNotify(float time, Avatar avatar) { - super(PacketOpcodes.AvatarSatiationDataNotify); - - var avatarSatiation = - AvatarSatiationData.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setFinishTime(time + (avatar.getSatiation() / 30f)) - // Penalty time always ends before finish time - .setPenaltyFinishTime(time + (avatar.getSatiationPenalty() / 100f)) - .build(); - - AvatarSatiationDataNotify notify = - AvatarSatiationDataNotify.newBuilder().addSatiationDataList(0, avatarSatiation).build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSatiationDataNotifyOuterClass.AvatarSatiationDataNotify; +import emu.grasscutter.net.proto.AvatarSatiationDataOuterClass.AvatarSatiationData; + +public class PacketAvatarSatiationDataNotify extends BasePacket { + + public PacketAvatarSatiationDataNotify(Avatar avatar, float finishTime, long penaltyTime) { + super(PacketOpcodes.AvatarSatiationDataNotify); + + AvatarSatiationData.Builder avatarSatiation = + AvatarSatiationData.newBuilder().setAvatarGuid(avatar.getGuid()).setFinishTime(finishTime); + + // Penalty for overeating + if (penaltyTime > 0) { + avatarSatiation.setPenaltyFinishTime(penaltyTime); + } + + avatarSatiation.build(); + + AvatarSatiationDataNotify notify = + AvatarSatiationDataNotify.newBuilder().addSatiationDataList(0, avatarSatiation).build(); + + this.setData(notify); + } + + public PacketAvatarSatiationDataNotify(float time, Avatar avatar) { + super(PacketOpcodes.AvatarSatiationDataNotify); + + var avatarSatiation = + AvatarSatiationData.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setFinishTime(time + (avatar.getSatiation() / 30f)) + // Penalty time always ends before finish time + .setPenaltyFinishTime(time + (avatar.getSatiationPenalty() / 100f)) + .build(); + + AvatarSatiationDataNotify notify = + AvatarSatiationDataNotify.newBuilder().addSatiationDataList(0, avatarSatiation).build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillChangeNotify.java index 3eb123dd8..5101c5122 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillChangeNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillChangeNotifyOuterClass.AvatarSkillChangeNotify; - -public class PacketAvatarSkillChangeNotify extends BasePacket { - - public PacketAvatarSkillChangeNotify(Avatar avatar, int skillId, int oldLevel, int curLevel) { - super(PacketOpcodes.AvatarSkillChangeNotify); - - AvatarSkillChangeNotify proto = - AvatarSkillChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEntityId(avatar.getEntityId()) - .setSkillDepotId(avatar.getSkillDepotId()) - .setAvatarSkillId(skillId) - .setOldLevel(oldLevel) - .setCurLevel(curLevel) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillChangeNotifyOuterClass.AvatarSkillChangeNotify; + +public class PacketAvatarSkillChangeNotify extends BasePacket { + + public PacketAvatarSkillChangeNotify(Avatar avatar, int skillId, int oldLevel, int curLevel) { + super(PacketOpcodes.AvatarSkillChangeNotify); + + AvatarSkillChangeNotify proto = + AvatarSkillChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEntityId(avatar.getEntityId()) + .setSkillDepotId(avatar.getSkillDepotId()) + .setAvatarSkillId(skillId) + .setOldLevel(oldLevel) + .setCurLevel(curLevel) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillDepotChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillDepotChangeNotify.java index 3187356d7..9e852e043 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillDepotChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillDepotChangeNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillDepotChangeNotifyOuterClass.AvatarSkillDepotChangeNotify; - -public class PacketAvatarSkillDepotChangeNotify extends BasePacket { - - public PacketAvatarSkillDepotChangeNotify(Avatar avatar) { - super(PacketOpcodes.AvatarSkillDepotChangeNotify); - - AvatarSkillDepotChangeNotify proto = - AvatarSkillDepotChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEntityId(avatar.getEntityId()) - .setSkillDepotId(avatar.getSkillDepotId()) - .setCoreProudSkillLevel(avatar.getCoreProudSkillLevel()) - .addAllTalentIdList(avatar.getTalentIdList()) - .addAllProudSkillList(avatar.getProudSkillList()) - .putAllSkillLevelMap(avatar.getSkillLevelMap()) - .putAllProudSkillExtraLevelMap(avatar.getProudSkillBonusMap()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillDepotChangeNotifyOuterClass.AvatarSkillDepotChangeNotify; + +public class PacketAvatarSkillDepotChangeNotify extends BasePacket { + + public PacketAvatarSkillDepotChangeNotify(Avatar avatar) { + super(PacketOpcodes.AvatarSkillDepotChangeNotify); + + AvatarSkillDepotChangeNotify proto = + AvatarSkillDepotChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEntityId(avatar.getEntityId()) + .setSkillDepotId(avatar.getSkillDepotId()) + .setCoreProudSkillLevel(avatar.getCoreProudSkillLevel()) + .addAllTalentIdList(avatar.getTalentIdList()) + .addAllProudSkillList(avatar.getProudSkillList()) + .putAllSkillLevelMap(avatar.getSkillLevelMap()) + .putAllProudSkillExtraLevelMap(avatar.getProudSkillBonusMap()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java index 145640354..b7237d3a0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillInfoNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillInfoNotifyOuterClass.AvatarSkillInfoNotify; -import emu.grasscutter.net.proto.AvatarSkillInfoOuterClass.AvatarSkillInfo; -import it.unimi.dsi.fastutil.ints.Int2IntMap; - -public class PacketAvatarSkillInfoNotify extends BasePacket { - public PacketAvatarSkillInfoNotify(long avatarGuid, Int2IntMap skillExtraChargeMap) { - super(PacketOpcodes.AvatarSkillInfoNotify); - - var proto = AvatarSkillInfoNotify.newBuilder().setGuid(avatarGuid); - - skillExtraChargeMap.forEach( - (skillId, count) -> - proto.putSkillMap( - skillId, AvatarSkillInfo.newBuilder().setMaxChargeCount(count).build())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillInfoNotifyOuterClass.AvatarSkillInfoNotify; +import emu.grasscutter.net.proto.AvatarSkillInfoOuterClass.AvatarSkillInfo; +import it.unimi.dsi.fastutil.ints.Int2IntMap; + +public class PacketAvatarSkillInfoNotify extends BasePacket { + public PacketAvatarSkillInfoNotify(long avatarGuid, Int2IntMap skillExtraChargeMap) { + super(PacketOpcodes.AvatarSkillInfoNotify); + + var proto = AvatarSkillInfoNotify.newBuilder().setGuid(avatarGuid); + + skillExtraChargeMap.forEach( + (skillId, count) -> + proto.putSkillMap( + skillId, AvatarSkillInfo.newBuilder().setMaxChargeCount(count).build())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillMaxChargeCountNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillMaxChargeCountNotify.java index 0a8bbf327..9deffd878 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillMaxChargeCountNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillMaxChargeCountNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillMaxChargeCountNotifyOuterClass.AvatarSkillMaxChargeCountNotify; - -public class PacketAvatarSkillMaxChargeCountNotify extends BasePacket { - - public PacketAvatarSkillMaxChargeCountNotify(Avatar avatar, int skillId, int maxCharges) { - super(PacketOpcodes.AvatarSkillMaxChargeCountNotify); - - AvatarSkillMaxChargeCountNotify proto = - AvatarSkillMaxChargeCountNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setSkillId(skillId) - .setMaxChargeCount(maxCharges) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillMaxChargeCountNotifyOuterClass.AvatarSkillMaxChargeCountNotify; + +public class PacketAvatarSkillMaxChargeCountNotify extends BasePacket { + + public PacketAvatarSkillMaxChargeCountNotify(Avatar avatar, int skillId, int maxCharges) { + super(PacketOpcodes.AvatarSkillMaxChargeCountNotify); + + AvatarSkillMaxChargeCountNotify proto = + AvatarSkillMaxChargeCountNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setSkillId(skillId) + .setMaxChargeCount(maxCharges) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillUpgradeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillUpgradeRsp.java index 6be8c2161..7683e3303 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillUpgradeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarSkillUpgradeRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarSkillUpgradeRspOuterClass.AvatarSkillUpgradeRsp; - -public class PacketAvatarSkillUpgradeRsp extends BasePacket { - - public PacketAvatarSkillUpgradeRsp(Avatar avatar, int skillId, int oldLevel, int newLevel) { - super(PacketOpcodes.AvatarSkillUpgradeRsp); - - AvatarSkillUpgradeRsp proto = - AvatarSkillUpgradeRsp.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setAvatarSkillId(skillId) - .setOldLevel(oldLevel) - .setCurLevel(newLevel) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarSkillUpgradeRspOuterClass.AvatarSkillUpgradeRsp; + +public class PacketAvatarSkillUpgradeRsp extends BasePacket { + + public PacketAvatarSkillUpgradeRsp(Avatar avatar, int skillId, int oldLevel, int newLevel) { + super(PacketOpcodes.AvatarSkillUpgradeRsp); + + AvatarSkillUpgradeRsp proto = + AvatarSkillUpgradeRsp.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setAvatarSkillId(skillId) + .setOldLevel(oldLevel) + .setCurLevel(newLevel) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamAllDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamAllDataNotify.java index 8f712c138..36248b184 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamAllDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarTeamAllDataNotify.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarTeamAllDataNotifyOuterClass.AvatarTeamAllDataNotify; - -public class PacketAvatarTeamAllDataNotify extends BasePacket { - public PacketAvatarTeamAllDataNotify(Player player) { - super(PacketOpcodes.AvatarTeamAllDataNotify); - - AvatarTeamAllDataNotify.Builder proto = AvatarTeamAllDataNotify.newBuilder(); - - // Add the id list for custom teams. - for (int id : player.getTeamManager().getTeams().keySet()) { - if (id > 4) { - proto.addBackupAvatarTeamOrderList(id); - } - } - - // Add the avatar lists for all the teams the player has. - player - .getTeamManager() - .getTeams() - .forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player))); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarTeamAllDataNotifyOuterClass.AvatarTeamAllDataNotify; + +public class PacketAvatarTeamAllDataNotify extends BasePacket { + public PacketAvatarTeamAllDataNotify(Player player) { + super(PacketOpcodes.AvatarTeamAllDataNotify); + + AvatarTeamAllDataNotify.Builder proto = AvatarTeamAllDataNotify.newBuilder(); + + // Add the id list for custom teams. + for (int id : player.getTeamManager().getTeams().keySet()) { + if (id > 4) { + proto.addBackupAvatarTeamOrderList(id); + } + } + + // Add the avatar lists for all the teams the player has. + player + .getTeamManager() + .getTeams() + .forEach((id, teamInfo) -> proto.putAvatarTeamMap(id, teamInfo.toProto(player))); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUnlockTalentNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUnlockTalentNotify.java index e0ace945f..34add99ff 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUnlockTalentNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUnlockTalentNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarUnlockTalentNotifyOuterClass.AvatarUnlockTalentNotify; - -public class PacketAvatarUnlockTalentNotify extends BasePacket { - - public PacketAvatarUnlockTalentNotify(Avatar avatar, int talentId) { - super(PacketOpcodes.AvatarUnlockTalentNotify); - - AvatarUnlockTalentNotify proto = - AvatarUnlockTalentNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEntityId(avatar.getEntityId()) - .setTalentId(talentId) - .setSkillDepotId(avatar.getSkillDepotId()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarUnlockTalentNotifyOuterClass.AvatarUnlockTalentNotify; + +public class PacketAvatarUnlockTalentNotify extends BasePacket { + + public PacketAvatarUnlockTalentNotify(Avatar avatar, int talentId) { + super(PacketOpcodes.AvatarUnlockTalentNotify); + + AvatarUnlockTalentNotify proto = + AvatarUnlockTalentNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEntityId(avatar.getEntityId()) + .setTalentId(talentId) + .setSkillDepotId(avatar.getSkillDepotId()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUpgradeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUpgradeRsp.java index beab5abf7..c587459df 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUpgradeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarUpgradeRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarUpgradeRspOuterClass.AvatarUpgradeRsp; -import java.util.Map; - -public class PacketAvatarUpgradeRsp extends BasePacket { - - public PacketAvatarUpgradeRsp(Avatar avatar, int oldLevel, Map oldFightPropMap) { - super(PacketOpcodes.AvatarUpgradeRsp); - - this.buildHeader(0); - - AvatarUpgradeRsp proto = - AvatarUpgradeRsp.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setOldLevel(oldLevel) - .setCurLevel(avatar.getLevel()) - .putAllOldFightPropMap(oldFightPropMap) - .putAllCurFightPropMap(avatar.getFightProperties()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarUpgradeRspOuterClass.AvatarUpgradeRsp; +import java.util.Map; + +public class PacketAvatarUpgradeRsp extends BasePacket { + + public PacketAvatarUpgradeRsp(Avatar avatar, int oldLevel, Map oldFightPropMap) { + super(PacketOpcodes.AvatarUpgradeRsp); + + this.buildHeader(0); + + AvatarUpgradeRsp proto = + AvatarUpgradeRsp.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setOldLevel(oldLevel) + .setCurLevel(avatar.getLevel()) + .putAllOldFightPropMap(oldFightPropMap) + .putAllCurFightPropMap(avatar.getFightProperties()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarWearFlycloakRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarWearFlycloakRsp.java index 74fec9b76..d98099714 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarWearFlycloakRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarWearFlycloakRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AvatarWearFlycloakRspOuterClass.AvatarWearFlycloakRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketAvatarWearFlycloakRsp extends BasePacket { - public PacketAvatarWearFlycloakRsp(long avatarGuid, int costumeId) { - super(PacketOpcodes.AvatarWearFlycloakRsp); - - AvatarWearFlycloakRsp proto = - AvatarWearFlycloakRsp.newBuilder() - .setAvatarGuid(avatarGuid) - .setFlycloakId(costumeId) - .build(); - - this.setData(proto); - } - - public PacketAvatarWearFlycloakRsp() { - super(PacketOpcodes.AvatarWearFlycloakRsp); - - AvatarWearFlycloakRsp proto = - AvatarWearFlycloakRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AvatarWearFlycloakRspOuterClass.AvatarWearFlycloakRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketAvatarWearFlycloakRsp extends BasePacket { + public PacketAvatarWearFlycloakRsp(long avatarGuid, int costumeId) { + super(PacketOpcodes.AvatarWearFlycloakRsp); + + AvatarWearFlycloakRsp proto = + AvatarWearFlycloakRsp.newBuilder() + .setAvatarGuid(avatarGuid) + .setFlycloakId(costumeId) + .build(); + + this.setData(proto); + } + + public PacketAvatarWearFlycloakRsp() { + super(PacketOpcodes.AvatarWearFlycloakRsp); + + AvatarWearFlycloakRsp proto = + AvatarWearFlycloakRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBackMyWorldRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBackMyWorldRsp.java index 887f47bba..90e02ca73 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBackMyWorldRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBackMyWorldRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BackMyWorldRspOuterClass; - -public class PacketBackMyWorldRsp extends BasePacket { - - public PacketBackMyWorldRsp() { - super(PacketOpcodes.BackMyWorldRsp); - - var proto = BackMyWorldRspOuterClass.BackMyWorldRsp.newBuilder(); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BackMyWorldRspOuterClass; + +public class PacketBackMyWorldRsp extends BasePacket { + + public PacketBackMyWorldRsp() { + super(PacketOpcodes.BackMyWorldRsp); + + var proto = BackMyWorldRspOuterClass.BackMyWorldRsp.newBuilder(); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassAllDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassAllDataNotify.java index a5b7ed871..c83297d30 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassAllDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassAllDataNotify.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BattlePassAllDataNotifyOuterClass.BattlePassAllDataNotify; - -public class PacketBattlePassAllDataNotify extends BasePacket { - public PacketBattlePassAllDataNotify(Player player) { - super(PacketOpcodes.BattlePassAllDataNotify); - - var proto = BattlePassAllDataNotify.newBuilder(); - - proto.setHaveCurSchedule(true).setCurSchedule(player.getBattlePassManager().getScheduleProto()); - - for (var missionData : GameData.getBattlePassMissionDataMap().values()) { - // Dont send invalid refresh types - if (!missionData.isValidRefreshType()) { - continue; - } - - // Check if player has mission in bp manager. If not, then add an empty proto from the mission - // data - if (player.getBattlePassManager().hasMission(missionData.getId())) { - proto.addMissionList( - player.getBattlePassManager().loadMissionById(missionData.getId()).toProto()); - } else { - proto.addMissionList(missionData.toProto()); - } - } - - setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BattlePassAllDataNotifyOuterClass.BattlePassAllDataNotify; + +public class PacketBattlePassAllDataNotify extends BasePacket { + public PacketBattlePassAllDataNotify(Player player) { + super(PacketOpcodes.BattlePassAllDataNotify); + + var proto = BattlePassAllDataNotify.newBuilder(); + + proto.setHaveCurSchedule(true).setCurSchedule(player.getBattlePassManager().getScheduleProto()); + + for (var missionData : GameData.getBattlePassMissionDataMap().values()) { + // Dont send invalid refresh types + if (!missionData.isValidRefreshType()) { + continue; + } + + // Check if player has mission in bp manager. If not, then add an empty proto from the mission + // data + if (player.getBattlePassManager().hasMission(missionData.getId())) { + proto.addMissionList( + player.getBattlePassManager().loadMissionById(missionData.getId()).toProto()); + } else { + proto.addMissionList(missionData.toProto()); + } + } + + setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassCurScheduleUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassCurScheduleUpdateNotify.java index 9350e4f50..b701b2296 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassCurScheduleUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassCurScheduleUpdateNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BattlePassCurScheduleUpdateNotifyOuterClass.BattlePassCurScheduleUpdateNotify; - -public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket { - - public PacketBattlePassCurScheduleUpdateNotify(Player player) { - super(PacketOpcodes.BattlePassCurScheduleUpdateNotify); - - var proto = BattlePassCurScheduleUpdateNotify.newBuilder(); - - proto - .setHaveCurSchedule(true) - .setCurSchedule(player.getBattlePassManager().getScheduleProto()) - .build(); - - setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BattlePassCurScheduleUpdateNotifyOuterClass.BattlePassCurScheduleUpdateNotify; + +public class PacketBattlePassCurScheduleUpdateNotify extends BasePacket { + + public PacketBattlePassCurScheduleUpdateNotify(Player player) { + super(PacketOpcodes.BattlePassCurScheduleUpdateNotify); + + var proto = BattlePassCurScheduleUpdateNotify.newBuilder(); + + proto + .setHaveCurSchedule(true) + .setCurSchedule(player.getBattlePassManager().getScheduleProto()) + .build(); + + setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java index 5c94fd9a7..423ba5ee3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBattlePassMissionUpdateNotify.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.battlepass.BattlePassMission; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BattlePassMissionUpdateNotifyOuterClass.BattlePassMissionUpdateNotify; -import java.util.Collection; - -public class PacketBattlePassMissionUpdateNotify extends BasePacket { - - public PacketBattlePassMissionUpdateNotify(BattlePassMission mission) { - super(PacketOpcodes.BattlePassMissionUpdateNotify); - - var proto = - BattlePassMissionUpdateNotify.newBuilder().addMissionList(mission.toProto()).build(); - - this.setData(proto); - } - - public PacketBattlePassMissionUpdateNotify(Collection missions) { - super(PacketOpcodes.BattlePassMissionUpdateNotify); - - var proto = BattlePassMissionUpdateNotify.newBuilder(); - - missions.forEach( - mission -> { - proto.addMissionList(mission.toProto()); - }); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.battlepass.BattlePassMission; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BattlePassMissionUpdateNotifyOuterClass.BattlePassMissionUpdateNotify; +import java.util.Collection; + +public class PacketBattlePassMissionUpdateNotify extends BasePacket { + + public PacketBattlePassMissionUpdateNotify(BattlePassMission mission) { + super(PacketOpcodes.BattlePassMissionUpdateNotify); + + var proto = + BattlePassMissionUpdateNotify.newBuilder().addMissionList(mission.toProto()).build(); + + this.setData(proto); + } + + public PacketBattlePassMissionUpdateNotify(Collection missions) { + super(PacketOpcodes.BattlePassMissionUpdateNotify); + + var proto = BattlePassMissionUpdateNotify.newBuilder(); + + missions.forEach( + mission -> { + proto.addMissionList(mission.toProto()); + }); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBlossomBriefInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBlossomBriefInfoNotify.java index 204c02836..d21ad2230 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBlossomBriefInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBlossomBriefInfoNotify.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BlossomBriefInfoNotifyOuterClass; -import emu.grasscutter.net.proto.BlossomBriefInfoOuterClass; - -public class PacketBlossomBriefInfoNotify extends BasePacket { - public PacketBlossomBriefInfoNotify( - Iterable blossoms) { - super(PacketOpcodes.BlossomBriefInfoNotify); - this.setData( - BlossomBriefInfoNotifyOuterClass.BlossomBriefInfoNotify.newBuilder() - .addAllBriefInfoList(blossoms)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BlossomBriefInfoNotifyOuterClass; +import emu.grasscutter.net.proto.BlossomBriefInfoOuterClass; + +public class PacketBlossomBriefInfoNotify extends BasePacket { + public PacketBlossomBriefInfoNotify( + Iterable blossoms) { + super(PacketOpcodes.BlossomBriefInfoNotify); + this.setData( + BlossomBriefInfoNotifyOuterClass.BlossomBriefInfoNotify.newBuilder() + .addAllBriefInfoList(blossoms)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyBattlePassLevelRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyBattlePassLevelRsp.java index 17da597ed..61284c2a2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyBattlePassLevelRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyBattlePassLevelRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BuyBattlePassLevelRspOuterClass.BuyBattlePassLevelRsp; - -public class PacketBuyBattlePassLevelRsp extends BasePacket { - - public PacketBuyBattlePassLevelRsp(int buyLevel) { - super(PacketOpcodes.BuyBattlePassLevelRsp); - - BuyBattlePassLevelRsp proto = BuyBattlePassLevelRsp.newBuilder().setBuyLevel(buyLevel).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BuyBattlePassLevelRspOuterClass.BuyBattlePassLevelRsp; + +public class PacketBuyBattlePassLevelRsp extends BasePacket { + + public PacketBuyBattlePassLevelRsp(int buyLevel) { + super(PacketOpcodes.BuyBattlePassLevelRsp); + + BuyBattlePassLevelRsp proto = BuyBattlePassLevelRsp.newBuilder().setBuyLevel(buyLevel).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyGoodsRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyGoodsRsp.java index 310c8c0d2..7b98c0cd6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketBuyGoodsRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketBuyGoodsRsp.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BuyGoodsRspOuterClass; -import emu.grasscutter.net.proto.ShopGoodsOuterClass; - -public class PacketBuyGoodsRsp extends BasePacket { - public PacketBuyGoodsRsp(int shopType, int boughtNum, ShopGoodsOuterClass.ShopGoods sg) { - super(PacketOpcodes.BuyGoodsRsp); - - BuyGoodsRspOuterClass.BuyGoodsRsp buyGoodsRsp = - BuyGoodsRspOuterClass.BuyGoodsRsp.newBuilder() - .setShopType(shopType) - .setBuyCount(boughtNum) - .addGoodsList( - ShopGoodsOuterClass.ShopGoods.newBuilder().mergeFrom(sg).setBoughtNum(boughtNum)) - .build(); - - this.setData(buyGoodsRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BuyGoodsRspOuterClass; +import emu.grasscutter.net.proto.ShopGoodsOuterClass; + +public class PacketBuyGoodsRsp extends BasePacket { + public PacketBuyGoodsRsp(int shopType, int boughtNum, ShopGoodsOuterClass.ShopGoods sg) { + super(PacketOpcodes.BuyGoodsRsp); + + BuyGoodsRspOuterClass.BuyGoodsRsp buyGoodsRsp = + BuyGoodsRspOuterClass.BuyGoodsRsp.newBuilder() + .setShopType(shopType) + .setBuyCount(boughtNum) + .addGoodsList( + ShopGoodsOuterClass.ShopGoods.newBuilder().mergeFrom(sg).setBoughtNum(boughtNum)) + .build(); + + this.setData(buyGoodsRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCalcWeaponUpgradeReturnItemsRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCalcWeaponUpgradeReturnItemsRsp.java index 303802125..75736cc88 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCalcWeaponUpgradeReturnItemsRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCalcWeaponUpgradeReturnItemsRsp.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CalcWeaponUpgradeReturnItemsRspOuterClass.CalcWeaponUpgradeReturnItemsRsp; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import java.util.List; - -public class PacketCalcWeaponUpgradeReturnItemsRsp extends BasePacket { - - public PacketCalcWeaponUpgradeReturnItemsRsp(long itemGuid, List returnItems) { - super(PacketOpcodes.CalcWeaponUpgradeReturnItemsRsp); - - CalcWeaponUpgradeReturnItemsRsp proto = - CalcWeaponUpgradeReturnItemsRsp.newBuilder() - .setTargetWeaponGuid(itemGuid) - .addAllItemParamList(returnItems) - .build(); - - this.setData(proto); - } - - public PacketCalcWeaponUpgradeReturnItemsRsp() { - super(PacketOpcodes.CalcWeaponUpgradeReturnItemsRsp); - - CalcWeaponUpgradeReturnItemsRsp proto = - CalcWeaponUpgradeReturnItemsRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CalcWeaponUpgradeReturnItemsRspOuterClass.CalcWeaponUpgradeReturnItemsRsp; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import java.util.List; + +public class PacketCalcWeaponUpgradeReturnItemsRsp extends BasePacket { + + public PacketCalcWeaponUpgradeReturnItemsRsp(long itemGuid, List returnItems) { + super(PacketOpcodes.CalcWeaponUpgradeReturnItemsRsp); + + CalcWeaponUpgradeReturnItemsRsp proto = + CalcWeaponUpgradeReturnItemsRsp.newBuilder() + .setTargetWeaponGuid(itemGuid) + .addAllItemParamList(returnItems) + .build(); + + this.setData(proto); + } + + public PacketCalcWeaponUpgradeReturnItemsRsp() { + super(PacketOpcodes.CalcWeaponUpgradeReturnItemsRsp); + + CalcWeaponUpgradeReturnItemsRsp proto = + CalcWeaponUpgradeReturnItemsRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCanUseSkillNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCanUseSkillNotify.java index 80f8eda0d..25678720b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCanUseSkillNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCanUseSkillNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CanUseSkillNotifyOuterClass; - -public class PacketCanUseSkillNotify extends BasePacket { - - public PacketCanUseSkillNotify(boolean canUseSkill) { - super(PacketOpcodes.CanUseSkillNotify); - - CanUseSkillNotifyOuterClass.CanUseSkillNotify proto = - CanUseSkillNotifyOuterClass.CanUseSkillNotify.newBuilder() - .setIsCanUseSkill(canUseSkill) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CanUseSkillNotifyOuterClass; + +public class PacketCanUseSkillNotify extends BasePacket { + + public PacketCanUseSkillNotify(boolean canUseSkill) { + super(PacketOpcodes.CanUseSkillNotify); + + CanUseSkillNotifyOuterClass.CanUseSkillNotify proto = + CanUseSkillNotifyOuterClass.CanUseSkillNotify.newBuilder() + .setIsCanUseSkill(canUseSkill) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCardProductRewardNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCardProductRewardNotify.java index 269de5d5c..16420bf1a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCardProductRewardNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCardProductRewardNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CardProductRewardNotifyOuterClass.CardProductRewardNotify; - -public class PacketCardProductRewardNotify extends BasePacket { - - public PacketCardProductRewardNotify(int remainsDay) { - super(PacketOpcodes.CardProductRewardNotify); - - CardProductRewardNotify proto = - CardProductRewardNotify.newBuilder() - .setProductId("ys_chn_blessofmoon_tier5") - .setHcoin(90) - .setRemainDays(remainsDay) - .build(); - - // Hard code Product id keep cool 😎 - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CardProductRewardNotifyOuterClass.CardProductRewardNotify; + +public class PacketCardProductRewardNotify extends BasePacket { + + public PacketCardProductRewardNotify(int remainsDay) { + super(PacketOpcodes.CardProductRewardNotify); + + CardProductRewardNotify proto = + CardProductRewardNotify.newBuilder() + .setProductId("ys_chn_blessofmoon_tier5") + .setHcoin(90) + .setRemainDays(remainsDay) + .build(); + + // Hard code Product id keep cool 😎 + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChallengeDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChallengeDataNotify.java index ac48896e7..7c2f81c5b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChallengeDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChallengeDataNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify; - -public class PacketChallengeDataNotify extends BasePacket { - - public PacketChallengeDataNotify(WorldChallenge challenge, int index, int value) { - super(PacketOpcodes.ChallengeDataNotify); - - ChallengeDataNotify proto = - ChallengeDataNotify.newBuilder() - .setChallengeIndex(challenge.getChallengeIndex()) - .setParamIndex(index) - .setValue(value) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChallengeDataNotifyOuterClass.ChallengeDataNotify; + +public class PacketChallengeDataNotify extends BasePacket { + + public PacketChallengeDataNotify(WorldChallenge challenge, int index, int value) { + super(PacketOpcodes.ChallengeDataNotify); + + ChallengeDataNotify proto = + ChallengeDataNotify.newBuilder() + .setChallengeIndex(challenge.getChallengeIndex()) + .setParamIndex(index) + .setValue(value) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeAvatarRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeAvatarRsp.java index 0c74fea6e..b53a19048 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeAvatarRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeAvatarRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeAvatarRspOuterClass.ChangeAvatarRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketChangeAvatarRsp extends BasePacket { - - public PacketChangeAvatarRsp(long guid) { - super(PacketOpcodes.ChangeAvatarRsp); - - ChangeAvatarRsp p = - ChangeAvatarRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) - .setCurGuid(guid) - .build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeAvatarRspOuterClass.ChangeAvatarRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketChangeAvatarRsp extends BasePacket { + + public PacketChangeAvatarRsp(long guid) { + super(PacketOpcodes.ChangeAvatarRsp); + + ChangeAvatarRsp p = + ChangeAvatarRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) + .setCurGuid(guid) + .build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeMpTeamAvatarRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeMpTeamAvatarRsp.java index 33d90a37f..37e05fe71 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeMpTeamAvatarRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeMpTeamAvatarRsp.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.player.TeamInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeMpTeamAvatarRspOuterClass.ChangeMpTeamAvatarRsp; - -public class PacketChangeMpTeamAvatarRsp extends BasePacket { - - public PacketChangeMpTeamAvatarRsp(Player player, TeamInfo teamInfo) { - super(PacketOpcodes.ChangeMpTeamAvatarRsp); - - ChangeMpTeamAvatarRsp.Builder proto = - ChangeMpTeamAvatarRsp.newBuilder() - .setCurAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()); - - for (int avatarId : teamInfo.getAvatars()) { - proto.addAvatarGuidList(player.getAvatars().getAvatarById(avatarId).getGuid()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.player.TeamInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeMpTeamAvatarRspOuterClass.ChangeMpTeamAvatarRsp; + +public class PacketChangeMpTeamAvatarRsp extends BasePacket { + + public PacketChangeMpTeamAvatarRsp(Player player, TeamInfo teamInfo) { + super(PacketOpcodes.ChangeMpTeamAvatarRsp); + + ChangeMpTeamAvatarRsp.Builder proto = + ChangeMpTeamAvatarRsp.newBuilder() + .setCurAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()); + + for (int avatarId : teamInfo.getAvatars()) { + proto.addAvatarGuidList(player.getAvatars().getAvatarById(avatarId).getGuid()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeTeamNameRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeTeamNameRsp.java index 8e1abb7b1..2accf453e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChangeTeamNameRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChangeTeamNameRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeTeamNameRspOuterClass.ChangeTeamNameRsp; - -public class PacketChangeTeamNameRsp extends BasePacket { - - public PacketChangeTeamNameRsp(int teamId, String teamName) { - super(PacketOpcodes.ChangeTeamNameRsp); - - ChangeTeamNameRsp proto = - ChangeTeamNameRsp.newBuilder().setTeamId(teamId).setTeamName(teamName).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeTeamNameRspOuterClass.ChangeTeamNameRsp; + +public class PacketChangeTeamNameRsp extends BasePacket { + + public PacketChangeTeamNameRsp(int teamId, String teamName) { + super(PacketOpcodes.ChangeTeamNameRsp); + + ChangeTeamNameRsp proto = + ChangeTeamNameRsp.newBuilder().setTeamId(teamId).setTeamName(teamName).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChapterStateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChapterStateNotify.java index 488fab184..ba4ad9b89 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChapterStateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChapterStateNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChapterStateNotifyOuterClass; -import emu.grasscutter.net.proto.ChapterStateOuterClass; - -public class PacketChapterStateNotify extends BasePacket { - - public PacketChapterStateNotify(int id, ChapterStateOuterClass.ChapterState state) { - super(PacketOpcodes.ChapterStateNotify); - - var proto = ChapterStateNotifyOuterClass.ChapterStateNotify.newBuilder(); - - proto.setChapterId(id).setChapterState(state); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChapterStateNotifyOuterClass; +import emu.grasscutter.net.proto.ChapterStateOuterClass; + +public class PacketChapterStateNotify extends BasePacket { + + public PacketChapterStateNotify(int id, ChapterStateOuterClass.ChapterState state) { + super(PacketOpcodes.ChapterStateNotify); + + var proto = ChapterStateNotifyOuterClass.ChapterStateNotify.newBuilder(); + + proto.setChapterId(id).setChapterState(state); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketChooseCurAvatarTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketChooseCurAvatarTeamRsp.java index 4acb3349d..33ebb57d1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketChooseCurAvatarTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketChooseCurAvatarTeamRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChooseCurAvatarTeamRspOuterClass.ChooseCurAvatarTeamRsp; - -public class PacketChooseCurAvatarTeamRsp extends BasePacket { - - public PacketChooseCurAvatarTeamRsp(int teamId) { - super(PacketOpcodes.ChooseCurAvatarTeamRsp); - - ChooseCurAvatarTeamRsp proto = ChooseCurAvatarTeamRsp.newBuilder().setCurTeamId(teamId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChooseCurAvatarTeamRspOuterClass.ChooseCurAvatarTeamRsp; + +public class PacketChooseCurAvatarTeamRsp extends BasePacket { + + public PacketChooseCurAvatarTeamRsp(int teamId) { + super(PacketOpcodes.ChooseCurAvatarTeamRsp); + + ChooseCurAvatarTeamRsp proto = ChooseCurAvatarTeamRsp.newBuilder().setCurTeamId(teamId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java index 8bfdc3ce4..bde56d254 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketClientAbilityInitFinishNotify.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; -import emu.grasscutter.net.proto.ClientAbilityInitFinishNotifyOuterClass.ClientAbilityInitFinishNotify; -import java.util.List; - -public class PacketClientAbilityInitFinishNotify extends BasePacket { - - public PacketClientAbilityInitFinishNotify(List entries) { - super(PacketOpcodes.ClientAbilityInitFinishNotify, true); - - int entityId = 0; - - if (entries.size() > 0) { - AbilityInvokeEntry entry = entries.get(0); - entityId = entry.getEntityId(); - } - - ClientAbilityInitFinishNotify proto = - ClientAbilityInitFinishNotify.newBuilder() - .setEntityId(entityId) - .addAllInvokes(entries) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; +import emu.grasscutter.net.proto.ClientAbilityInitFinishNotifyOuterClass.ClientAbilityInitFinishNotify; +import java.util.List; + +public class PacketClientAbilityInitFinishNotify extends BasePacket { + + public PacketClientAbilityInitFinishNotify(List entries) { + super(PacketOpcodes.ClientAbilityInitFinishNotify, true); + + int entityId = 0; + + if (entries.size() > 0) { + AbilityInvokeEntry entry = entries.get(0); + entityId = entry.getEntityId(); + } + + ClientAbilityInitFinishNotify proto = + ClientAbilityInitFinishNotify.newBuilder() + .setEntityId(entityId) + .addAllInvokes(entries) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java index 3430c36b8..7f74a7839 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataFullNotify.java @@ -1,116 +1,116 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CodexDataFullNotifyOuterClass.CodexDataFullNotify; -import emu.grasscutter.net.proto.CodexTypeDataOuterClass.CodexTypeData; -import java.util.Collections; - -public class PacketCodexDataFullNotify extends BasePacket { - public PacketCodexDataFullNotify(Player player) { - super(PacketOpcodes.CodexDataFullNotify, true); - - // Quests - CodexTypeData.Builder questTypeData = CodexTypeData.newBuilder().setTypeValue(1); - - // Weapons - CodexTypeData.Builder weaponTypeData = CodexTypeData.newBuilder().setTypeValue(2); - - // Animals - CodexTypeData.Builder animalTypeData = CodexTypeData.newBuilder().setTypeValue(3); - - // Materials - CodexTypeData.Builder materialTypeData = CodexTypeData.newBuilder().setTypeValue(4); - - // Books - CodexTypeData.Builder bookTypeData = CodexTypeData.newBuilder().setTypeValue(5); - - // Tips - CodexTypeData.Builder pushTipsTypeData = CodexTypeData.newBuilder().setTypeValue(6); - - // Views - CodexTypeData.Builder viewTypeData = CodexTypeData.newBuilder().setTypeValue(7); - - // Reliquary - CodexTypeData.Builder reliquaryData = CodexTypeData.newBuilder().setTypeValue(8); - - player - .getQuestManager() - .forEachMainQuest( - mainQuest -> { - if (mainQuest.isFinished()) { - var codexQuest = - GameData.getCodexQuestDataIdMap().get(mainQuest.getParentQuestId()); - if (codexQuest != null) { - questTypeData - .addCodexIdList(codexQuest.getId()) - .addAllHaveViewedList(Collections.singleton(true)); - } - } - }); - - player - .getCodex() - .getUnlockedWeapon() - .forEach( - weapon -> { - var codexWeapon = GameData.getCodexWeaponDataIdMap().get(weapon); - if (codexWeapon != null) { - weaponTypeData - .addCodexIdList(codexWeapon.getId()) - .addAllHaveViewedList(Collections.singleton(true)); - } - }); - - player - .getCodex() - .getUnlockedAnimal() - .forEach( - (animal, amount) -> { - var codexAnimal = GameData.getCodexAnimalDataMap().get(animal); - if (codexAnimal != null) { - animalTypeData - .addCodexIdList(codexAnimal.getId()) - .addAllHaveViewedList(Collections.singleton(true)); - } - }); - - player - .getCodex() - .getUnlockedMaterial() - .forEach( - material -> { - var codexMaterial = GameData.getCodexMaterialDataIdMap().get(material); - if (codexMaterial != null) { - materialTypeData - .addCodexIdList(codexMaterial.getId()) - .addAllHaveViewedList(Collections.singleton(true)); - } - }); - - player - .getCodex() - .getUnlockedReliquarySuitCodex() - .forEach( - reliquarySuit -> { - reliquaryData - .addCodexIdList(reliquarySuit) - .addAllHaveViewedList(Collections.singleton(true)); - }); - - CodexDataFullNotify.Builder proto = - CodexDataFullNotify.newBuilder() - .addTypeDataList(questTypeData.build()) - .addTypeDataList(weaponTypeData) - .addTypeDataList(animalTypeData) - .addTypeDataList(materialTypeData) - .addTypeDataList(bookTypeData) - .addTypeDataList(pushTipsTypeData.build()) - .addTypeDataList(viewTypeData.build()) - .addTypeDataList(reliquaryData); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CodexDataFullNotifyOuterClass.CodexDataFullNotify; +import emu.grasscutter.net.proto.CodexTypeDataOuterClass.CodexTypeData; +import java.util.Collections; + +public class PacketCodexDataFullNotify extends BasePacket { + public PacketCodexDataFullNotify(Player player) { + super(PacketOpcodes.CodexDataFullNotify, true); + + // Quests + CodexTypeData.Builder questTypeData = CodexTypeData.newBuilder().setTypeValue(1); + + // Weapons + CodexTypeData.Builder weaponTypeData = CodexTypeData.newBuilder().setTypeValue(2); + + // Animals + CodexTypeData.Builder animalTypeData = CodexTypeData.newBuilder().setTypeValue(3); + + // Materials + CodexTypeData.Builder materialTypeData = CodexTypeData.newBuilder().setTypeValue(4); + + // Books + CodexTypeData.Builder bookTypeData = CodexTypeData.newBuilder().setTypeValue(5); + + // Tips + CodexTypeData.Builder pushTipsTypeData = CodexTypeData.newBuilder().setTypeValue(6); + + // Views + CodexTypeData.Builder viewTypeData = CodexTypeData.newBuilder().setTypeValue(7); + + // Reliquary + CodexTypeData.Builder reliquaryData = CodexTypeData.newBuilder().setTypeValue(8); + + player + .getQuestManager() + .forEachMainQuest( + mainQuest -> { + if (mainQuest.isFinished()) { + var codexQuest = + GameData.getCodexQuestDataIdMap().get(mainQuest.getParentQuestId()); + if (codexQuest != null) { + questTypeData + .addCodexIdList(codexQuest.getId()) + .addAllHaveViewedList(Collections.singleton(true)); + } + } + }); + + player + .getCodex() + .getUnlockedWeapon() + .forEach( + weapon -> { + var codexWeapon = GameData.getCodexWeaponDataIdMap().get(weapon); + if (codexWeapon != null) { + weaponTypeData + .addCodexIdList(codexWeapon.getId()) + .addAllHaveViewedList(Collections.singleton(true)); + } + }); + + player + .getCodex() + .getUnlockedAnimal() + .forEach( + (animal, amount) -> { + var codexAnimal = GameData.getCodexAnimalDataMap().get(animal); + if (codexAnimal != null) { + animalTypeData + .addCodexIdList(codexAnimal.getId()) + .addAllHaveViewedList(Collections.singleton(true)); + } + }); + + player + .getCodex() + .getUnlockedMaterial() + .forEach( + material -> { + var codexMaterial = GameData.getCodexMaterialDataIdMap().get(material); + if (codexMaterial != null) { + materialTypeData + .addCodexIdList(codexMaterial.getId()) + .addAllHaveViewedList(Collections.singleton(true)); + } + }); + + player + .getCodex() + .getUnlockedReliquarySuitCodex() + .forEach( + reliquarySuit -> { + reliquaryData + .addCodexIdList(reliquarySuit) + .addAllHaveViewedList(Collections.singleton(true)); + }); + + CodexDataFullNotify.Builder proto = + CodexDataFullNotify.newBuilder() + .addTypeDataList(questTypeData.build()) + .addTypeDataList(weaponTypeData) + .addTypeDataList(animalTypeData) + .addTypeDataList(materialTypeData) + .addTypeDataList(bookTypeData) + .addTypeDataList(pushTipsTypeData.build()) + .addTypeDataList(viewTypeData.build()) + .addTypeDataList(reliquaryData); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java index 760e0a40c..75128f1e6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCodexDataUpdateNotify.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CodexDataUpdateNotifyOuterClass.CodexDataUpdateNotify; - -public class PacketCodexDataUpdateNotify extends BasePacket { - public PacketCodexDataUpdateNotify(GameMainQuest quest) { - super(PacketOpcodes.CodexDataUpdateNotify, true); - var codexQuest = GameData.getCodexQuestDataIdMap().get(quest.getParentQuestId()); - if (codexQuest != null) { - CodexDataUpdateNotify proto = - CodexDataUpdateNotify.newBuilder().setTypeValue(1).setId(codexQuest.getId()).build(); - this.setData(proto); - } - } - - public PacketCodexDataUpdateNotify(int typeValue, int codexId) { - super(PacketOpcodes.CodexDataUpdateNotify, true); - CodexDataUpdateNotify proto = - CodexDataUpdateNotify.newBuilder().setTypeValue(typeValue).setId(codexId).build(); - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.quest.GameMainQuest; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CodexDataUpdateNotifyOuterClass.CodexDataUpdateNotify; + +public class PacketCodexDataUpdateNotify extends BasePacket { + public PacketCodexDataUpdateNotify(GameMainQuest quest) { + super(PacketOpcodes.CodexDataUpdateNotify, true); + var codexQuest = GameData.getCodexQuestDataIdMap().get(quest.getParentQuestId()); + if (codexQuest != null) { + CodexDataUpdateNotify proto = + CodexDataUpdateNotify.newBuilder().setTypeValue(1).setId(codexQuest.getId()).build(); + this.setData(proto); + } + } + + public PacketCodexDataUpdateNotify(int typeValue, int codexId) { + super(PacketOpcodes.CodexDataUpdateNotify, true); + CodexDataUpdateNotify proto = + CodexDataUpdateNotify.newBuilder().setTypeValue(typeValue).setId(codexId).build(); + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCombatInvocationsNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCombatInvocationsNotify.java index ef6feb003..7bd04d52b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCombatInvocationsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCombatInvocationsNotify.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CombatInvocationsNotifyOuterClass.CombatInvocationsNotify; -import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry; -import java.util.List; - -public class PacketCombatInvocationsNotify extends BasePacket { - - public PacketCombatInvocationsNotify(CombatInvokeEntry entry) { - super(PacketOpcodes.CombatInvocationsNotify, true); - - CombatInvocationsNotify proto = - CombatInvocationsNotify.newBuilder().addInvokeList(entry).build(); - - this.setData(proto); - } - - public PacketCombatInvocationsNotify(List entries) { - super(PacketOpcodes.CombatInvocationsNotify, true); - - CombatInvocationsNotify proto = - CombatInvocationsNotify.newBuilder().addAllInvokeList(entries).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CombatInvocationsNotifyOuterClass.CombatInvocationsNotify; +import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry; +import java.util.List; + +public class PacketCombatInvocationsNotify extends BasePacket { + + public PacketCombatInvocationsNotify(CombatInvokeEntry entry) { + super(PacketOpcodes.CombatInvocationsNotify, true); + + CombatInvocationsNotify proto = + CombatInvocationsNotify.newBuilder().addInvokeList(entry).build(); + + this.setData(proto); + } + + public PacketCombatInvocationsNotify(List entries) { + super(PacketOpcodes.CombatInvocationsNotify, true); + + CombatInvocationsNotify proto = + CombatInvocationsNotify.newBuilder().addAllInvokeList(entries).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineDataNotify.java index 68c1f6602..354d50c28 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineDataNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CombineDataNotifyOuterClass.CombineDataNotify; - -public class PacketCombineDataNotify extends BasePacket { - - public PacketCombineDataNotify(Iterable unlockedCombines) { - super(PacketOpcodes.CombineDataNotify); - - CombineDataNotify proto = - CombineDataNotify.newBuilder().addAllCombineIdList(unlockedCombines).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CombineDataNotifyOuterClass.CombineDataNotify; + +public class PacketCombineDataNotify extends BasePacket { + + public PacketCombineDataNotify(Iterable unlockedCombines) { + super(PacketOpcodes.CombineDataNotify); + + CombineDataNotify proto = + CombineDataNotify.newBuilder().addAllCombineIdList(unlockedCombines).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineFormulaDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineFormulaDataNotify.java index 397c3116c..b2c382210 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineFormulaDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineFormulaDataNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CombineFormulaDataNotifyOuterClass.CombineFormulaDataNotify; - -public class PacketCombineFormulaDataNotify extends BasePacket { - - public PacketCombineFormulaDataNotify(int combineId) { - super(PacketOpcodes.CombineFormulaDataNotify); - - CombineFormulaDataNotify proto = - CombineFormulaDataNotify.newBuilder().setCombineId(combineId).setIsLocked(false).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CombineFormulaDataNotifyOuterClass.CombineFormulaDataNotify; + +public class PacketCombineFormulaDataNotify extends BasePacket { + + public PacketCombineFormulaDataNotify(int combineId) { + super(PacketOpcodes.CombineFormulaDataNotify); + + CombineFormulaDataNotify proto = + CombineFormulaDataNotify.newBuilder().setCombineId(combineId).setIsLocked(false).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineRsp.java index 31989aaa2..025b2d3a9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCombineRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCombineRsp.java @@ -1,57 +1,57 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CombineReqOuterClass; -import emu.grasscutter.net.proto.CombineRspOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketCombineRsp extends BasePacket { - - public PacketCombineRsp() { - super(PacketOpcodes.CombineRsp); - - CombineRspOuterClass.CombineRsp proto = - CombineRspOuterClass.CombineRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } - - public PacketCombineRsp(int retcode) { - super(PacketOpcodes.CombineRsp); - - CombineRspOuterClass.CombineRsp proto = - CombineRspOuterClass.CombineRsp.newBuilder().setRetcode(retcode).build(); - - this.setData(proto); - } - - public PacketCombineRsp( - CombineReqOuterClass.CombineReq combineReq, - Iterable costItemList, - Iterable resultItemList, - Iterable totalRandomItemList, - Iterable totalReturnItemList, - Iterable totalExtraItemList) { - - super(PacketOpcodes.CombineRsp); - - CombineRspOuterClass.CombineRsp proto = - CombineRspOuterClass.CombineRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) - .setCombineId(combineReq.getCombineId()) - .setCombineCount(combineReq.getCombineCount()) - .setAvatarGuid(combineReq.getAvatarGuid()) - .addAllCostItemList(costItemList) - .addAllResultItemList(resultItemList) - .addAllTotalRandomItemList(totalRandomItemList) - .addAllTotalReturnItemList(totalReturnItemList) - .addAllTotalExtraItemList(totalExtraItemList) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CombineReqOuterClass; +import emu.grasscutter.net.proto.CombineRspOuterClass; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketCombineRsp extends BasePacket { + + public PacketCombineRsp() { + super(PacketOpcodes.CombineRsp); + + CombineRspOuterClass.CombineRsp proto = + CombineRspOuterClass.CombineRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } + + public PacketCombineRsp(int retcode) { + super(PacketOpcodes.CombineRsp); + + CombineRspOuterClass.CombineRsp proto = + CombineRspOuterClass.CombineRsp.newBuilder().setRetcode(retcode).build(); + + this.setData(proto); + } + + public PacketCombineRsp( + CombineReqOuterClass.CombineReq combineReq, + Iterable costItemList, + Iterable resultItemList, + Iterable totalRandomItemList, + Iterable totalReturnItemList, + Iterable totalExtraItemList) { + + super(PacketOpcodes.CombineRsp); + + CombineRspOuterClass.CombineRsp proto = + CombineRspOuterClass.CombineRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) + .setCombineId(combineReq.getCombineId()) + .setCombineCount(combineReq.getCombineCount()) + .setAvatarGuid(combineReq.getAvatarGuid()) + .addAllCostItemList(costItemList) + .addAllResultItemList(resultItemList) + .addAllTotalRandomItemList(totalRandomItemList) + .addAllTotalReturnItemList(totalReturnItemList) + .addAllTotalExtraItemList(totalExtraItemList) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCompoundDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCompoundDataNotify.java index b54ad7598..47f1c7093 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCompoundDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCompoundDataNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CompoundDataNotifyOuterClass.CompoundDataNotify; -import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; -import java.util.List; -import java.util.Set; - -public class PacketCompoundDataNotify extends BasePacket { - - public PacketCompoundDataNotify( - Set unlockedCompounds, List compoundQueueData) { - super(PacketOpcodes.CompoundDataNotify); - var proto = - CompoundDataNotify.newBuilder() - .addAllUnlockCompoundList(unlockedCompounds) - .addAllCompoundQueueDataList(compoundQueueData) - .build(); - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CompoundDataNotifyOuterClass.CompoundDataNotify; +import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; +import java.util.List; +import java.util.Set; + +public class PacketCompoundDataNotify extends BasePacket { + + public PacketCompoundDataNotify( + Set unlockedCompounds, List compoundQueueData) { + super(PacketOpcodes.CompoundDataNotify); + var proto = + CompoundDataNotify.newBuilder() + .addAllUnlockCompoundList(unlockedCompounds) + .addAllCompoundQueueDataList(compoundQueueData) + .build(); + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCookDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCookDataNotify.java index b35475681..9d157c137 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCookDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCookDataNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CookDataNotifyOuterClass.CookDataNotify; -import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; -import java.util.List; - -public class PacketCookDataNotify extends BasePacket { - - public PacketCookDataNotify(List recipes) { - super(PacketOpcodes.CookDataNotify); - - CookDataNotify proto = CookDataNotify.newBuilder().addAllRecipeDataList(recipes).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CookDataNotifyOuterClass.CookDataNotify; +import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; +import java.util.List; + +public class PacketCookDataNotify extends BasePacket { + + public PacketCookDataNotify(List recipes) { + super(PacketOpcodes.CookDataNotify); + + CookDataNotify proto = CookDataNotify.newBuilder().addAllRecipeDataList(recipes).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCookRecipeDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCookRecipeDataNotify.java index 2fca3b7e4..ea9fd99bb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCookRecipeDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCookRecipeDataNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CookRecipeDataNotifyOuterClass.CookRecipeDataNotify; -import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; - -public class PacketCookRecipeDataNotify extends BasePacket { - public PacketCookRecipeDataNotify(CookRecipeData recipe) { - super(PacketOpcodes.CookRecipeDataNotify); - - CookRecipeDataNotify proto = CookRecipeDataNotify.newBuilder().setRecipeData(recipe).build(); - - this.setData(proto); - } - - public PacketCookRecipeDataNotify(int recipeId) { - super(PacketOpcodes.CookRecipeDataNotify); - - CookRecipeDataNotify proto = - CookRecipeDataNotify.newBuilder() - .setRecipeData(CookRecipeData.newBuilder().setRecipeId(recipeId)) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CookRecipeDataNotifyOuterClass.CookRecipeDataNotify; +import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; + +public class PacketCookRecipeDataNotify extends BasePacket { + public PacketCookRecipeDataNotify(CookRecipeData recipe) { + super(PacketOpcodes.CookRecipeDataNotify); + + CookRecipeDataNotify proto = CookRecipeDataNotify.newBuilder().setRecipeData(recipe).build(); + + this.setData(proto); + } + + public PacketCookRecipeDataNotify(int recipeId) { + super(PacketOpcodes.CookRecipeDataNotify); + + CookRecipeDataNotify proto = + CookRecipeDataNotify.newBuilder() + .setRecipeData(CookRecipeData.newBuilder().setRecipeId(recipeId)) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java index fde7add22..4da63690a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketCreateVehicleRsp.java @@ -1,62 +1,62 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityVehicle; -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CreateVehicleRspOuterClass.CreateVehicleRsp; -import emu.grasscutter.net.proto.VehicleInteractTypeOuterClass; -import emu.grasscutter.net.proto.VehicleMemberOuterClass.VehicleMember; -import emu.grasscutter.utils.Position; -import java.util.List; - -public class PacketCreateVehicleRsp extends BasePacket { - - public PacketCreateVehicleRsp( - Player player, int vehicleId, int pointId, Position pos, Position rot) { - super(PacketOpcodes.CreateVehicleRsp); - CreateVehicleRsp.Builder proto = CreateVehicleRsp.newBuilder(); - - // Eject vehicle members and Kill previous vehicles if there are any - List previousVehicles = - player.getScene().getEntities().values().stream() - .filter( - entity -> - entity instanceof EntityVehicle - && ((EntityVehicle) entity).getGadgetId() == vehicleId - && ((EntityVehicle) entity).getOwner().equals(player)) - .toList(); - - previousVehicles.stream() - .forEach( - entity -> { - List vehicleMembers = - ((EntityVehicle) entity).getVehicleMembers().stream().toList(); - - vehicleMembers.stream() - .forEach( - vehicleMember -> { - player - .getScene() - .broadcastPacket( - new PacketVehicleInteractRsp( - ((EntityVehicle) entity), - vehicleMember, - VehicleInteractTypeOuterClass.VehicleInteractType - .VEHICLE_INTERACT_TYPE_OUT)); - }); - - player.getScene().killEntity(entity, 0); - }); - - EntityVehicle vehicle = - new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot); - player.getScene().addEntity(vehicle); - - proto.setVehicleId(vehicleId); - proto.setEntityId(vehicle.getId()); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityVehicle; +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CreateVehicleRspOuterClass.CreateVehicleRsp; +import emu.grasscutter.net.proto.VehicleInteractTypeOuterClass; +import emu.grasscutter.net.proto.VehicleMemberOuterClass.VehicleMember; +import emu.grasscutter.utils.Position; +import java.util.List; + +public class PacketCreateVehicleRsp extends BasePacket { + + public PacketCreateVehicleRsp( + Player player, int vehicleId, int pointId, Position pos, Position rot) { + super(PacketOpcodes.CreateVehicleRsp); + CreateVehicleRsp.Builder proto = CreateVehicleRsp.newBuilder(); + + // Eject vehicle members and Kill previous vehicles if there are any + List previousVehicles = + player.getScene().getEntities().values().stream() + .filter( + entity -> + entity instanceof EntityVehicle + && ((EntityVehicle) entity).getGadgetId() == vehicleId + && ((EntityVehicle) entity).getOwner().equals(player)) + .toList(); + + previousVehicles.stream() + .forEach( + entity -> { + List vehicleMembers = + ((EntityVehicle) entity).getVehicleMembers().stream().toList(); + + vehicleMembers.stream() + .forEach( + vehicleMember -> { + player + .getScene() + .broadcastPacket( + new PacketVehicleInteractRsp( + ((EntityVehicle) entity), + vehicleMember, + VehicleInteractTypeOuterClass.VehicleInteractType + .VEHICLE_INTERACT_TYPE_OUT)); + }); + + player.getScene().killEntity(entity, 0); + }); + + EntityVehicle vehicle = + new EntityVehicle(player.getScene(), player, vehicleId, pointId, pos, rot); + player.getScene().addEntity(vehicle); + + proto.setVehicleId(vehicleId); + proto.setEntityId(vehicle.getId()); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDealAddFriendRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDealAddFriendRsp.java index 9072c97f7..8259e4044 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDealAddFriendRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDealAddFriendRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType; -import emu.grasscutter.net.proto.DealAddFriendRspOuterClass.DealAddFriendRsp; - -public class PacketDealAddFriendRsp extends BasePacket { - - public PacketDealAddFriendRsp(int targetUid, DealAddFriendResultType result) { - super(PacketOpcodes.DealAddFriendRsp); - - DealAddFriendRsp proto = - DealAddFriendRsp.newBuilder() - .setTargetUid(targetUid) - .setDealAddFriendResult(result) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType; +import emu.grasscutter.net.proto.DealAddFriendRspOuterClass.DealAddFriendRsp; + +public class PacketDealAddFriendRsp extends BasePacket { + + public PacketDealAddFriendRsp(int targetUid, DealAddFriendResultType result) { + super(PacketOpcodes.DealAddFriendRsp); + + DealAddFriendRsp proto = + DealAddFriendRsp.newBuilder() + .setTargetUid(targetUid) + .setDealAddFriendResult(result) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDelBackupAvatarTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDelBackupAvatarTeamRsp.java index 4cbe26748..cdfddfea5 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDelBackupAvatarTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDelBackupAvatarTeamRsp.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DelBackupAvatarTeamRspOuterClass.DelBackupAvatarTeamRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; - -public class PacketDelBackupAvatarTeamRsp extends BasePacket { - public PacketDelBackupAvatarTeamRsp(Retcode retcode, int id) { - super(PacketOpcodes.DelBackupAvatarTeamRsp); - - DelBackupAvatarTeamRsp proto = - DelBackupAvatarTeamRsp.newBuilder() - .setRetcode(retcode.getNumber()) - .setBackupAvatarTeamId(id) - .build(); - - this.setData(proto); - } - - public PacketDelBackupAvatarTeamRsp(int id) { - this(Retcode.RET_SUCC, id); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DelBackupAvatarTeamRspOuterClass.DelBackupAvatarTeamRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketDelBackupAvatarTeamRsp extends BasePacket { + public PacketDelBackupAvatarTeamRsp(Retcode retcode, int id) { + super(PacketOpcodes.DelBackupAvatarTeamRsp); + + DelBackupAvatarTeamRsp proto = + DelBackupAvatarTeamRsp.newBuilder() + .setRetcode(retcode.getNumber()) + .setBackupAvatarTeamId(id) + .build(); + + this.setData(proto); + } + + public PacketDelBackupAvatarTeamRsp(int id) { + this(Retcode.RET_SUCC, id); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDelMailRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDelMailRsp.java index 92c6d63a4..e41ffc5ae 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDelMailRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDelMailRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DelMailRspOuterClass.DelMailRsp; -import java.util.List; - -public class PacketDelMailRsp extends BasePacket { - - public PacketDelMailRsp(Player player, List toDeleteIds) { - super(PacketOpcodes.DelMailRsp); - - DelMailRsp proto = DelMailRsp.newBuilder().addAllMailIdList(toDeleteIds).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DelMailRspOuterClass.DelMailRsp; +import java.util.List; + +public class PacketDelMailRsp extends BasePacket { + + public PacketDelMailRsp(Player player, List toDeleteIds) { + super(PacketOpcodes.DelMailRsp); + + DelMailRsp proto = DelMailRsp.newBuilder().addAllMailIdList(toDeleteIds).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDelTeamEntityNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDelTeamEntityNotify.java index 904b9baa8..b31b29a6c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDelTeamEntityNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDelTeamEntityNotify.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DelTeamEntityNotifyOuterClass.DelTeamEntityNotify; -import java.util.List; - -public class PacketDelTeamEntityNotify extends BasePacket { - - public PacketDelTeamEntityNotify(int sceneId, int teamEntityId) { - super(PacketOpcodes.DelTeamEntityNotify); - - DelTeamEntityNotify proto = - DelTeamEntityNotify.newBuilder() - .setSceneId(sceneId) - .addDelEntityIdList(teamEntityId) - .build(); - - this.setData(proto); - } - - public PacketDelTeamEntityNotify(int sceneId, List list) { - super(PacketOpcodes.DelTeamEntityNotify); - - DelTeamEntityNotify proto = - DelTeamEntityNotify.newBuilder().setSceneId(sceneId).addAllDelEntityIdList(list).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DelTeamEntityNotifyOuterClass.DelTeamEntityNotify; +import java.util.List; + +public class PacketDelTeamEntityNotify extends BasePacket { + + public PacketDelTeamEntityNotify(int sceneId, int teamEntityId) { + super(PacketOpcodes.DelTeamEntityNotify); + + DelTeamEntityNotify proto = + DelTeamEntityNotify.newBuilder() + .setSceneId(sceneId) + .addDelEntityIdList(teamEntityId) + .build(); + + this.setData(proto); + } + + public PacketDelTeamEntityNotify(int sceneId, List list) { + super(PacketOpcodes.DelTeamEntityNotify); + + DelTeamEntityNotify proto = + DelTeamEntityNotify.newBuilder().setSceneId(sceneId).addAllDelEntityIdList(list).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendNotify.java index 72105374e..b0c64e906 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendNotify.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DeleteFriendNotifyOuterClass.DeleteFriendNotify; - -public class PacketDeleteFriendNotify extends BasePacket { - - public PacketDeleteFriendNotify(int targetUid) { - super(PacketOpcodes.DeleteFriendNotify); - - DeleteFriendNotify proto = DeleteFriendNotify.newBuilder().setTargetUid(targetUid).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DeleteFriendNotifyOuterClass.DeleteFriendNotify; + +public class PacketDeleteFriendNotify extends BasePacket { + + public PacketDeleteFriendNotify(int targetUid) { + super(PacketOpcodes.DeleteFriendNotify); + + DeleteFriendNotify proto = DeleteFriendNotify.newBuilder().setTargetUid(targetUid).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendRsp.java index 2bb475702..ad98eb804 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDeleteFriendRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DeleteFriendRspOuterClass.DeleteFriendRsp; - -public class PacketDeleteFriendRsp extends BasePacket { - - public PacketDeleteFriendRsp(int targetUid) { - super(PacketOpcodes.DeleteFriendRsp); - - DeleteFriendRsp proto = DeleteFriendRsp.newBuilder().setTargetUid(targetUid).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DeleteFriendRspOuterClass.DeleteFriendRsp; + +public class PacketDeleteFriendRsp extends BasePacket { + + public PacketDeleteFriendRsp(int targetUid) { + super(PacketOpcodes.DeleteFriendRsp); + + DeleteFriendRsp proto = DeleteFriendRsp.newBuilder().setTargetUid(targetUid).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDestroyMaterialRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDestroyMaterialRsp.java index e137d2174..d4463f6dc 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDestroyMaterialRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDestroyMaterialRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DestroyMaterialRspOuterClass.DestroyMaterialRsp; -import it.unimi.dsi.fastutil.ints.Int2IntMap; - -public class PacketDestroyMaterialRsp extends BasePacket { - - public PacketDestroyMaterialRsp(Int2IntMap returnMaterialMap) { - super(PacketOpcodes.DestroyMaterialRsp); - - var proto = DestroyMaterialRsp.newBuilder(); - - returnMaterialMap.forEach( - (id, count) -> { - proto.addItemIdList(id); - proto.addItemCountList(count); - }); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DestroyMaterialRspOuterClass.DestroyMaterialRsp; +import it.unimi.dsi.fastutil.ints.Int2IntMap; + +public class PacketDestroyMaterialRsp extends BasePacket { + + public PacketDestroyMaterialRsp(Int2IntMap returnMaterialMap) { + super(PacketOpcodes.DestroyMaterialRsp); + + var proto = DestroyMaterialRsp.newBuilder(); + + returnMaterialMap.forEach( + (id, count) -> { + proto.addItemIdList(id); + proto.addItemCountList(count); + }); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDoGachaRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDoGachaRsp.java index 7d22d01ba..9697a2699 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDoGachaRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDoGachaRsp.java @@ -1,67 +1,67 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.game.gacha.GachaBanner; -import emu.grasscutter.game.gacha.PlayerGachaBannerInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DoGachaRspOuterClass.DoGachaRsp; -import emu.grasscutter.net.proto.GachaItemOuterClass.GachaItem; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; - -public class PacketDoGachaRsp extends BasePacket { - - public PacketDoGachaRsp( - GachaBanner banner, List list, PlayerGachaBannerInfo gachaInfo) { - super(PacketOpcodes.DoGachaRsp); - - ItemParamData costItem = banner.getCost(1); - ItemParamData costItem10 = banner.getCost(10); - int gachaTimesLimit = banner.getGachaTimesLimit(); - int leftGachaTimes = - switch (gachaTimesLimit) { - case Integer.MAX_VALUE -> Integer.MAX_VALUE; - default -> Math.max(gachaTimesLimit - gachaInfo.getTotalPulls(), 0); - }; - DoGachaRsp.Builder rsp = - DoGachaRsp.newBuilder() - .setGachaType(banner.getGachaType()) - .setGachaScheduleId(banner.getScheduleId()) - .setGachaTimes(list.size()) - .setNewGachaRandom(12345) - .setLeftGachaTimes(leftGachaTimes) - .setGachaTimesLimit(gachaTimesLimit) - .setCostItemId(costItem.getId()) - .setCostItemNum(costItem.getCount()) - .setTenCostItemId(costItem10.getId()) - .setTenCostItemNum(costItem10.getCount()) - .addAllGachaItemList(list); - - if (banner.hasEpitomized()) { - rsp.setWishItemId(gachaInfo.getWishItemId()) - .setWishProgress(gachaInfo.getFailedChosenItemPulls()) - .setWishMaxProgress(banner.getWishMaxProgress()); - } - - this.setData(rsp.build()); - } - - public PacketDoGachaRsp() { - super(PacketOpcodes.DoGachaRsp); - - DoGachaRsp p = - DoGachaRsp.newBuilder().setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE).build(); - - this.setData(p); - } - - public PacketDoGachaRsp(Retcode retcode) { - super(PacketOpcodes.DoGachaRsp); - - DoGachaRsp p = DoGachaRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.common.ItemParamData; +import emu.grasscutter.game.gacha.GachaBanner; +import emu.grasscutter.game.gacha.PlayerGachaBannerInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DoGachaRspOuterClass.DoGachaRsp; +import emu.grasscutter.net.proto.GachaItemOuterClass.GachaItem; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; + +public class PacketDoGachaRsp extends BasePacket { + + public PacketDoGachaRsp( + GachaBanner banner, List list, PlayerGachaBannerInfo gachaInfo) { + super(PacketOpcodes.DoGachaRsp); + + ItemParamData costItem = banner.getCost(1); + ItemParamData costItem10 = banner.getCost(10); + int gachaTimesLimit = banner.getGachaTimesLimit(); + int leftGachaTimes = + switch (gachaTimesLimit) { + case Integer.MAX_VALUE -> Integer.MAX_VALUE; + default -> Math.max(gachaTimesLimit - gachaInfo.getTotalPulls(), 0); + }; + DoGachaRsp.Builder rsp = + DoGachaRsp.newBuilder() + .setGachaType(banner.getGachaType()) + .setGachaScheduleId(banner.getScheduleId()) + .setGachaTimes(list.size()) + .setNewGachaRandom(12345) + .setLeftGachaTimes(leftGachaTimes) + .setGachaTimesLimit(gachaTimesLimit) + .setCostItemId(costItem.getId()) + .setCostItemNum(costItem.getCount()) + .setTenCostItemId(costItem10.getId()) + .setTenCostItemNum(costItem10.getCount()) + .addAllGachaItemList(list); + + if (banner.hasEpitomized()) { + rsp.setWishItemId(gachaInfo.getWishItemId()) + .setWishProgress(gachaInfo.getFailedChosenItemPulls()) + .setWishMaxProgress(banner.getWishMaxProgress()); + } + + this.setData(rsp.build()); + } + + public PacketDoGachaRsp() { + super(PacketOpcodes.DoGachaRsp); + + DoGachaRsp p = + DoGachaRsp.newBuilder().setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE).build(); + + this.setData(p); + } + + public PacketDoGachaRsp(Retcode retcode) { + super(PacketOpcodes.DoGachaRsp); + + DoGachaRsp p = DoGachaRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeBeginNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeBeginNotify.java index 6eca4bf33..d59bfb9cb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeBeginNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeBeginNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify; - -public class PacketDungeonChallengeBeginNotify extends BasePacket { - - public PacketDungeonChallengeBeginNotify(WorldChallenge challenge) { - super(PacketOpcodes.DungeonChallengeBeginNotify, true); - - DungeonChallengeBeginNotify proto = - DungeonChallengeBeginNotify.newBuilder() - .setChallengeId(challenge.getChallengeId()) - .setChallengeIndex(challenge.getChallengeIndex()) - .setGroupId(challenge.getGroup().id) - .addAllParamList(challenge.getParamList()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonChallengeBeginNotifyOuterClass.DungeonChallengeBeginNotify; + +public class PacketDungeonChallengeBeginNotify extends BasePacket { + + public PacketDungeonChallengeBeginNotify(WorldChallenge challenge) { + super(PacketOpcodes.DungeonChallengeBeginNotify, true); + + DungeonChallengeBeginNotify proto = + DungeonChallengeBeginNotify.newBuilder() + .setChallengeId(challenge.getChallengeId()) + .setChallengeIndex(challenge.getChallengeIndex()) + .setGroupId(challenge.getGroup().id) + .addAllParamList(challenge.getParamList()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeFinishNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeFinishNotify.java index 01922f6c4..e2bb932f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeFinishNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonChallengeFinishNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.dungeons.challenge.WorldChallenge; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify; - -public class PacketDungeonChallengeFinishNotify extends BasePacket { - - public PacketDungeonChallengeFinishNotify(WorldChallenge challenge) { - super(PacketOpcodes.DungeonChallengeFinishNotify, true); - - DungeonChallengeFinishNotify proto = - DungeonChallengeFinishNotify.newBuilder() - .setChallengeIndex(challenge.getChallengeIndex()) - .setIsSuccess(challenge.isSuccess()) - .setChallengeRecordType(2) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.dungeons.challenge.WorldChallenge; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonChallengeFinishNotifyOuterClass.DungeonChallengeFinishNotify; + +public class PacketDungeonChallengeFinishNotify extends BasePacket { + + public PacketDungeonChallengeFinishNotify(WorldChallenge challenge) { + super(PacketOpcodes.DungeonChallengeFinishNotify, true); + + DungeonChallengeFinishNotify proto = + DungeonChallengeFinishNotify.newBuilder() + .setChallengeIndex(challenge.getChallengeIndex()) + .setIsSuccess(challenge.isSuccess()) + .setChallengeRecordType(2) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java index 48b05d3cc..c0c612ff8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketDungeonShowReminderNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.DungeonShowReminderNotifyOuterClass; - -public class PacketDungeonShowReminderNotify extends BasePacket { - - public PacketDungeonShowReminderNotify(int reminderId) { - super(PacketOpcodes.DungeonShowReminderNotify); - - var proto = DungeonShowReminderNotifyOuterClass.DungeonShowReminderNotify.newBuilder(); - - proto.setReminderId(reminderId); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.DungeonShowReminderNotifyOuterClass; + +public class PacketDungeonShowReminderNotify extends BasePacket { + + public PacketDungeonShowReminderNotify(int reminderId) { + super(PacketOpcodes.DungeonShowReminderNotify); + + var proto = DungeonShowReminderNotifyOuterClass.DungeonShowReminderNotify.newBuilder(); + + proto.setReminderId(reminderId); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneDoneRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneDoneRsp.java index fe774e82f..6eb9607e5 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneDoneRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneDoneRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterSceneDoneRspOuterClass.EnterSceneDoneRsp; - -public class PacketEnterSceneDoneRsp extends BasePacket { - - public PacketEnterSceneDoneRsp(Player player) { - super(PacketOpcodes.EnterSceneDoneRsp); - - EnterSceneDoneRsp p = - EnterSceneDoneRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterSceneDoneRspOuterClass.EnterSceneDoneRsp; + +public class PacketEnterSceneDoneRsp extends BasePacket { + + public PacketEnterSceneDoneRsp(Player player) { + super(PacketOpcodes.EnterSceneDoneRsp); + + EnterSceneDoneRsp p = + EnterSceneDoneRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterScenePeerNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterScenePeerNotify.java index ca4974e4d..e638ec448 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterScenePeerNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterScenePeerNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterScenePeerNotifyOuterClass.EnterScenePeerNotify; - -public class PacketEnterScenePeerNotify extends BasePacket { - - public PacketEnterScenePeerNotify(Player player) { - super(PacketOpcodes.EnterScenePeerNotify); - - EnterScenePeerNotify proto = - EnterScenePeerNotify.newBuilder() - .setDestSceneId(player.getSceneId()) - .setPeerId(player.getPeerId()) - .setHostPeerId(player.getWorld().getHost().getPeerId()) - .setEnterSceneToken(player.getEnterSceneToken()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterScenePeerNotifyOuterClass.EnterScenePeerNotify; + +public class PacketEnterScenePeerNotify extends BasePacket { + + public PacketEnterScenePeerNotify(Player player) { + super(PacketOpcodes.EnterScenePeerNotify); + + EnterScenePeerNotify proto = + EnterScenePeerNotify.newBuilder() + .setDestSceneId(player.getSceneId()) + .setPeerId(player.getPeerId()) + .setHostPeerId(player.getWorld().getHost().getPeerId()) + .setEnterSceneToken(player.getEnterSceneToken()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneReadyRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneReadyRsp.java index 9dd481c0c..e5bc13a04 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneReadyRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterSceneReadyRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterSceneReadyRspOuterClass.EnterSceneReadyRsp; - -public class PacketEnterSceneReadyRsp extends BasePacket { - - public PacketEnterSceneReadyRsp(Player player) { - super(PacketOpcodes.EnterSceneReadyRsp, 11); - - EnterSceneReadyRsp p = - EnterSceneReadyRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterSceneReadyRspOuterClass.EnterSceneReadyRsp; + +public class PacketEnterSceneReadyRsp extends BasePacket { + + public PacketEnterSceneReadyRsp(Player player) { + super(PacketOpcodes.EnterSceneReadyRsp, 11); + + EnterSceneReadyRsp p = + EnterSceneReadyRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterWorldAreaRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterWorldAreaRsp.java index e978c0d6c..2fe29d21d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEnterWorldAreaRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEnterWorldAreaRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EnterWorldAreaReqOuterClass.EnterWorldAreaReq; -import emu.grasscutter.net.proto.EnterWorldAreaRspOuterClass.EnterWorldAreaRsp; - -public class PacketEnterWorldAreaRsp extends BasePacket { - - public PacketEnterWorldAreaRsp(int clientSequence, EnterWorldAreaReq enterWorld) { - super(PacketOpcodes.EnterWorldAreaRsp, clientSequence); - - EnterWorldAreaRsp p = - EnterWorldAreaRsp.newBuilder() - .setAreaType(enterWorld.getAreaType()) - .setAreaId(enterWorld.getAreaId()) - .build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EnterWorldAreaReqOuterClass.EnterWorldAreaReq; +import emu.grasscutter.net.proto.EnterWorldAreaRspOuterClass.EnterWorldAreaRsp; + +public class PacketEnterWorldAreaRsp extends BasePacket { + + public PacketEnterWorldAreaRsp(int clientSequence, EnterWorldAreaReq enterWorld) { + super(PacketOpcodes.EnterWorldAreaRsp, clientSequence); + + EnterWorldAreaRsp p = + EnterWorldAreaRsp.newBuilder() + .setAreaType(enterWorld.getAreaType()) + .setAreaId(enterWorld.getAreaId()) + .build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEntityAiSyncNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEntityAiSyncNotify.java index ad8b9640d..a3f093982 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEntityAiSyncNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEntityAiSyncNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AiSyncInfoOuterClass.AiSyncInfo; -import emu.grasscutter.net.proto.EntityAiSyncNotifyOuterClass.EntityAiSyncNotify; - -public class PacketEntityAiSyncNotify extends BasePacket { - - public PacketEntityAiSyncNotify(EntityAiSyncNotify notify) { - super(PacketOpcodes.EntityAiSyncNotify, true); - - EntityAiSyncNotify.Builder proto = EntityAiSyncNotify.newBuilder(); - - for (int monsterId : notify.getLocalAvatarAlertedMonsterListList()) { - proto.addInfoList(AiSyncInfo.newBuilder().setEntityId(monsterId).setHasPathToTarget(true)); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AiSyncInfoOuterClass.AiSyncInfo; +import emu.grasscutter.net.proto.EntityAiSyncNotifyOuterClass.EntityAiSyncNotify; + +public class PacketEntityAiSyncNotify extends BasePacket { + + public PacketEntityAiSyncNotify(EntityAiSyncNotify notify) { + super(PacketOpcodes.EntityAiSyncNotify, true); + + EntityAiSyncNotify.Builder proto = EntityAiSyncNotify.newBuilder(); + + for (int monsterId : notify.getLocalAvatarAlertedMonsterListList()) { + proto.addInfoList(AiSyncInfo.newBuilder().setEntityId(monsterId).setHasPathToTarget(true)); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEntityFightPropChangeReasonNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEntityFightPropChangeReasonNotify.java index b0300fca0..bbb8f255a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEntityFightPropChangeReasonNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEntityFightPropChangeReasonNotify.java @@ -1,88 +1,88 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChangeEnergyReasonOuterClass.ChangeEnergyReason; -import emu.grasscutter.net.proto.ChangeHpReasonOuterClass.ChangeHpReason; -import emu.grasscutter.net.proto.EntityFightPropChangeReasonNotifyOuterClass.EntityFightPropChangeReasonNotify; -import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; -import java.util.List; - -public class PacketEntityFightPropChangeReasonNotify extends BasePacket { - - public PacketEntityFightPropChangeReasonNotify( - GameEntity entity, - FightProperty prop, - Float value, - List param, - PropChangeReason reason, - ChangeHpReason changeHpReason) { - super(PacketOpcodes.EntityFightPropChangeReasonNotify); - - EntityFightPropChangeReasonNotify.Builder proto = - EntityFightPropChangeReasonNotify.newBuilder() - .setEntityId(entity.getId()) - .setPropType(prop.getId()) - .setPropDelta(value) - .setReason(reason) - .setChangeHpReason(changeHpReason); - - for (int p : param) { - proto.addParamList(p); - } - - this.setData(proto); - } - - public PacketEntityFightPropChangeReasonNotify( - GameEntity entity, - FightProperty prop, - Float value, - PropChangeReason reason, - ChangeHpReason changeHpReason) { - super(PacketOpcodes.EntityFightPropChangeReasonNotify); - - EntityFightPropChangeReasonNotify proto = - EntityFightPropChangeReasonNotify.newBuilder() - .setEntityId(entity.getId()) - .setPropType(prop.getId()) - .setPropDelta(value) - .setReason(reason) - .setChangeHpReason(changeHpReason) - .build(); - - this.setData(proto); - } - - public PacketEntityFightPropChangeReasonNotify( - GameEntity entity, FightProperty prop, Float value, PropChangeReason reason) { - super(PacketOpcodes.EntityFightPropChangeReasonNotify); - - EntityFightPropChangeReasonNotify proto = - EntityFightPropChangeReasonNotify.newBuilder() - .setEntityId(entity.getId()) - .setPropType(prop.getId()) - .setPropDelta(value) - .setReason(reason) - .build(); - - this.setData(proto); - } - - public PacketEntityFightPropChangeReasonNotify( - GameEntity entity, FightProperty prop, Float value, ChangeEnergyReason reason) { - super(PacketOpcodes.EntityFightPropChangeReasonNotify); - - EntityFightPropChangeReasonNotify proto = - EntityFightPropChangeReasonNotify.newBuilder() - .setEntityId(entity.getId()) - .setPropType(prop.getId()) - .setPropDelta(value) - .setChangeEnergyReason(reason) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChangeEnergyReasonOuterClass.ChangeEnergyReason; +import emu.grasscutter.net.proto.ChangeHpReasonOuterClass.ChangeHpReason; +import emu.grasscutter.net.proto.EntityFightPropChangeReasonNotifyOuterClass.EntityFightPropChangeReasonNotify; +import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; +import java.util.List; + +public class PacketEntityFightPropChangeReasonNotify extends BasePacket { + + public PacketEntityFightPropChangeReasonNotify( + GameEntity entity, + FightProperty prop, + Float value, + List param, + PropChangeReason reason, + ChangeHpReason changeHpReason) { + super(PacketOpcodes.EntityFightPropChangeReasonNotify); + + EntityFightPropChangeReasonNotify.Builder proto = + EntityFightPropChangeReasonNotify.newBuilder() + .setEntityId(entity.getId()) + .setPropType(prop.getId()) + .setPropDelta(value) + .setReason(reason) + .setChangeHpReason(changeHpReason); + + for (int p : param) { + proto.addParamList(p); + } + + this.setData(proto); + } + + public PacketEntityFightPropChangeReasonNotify( + GameEntity entity, + FightProperty prop, + Float value, + PropChangeReason reason, + ChangeHpReason changeHpReason) { + super(PacketOpcodes.EntityFightPropChangeReasonNotify); + + EntityFightPropChangeReasonNotify proto = + EntityFightPropChangeReasonNotify.newBuilder() + .setEntityId(entity.getId()) + .setPropType(prop.getId()) + .setPropDelta(value) + .setReason(reason) + .setChangeHpReason(changeHpReason) + .build(); + + this.setData(proto); + } + + public PacketEntityFightPropChangeReasonNotify( + GameEntity entity, FightProperty prop, Float value, PropChangeReason reason) { + super(PacketOpcodes.EntityFightPropChangeReasonNotify); + + EntityFightPropChangeReasonNotify proto = + EntityFightPropChangeReasonNotify.newBuilder() + .setEntityId(entity.getId()) + .setPropType(prop.getId()) + .setPropDelta(value) + .setReason(reason) + .build(); + + this.setData(proto); + } + + public PacketEntityFightPropChangeReasonNotify( + GameEntity entity, FightProperty prop, Float value, ChangeEnergyReason reason) { + super(PacketOpcodes.EntityFightPropChangeReasonNotify); + + EntityFightPropChangeReasonNotify proto = + EntityFightPropChangeReasonNotify.newBuilder() + .setEntityId(entity.getId()) + .setPropType(prop.getId()) + .setPropDelta(value) + .setChangeEnergyReason(reason) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarLockChairRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarLockChairRsp.java index 140c6a9b3..43050dbd5 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarLockChairRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarLockChairRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarLockChairReqOuterClass.EvtAvatarLockChairReq; -import emu.grasscutter.net.proto.EvtAvatarLockChairRspOuterClass.EvtAvatarLockChairRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketEvtAvatarLockChairRsp extends BasePacket { - public PacketEvtAvatarLockChairRsp( - int clientSequence, EntityAvatar entityAvatar, EvtAvatarLockChairReq lockChairReq) { - super(PacketOpcodes.EvtAvatarLockChairRsp); - - EvtAvatarLockChairRsp p = - EvtAvatarLockChairRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) - .setEntityId(entityAvatar.getId()) - .setPosition(lockChairReq.getPosition()) - .setChairId(lockChairReq.getChairId()) - .build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarLockChairReqOuterClass.EvtAvatarLockChairReq; +import emu.grasscutter.net.proto.EvtAvatarLockChairRspOuterClass.EvtAvatarLockChairRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketEvtAvatarLockChairRsp extends BasePacket { + public PacketEvtAvatarLockChairRsp( + int clientSequence, EntityAvatar entityAvatar, EvtAvatarLockChairReq lockChairReq) { + super(PacketOpcodes.EvtAvatarLockChairRsp); + + EvtAvatarLockChairRsp p = + EvtAvatarLockChairRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SUCC_VALUE) + .setEntityId(entityAvatar.getId()) + .setPosition(lockChairReq.getPosition()) + .setChairId(lockChairReq.getChairId()) + .build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java index 70c4ef387..a0e3de447 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; - -public class PacketEvtAvatarSitDownNotify extends BasePacket { - - public PacketEvtAvatarSitDownNotify(EvtAvatarSitDownNotify notify) { - super(PacketOpcodes.EvtAvatarSitDownNotify); - - EvtAvatarSitDownNotify proto = - EvtAvatarSitDownNotify.newBuilder() - .setEntityId(notify.getEntityId()) - .setPosition(notify.getPosition()) - .setChairId(notify.getChairId()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; + +public class PacketEvtAvatarSitDownNotify extends BasePacket { + + public PacketEvtAvatarSitDownNotify(EvtAvatarSitDownNotify notify) { + super(PacketOpcodes.EvtAvatarSitDownNotify); + + EvtAvatarSitDownNotify proto = + EvtAvatarSitDownNotify.newBuilder() + .setEntityId(notify.getEntityId()) + .setPosition(notify.getPosition()) + .setChairId(notify.getChairId()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarStandUpNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarStandUpNotify.java index d20a68d32..a13a626ad 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarStandUpNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarStandUpNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtAvatarStandUpNotifyOuterClass.EvtAvatarStandUpNotify; - -public class PacketEvtAvatarStandUpNotify extends BasePacket { - - public PacketEvtAvatarStandUpNotify(EvtAvatarStandUpNotify notify) { - super(PacketOpcodes.EvtAvatarStandUpNotify); - - EvtAvatarStandUpNotify proto = - EvtAvatarStandUpNotify.newBuilder() - .setEntityId(notify.getEntityId()) - .setDirection(notify.getDirection()) - .setPerformId(notify.getPerformId()) - .setChairId(notify.getChairId()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarStandUpNotifyOuterClass.EvtAvatarStandUpNotify; + +public class PacketEvtAvatarStandUpNotify extends BasePacket { + + public PacketEvtAvatarStandUpNotify(EvtAvatarStandUpNotify notify) { + super(PacketOpcodes.EvtAvatarStandUpNotify); + + EvtAvatarStandUpNotify proto = + EvtAvatarStandUpNotify.newBuilder() + .setEntityId(notify.getEntityId()) + .setDirection(notify.getDirection()) + .setPerformId(notify.getPerformId()) + .setChairId(notify.getChairId()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtEntityRenderersChangedNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtEntityRenderersChangedNotify.java index b1075f8da..246d7da96 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtEntityRenderersChangedNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtEntityRenderersChangedNotify.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EvtEntityRenderersChangedNotifyOuterClass; - -public class PacketEvtEntityRenderersChangedNotify extends BasePacket { - - public PacketEvtEntityRenderersChangedNotify( - EvtEntityRenderersChangedNotifyOuterClass.EvtEntityRenderersChangedNotify req) { - super(PacketOpcodes.EvtEntityRenderersChangedNotify, true); - - this.setData(req); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtEntityRenderersChangedNotifyOuterClass; + +public class PacketEvtEntityRenderersChangedNotify extends BasePacket { + + public PacketEvtEntityRenderersChangedNotify( + EvtEntityRenderersChangedNotifyOuterClass.EvtEntityRenderersChangedNotify req) { + super(PacketOpcodes.EvtEntityRenderersChangedNotify, true); + + this.setData(req); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java index 23ca2c130..f3df6e68b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify; -import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; -import java.util.Map; - -public class PacketForgeDataNotify extends BasePacket { - - public PacketForgeDataNotify( - Iterable unlockedItem, int numQueues, Map queueData) { - super(PacketOpcodes.ForgeDataNotify); - - ForgeDataNotify.Builder builder = - ForgeDataNotify.newBuilder().addAllForgeIdList(unlockedItem).setMaxQueueNum(numQueues); - - for (int queueId : queueData.keySet()) { - var data = queueData.get(queueId); - builder.putForgeQueueMap(queueId, data); - } - - this.setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; +import java.util.Map; + +public class PacketForgeDataNotify extends BasePacket { + + public PacketForgeDataNotify( + Iterable unlockedItem, int numQueues, Map queueData) { + super(PacketOpcodes.ForgeDataNotify); + + ForgeDataNotify.Builder builder = + ForgeDataNotify.newBuilder().addAllForgeIdList(unlockedItem).setMaxQueueNum(numQueues); + + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } + + this.setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeFormulaDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeFormulaDataNotify.java index cad180b70..c4f861e9c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeFormulaDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeFormulaDataNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeFormulaDataNotifyOuterClass.ForgeFormulaDataNotify; - -public class PacketForgeFormulaDataNotify extends BasePacket { - - public PacketForgeFormulaDataNotify(int itemId) { - super(PacketOpcodes.ForgeFormulaDataNotify); - - ForgeFormulaDataNotify proto = - ForgeFormulaDataNotify.newBuilder().setForgeId(itemId).setIsLocked(false).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeFormulaDataNotifyOuterClass.ForgeFormulaDataNotify; + +public class PacketForgeFormulaDataNotify extends BasePacket { + + public PacketForgeFormulaDataNotify(int itemId) { + super(PacketOpcodes.ForgeFormulaDataNotify); + + ForgeFormulaDataNotify proto = + ForgeFormulaDataNotify.newBuilder().setForgeId(itemId).setIsLocked(false).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java index f03f15987..50f4b94ef 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeGetQueueDataRspOuterClass.ForgeGetQueueDataRsp; -import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.Map; - -public class PacketForgeGetQueueDataRsp extends BasePacket { - - public PacketForgeGetQueueDataRsp( - Retcode retcode, int numQueues, Map queueData) { - super(PacketOpcodes.ForgeGetQueueDataRsp); - - ForgeGetQueueDataRsp.Builder builder = - ForgeGetQueueDataRsp.newBuilder().setRetcode(retcode.getNumber()).setMaxQueueNum(numQueues); - - for (int queueId : queueData.keySet()) { - var data = queueData.get(queueId); - builder.putForgeQueueMap(queueId, data); - } - - this.setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeGetQueueDataRspOuterClass.ForgeGetQueueDataRsp; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.Map; + +public class PacketForgeGetQueueDataRsp extends BasePacket { + + public PacketForgeGetQueueDataRsp( + Retcode retcode, int numQueues, Map queueData) { + super(PacketOpcodes.ForgeGetQueueDataRsp); + + ForgeGetQueueDataRsp.Builder builder = + ForgeGetQueueDataRsp.newBuilder().setRetcode(retcode.getNumber()).setMaxQueueNum(numQueues); + + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } + + this.setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java index 6f5fb8ba6..4cd9473a8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeQueueDataNotifyOuterClass.ForgeQueueDataNotify; -import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; -import java.util.List; -import java.util.Map; - -public class PacketForgeQueueDataNotify extends BasePacket { - - public PacketForgeQueueDataNotify( - Map queueData, List removedQueues) { - super(PacketOpcodes.ForgeQueueDataNotify); - - ForgeQueueDataNotify.Builder builder = - ForgeQueueDataNotify.newBuilder().addAllRemovedForgeQueueList(removedQueues); - - for (int queueId : queueData.keySet()) { - var data = queueData.get(queueId); - builder.putForgeQueueMap(queueId, data); - } - - this.setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeQueueDataNotifyOuterClass.ForgeQueueDataNotify; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; +import java.util.List; +import java.util.Map; + +public class PacketForgeQueueDataNotify extends BasePacket { + + public PacketForgeQueueDataNotify( + Map queueData, List removedQueues) { + super(PacketOpcodes.ForgeQueueDataNotify); + + ForgeQueueDataNotify.Builder builder = + ForgeQueueDataNotify.newBuilder().addAllRemovedForgeQueueList(removedQueues); + + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } + + this.setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java index 20e00143d..297fb8b14 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueManipulateRsp.java @@ -1,45 +1,45 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeQueueManipulateRspOuterClass.ForgeQueueManipulateRsp; -import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; - -public class PacketForgeQueueManipulateRsp extends BasePacket { - - public PacketForgeQueueManipulateRsp( - Retcode retcode, - ForgeQueueManipulateType type, - List output, - List refund, - List extra) { - super(PacketOpcodes.ForgeQueueManipulateRsp); - - ForgeQueueManipulateRsp.Builder builder = - ForgeQueueManipulateRsp.newBuilder() - .setRetcode(retcode.getNumber()) - .setManipulateType(type); - - for (GameItem item : output) { - ItemParam toAdd = - ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount()).build(); - - builder.addExtraOutputItemList(toAdd); - } - - for (GameItem item : refund) { - ItemParam toAdd = - ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount()).build(); - - builder.addReturnItemList(toAdd); - } - - // ToDo: Add extra items when once we have handling for it. - - this.setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeQueueManipulateRspOuterClass.ForgeQueueManipulateRsp; +import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; + +public class PacketForgeQueueManipulateRsp extends BasePacket { + + public PacketForgeQueueManipulateRsp( + Retcode retcode, + ForgeQueueManipulateType type, + List output, + List refund, + List extra) { + super(PacketOpcodes.ForgeQueueManipulateRsp); + + ForgeQueueManipulateRsp.Builder builder = + ForgeQueueManipulateRsp.newBuilder() + .setRetcode(retcode.getNumber()) + .setManipulateType(type); + + for (GameItem item : output) { + ItemParam toAdd = + ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount()).build(); + + builder.addExtraOutputItemList(toAdd); + } + + for (GameItem item : refund) { + ItemParam toAdd = + ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount()).build(); + + builder.addReturnItemList(toAdd); + } + + // ToDo: Add extra items when once we have handling for it. + + this.setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java index 628c1983e..dc2adc3a8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ForgeStartRspOuterClass.ForgeStartRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; - -public class PacketForgeStartRsp extends BasePacket { - - public PacketForgeStartRsp(Retcode retcode) { - super(PacketOpcodes.ForgeStartRsp); - - ForgeStartRsp proto = ForgeStartRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeStartRspOuterClass.ForgeStartRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketForgeStartRsp extends BasePacket { + + public PacketForgeStartRsp(Retcode retcode) { + super(PacketOpcodes.ForgeStartRsp); + + ForgeStartRsp proto = ForgeStartRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureCurModuleArrangeCountNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureCurModuleArrangeCountNotify.java index dbc118979..b3f31a55e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureCurModuleArrangeCountNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureCurModuleArrangeCountNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FurnitureCurModuleArrangeCountNotifyOuterClass; - -public class PacketFurnitureCurModuleArrangeCountNotify extends BasePacket { - - public PacketFurnitureCurModuleArrangeCountNotify() { - super(PacketOpcodes.FurnitureCurModuleArrangeCountNotify); - - var proto = - FurnitureCurModuleArrangeCountNotifyOuterClass.FurnitureCurModuleArrangeCountNotify - .newBuilder(); - - // TODO - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FurnitureCurModuleArrangeCountNotifyOuterClass; + +public class PacketFurnitureCurModuleArrangeCountNotify extends BasePacket { + + public PacketFurnitureCurModuleArrangeCountNotify() { + super(PacketOpcodes.FurnitureCurModuleArrangeCountNotify); + + var proto = + FurnitureCurModuleArrangeCountNotifyOuterClass.FurnitureCurModuleArrangeCountNotify + .newBuilder(); + + // TODO + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeRsp.java index e897084f6..7ee6964c7 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.home.FurnitureMakeSlotItem; -import emu.grasscutter.game.home.GameHome; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FurnitureMakeRspOuterClass; -import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; - -public class PacketFurnitureMakeRsp extends BasePacket { - - public PacketFurnitureMakeRsp(GameHome home) { - super(PacketOpcodes.FurnitureMakeRsp); - - var proto = FurnitureMakeRspOuterClass.FurnitureMakeRsp.newBuilder(); - - proto.setFurnitureMakeSlot( - FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() - .addAllFurnitureMakeDataList( - home.getFurnitureMakeSlotItemList().stream() - .map(FurnitureMakeSlotItem::toProto) - .toList()) - .build()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.home.FurnitureMakeSlotItem; +import emu.grasscutter.game.home.GameHome; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FurnitureMakeRspOuterClass; +import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; + +public class PacketFurnitureMakeRsp extends BasePacket { + + public PacketFurnitureMakeRsp(GameHome home) { + super(PacketOpcodes.FurnitureMakeRsp); + + var proto = FurnitureMakeRspOuterClass.FurnitureMakeRsp.newBuilder(); + + proto.setFurnitureMakeSlot( + FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() + .addAllFurnitureMakeDataList( + home.getFurnitureMakeSlotItemList().stream() + .map(FurnitureMakeSlotItem::toProto) + .toList()) + .build()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeStartRsp.java index 94745435a..d50a67a6d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeStartRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketFurnitureMakeStartRsp.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FurnitureMakeDataOuterClass; -import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; -import emu.grasscutter.net.proto.FurnitureMakeStartRspOuterClass; -import java.util.List; - -public class PacketFurnitureMakeStartRsp extends BasePacket { - - public PacketFurnitureMakeStartRsp( - int ret, List furnitureMakeData) { - super(PacketOpcodes.FurnitureMakeStartRsp); - - var proto = FurnitureMakeStartRspOuterClass.FurnitureMakeStartRsp.newBuilder(); - - proto.setRetcode(ret); - - if (furnitureMakeData != null) { - proto.setFurnitureMakeSlot( - FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() - .addAllFurnitureMakeDataList(furnitureMakeData) - .build()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FurnitureMakeDataOuterClass; +import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; +import emu.grasscutter.net.proto.FurnitureMakeStartRspOuterClass; +import java.util.List; + +public class PacketFurnitureMakeStartRsp extends BasePacket { + + public PacketFurnitureMakeStartRsp( + int ret, List furnitureMakeData) { + super(PacketOpcodes.FurnitureMakeStartRsp); + + var proto = FurnitureMakeStartRspOuterClass.FurnitureMakeStartRsp.newBuilder(); + + proto.setRetcode(ret); + + if (furnitureMakeData != null) { + proto.setFurnitureMakeSlot( + FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() + .addAllFurnitureMakeDataList(furnitureMakeData) + .build()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGachaWishRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGachaWishRsp.java index f87ce5bbb..fac0dbbaa 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGachaWishRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGachaWishRsp.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GachaWishRspOuterClass.GachaWishRsp; - -public class PacketGachaWishRsp extends BasePacket { - - public PacketGachaWishRsp( - int gachaType, int scheduleId, int itemId, int progress, int maxProgress) { - super(PacketOpcodes.GachaWishRsp); - - GachaWishRsp proto = - GachaWishRsp.newBuilder() - .setGachaType(gachaType) - .setGachaScheduleId(scheduleId) - .setWishItemId(itemId) - .setWishProgress(progress) - .setWishMaxProgress(maxProgress) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GachaWishRspOuterClass.GachaWishRsp; + +public class PacketGachaWishRsp extends BasePacket { + + public PacketGachaWishRsp( + int gachaType, int scheduleId, int itemId, int progress, int maxProgress) { + super(PacketOpcodes.GachaWishRsp); + + GachaWishRsp proto = + GachaWishRsp.newBuilder() + .setGachaType(gachaType) + .setGachaScheduleId(scheduleId) + .setWishItemId(itemId) + .setWishProgress(progress) + .setWishMaxProgress(maxProgress) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetAutoPickDropInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetAutoPickDropInfoNotify.java index 94765a553..936454e27 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetAutoPickDropInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetAutoPickDropInfoNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GadgetAutoPickDropInfoNotifyOuterClass.GadgetAutoPickDropInfoNotify; -import java.util.Collection; - -public class PacketGadgetAutoPickDropInfoNotify extends BasePacket { - - public PacketGadgetAutoPickDropInfoNotify(Collection items) { - super(PacketOpcodes.GadgetAutoPickDropInfoNotify); - - GadgetAutoPickDropInfoNotify.Builder proto = GadgetAutoPickDropInfoNotify.newBuilder(); - - items.forEach(item -> proto.addItemList(item.toProto())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GadgetAutoPickDropInfoNotifyOuterClass.GadgetAutoPickDropInfoNotify; +import java.util.Collection; + +public class PacketGadgetAutoPickDropInfoNotify extends BasePacket { + + public PacketGadgetAutoPickDropInfoNotify(Collection items) { + super(PacketOpcodes.GadgetAutoPickDropInfoNotify); + + GadgetAutoPickDropInfoNotify.Builder proto = GadgetAutoPickDropInfoNotify.newBuilder(); + + items.forEach(item -> proto.addItemList(item.toProto())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetInteractRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetInteractRsp.java index 71a80ad3e..e964693a8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetInteractRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetInteractRsp.java @@ -1,43 +1,43 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityBaseGadget; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GadgetInteractRspOuterClass.GadgetInteractRsp; -import emu.grasscutter.net.proto.InterOpTypeOuterClass.InterOpType; -import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketGadgetInteractRsp extends BasePacket { - public PacketGadgetInteractRsp(EntityBaseGadget gadget, InteractType interact) { - this(gadget, interact, null); - } - - public PacketGadgetInteractRsp( - EntityBaseGadget gadget, InteractType interact, InterOpType opType) { - super(PacketOpcodes.GadgetInteractRsp); - - var proto = - GadgetInteractRsp.newBuilder() - .setGadgetEntityId(gadget.getId()) - .setInteractType(interact) - .setGadgetId(gadget.getGadgetId()); - - if (opType != null) { - proto.setOpType(opType); - } - - this.setData(proto.build()); - } - - public PacketGadgetInteractRsp() { - super(PacketOpcodes.GadgetInteractRsp); - - GadgetInteractRsp proto = - GadgetInteractRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityBaseGadget; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GadgetInteractRspOuterClass.GadgetInteractRsp; +import emu.grasscutter.net.proto.InterOpTypeOuterClass.InterOpType; +import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketGadgetInteractRsp extends BasePacket { + public PacketGadgetInteractRsp(EntityBaseGadget gadget, InteractType interact) { + this(gadget, interact, null); + } + + public PacketGadgetInteractRsp( + EntityBaseGadget gadget, InteractType interact, InterOpType opType) { + super(PacketOpcodes.GadgetInteractRsp); + + var proto = + GadgetInteractRsp.newBuilder() + .setGadgetEntityId(gadget.getId()) + .setInteractType(interact) + .setGadgetId(gadget.getGadgetId()); + + if (opType != null) { + proto.setOpType(opType); + } + + this.setData(proto.build()); + } + + public PacketGadgetInteractRsp() { + super(PacketOpcodes.GadgetInteractRsp); + + GadgetInteractRsp proto = + GadgetInteractRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetStateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetStateNotify.java index 9847027dd..1b46c224f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetStateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGadgetStateNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GadgetStateNotifyOuterClass.GadgetStateNotify; - -public class PacketGadgetStateNotify extends BasePacket { - - public PacketGadgetStateNotify(EntityGadget gadget, int newState) { - super(PacketOpcodes.GadgetStateNotify); - - GadgetStateNotify proto = - GadgetStateNotify.newBuilder() - .setGadgetEntityId(gadget.getId()) - .setGadgetState(newState) - .setIsEnableInteract(true) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GadgetStateNotifyOuterClass.GadgetStateNotify; + +public class PacketGadgetStateNotify extends BasePacket { + + public PacketGadgetStateNotify(EntityGadget gadget, int newState) { + super(PacketOpcodes.GadgetStateNotify); + + GadgetStateNotify proto = + GadgetStateNotify.newBuilder() + .setGadgetEntityId(gadget.getId()) + .setGadgetState(newState) + .setIsEnableInteract(true) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityInfoRsp.java index 736bd9bfe..f23cc4a73 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityInfoRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.activity.ActivityManager; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetActivityInfoRspOuterClass.GetActivityInfoRsp; -import java.util.Set; - -public class PacketGetActivityInfoRsp extends BasePacket { - public PacketGetActivityInfoRsp(Set activityIdList, ActivityManager activityManager) { - super(PacketOpcodes.GetActivityInfoRsp); - - var proto = GetActivityInfoRsp.newBuilder(); - - activityIdList.stream() - .map(activityManager::getInfoProtoByActivityId) - .forEach(proto::addActivityInfoList); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.activity.ActivityManager; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetActivityInfoRspOuterClass.GetActivityInfoRsp; +import java.util.Set; + +public class PacketGetActivityInfoRsp extends BasePacket { + public PacketGetActivityInfoRsp(Set activityIdList, ActivityManager activityManager) { + super(PacketOpcodes.GetActivityInfoRsp); + + var proto = GetActivityInfoRsp.newBuilder(); + + activityIdList.stream() + .map(activityManager::getInfoProtoByActivityId) + .forEach(proto::addActivityInfoList); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityShopSheetInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityShopSheetInfoRsp.java index fc726079c..c8afa93b4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityShopSheetInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetActivityShopSheetInfoRsp.java @@ -1,52 +1,52 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.activity.ActivityConfigItem; -import emu.grasscutter.game.activity.ActivityManager; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ActivityShopSheetInfoOuterClass.ActivityShopSheetInfo; -import emu.grasscutter.net.proto.GetActivityShopSheetInfoRspOuterClass.GetActivityShopSheetInfoRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import java.util.ArrayList; -import java.util.List; - -public class PacketGetActivityShopSheetInfoRsp extends BasePacket { - - public PacketGetActivityShopSheetInfoRsp(int shopType) { - super(PacketOpcodes.GetActivityShopSheetInfoRsp); - - var sheetInfo = GameData.getActivityShopDataMap().get(shopType); - ActivityConfigItem activityConfigItem = null; - - if (sheetInfo != null) { - activityConfigItem = - ActivityManager.getScheduleActivityConfigMap().get(sheetInfo.getScheduleId()); - } - - if (sheetInfo == null || activityConfigItem == null) { - setData( - GetActivityShopSheetInfoRsp.newBuilder() - .setShopType(shopType) - .setRetcode(RetcodeOuterClass.Retcode.RET_SHOP_NOT_OPEN_VALUE) - .build()); - return; - } - - List sheetInfos = new ArrayList<>(sheetInfo.getSheetList().size()); - for (int id : sheetInfo.getSheetList()) { - sheetInfos.add( - ActivityShopSheetInfo.newBuilder() - .setSheetId(id) - .setBeginTime((int) activityConfigItem.getBeginTime().getTime()) - .setEndTime((int) activityConfigItem.getEndTime().getTime()) - .build()); - } - - setData( - GetActivityShopSheetInfoRsp.newBuilder() - .setShopType(shopType) - .addAllSheetInfoList(sheetInfos) - .build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.activity.ActivityConfigItem; +import emu.grasscutter.game.activity.ActivityManager; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ActivityShopSheetInfoOuterClass.ActivityShopSheetInfo; +import emu.grasscutter.net.proto.GetActivityShopSheetInfoRspOuterClass.GetActivityShopSheetInfoRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import java.util.ArrayList; +import java.util.List; + +public class PacketGetActivityShopSheetInfoRsp extends BasePacket { + + public PacketGetActivityShopSheetInfoRsp(int shopType) { + super(PacketOpcodes.GetActivityShopSheetInfoRsp); + + var sheetInfo = GameData.getActivityShopDataMap().get(shopType); + ActivityConfigItem activityConfigItem = null; + + if (sheetInfo != null) { + activityConfigItem = + ActivityManager.getScheduleActivityConfigMap().get(sheetInfo.getScheduleId()); + } + + if (sheetInfo == null || activityConfigItem == null) { + setData( + GetActivityShopSheetInfoRsp.newBuilder() + .setShopType(shopType) + .setRetcode(RetcodeOuterClass.Retcode.RET_SHOP_NOT_OPEN_VALUE) + .build()); + return; + } + + List sheetInfos = new ArrayList<>(sheetInfo.getSheetList().size()); + for (int id : sheetInfo.getSheetList()) { + sheetInfos.add( + ActivityShopSheetInfo.newBuilder() + .setSheetId(id) + .setBeginTime((int) activityConfigItem.getBeginTime().getTime()) + .setEndTime((int) activityConfigItem.getEndTime().getTime()) + .build()); + } + + setData( + GetActivityShopSheetInfoRsp.newBuilder() + .setShopType(shopType) + .addAllSheetInfoList(sheetInfos) + .build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllUnlockNameCardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllUnlockNameCardRsp.java index 9cc78c98b..a4c7f709c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllUnlockNameCardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAllUnlockNameCardRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetAllUnlockNameCardRspOuterClass.GetAllUnlockNameCardRsp; - -public class PacketGetAllUnlockNameCardRsp extends BasePacket { - - public PacketGetAllUnlockNameCardRsp(Player player) { - super(PacketOpcodes.GetAllUnlockNameCardRsp); - - GetAllUnlockNameCardRsp proto = - GetAllUnlockNameCardRsp.newBuilder().addAllNameCardList(player.getNameCardList()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetAllUnlockNameCardRspOuterClass.GetAllUnlockNameCardRsp; + +public class PacketGetAllUnlockNameCardRsp extends BasePacket { + + public PacketGetAllUnlockNameCardRsp(Player player) { + super(PacketOpcodes.GetAllUnlockNameCardRsp); + + GetAllUnlockNameCardRsp proto = + GetAllUnlockNameCardRsp.newBuilder().addAllNameCardList(player.getNameCardList()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAuthkeyRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAuthkeyRsp.java index aca745fb0..e6f0c3432 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetAuthkeyRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetAuthkeyRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetAuthkeyRspOuterClass.GetAuthkeyRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; - -public class PacketGetAuthkeyRsp extends BasePacket { - - public PacketGetAuthkeyRsp() { - super(PacketOpcodes.GetAuthkeyRsp); - - GetAuthkeyRsp proto = - GetAuthkeyRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetAuthkeyRspOuterClass.GetAuthkeyRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; + +public class PacketGetAuthkeyRsp extends BasePacket { + + public PacketGetAuthkeyRsp() { + super(PacketOpcodes.GetAuthkeyRsp); + + GetAuthkeyRsp proto = + GetAuthkeyRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetChatEmojiCollectionRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetChatEmojiCollectionRsp.java index 195c5f88e..70cae4e6c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetChatEmojiCollectionRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetChatEmojiCollectionRsp.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChatEmojiCollectionDataOuterClass; -import emu.grasscutter.net.proto.GetChatEmojiCollectionRspOuterClass; -import java.util.List; - -public class PacketGetChatEmojiCollectionRsp extends BasePacket { - public PacketGetChatEmojiCollectionRsp(List emojiIds) { - super(PacketOpcodes.GetChatEmojiCollectionRsp); - - var rsp = - GetChatEmojiCollectionRspOuterClass.GetChatEmojiCollectionRsp.newBuilder() - .setChatEmojiCollectionData( - ChatEmojiCollectionDataOuterClass.ChatEmojiCollectionData.newBuilder() - .addAllEmojiIdList(emojiIds) - .build()); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChatEmojiCollectionDataOuterClass; +import emu.grasscutter.net.proto.GetChatEmojiCollectionRspOuterClass; +import java.util.List; + +public class PacketGetChatEmojiCollectionRsp extends BasePacket { + public PacketGetChatEmojiCollectionRsp(List emojiIds) { + super(PacketOpcodes.GetChatEmojiCollectionRsp); + + var rsp = + GetChatEmojiCollectionRspOuterClass.GetChatEmojiCollectionRsp.newBuilder() + .setChatEmojiCollectionData( + ChatEmojiCollectionDataOuterClass.ChatEmojiCollectionData.newBuilder() + .addAllEmojiIdList(emojiIds) + .build()); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetCompoundDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetCompoundDataRsp.java index cfdc15afd..b89273432 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetCompoundDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetCompoundDataRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; -import emu.grasscutter.net.proto.GetCompoundDataRspOuterClass.GetCompoundDataRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; -import java.util.Set; - -public class PacketGetCompoundDataRsp extends BasePacket { - public PacketGetCompoundDataRsp( - Set unlockedCompounds, List compoundQueueData) { - super(PacketOpcodes.GetCompoundDataRsp); - var proto = - GetCompoundDataRsp.newBuilder() - .addAllUnlockCompoundList(unlockedCompounds) - .addAllCompoundQueueDataList(compoundQueueData) - .setRetcode(Retcode.RET_SUCC_VALUE) - .build(); - setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; +import emu.grasscutter.net.proto.GetCompoundDataRspOuterClass.GetCompoundDataRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; +import java.util.Set; + +public class PacketGetCompoundDataRsp extends BasePacket { + public PacketGetCompoundDataRsp( + Set unlockedCompounds, List compoundQueueData) { + super(PacketOpcodes.GetCompoundDataRsp); + var proto = + GetCompoundDataRsp.newBuilder() + .addAllUnlockCompoundList(unlockedCompounds) + .addAllCompoundQueueDataList(compoundQueueData) + .setRetcode(Retcode.RET_SUCC_VALUE) + .build(); + setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowAvatarInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowAvatarInfoRsp.java index 8c13a87ca..6f7eb62b4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowAvatarInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowAvatarInfoRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetFriendShowAvatarInfoRspOuterClass.GetFriendShowAvatarInfoRsp; -import emu.grasscutter.net.proto.ShowAvatarInfoOuterClass.ShowAvatarInfo; -import java.util.List; - -@Opcodes(PacketOpcodes.GetFriendShowAvatarInfoRsp) -public class PacketGetFriendShowAvatarInfoRsp extends BasePacket { - - public PacketGetFriendShowAvatarInfoRsp(int uid, List showAvatarInfoList) { - super(PacketOpcodes.GetFriendShowAvatarInfoRsp); - - GetFriendShowAvatarInfoRsp.Builder p = - GetFriendShowAvatarInfoRsp.newBuilder() - .setUid(uid) - .addAllShowAvatarInfoList(showAvatarInfoList); - - this.setData(p.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetFriendShowAvatarInfoRspOuterClass.GetFriendShowAvatarInfoRsp; +import emu.grasscutter.net.proto.ShowAvatarInfoOuterClass.ShowAvatarInfo; +import java.util.List; + +@Opcodes(PacketOpcodes.GetFriendShowAvatarInfoRsp) +public class PacketGetFriendShowAvatarInfoRsp extends BasePacket { + + public PacketGetFriendShowAvatarInfoRsp(int uid, List showAvatarInfoList) { + super(PacketOpcodes.GetFriendShowAvatarInfoRsp); + + GetFriendShowAvatarInfoRsp.Builder p = + GetFriendShowAvatarInfoRsp.newBuilder() + .setUid(uid) + .addAllShowAvatarInfoList(showAvatarInfoList); + + this.setData(p.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowNameCardInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowNameCardInfoRsp.java index 7eba3da37..5c8a4bee2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowNameCardInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetFriendShowNameCardInfoRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetFriendShowNameCardInfoRspOuterClass; -import java.util.List; - -public class PacketGetFriendShowNameCardInfoRsp extends BasePacket { - public PacketGetFriendShowNameCardInfoRsp(int uid, List cardIds) { - super(PacketOpcodes.GetFriendShowNameCardInfoRsp); - - var rsp = - GetFriendShowNameCardInfoRspOuterClass.GetFriendShowNameCardInfoRsp.newBuilder() - .setUid(uid) - .addAllShowNameCardIdList(cardIds) - .setRetcode(0) - .build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetFriendShowNameCardInfoRspOuterClass; +import java.util.List; + +public class PacketGetFriendShowNameCardInfoRsp extends BasePacket { + public PacketGetFriendShowNameCardInfoRsp(int uid, List cardIds) { + super(PacketOpcodes.GetFriendShowNameCardInfoRsp); + + var rsp = + GetFriendShowNameCardInfoRspOuterClass.GetFriendShowNameCardInfoRsp.newBuilder() + .setUid(uid) + .addAllShowNameCardIdList(cardIds) + .setRetcode(0) + .build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetGachaInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetGachaInfoRsp.java index e3d1ac27c..2e7addb00 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetGachaInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetGachaInfoRsp.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.gacha.GachaSystem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketGetGachaInfoRsp extends BasePacket { - - public PacketGetGachaInfoRsp(GachaSystem manager, Player player) { - super(PacketOpcodes.GetGachaInfoRsp); - - this.setData(manager.toProto(player)); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.gacha.GachaSystem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketGetGachaInfoRsp extends BasePacket { + + public PacketGetGachaInfoRsp(GachaSystem manager, Player player) { + super(PacketOpcodes.GetGachaInfoRsp); + + this.setData(manager.toProto(player)); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetHomeLevelUpRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetHomeLevelUpRewardRsp.java index 53492a2d4..12964f603 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetHomeLevelUpRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetHomeLevelUpRewardRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetHomeLevelUpRewardRspOuterClass.GetHomeLevelUpRewardRsp; - -public class PacketGetHomeLevelUpRewardRsp extends BasePacket { - - public PacketGetHomeLevelUpRewardRsp(int level, int rewardId) { - super(PacketOpcodes.GetHomeLevelUpRewardRsp); - - int retcode = 0; - - if (rewardId == 0) { - retcode = 1; - } - - GetHomeLevelUpRewardRsp proto = - GetHomeLevelUpRewardRsp.newBuilder().setLevel(level).setRetcode(retcode).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetHomeLevelUpRewardRspOuterClass.GetHomeLevelUpRewardRsp; + +public class PacketGetHomeLevelUpRewardRsp extends BasePacket { + + public PacketGetHomeLevelUpRewardRsp(int level, int rewardId) { + super(PacketOpcodes.GetHomeLevelUpRewardRsp); + + int retcode = 0; + + if (rewardId == 0) { + retcode = 1; + } + + GetHomeLevelUpRewardRsp proto = + GetHomeLevelUpRewardRsp.newBuilder().setLevel(level).setRetcode(retcode).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetInvestigationMonsterRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetInvestigationMonsterRsp.java index 8dcf6d585..81ac3da57 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetInvestigationMonsterRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetInvestigationMonsterRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.WorldDataSystem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetInvestigationMonsterRspOuterClass; -import java.util.List; - -public class PacketGetInvestigationMonsterRsp extends BasePacket { - - public PacketGetInvestigationMonsterRsp( - Player player, WorldDataSystem worldDataManager, List cityIdListList) { - - super(PacketOpcodes.GetInvestigationMonsterRsp); - - var resp = GetInvestigationMonsterRspOuterClass.GetInvestigationMonsterRsp.newBuilder(); - - cityIdListList.forEach( - id -> - resp.addAllMonsterList(worldDataManager.getInvestigationMonstersByCityId(player, id))); - - this.setData(resp.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.WorldDataSystem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetInvestigationMonsterRspOuterClass; +import java.util.List; + +public class PacketGetInvestigationMonsterRsp extends BasePacket { + + public PacketGetInvestigationMonsterRsp( + Player player, WorldDataSystem worldDataManager, List cityIdListList) { + + super(PacketOpcodes.GetInvestigationMonsterRsp); + + var resp = GetInvestigationMonsterRspOuterClass.GetInvestigationMonsterRsp.newBuilder(); + + cityIdListList.forEach( + id -> + resp.addAllMonsterList(worldDataManager.getInvestigationMonstersByCityId(player, id))); + + this.setData(resp.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java index 2c2788af6..63a365c57 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java @@ -1,73 +1,73 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.mail.Mail; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EquipParamOuterClass; -import emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class PacketGetMailItemRsp extends BasePacket { - - public PacketGetMailItemRsp(Player player, List mailList) { - super(PacketOpcodes.GetMailItemRsp); - List claimedMessages = new ArrayList<>(); - List claimedItems = new ArrayList<>(); - - GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder(); - - synchronized (player) { - boolean modified = false; - for (int mailId : mailList) { - Mail message = player.getMail(mailId); - if (!message.isAttachmentGot) { // No duplicated item - for (Mail.MailItem mailItem : message.itemList) { - EquipParamOuterClass.EquipParam.Builder item = - EquipParamOuterClass.EquipParam.newBuilder(); - int promoteLevel = GameItem.getMinPromoteLevel(mailItem.itemLevel); - - item.setItemId(mailItem.itemId); - item.setItemNum(mailItem.itemCount); - item.setItemLevel(mailItem.itemLevel); - item.setPromoteLevel(promoteLevel); - claimedItems.add(item.build()); - - GameItem gameItem = new GameItem(GameData.getItemDataMap().get(mailItem.itemId)); - gameItem.setCount(mailItem.itemCount); - gameItem.setLevel(mailItem.itemLevel); - gameItem.setPromoteLevel(promoteLevel); - player.getInventory().addItem(gameItem, ActionReason.MailAttachment); - } - - message.isAttachmentGot = true; - claimedMessages.add(message); - - player.replaceMailByIndex(mailId, message); - modified = true; - } - } - if (modified) { - player.save(); - } - } - - proto.addAllMailIdList( - claimedMessages.stream().map(player::getMailId).collect(Collectors.toList())); - proto.addAllItemList(claimedItems); - - this.setData(proto.build()); - player - .getSession() - .send( - new PacketMailChangeNotify( - player, - claimedMessages)); // For some reason you have to also send the MailChangeNotify - // packet - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EquipParamOuterClass; +import emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PacketGetMailItemRsp extends BasePacket { + + public PacketGetMailItemRsp(Player player, List mailList) { + super(PacketOpcodes.GetMailItemRsp); + List claimedMessages = new ArrayList<>(); + List claimedItems = new ArrayList<>(); + + GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder(); + + synchronized (player) { + boolean modified = false; + for (int mailId : mailList) { + Mail message = player.getMail(mailId); + if (!message.isAttachmentGot) { // No duplicated item + for (Mail.MailItem mailItem : message.itemList) { + EquipParamOuterClass.EquipParam.Builder item = + EquipParamOuterClass.EquipParam.newBuilder(); + int promoteLevel = GameItem.getMinPromoteLevel(mailItem.itemLevel); + + item.setItemId(mailItem.itemId); + item.setItemNum(mailItem.itemCount); + item.setItemLevel(mailItem.itemLevel); + item.setPromoteLevel(promoteLevel); + claimedItems.add(item.build()); + + GameItem gameItem = new GameItem(GameData.getItemDataMap().get(mailItem.itemId)); + gameItem.setCount(mailItem.itemCount); + gameItem.setLevel(mailItem.itemLevel); + gameItem.setPromoteLevel(promoteLevel); + player.getInventory().addItem(gameItem, ActionReason.MailAttachment); + } + + message.isAttachmentGot = true; + claimedMessages.add(message); + + player.replaceMailByIndex(mailId, message); + modified = true; + } + } + if (modified) { + player.save(); + } + } + + proto.addAllMailIdList( + claimedMessages.stream().map(player::getMailId).collect(Collectors.toList())); + proto.addAllItemList(claimedItems); + + this.setData(proto.build()); + player + .getSession() + .send( + new PacketMailChangeNotify( + player, + claimedMessages)); // For some reason you have to also send the MailChangeNotify + // packet + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java index 931ae364c..a81a632cc 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetOnlinePlayerListRspOuterClass.GetOnlinePlayerListRsp; -import java.util.List; - -public class PacketGetOnlinePlayerListRsp extends BasePacket { - public PacketGetOnlinePlayerListRsp(Player session) { - super(PacketOpcodes.GetOnlinePlayerListRsp); - - List players = - Grasscutter.getGameServer().getPlayers().values().stream().limit(50).toList(); - - GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder(); - - if (players.size() != 0) { - for (Player player : players) { - if (player.getUid() == session.getUid()) continue; - - proto.addPlayerInfoList(player.getOnlinePlayerInfo()); - } - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetOnlinePlayerListRspOuterClass.GetOnlinePlayerListRsp; +import java.util.List; + +public class PacketGetOnlinePlayerListRsp extends BasePacket { + public PacketGetOnlinePlayerListRsp(Player session) { + super(PacketOpcodes.GetOnlinePlayerListRsp); + + List players = + Grasscutter.getGameServer().getPlayers().values().stream().limit(50).toList(); + + GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder(); + + if (players.size() != 0) { + for (Player player : players) { + if (player.getUid() == session.getUid()) continue; + + proto.addPlayerInfoList(player.getOnlinePlayerInfo()); + } + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerAskFriendListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerAskFriendListRsp.java index a45195f6e..9f8573008 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerAskFriendListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerAskFriendListRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.friends.Friendship; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetPlayerAskFriendListRspOuterClass.GetPlayerAskFriendListRsp; - -public class PacketGetPlayerAskFriendListRsp extends BasePacket { - - public PacketGetPlayerAskFriendListRsp(Player player) { - super(PacketOpcodes.GetPlayerAskFriendListRsp); - - GetPlayerAskFriendListRsp.Builder proto = GetPlayerAskFriendListRsp.newBuilder(); - - for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) { - if (friendship.getAskerId() == player.getUid()) { - continue; - } - proto.addAskFriendList(friendship.toProto()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.friends.Friendship; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetPlayerAskFriendListRspOuterClass.GetPlayerAskFriendListRsp; + +public class PacketGetPlayerAskFriendListRsp extends BasePacket { + + public PacketGetPlayerAskFriendListRsp(Player player) { + super(PacketOpcodes.GetPlayerAskFriendListRsp); + + GetPlayerAskFriendListRsp.Builder proto = GetPlayerAskFriendListRsp.newBuilder(); + + for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) { + if (friendship.getAskerId() == player.getUid()) { + continue; + } + proto.addAskFriendList(friendship.toProto()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java index 6382378f2..9001ae0c3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java @@ -1,47 +1,47 @@ -package emu.grasscutter.server.packet.send; - -import static emu.grasscutter.config.Configuration.GAME_INFO; - -import emu.grasscutter.GameConstants; -import emu.grasscutter.game.friends.Friendship; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; -import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; -import emu.grasscutter.net.proto.GetPlayerFriendListRspOuterClass.GetPlayerFriendListRsp; -import emu.grasscutter.net.proto.PlatformTypeOuterClass; -import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; - -public class PacketGetPlayerFriendListRsp extends BasePacket { - - public PacketGetPlayerFriendListRsp(Player player) { - super(PacketOpcodes.GetPlayerFriendListRsp); - - var serverAccount = GAME_INFO.serverAccount; - FriendBrief serverFriend = - FriendBrief.newBuilder() - .setUid(GameConstants.SERVER_CONSOLE_UID) - .setNickname(serverAccount.nickName) - .setLevel(serverAccount.adventureRank) - .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(serverAccount.avatarId)) - .setWorldLevel(serverAccount.worldLevel) - .setSignature(serverAccount.signature) - .setLastActiveTime((int) (System.currentTimeMillis() / 1000f)) - .setNameCardId(serverAccount.nameCardId) - .setOnlineState(FriendOnlineState.FRIEND_ONLINE_STATE_ONLINE) - .setParam(1) - .setIsGameSource(true) - .setPlatformType(PlatformTypeOuterClass.PlatformType.PLATFORM_TYPE_PC) - .build(); - - GetPlayerFriendListRsp.Builder proto = - GetPlayerFriendListRsp.newBuilder().addFriendList(serverFriend); - - for (Friendship friendship : player.getFriendsList().getFriends().values()) { - proto.addFriendList(friendship.toProto()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import static emu.grasscutter.config.Configuration.GAME_INFO; + +import emu.grasscutter.GameConstants; +import emu.grasscutter.game.friends.Friendship; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; +import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; +import emu.grasscutter.net.proto.GetPlayerFriendListRspOuterClass.GetPlayerFriendListRsp; +import emu.grasscutter.net.proto.PlatformTypeOuterClass; +import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; + +public class PacketGetPlayerFriendListRsp extends BasePacket { + + public PacketGetPlayerFriendListRsp(Player player) { + super(PacketOpcodes.GetPlayerFriendListRsp); + + var serverAccount = GAME_INFO.serverAccount; + FriendBrief serverFriend = + FriendBrief.newBuilder() + .setUid(GameConstants.SERVER_CONSOLE_UID) + .setNickname(serverAccount.nickName) + .setLevel(serverAccount.adventureRank) + .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(serverAccount.avatarId)) + .setWorldLevel(serverAccount.worldLevel) + .setSignature(serverAccount.signature) + .setLastActiveTime((int) (System.currentTimeMillis() / 1000f)) + .setNameCardId(serverAccount.nameCardId) + .setOnlineState(FriendOnlineState.FRIEND_ONLINE_STATE_ONLINE) + .setParam(1) + .setIsGameSource(true) + .setPlatformType(PlatformTypeOuterClass.PlatformType.PLATFORM_TYPE_PC) + .build(); + + GetPlayerFriendListRsp.Builder proto = + GetPlayerFriendListRsp.newBuilder().addFriendList(serverFriend); + + for (Friendship friendship : player.getFriendsList().getFriends().values()) { + proto.addFriendList(friendship.toProto()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerSocialDetailRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerSocialDetailRsp.java index 4c997960b..d5b80045b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerSocialDetailRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerSocialDetailRsp.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetPlayerSocialDetailRspOuterClass.GetPlayerSocialDetailRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; - -public class PacketGetPlayerSocialDetailRsp extends BasePacket { - - public PacketGetPlayerSocialDetailRsp(SocialDetail.Builder detail) { - super(PacketOpcodes.GetPlayerSocialDetailRsp); - - GetPlayerSocialDetailRsp.Builder proto = GetPlayerSocialDetailRsp.newBuilder(); - - if (detail != null) { - proto.setDetailData(detail); - } else { - proto.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetPlayerSocialDetailRspOuterClass.GetPlayerSocialDetailRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; + +public class PacketGetPlayerSocialDetailRsp extends BasePacket { + + public PacketGetPlayerSocialDetailRsp(SocialDetail.Builder detail) { + super(PacketOpcodes.GetPlayerSocialDetailRsp); + + GetPlayerSocialDetailRsp.Builder proto = GetPlayerSocialDetailRsp.newBuilder(); + + if (detail != null) { + proto.setDetailData(detail); + } else { + proto.setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java index 413edde81..2f681d75c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerTokenRsp.java @@ -1,84 +1,84 @@ -package emu.grasscutter.server.packet.send; - -import com.google.protobuf.ByteString; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetPlayerTokenRspOuterClass.GetPlayerTokenRsp; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.utils.Crypto; - -public class PacketGetPlayerTokenRsp extends BasePacket { - - public PacketGetPlayerTokenRsp(GameSession session) { - super(PacketOpcodes.GetPlayerTokenRsp, true); - - this.setUseDispatchKey(true); - - GetPlayerTokenRsp p = - GetPlayerTokenRsp.newBuilder() - .setUid(session.getPlayer().getUid()) - .setToken(session.getAccount().getToken()) - .setAccountType(1) - .setIsProficientPlayer( - session.getPlayer().getAvatars().getAvatarCount() > 0) // Not sure where this goes - .setSecretKeySeed(Crypto.ENCRYPT_SEED) - .setSecurityCmdBuffer(ByteString.copyFrom(Crypto.ENCRYPT_SEED_BUFFER)) - .setPlatformType(3) - .setChannelId(1) - .setCountryCode("US") - .setClientVersionRandomKey("c25-314dd05b0b5f") - .setRegPlatform(3) - .setClientIpStr(session.getAddress().getAddress().getHostAddress()) - .build(); - - this.setData(p.toByteArray()); - } - - public PacketGetPlayerTokenRsp(GameSession session, int retcode, String msg, int blackEndTime) { - super(PacketOpcodes.GetPlayerTokenRsp, true); - - this.setUseDispatchKey(true); - - GetPlayerTokenRsp p = - GetPlayerTokenRsp.newBuilder() - .setUid(session.getPlayer().getUid()) - .setIsProficientPlayer(session.getPlayer().getAvatars().getAvatarCount() > 0) - .setRetcode(retcode) - .setMsg(msg) - .setBlackUidEndTime(blackEndTime) - .setRegPlatform(3) - .setCountryCode("US") - .setClientIpStr(session.getAddress().getAddress().getHostAddress()) - .build(); - - this.setData(p.toByteArray()); - } - - public PacketGetPlayerTokenRsp( - GameSession session, String encryptedSeed, String encryptedSeedSign) { - super(PacketOpcodes.GetPlayerTokenRsp, true); - - this.setUseDispatchKey(true); - - GetPlayerTokenRsp p = - GetPlayerTokenRsp.newBuilder() - .setUid(session.getPlayer().getUid()) - .setToken(session.getAccount().getToken()) - .setAccountType(1) - .setIsProficientPlayer( - session.getPlayer().getAvatars().getAvatarCount() > 0) // Not sure where this goes - .setSecretKeySeed(Crypto.ENCRYPT_SEED) - .setSecurityCmdBuffer(ByteString.copyFrom(Crypto.ENCRYPT_SEED_BUFFER)) - .setPlatformType(3) - .setChannelId(1) - .setCountryCode("US") - .setClientVersionRandomKey("c25-314dd05b0b5f") - .setRegPlatform(3) - .setClientIpStr(session.getAddress().getAddress().getHostAddress()) - .setServerRandKey(encryptedSeed) - .setSign(encryptedSeedSign) - .build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import com.google.protobuf.ByteString; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetPlayerTokenRspOuterClass.GetPlayerTokenRsp; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.utils.Crypto; + +public class PacketGetPlayerTokenRsp extends BasePacket { + + public PacketGetPlayerTokenRsp(GameSession session) { + super(PacketOpcodes.GetPlayerTokenRsp, true); + + this.setUseDispatchKey(true); + + GetPlayerTokenRsp p = + GetPlayerTokenRsp.newBuilder() + .setUid(session.getPlayer().getUid()) + .setToken(session.getAccount().getToken()) + .setAccountType(1) + .setIsProficientPlayer( + session.getPlayer().getAvatars().getAvatarCount() > 0) // Not sure where this goes + .setSecretKeySeed(Crypto.ENCRYPT_SEED) + .setSecurityCmdBuffer(ByteString.copyFrom(Crypto.ENCRYPT_SEED_BUFFER)) + .setPlatformType(3) + .setChannelId(1) + .setCountryCode("US") + .setClientVersionRandomKey("c25-314dd05b0b5f") + .setRegPlatform(3) + .setClientIpStr(session.getAddress().getAddress().getHostAddress()) + .build(); + + this.setData(p.toByteArray()); + } + + public PacketGetPlayerTokenRsp(GameSession session, int retcode, String msg, int blackEndTime) { + super(PacketOpcodes.GetPlayerTokenRsp, true); + + this.setUseDispatchKey(true); + + GetPlayerTokenRsp p = + GetPlayerTokenRsp.newBuilder() + .setUid(session.getPlayer().getUid()) + .setIsProficientPlayer(session.getPlayer().getAvatars().getAvatarCount() > 0) + .setRetcode(retcode) + .setMsg(msg) + .setBlackUidEndTime(blackEndTime) + .setRegPlatform(3) + .setCountryCode("US") + .setClientIpStr(session.getAddress().getAddress().getHostAddress()) + .build(); + + this.setData(p.toByteArray()); + } + + public PacketGetPlayerTokenRsp( + GameSession session, String encryptedSeed, String encryptedSeedSign) { + super(PacketOpcodes.GetPlayerTokenRsp, true); + + this.setUseDispatchKey(true); + + GetPlayerTokenRsp p = + GetPlayerTokenRsp.newBuilder() + .setUid(session.getPlayer().getUid()) + .setToken(session.getAccount().getToken()) + .setAccountType(1) + .setIsProficientPlayer( + session.getPlayer().getAvatars().getAvatarCount() > 0) // Not sure where this goes + .setSecretKeySeed(Crypto.ENCRYPT_SEED) + .setSecurityCmdBuffer(ByteString.copyFrom(Crypto.ENCRYPT_SEED_BUFFER)) + .setPlatformType(3) + .setChannelId(1) + .setCountryCode("US") + .setClientVersionRandomKey("c25-314dd05b0b5f") + .setRegPlatform(3) + .setClientIpStr(session.getAddress().getAddress().getHostAddress()) + .setServerRandKey(encryptedSeed) + .setSign(encryptedSeedSign) + .build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetSceneAreaRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetSceneAreaRsp.java index 925769be4..d7e3b32f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetSceneAreaRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetSceneAreaRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CityInfoOuterClass.CityInfo; -import emu.grasscutter.net.proto.GetSceneAreaRspOuterClass.GetSceneAreaRsp; - -public class PacketGetSceneAreaRsp extends BasePacket { - - public PacketGetSceneAreaRsp(Player player, int sceneId) { - super(PacketOpcodes.GetSceneAreaRsp); - - this.buildHeader(0); - - GetSceneAreaRsp p = - GetSceneAreaRsp.newBuilder() - .setSceneId(sceneId) - .addAllAreaIdList(player.getUnlockedSceneAreas(sceneId)) - .addCityInfoList(CityInfo.newBuilder().setCityId(1).setLevel(1).build()) - .addCityInfoList(CityInfo.newBuilder().setCityId(2).setLevel(1).build()) - .addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build()) - .build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CityInfoOuterClass.CityInfo; +import emu.grasscutter.net.proto.GetSceneAreaRspOuterClass.GetSceneAreaRsp; + +public class PacketGetSceneAreaRsp extends BasePacket { + + public PacketGetSceneAreaRsp(Player player, int sceneId) { + super(PacketOpcodes.GetSceneAreaRsp); + + this.buildHeader(0); + + GetSceneAreaRsp p = + GetSceneAreaRsp.newBuilder() + .setSceneId(sceneId) + .addAllAreaIdList(player.getUnlockedSceneAreas(sceneId)) + .addCityInfoList(CityInfo.newBuilder().setCityId(1).setLevel(1).build()) + .addCityInfoList(CityInfo.newBuilder().setCityId(2).setLevel(1).build()) + .addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build()) + .build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java index b585398ed..b5fa53903 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetScenePointRsp.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetScenePointRspOuterClass.GetScenePointRsp; - -public class PacketGetScenePointRsp extends BasePacket { - - public PacketGetScenePointRsp(Player player, int sceneId) { - super(PacketOpcodes.GetScenePointRsp); - - GetScenePointRsp.Builder p = GetScenePointRsp.newBuilder().setSceneId(sceneId); - - if (GameData.getScenePointIdList().size() == 0) { - for (int i = 1; i < 1000; i++) { - p.addUnlockedPointList(i); - p.addUnhidePointList(i); - } - } else { - p.addAllUnlockedPointList(player.getUnlockedScenePoints(sceneId)); - p.addAllUnhidePointList(player.getUnlockedScenePoints(sceneId)); - } - - for (int i = 1; i < 9; i++) { - p.addUnlockAreaList(i); - } - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetScenePointRspOuterClass.GetScenePointRsp; + +public class PacketGetScenePointRsp extends BasePacket { + + public PacketGetScenePointRsp(Player player, int sceneId) { + super(PacketOpcodes.GetScenePointRsp); + + GetScenePointRsp.Builder p = GetScenePointRsp.newBuilder().setSceneId(sceneId); + + if (GameData.getScenePointIdList().size() == 0) { + for (int i = 1; i < 1000; i++) { + p.addUnlockedPointList(i); + p.addUnhidePointList(i); + } + } else { + p.addAllUnlockedPointList(player.getUnlockedScenePoints(sceneId)); + p.addAllUnhidePointList(player.getUnlockedScenePoints(sceneId)); + } + + for (int i = 1; i < 9; i++) { + p.addUnlockAreaList(i); + } + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopRsp.java index c625e62b8..3312e452c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopRsp.java @@ -1,91 +1,91 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.shop.ShopInfo; -import emu.grasscutter.game.shop.ShopLimit; -import emu.grasscutter.game.shop.ShopSystem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetShopRspOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.ShopGoodsOuterClass.ShopGoods; -import emu.grasscutter.net.proto.ShopOuterClass.Shop; -import emu.grasscutter.utils.Utils; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class PacketGetShopRsp extends BasePacket { - public PacketGetShopRsp(Player inv, int shopType) { - super(PacketOpcodes.GetShopRsp); - - // TODO: CityReputationLevel - Shop.Builder shop = - Shop.newBuilder() - .setShopType(shopType) - .setCityId(1) // mock - .setCityReputationLevel(10); // mock - - ShopSystem manager = Grasscutter.getGameServer().getShopSystem(); - if (manager.getShopData().get(shopType) != null) { - List list = manager.getShopData().get(shopType); - List goodsList = new ArrayList<>(); - for (ShopInfo info : list) { - ShopGoods.Builder goods = - ShopGoods.newBuilder() - .setGoodsId(info.getGoodsId()) - .setGoodsItem( - ItemParamOuterClass.ItemParam.newBuilder() - .setItemId(info.getGoodsItem().getId()) - .setCount(info.getGoodsItem().getCount()) - .build()) - .setScoin(info.getScoin()) - .setHcoin(info.getHcoin()) - .setBuyLimit(info.getBuyLimit()) - .setBeginTime(info.getBeginTime()) - .setEndTime(info.getEndTime()) - .setMinLevel(info.getMinLevel()) - .setMaxLevel(info.getMaxLevel()) - .setMcoin(info.getMcoin()) - .setDisableType(info.getDisableType()) - .setSecondarySheetId(info.getSecondarySheetId()); - if (info.getCostItemList() != null) { - goods.addAllCostItemList( - info.getCostItemList().stream() - .map( - x -> - ItemParamOuterClass.ItemParam.newBuilder() - .setItemId(x.getId()) - .setCount(x.getCount()) - .build()) - .collect(Collectors.toList())); - } - if (info.getPreGoodsIdList() != null) { - goods.addAllPreGoodsIdList(info.getPreGoodsIdList()); - } - - int currentTs = Utils.getCurrentSeconds(); - ShopLimit currentShopLimit = inv.getGoodsLimit(info.getGoodsId()); - int nextRefreshTime = ShopSystem.getShopNextRefreshTime(info); - if (currentShopLimit != null) { - if (currentShopLimit.getNextRefreshTime() < currentTs) { // second game day - currentShopLimit.setHasBoughtInPeriod(0); - currentShopLimit.setNextRefreshTime(nextRefreshTime); - } - goods.setBoughtNum(currentShopLimit.getHasBoughtInPeriod()); - goods.setNextRefreshTime(currentShopLimit.getNextRefreshTime()); - } else { - inv.addShopLimit(goods.getGoodsId(), 0, nextRefreshTime); // save generated refresh time - goods.setNextRefreshTime(nextRefreshTime); - } - - goodsList.add(goods.build()); - } - shop.addAllGoodsList(goodsList); - } - - inv.save(); - this.setData(GetShopRspOuterClass.GetShopRsp.newBuilder().setShop(shop).build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.shop.ShopInfo; +import emu.grasscutter.game.shop.ShopLimit; +import emu.grasscutter.game.shop.ShopSystem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetShopRspOuterClass; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.ShopGoodsOuterClass.ShopGoods; +import emu.grasscutter.net.proto.ShopOuterClass.Shop; +import emu.grasscutter.utils.Utils; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class PacketGetShopRsp extends BasePacket { + public PacketGetShopRsp(Player inv, int shopType) { + super(PacketOpcodes.GetShopRsp); + + // TODO: CityReputationLevel + Shop.Builder shop = + Shop.newBuilder() + .setShopType(shopType) + .setCityId(1) // mock + .setCityReputationLevel(10); // mock + + ShopSystem manager = Grasscutter.getGameServer().getShopSystem(); + if (manager.getShopData().get(shopType) != null) { + List list = manager.getShopData().get(shopType); + List goodsList = new ArrayList<>(); + for (ShopInfo info : list) { + ShopGoods.Builder goods = + ShopGoods.newBuilder() + .setGoodsId(info.getGoodsId()) + .setGoodsItem( + ItemParamOuterClass.ItemParam.newBuilder() + .setItemId(info.getGoodsItem().getId()) + .setCount(info.getGoodsItem().getCount()) + .build()) + .setScoin(info.getScoin()) + .setHcoin(info.getHcoin()) + .setBuyLimit(info.getBuyLimit()) + .setBeginTime(info.getBeginTime()) + .setEndTime(info.getEndTime()) + .setMinLevel(info.getMinLevel()) + .setMaxLevel(info.getMaxLevel()) + .setMcoin(info.getMcoin()) + .setDisableType(info.getDisableType()) + .setSecondarySheetId(info.getSecondarySheetId()); + if (info.getCostItemList() != null) { + goods.addAllCostItemList( + info.getCostItemList().stream() + .map( + x -> + ItemParamOuterClass.ItemParam.newBuilder() + .setItemId(x.getId()) + .setCount(x.getCount()) + .build()) + .collect(Collectors.toList())); + } + if (info.getPreGoodsIdList() != null) { + goods.addAllPreGoodsIdList(info.getPreGoodsIdList()); + } + + int currentTs = Utils.getCurrentSeconds(); + ShopLimit currentShopLimit = inv.getGoodsLimit(info.getGoodsId()); + int nextRefreshTime = ShopSystem.getShopNextRefreshTime(info); + if (currentShopLimit != null) { + if (currentShopLimit.getNextRefreshTime() < currentTs) { // second game day + currentShopLimit.setHasBoughtInPeriod(0); + currentShopLimit.setNextRefreshTime(nextRefreshTime); + } + goods.setBoughtNum(currentShopLimit.getHasBoughtInPeriod()); + goods.setNextRefreshTime(currentShopLimit.getNextRefreshTime()); + } else { + inv.addShopLimit(goods.getGoodsId(), 0, nextRefreshTime); // save generated refresh time + goods.setNextRefreshTime(nextRefreshTime); + } + + goodsList.add(goods.build()); + } + shop.addAllGoodsList(goodsList); + } + + inv.save(); + this.setData(GetShopRspOuterClass.GetShopRsp.newBuilder().setShop(shop).build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopmallDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopmallDataRsp.java index 2e6cda4cf..437cb0b5c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopmallDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetShopmallDataRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetShopmallDataRspOuterClass.GetShopmallDataRsp; -import java.util.List; - -public class PacketGetShopmallDataRsp extends BasePacket { - - public PacketGetShopmallDataRsp() { - super(PacketOpcodes.GetShopmallDataRsp); - - List shop_malls = List.of(900, 1052, 902, 1001, 903); - - GetShopmallDataRsp proto = - GetShopmallDataRsp.newBuilder().addAllShopTypeList(shop_malls).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetShopmallDataRspOuterClass.GetShopmallDataRsp; +import java.util.List; + +public class PacketGetShopmallDataRsp extends BasePacket { + + public PacketGetShopmallDataRsp() { + super(PacketOpcodes.GetShopmallDataRsp); + + List shop_malls = List.of(900, 1052, 902, 1001, 903); + + GetShopmallDataRsp proto = + GetShopmallDataRsp.newBuilder().addAllShopTypeList(shop_malls).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetWidgetSlotRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetWidgetSlotRsp.java index 9d700c4ca..1d20c1b09 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetWidgetSlotRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetWidgetSlotRsp.java @@ -1,40 +1,40 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetWidgetSlotRspOuterClass; -import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; -import emu.grasscutter.net.proto.WidgetSlotTagOuterClass; -import java.util.List; - -public class PacketGetWidgetSlotRsp extends BasePacket { - - public PacketGetWidgetSlotRsp(Player player) { - super(PacketOpcodes.GetWidgetSlotRsp); - - GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto = - GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder(); - - if (player.getWidgetId() - == 0) { // TODO: check this logic later, it was null-checking an int before which made it - // dead code - proto.addAllSlotList(List.of()); - } else { - proto.addSlotList( - WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() - .setIsActive(true) - .setMaterialId(player.getWidgetId()) - .build()); - - proto.addSlotList( - WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() - .setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_TAG_ATTACH_AVATAR) - .build()); - } - - GetWidgetSlotRspOuterClass.GetWidgetSlotRsp protoData = proto.build(); - - this.setData(protoData); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetWidgetSlotRspOuterClass; +import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; +import emu.grasscutter.net.proto.WidgetSlotTagOuterClass; +import java.util.List; + +public class PacketGetWidgetSlotRsp extends BasePacket { + + public PacketGetWidgetSlotRsp(Player player) { + super(PacketOpcodes.GetWidgetSlotRsp); + + GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto = + GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder(); + + if (player.getWidgetId() + == 0) { // TODO: check this logic later, it was null-checking an int before which made it + // dead code + proto.addAllSlotList(List.of()); + } else { + proto.addSlotList( + WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() + .setIsActive(true) + .setMaterialId(player.getWidgetId()) + .build()); + + proto.addSlotList( + WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() + .setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_TAG_ATTACH_AVATAR) + .build()); + } + + GetWidgetSlotRspOuterClass.GetWidgetSlotRsp protoData = proto.build(); + + this.setData(protoData); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetWorldMpInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetWorldMpInfoRsp.java index 2884e5b6e..0306f6c91 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetWorldMpInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetWorldMpInfoRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GetWorldMpInfoRspOuterClass.GetWorldMpInfoRsp; - -public class PacketGetWorldMpInfoRsp extends BasePacket { - - public PacketGetWorldMpInfoRsp(World world) { - super(PacketOpcodes.GetWorldMpInfoRsp); - - GetWorldMpInfoRsp proto = - GetWorldMpInfoRsp.newBuilder().setIsInMpMode(world.isMultiplayer()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetWorldMpInfoRspOuterClass.GetWorldMpInfoRsp; + +public class PacketGetWorldMpInfoRsp extends BasePacket { + + public PacketGetWorldMpInfoRsp(World world) { + super(PacketOpcodes.GetWorldMpInfoRsp); + + GetWorldMpInfoRsp proto = + GetWorldMpInfoRsp.newBuilder().setIsInMpMode(world.isMultiplayer()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java index dcaf2bc14..0afd78e2e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupSuiteNotify.java @@ -1,45 +1,45 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.binout.SceneNpcBornEntry; -import emu.grasscutter.game.quest.QuestGroupSuite; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GroupSuiteNotifyOuterClass; -import java.util.Collection; -import java.util.List; - -public class PacketGroupSuiteNotify extends BasePacket { - - /** Real control which npc suite is loaded EntityNPC is useless */ - public PacketGroupSuiteNotify(List npcBornEntries) { - super(PacketOpcodes.GroupSuiteNotify); - - var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); - - npcBornEntries.stream() - .filter(x -> x.getGroupId() > 0 && x.getSuiteIdList() != null) - .forEach(x -> x.getSuiteIdList().forEach(y -> proto.putGroupMap(x.getGroupId(), y))); - - this.setData(proto); - } - - public PacketGroupSuiteNotify(int groupId, int suiteId) { - super(PacketOpcodes.GroupSuiteNotify); - - var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); - - proto.putGroupMap(groupId, suiteId); - - this.setData(proto); - } - - public PacketGroupSuiteNotify(Collection questGroupSuites) { - super(PacketOpcodes.GroupSuiteNotify); - - var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); - - questGroupSuites.forEach(i -> proto.putGroupMap(i.getGroup(), i.getSuite())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.binout.SceneNpcBornEntry; +import emu.grasscutter.game.quest.QuestGroupSuite; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GroupSuiteNotifyOuterClass; +import java.util.Collection; +import java.util.List; + +public class PacketGroupSuiteNotify extends BasePacket { + + /** Real control which npc suite is loaded EntityNPC is useless */ + public PacketGroupSuiteNotify(List npcBornEntries) { + super(PacketOpcodes.GroupSuiteNotify); + + var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); + + npcBornEntries.stream() + .filter(x -> x.getGroupId() > 0 && x.getSuiteIdList() != null) + .forEach(x -> x.getSuiteIdList().forEach(y -> proto.putGroupMap(x.getGroupId(), y))); + + this.setData(proto); + } + + public PacketGroupSuiteNotify(int groupId, int suiteId) { + super(PacketOpcodes.GroupSuiteNotify); + + var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); + + proto.putGroupMap(groupId, suiteId); + + this.setData(proto); + } + + public PacketGroupSuiteNotify(Collection questGroupSuites) { + super(PacketOpcodes.GroupSuiteNotify); + + var proto = GroupSuiteNotifyOuterClass.GroupSuiteNotify.newBuilder(); + + questGroupSuites.forEach(i -> proto.putGroupMap(i.getGroup(), i.getSuite())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupUnloadNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupUnloadNotify.java index ad7578c18..928e4dbb0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGroupUnloadNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGroupUnloadNotify.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.GroupUnloadNotifyOuterClass; -import java.util.List; - -public class PacketGroupUnloadNotify extends BasePacket { - - public PacketGroupUnloadNotify(List groupList) { - super(PacketOpcodes.GroupUnloadNotify); - - var proto = GroupUnloadNotifyOuterClass.GroupUnloadNotify.newBuilder(); - - proto.addAllGroupList(groupList); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GroupUnloadNotifyOuterClass; +import java.util.List; + +public class PacketGroupUnloadNotify extends BasePacket { + + public PacketGroupUnloadNotify(List groupList) { + super(PacketOpcodes.GroupUnloadNotify); + + var proto = GroupUnloadNotifyOuterClass.GroupUnloadNotify.newBuilder(); + + proto.addAllGroupList(groupList); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketH5ActivityIdsNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketH5ActivityIdsNotify.java index 03754da10..4fc6968ec 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketH5ActivityIdsNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketH5ActivityIdsNotify.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.H5ActivityIdsNotifyOuterClass.H5ActivityIdsNotify; - -public class PacketH5ActivityIdsNotify extends BasePacket { - - public PacketH5ActivityIdsNotify() { - super(PacketOpcodes.H5ActivityIdsNotify); - - H5ActivityIdsNotify proto = H5ActivityIdsNotify.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.H5ActivityIdsNotifyOuterClass.H5ActivityIdsNotify; + +public class PacketH5ActivityIdsNotify extends BasePacket { + + public PacketH5ActivityIdsNotify() { + super(PacketOpcodes.H5ActivityIdsNotify); + + H5ActivityIdsNotify proto = H5ActivityIdsNotify.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAllUnlockedBgmIdListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAllUnlockedBgmIdListNotify.java index a65162390..b5a77aad0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAllUnlockedBgmIdListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeAllUnlockedBgmIdListNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeAllUnlockedBgmIdListNotifyOuterClass; - -public class PacketHomeAllUnlockedBgmIdListNotify extends BasePacket { - public PacketHomeAllUnlockedBgmIdListNotify(Player player) { - super(PacketOpcodes.HomeAllUnlockedBgmIdListNotify); - - if (player.getRealmList() == null) { - return; - } - - var unlocked = player.getHome().getUnlockedHomeBgmList(); - - var notify = - HomeAllUnlockedBgmIdListNotifyOuterClass.HomeAllUnlockedBgmIdListNotify.newBuilder() - .addAllAllUnlockedBgmIdList(unlocked) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeAllUnlockedBgmIdListNotifyOuterClass; + +public class PacketHomeAllUnlockedBgmIdListNotify extends BasePacket { + public PacketHomeAllUnlockedBgmIdListNotify(Player player) { + super(PacketOpcodes.HomeAllUnlockedBgmIdListNotify); + + if (player.getRealmList() == null) { + return; + } + + var unlocked = player.getHome().getUnlockedHomeBgmList(); + + var notify = + HomeAllUnlockedBgmIdListNotifyOuterClass.HomeAllUnlockedBgmIdListNotify.newBuilder() + .addAllAllUnlockedBgmIdList(unlocked) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeBasicInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeBasicInfoNotify.java index 6cccfe5aa..f8654de18 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeBasicInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeBasicInfoNotify.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeBasicInfoNotifyOuterClass; -import emu.grasscutter.net.proto.HomeBasicInfoOuterClass; - -public class PacketHomeBasicInfoNotify extends BasePacket { - - public PacketHomeBasicInfoNotify(Player player, boolean editMode) { - super(PacketOpcodes.HomeBasicInfoNotify); - - if (player.getCurrentRealmId() <= 0) { - return; - } - - var proto = HomeBasicInfoNotifyOuterClass.HomeBasicInfoNotify.newBuilder(); - - var sceneId = player.getCurrentRealmId() + 2000; - var homeScene = player.getHome().getHomeSceneItem(sceneId); - - proto.setBasicInfo( - HomeBasicInfoOuterClass.HomeBasicInfo.newBuilder() - .setCurModuleId(player.getCurrentRealmId()) - .setCurRoomSceneId(homeScene.getRoomSceneId()) - .setIsInEditMode(editMode) - .setHomeOwnerUid(player.getUid()) - .setExp(player.getHome().getExp()) - .setLevel(player.getHome().getLevel()) - .setOwnerNickName(player.getNickname()) - // TODO limit shop - .build()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeBasicInfoNotifyOuterClass; +import emu.grasscutter.net.proto.HomeBasicInfoOuterClass; + +public class PacketHomeBasicInfoNotify extends BasePacket { + + public PacketHomeBasicInfoNotify(Player player, boolean editMode) { + super(PacketOpcodes.HomeBasicInfoNotify); + + if (player.getCurrentRealmId() <= 0) { + return; + } + + var proto = HomeBasicInfoNotifyOuterClass.HomeBasicInfoNotify.newBuilder(); + + var sceneId = player.getCurrentRealmId() + 2000; + var homeScene = player.getHome().getHomeSceneItem(sceneId); + + proto.setBasicInfo( + HomeBasicInfoOuterClass.HomeBasicInfo.newBuilder() + .setCurModuleId(player.getCurrentRealmId()) + .setCurRoomSceneId(homeScene.getRoomSceneId()) + .setIsInEditMode(editMode) + .setHomeOwnerUid(player.getUid()) + .setExp(player.getHome().getExp()) + .setLevel(player.getHome().getLevel()) + .setOwnerNickName(player.getNickname()) + // TODO limit shop + .build()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmNotify.java index 73a7911ad..d1d52fbcd 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmNotify.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeBgmNotifyOuterClass; - -public class PacketHomeChangeBgmNotify extends BasePacket { - public PacketHomeChangeBgmNotify(int homeBgmId) { - super(PacketOpcodes.HomeChangeBgmNotify); - - var notify = - HomeChangeBgmNotifyOuterClass.HomeChangeBgmNotify.newBuilder().setBgmId(homeBgmId).build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeBgmNotifyOuterClass; + +public class PacketHomeChangeBgmNotify extends BasePacket { + public PacketHomeChangeBgmNotify(int homeBgmId) { + super(PacketOpcodes.HomeChangeBgmNotify); + + var notify = + HomeChangeBgmNotifyOuterClass.HomeChangeBgmNotify.newBuilder().setBgmId(homeBgmId).build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmRsp.java index 7a3c2ab71..7d66e8c4c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeBgmRsp.java @@ -1,15 +1,15 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeBgmRspOuterClass; - -public class PacketHomeChangeBgmRsp extends BasePacket { - public PacketHomeChangeBgmRsp() { - super(PacketOpcodes.HomeChangeBgmRsp); - - var rsp = HomeChangeBgmRspOuterClass.HomeChangeBgmRsp.newBuilder().setRetcode(0).build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeBgmRspOuterClass; + +public class PacketHomeChangeBgmRsp extends BasePacket { + public PacketHomeChangeBgmRsp() { + super(PacketOpcodes.HomeChangeBgmRsp); + + var rsp = HomeChangeBgmRspOuterClass.HomeChangeBgmRsp.newBuilder().setRetcode(0).build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeEditModeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeEditModeRsp.java index 9ebcb6c8b..9a2f91cc4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeEditModeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeEditModeRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeEditModeRspOuterClass; - -public class PacketHomeChangeEditModeRsp extends BasePacket { - - public PacketHomeChangeEditModeRsp(boolean enterEditMode) { - super(PacketOpcodes.HomeChangeEditModeRsp); - - var proto = HomeChangeEditModeRspOuterClass.HomeChangeEditModeRsp.newBuilder(); - - proto.setIsEnterEditMode(enterEditMode); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeEditModeRspOuterClass; + +public class PacketHomeChangeEditModeRsp extends BasePacket { + + public PacketHomeChangeEditModeRsp(boolean enterEditMode) { + super(PacketOpcodes.HomeChangeEditModeRsp); + + var proto = HomeChangeEditModeRspOuterClass.HomeChangeEditModeRsp.newBuilder(); + + proto.setIsEnterEditMode(enterEditMode); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeModuleRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeModuleRsp.java index d54a938d7..4cb00b9ed 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeModuleRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChangeModuleRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChangeModuleRspOuterClass; - -public class PacketHomeChangeModuleRsp extends BasePacket { - - public PacketHomeChangeModuleRsp(int targetModuleId) { - super(PacketOpcodes.HomeChangeModuleRsp); - - HomeChangeModuleRspOuterClass.HomeChangeModuleRsp proto = - HomeChangeModuleRspOuterClass.HomeChangeModuleRsp.newBuilder() - .setRetcode(0) - .setTargetModuleId(targetModuleId) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChangeModuleRspOuterClass; + +public class PacketHomeChangeModuleRsp extends BasePacket { + + public PacketHomeChangeModuleRsp(int targetModuleId) { + super(PacketOpcodes.HomeChangeModuleRsp); + + HomeChangeModuleRspOuterClass.HomeChangeModuleRsp proto = + HomeChangeModuleRspOuterClass.HomeChangeModuleRsp.newBuilder() + .setRetcode(0) + .setTargetModuleId(targetModuleId) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChooseModuleRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChooseModuleRsp.java index 836931068..3890f79bb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChooseModuleRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeChooseModuleRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeChooseModuleRspOuterClass; - -public class PacketHomeChooseModuleRsp extends BasePacket { - - public PacketHomeChooseModuleRsp(int moduleId) { - super(PacketOpcodes.HomeChooseModuleRsp); - - HomeChooseModuleRspOuterClass.HomeChooseModuleRsp proto = - HomeChooseModuleRspOuterClass.HomeChooseModuleRsp.newBuilder() - .setRetcode(0) - .setModuleId(moduleId) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeChooseModuleRspOuterClass; + +public class PacketHomeChooseModuleRsp extends BasePacket { + + public PacketHomeChooseModuleRsp(int moduleId) { + super(PacketOpcodes.HomeChooseModuleRsp); + + HomeChooseModuleRspOuterClass.HomeChooseModuleRsp proto = + HomeChooseModuleRspOuterClass.HomeChooseModuleRsp.newBuilder() + .setRetcode(0) + .setModuleId(moduleId) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeComfortInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeComfortInfoNotify.java index c58304358..d3a3371fe 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeComfortInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeComfortInfoNotify.java @@ -1,45 +1,45 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.home.HomeBlockItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeComfortInfoNotifyOuterClass; -import emu.grasscutter.net.proto.HomeModuleComfortInfoOuterClass; -import java.util.ArrayList; -import java.util.List; - -public class PacketHomeComfortInfoNotify extends BasePacket { - - public PacketHomeComfortInfoNotify(Player player) { - super(PacketOpcodes.HomeComfortInfoNotify); - - if (player.getRealmList() == null) { - // Do not send - return; - } - - List comfortInfoList = new ArrayList<>(); - - for (int moduleId : player.getRealmList()) { - var homeScene = player.getHome().getHomeSceneItem(moduleId + 2000); - var blockComfortList = - homeScene.getBlockItems().values().stream().map(HomeBlockItem::calComfort).toList(); - var homeRoomScene = player.getHome().getHomeSceneItem(homeScene.getRoomSceneId()); - - comfortInfoList.add( - HomeModuleComfortInfoOuterClass.HomeModuleComfortInfo.newBuilder() - .setModuleId(moduleId) - .setRoomSceneComfortValue(homeRoomScene.calComfort()) - .addAllWorldSceneBlockComfortValueList(blockComfortList) - .build()); - } - - HomeComfortInfoNotifyOuterClass.HomeComfortInfoNotify proto = - HomeComfortInfoNotifyOuterClass.HomeComfortInfoNotify.newBuilder() - .addAllModuleInfoList(comfortInfoList) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.home.HomeBlockItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeComfortInfoNotifyOuterClass; +import emu.grasscutter.net.proto.HomeModuleComfortInfoOuterClass; +import java.util.ArrayList; +import java.util.List; + +public class PacketHomeComfortInfoNotify extends BasePacket { + + public PacketHomeComfortInfoNotify(Player player) { + super(PacketOpcodes.HomeComfortInfoNotify); + + if (player.getRealmList() == null) { + // Do not send + return; + } + + List comfortInfoList = new ArrayList<>(); + + for (int moduleId : player.getRealmList()) { + var homeScene = player.getHome().getHomeSceneItem(moduleId + 2000); + var blockComfortList = + homeScene.getBlockItems().values().stream().map(HomeBlockItem::calComfort).toList(); + var homeRoomScene = player.getHome().getHomeSceneItem(homeScene.getRoomSceneId()); + + comfortInfoList.add( + HomeModuleComfortInfoOuterClass.HomeModuleComfortInfo.newBuilder() + .setModuleId(moduleId) + .setRoomSceneComfortValue(homeRoomScene.calComfort()) + .addAllWorldSceneBlockComfortValueList(blockComfortList) + .build()); + } + + HomeComfortInfoNotifyOuterClass.HomeComfortInfoNotify proto = + HomeComfortInfoNotifyOuterClass.HomeComfortInfoNotify.newBuilder() + .addAllModuleInfoList(comfortInfoList) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeEnterEditModeFinishRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeEnterEditModeFinishRsp.java index 9e9f1b0fd..903a08481 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeEnterEditModeFinishRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeEnterEditModeFinishRsp.java @@ -1,11 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketHomeEnterEditModeFinishRsp extends BasePacket { - - public PacketHomeEnterEditModeFinishRsp() { - super(PacketOpcodes.HomeEnterEditModeFinishRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketHomeEnterEditModeFinishRsp extends BasePacket { + + public PacketHomeEnterEditModeFinishRsp() { + super(PacketOpcodes.HomeEnterEditModeFinishRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeGetArrangementInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeGetArrangementInfoRsp.java index 30033bc07..ec76b18c8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeGetArrangementInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeGetArrangementInfoRsp.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.home.HomeSceneItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeGetArrangementInfoRspOuterClass; -import java.util.List; - -public class PacketHomeGetArrangementInfoRsp extends BasePacket { - - public PacketHomeGetArrangementInfoRsp(Player player, List sceneIdList) { - super(PacketOpcodes.HomeGetArrangementInfoRsp); - - var home = player.getHome(); - - var homeScenes = - sceneIdList.stream().map(home::getHomeSceneItem).map(HomeSceneItem::toProto).toList(); - - home.save(); - - var proto = HomeGetArrangementInfoRspOuterClass.HomeGetArrangementInfoRsp.newBuilder(); - - proto.addAllSceneArrangementInfoList(homeScenes); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.home.HomeSceneItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeGetArrangementInfoRspOuterClass; +import java.util.List; + +public class PacketHomeGetArrangementInfoRsp extends BasePacket { + + public PacketHomeGetArrangementInfoRsp(Player player, List sceneIdList) { + super(PacketOpcodes.HomeGetArrangementInfoRsp); + + var home = player.getHome(); + + var homeScenes = + sceneIdList.stream().map(home::getHomeSceneItem).map(HomeSceneItem::toProto).toList(); + + home.save(); + + var proto = HomeGetArrangementInfoRspOuterClass.HomeGetArrangementInfoRsp.newBuilder(); + + proto.addAllSceneArrangementInfoList(homeScenes); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java index 8c65e5926..a5793d596 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeMarkPointNotify.java @@ -1,46 +1,46 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.home.HomeBlockItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass; -import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass; -import java.util.Collection; - -public class PacketHomeMarkPointNotify extends BasePacket { - - public PacketHomeMarkPointNotify(Player player) { - super(PacketOpcodes.HomeMarkPointNotify); - - var proto = HomeMarkPointNotifyOuterClass.HomeMarkPointNotify.newBuilder(); - - if (player.getRealmList() == null) { - return; - } - for (var moduleId : player.getRealmList()) { - var homeScene = player.getHome().getHomeSceneItem(moduleId + 2000); - - var markPointData = - HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData.newBuilder() - .setModuleId(moduleId) - .setSceneId(moduleId + 2000) - .setTeapotSpiritPos(homeScene.getDjinnPos().toProto()); - - // Now it only supports the teleport point - // TODO add more types - var marks = - homeScene.getBlockItems().values().stream() - .map(HomeBlockItem::getDeployFurnitureList) - .flatMap(Collection::stream) - .filter(i -> i.getFurnitureId() == 373501) - .map(x -> x.toMarkPointProto(3)) - .toList(); - - markPointData.addAllFurnitureList(marks); - proto.addMarkPointDataList(markPointData); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.home.HomeBlockItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass; +import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass; +import java.util.Collection; + +public class PacketHomeMarkPointNotify extends BasePacket { + + public PacketHomeMarkPointNotify(Player player) { + super(PacketOpcodes.HomeMarkPointNotify); + + var proto = HomeMarkPointNotifyOuterClass.HomeMarkPointNotify.newBuilder(); + + if (player.getRealmList() == null) { + return; + } + for (var moduleId : player.getRealmList()) { + var homeScene = player.getHome().getHomeSceneItem(moduleId + 2000); + + var markPointData = + HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData.newBuilder() + .setModuleId(moduleId) + .setSceneId(moduleId + 2000) + .setTeapotSpiritPos(homeScene.getDjinnPos().toProto()); + + // Now it only supports the teleport point + // TODO add more types + var marks = + homeScene.getBlockItems().values().stream() + .map(HomeBlockItem::getDeployFurnitureList) + .flatMap(Collection::stream) + .filter(i -> i.getFurnitureId() == 373501) + .map(x -> x.toMarkPointProto(3)) + .toList(); + + markPointData.addAllFurnitureList(marks); + proto.addMarkPointDataList(markPointData); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleSeenRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleSeenRsp.java index 1ca0a570d..51a590818 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleSeenRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleSeenRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeModuleSeenRspOuterClass.HomeModuleSeenRsp; -import java.util.List; - -public class PacketHomeModuleSeenRsp extends BasePacket { - - public PacketHomeModuleSeenRsp(List seen) { - super(PacketOpcodes.HomeModuleSeenRsp); - - HomeModuleSeenRsp proto = HomeModuleSeenRsp.newBuilder().addAllSeenModuleIdList(seen).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeModuleSeenRspOuterClass.HomeModuleSeenRsp; +import java.util.List; + +public class PacketHomeModuleSeenRsp extends BasePacket { + + public PacketHomeModuleSeenRsp(List seen) { + super(PacketOpcodes.HomeModuleSeenRsp); + + HomeModuleSeenRsp proto = HomeModuleSeenRsp.newBuilder().addAllSeenModuleIdList(seen).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleUnlockNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleUnlockNotify.java index 3893c96ba..a2bdec141 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleUnlockNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeModuleUnlockNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeModuleUnlockNotifyOuterClass.HomeModuleUnlockNotify; - -public class PacketHomeModuleUnlockNotify extends BasePacket { - - public PacketHomeModuleUnlockNotify(int targetModuleId) { - super(PacketOpcodes.HomeModuleUnlockNotify); - - HomeModuleUnlockNotify proto = - HomeModuleUnlockNotify.newBuilder().setModuleId(targetModuleId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeModuleUnlockNotifyOuterClass.HomeModuleUnlockNotify; + +public class PacketHomeModuleUnlockNotify extends BasePacket { + + public PacketHomeModuleUnlockNotify(int targetModuleId) { + super(PacketOpcodes.HomeModuleUnlockNotify); + + HomeModuleUnlockNotify proto = + HomeModuleUnlockNotify.newBuilder().setModuleId(targetModuleId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeNewUnlockedBgmIdListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeNewUnlockedBgmIdListNotify.java index c57b32157..e7402ce84 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeNewUnlockedBgmIdListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeNewUnlockedBgmIdListNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeNewUnlockedBgmIdListNotifyOuterClass; - -public class PacketHomeNewUnlockedBgmIdListNotify extends BasePacket { - public PacketHomeNewUnlockedBgmIdListNotify(int homeBgmId) { - super(PacketOpcodes.HomeNewUnlockedBgmIdListNotify); - - var notify = - HomeNewUnlockedBgmIdListNotifyOuterClass.HomeNewUnlockedBgmIdListNotify.newBuilder() - .addNewUnlockedBgmIdList(homeBgmId) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeNewUnlockedBgmIdListNotifyOuterClass; + +public class PacketHomeNewUnlockedBgmIdListNotify extends BasePacket { + public PacketHomeNewUnlockedBgmIdListNotify(int homeBgmId) { + super(PacketOpcodes.HomeNewUnlockedBgmIdListNotify); + + var notify = + HomeNewUnlockedBgmIdListNotifyOuterClass.HomeNewUnlockedBgmIdListNotify.newBuilder() + .addNewUnlockedBgmIdList(homeBgmId) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceNotify.java index aaeae4bc0..2b6928fbf 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceNotify.java @@ -1,38 +1,38 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeResourceNotifyOuterClass; -import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; - -public class PacketHomeResourceNotify extends BasePacket { - public PacketHomeResourceNotify(Player player) { - super(PacketOpcodes.HomeResourceNotify); - - var home = player.getHome(); - var level = home.getLevel(); - - HomeResource coin = - HomeResource.newBuilder() - .setNextRefreshTime(home.getNextUpdateTime()) - .setStoreLimit(home.getMaxCoin(level)) - .setStoreValue(home.getStoredCoin()) - .build(); - - HomeResource fetter = - HomeResource.newBuilder() - .setNextRefreshTime(home.getNextUpdateTime()) - .setStoreLimit(home.getMaxFetter(level)) - .setStoreValue(home.getStoredFetterExp()) - .build(); - - var notify = - HomeResourceNotifyOuterClass.HomeResourceNotify.newBuilder() - .setFetterExp(fetter) - .setHomeCoin(coin) - .build(); - - this.setData(notify); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeResourceNotifyOuterClass; +import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; + +public class PacketHomeResourceNotify extends BasePacket { + public PacketHomeResourceNotify(Player player) { + super(PacketOpcodes.HomeResourceNotify); + + var home = player.getHome(); + var level = home.getLevel(); + + HomeResource coin = + HomeResource.newBuilder() + .setNextRefreshTime(home.getNextUpdateTime()) + .setStoreLimit(home.getMaxCoin(level)) + .setStoreValue(home.getStoredCoin()) + .build(); + + HomeResource fetter = + HomeResource.newBuilder() + .setNextRefreshTime(home.getNextUpdateTime()) + .setStoreLimit(home.getMaxFetter(level)) + .setStoreValue(home.getStoredFetterExp()) + .build(); + + var notify = + HomeResourceNotifyOuterClass.HomeResourceNotify.newBuilder() + .setFetterExp(fetter) + .setHomeCoin(coin) + .build(); + + this.setData(notify); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeFetterExpRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeFetterExpRsp.java index fb98e659c..55ae5a0f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeFetterExpRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeFetterExpRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; -import emu.grasscutter.net.proto.HomeResourceTakeFetterExpRspOuterClass; - -public class PacketHomeResourceTakeFetterExpRsp extends BasePacket { - public PacketHomeResourceTakeFetterExpRsp(Player player) { - super(PacketOpcodes.HomeResourceTakeFetterExpRsp); - - var home = player.getHome(); - - home.takeHomeFetter(player); - - var fetterExp = - HomeResource.newBuilder() - .setNextRefreshTime(home.getNextUpdateTime()) - .setStoreLimit(home.getMaxFetter(home.getLevel())) - .setStoreValue(0) - .build(); - - var proto = - HomeResourceTakeFetterExpRspOuterClass.HomeResourceTakeFetterExpRsp.newBuilder() - .setFetterExp(fetterExp) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; +import emu.grasscutter.net.proto.HomeResourceTakeFetterExpRspOuterClass; + +public class PacketHomeResourceTakeFetterExpRsp extends BasePacket { + public PacketHomeResourceTakeFetterExpRsp(Player player) { + super(PacketOpcodes.HomeResourceTakeFetterExpRsp); + + var home = player.getHome(); + + home.takeHomeFetter(player); + + var fetterExp = + HomeResource.newBuilder() + .setNextRefreshTime(home.getNextUpdateTime()) + .setStoreLimit(home.getMaxFetter(home.getLevel())) + .setStoreValue(0) + .build(); + + var proto = + HomeResourceTakeFetterExpRspOuterClass.HomeResourceTakeFetterExpRsp.newBuilder() + .setFetterExp(fetterExp) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeHomeCoinRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeHomeCoinRsp.java index c273d80a4..b5283ed4b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeHomeCoinRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeResourceTakeHomeCoinRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; -import emu.grasscutter.net.proto.HomeResourceTakeHomeCoinRspOuterClass; - -public class PacketHomeResourceTakeHomeCoinRsp extends BasePacket { - public PacketHomeResourceTakeHomeCoinRsp(Player player) { - super(PacketOpcodes.HomeResourceTakeHomeCoinRsp); - - var home = player.getHome(); - - home.takeHomeCoin(player); - - var coin = - HomeResource.newBuilder() - .setNextRefreshTime(home.getNextUpdateTime()) - .setStoreLimit(home.getMaxCoin(home.getLevel())) - .setStoreValue(0) - .build(); - - var proto = - HomeResourceTakeHomeCoinRspOuterClass.HomeResourceTakeHomeCoinRsp.newBuilder() - .setHomeCoin(coin) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeResourceOuterClass.HomeResource; +import emu.grasscutter.net.proto.HomeResourceTakeHomeCoinRspOuterClass; + +public class PacketHomeResourceTakeHomeCoinRsp extends BasePacket { + public PacketHomeResourceTakeHomeCoinRsp(Player player) { + super(PacketOpcodes.HomeResourceTakeHomeCoinRsp); + + var home = player.getHome(); + + home.takeHomeCoin(player); + + var coin = + HomeResource.newBuilder() + .setNextRefreshTime(home.getNextUpdateTime()) + .setStoreLimit(home.getMaxCoin(home.getLevel())) + .setStoreValue(0) + .build(); + + var proto = + HomeResourceTakeHomeCoinRspOuterClass.HomeResourceTakeHomeCoinRsp.newBuilder() + .setHomeCoin(coin) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneInitFinishRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneInitFinishRsp.java index 6f1005b5d..2595cc40e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneInitFinishRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneInitFinishRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeSceneInitFinishReqOuterClass; - -public class PacketHomeSceneInitFinishRsp extends BasePacket { - - public PacketHomeSceneInitFinishRsp() { - super(PacketOpcodes.HomeSceneInitFinishRsp); - - var proto = HomeSceneInitFinishReqOuterClass.HomeSceneInitFinishReq.newBuilder(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeSceneInitFinishReqOuterClass; + +public class PacketHomeSceneInitFinishRsp extends BasePacket { + + public PacketHomeSceneInitFinishRsp() { + super(PacketOpcodes.HomeSceneInitFinishRsp); + + var proto = HomeSceneInitFinishReqOuterClass.HomeSceneInitFinishReq.newBuilder(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneJumpRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneJumpRsp.java index 3ce855a0c..0da6158d6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneJumpRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeSceneJumpRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HomeSceneJumpRspOuterClass; - -public class PacketHomeSceneJumpRsp extends BasePacket { - - public PacketHomeSceneJumpRsp(boolean enterRoomScene) { - super(PacketOpcodes.HomeSceneJumpRsp); - - var proto = HomeSceneJumpRspOuterClass.HomeSceneJumpRsp.newBuilder(); - - proto.setIsEnterRoomScene(enterRoomScene); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HomeSceneJumpRspOuterClass; + +public class PacketHomeSceneJumpRsp extends BasePacket { + + public PacketHomeSceneJumpRsp(boolean enterRoomScene) { + super(PacketOpcodes.HomeSceneJumpRsp); + + var proto = HomeSceneJumpRspOuterClass.HomeSceneJumpRsp.newBuilder(); + + proto.setIsEnterRoomScene(enterRoomScene); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUpdateArrangementInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUpdateArrangementInfoRsp.java index bd71654d0..10dbd65e4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUpdateArrangementInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHomeUpdateArrangementInfoRsp.java @@ -1,11 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketHomeUpdateArrangementInfoRsp extends BasePacket { - - public PacketHomeUpdateArrangementInfoRsp() { - super(PacketOpcodes.HomeUpdateArrangementInfoRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketHomeUpdateArrangementInfoRsp extends BasePacket { + + public PacketHomeUpdateArrangementInfoRsp() { + super(PacketOpcodes.HomeUpdateArrangementInfoRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketHostPlayerNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketHostPlayerNotify.java index a089ac1e7..eadc0f274 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketHostPlayerNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketHostPlayerNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.HostPlayerNotifyOuterClass.HostPlayerNotify; - -public class PacketHostPlayerNotify extends BasePacket { - - public PacketHostPlayerNotify(World world) { - super(PacketOpcodes.HostPlayerNotify); - - HostPlayerNotify proto = - HostPlayerNotify.newBuilder() - .setHostUid(world.getHost().getUid()) - .setHostPeerId(world.getHost().getPeerId()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.HostPlayerNotifyOuterClass.HostPlayerNotify; + +public class PacketHostPlayerNotify extends BasePacket { + + public PacketHostPlayerNotify(World world) { + super(PacketOpcodes.HostPlayerNotify); + + HostPlayerNotify proto = + HostPlayerNotify.newBuilder() + .setHostUid(world.getHost().getUid()) + .setHostPeerId(world.getHost().getPeerId()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java index 409dd9b06..60bb94080 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemAddHintNotifyOuterClass.ItemAddHintNotify; -import java.util.Collection; - -public class PacketItemAddHintNotify extends BasePacket { - - public PacketItemAddHintNotify(GameItem item, ActionReason reason) { - super(PacketOpcodes.ItemAddHintNotify); - - ItemAddHintNotify proto = - ItemAddHintNotify.newBuilder() - .addItemList(item.toItemHintProto()) - .setReason(reason.getValue()) - .build(); - - this.setData(proto); - } - - public PacketItemAddHintNotify(Collection items, ActionReason reason) { - super(PacketOpcodes.ItemAddHintNotify); - - ItemAddHintNotify.Builder proto = ItemAddHintNotify.newBuilder().setReason(reason.getValue()); - - for (GameItem item : items) { - proto.addItemList(item.toItemHintProto()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemAddHintNotifyOuterClass.ItemAddHintNotify; +import java.util.Collection; + +public class PacketItemAddHintNotify extends BasePacket { + + public PacketItemAddHintNotify(GameItem item, ActionReason reason) { + super(PacketOpcodes.ItemAddHintNotify); + + ItemAddHintNotify proto = + ItemAddHintNotify.newBuilder() + .addItemList(item.toItemHintProto()) + .setReason(reason.getValue()) + .build(); + + this.setData(proto); + } + + public PacketItemAddHintNotify(Collection items, ActionReason reason) { + super(PacketOpcodes.ItemAddHintNotify); + + ItemAddHintNotify.Builder proto = ItemAddHintNotify.newBuilder().setReason(reason.getValue()); + + for (GameItem item : items) { + proto.addItemList(item.toItemHintProto()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketLaunchFireworksRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketLaunchFireworksRsp.java index 271dfc2db..35e9375de 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketLaunchFireworksRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketLaunchFireworksRsp.java @@ -1,11 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketLaunchFireworksRsp extends BasePacket { - - public PacketLaunchFireworksRsp() { - super(PacketOpcodes.LaunchFireworksRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketLaunchFireworksRsp extends BasePacket { + + public PacketLaunchFireworksRsp() { + super(PacketOpcodes.LaunchFireworksRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketLifeStateChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketLifeStateChangeNotify.java index 141e1ffc4..2aed8e7cf 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketLifeStateChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketLifeStateChangeNotify.java @@ -1,74 +1,74 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.props.LifeState; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify; -import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; - -public class PacketLifeStateChangeNotify extends BasePacket { - public PacketLifeStateChangeNotify(GameEntity target, LifeState lifeState) { - super(PacketOpcodes.LifeStateChangeNotify); - - LifeStateChangeNotify proto = - LifeStateChangeNotify.newBuilder() - .setEntityId(target.getId()) - .setLifeState(lifeState.getValue()) - .build(); - - this.setData(proto); - } - - public PacketLifeStateChangeNotify(GameEntity attacker, GameEntity target, LifeState lifeState) { - super(PacketOpcodes.LifeStateChangeNotify); - - LifeStateChangeNotify proto = - LifeStateChangeNotify.newBuilder() - .setEntityId(target.getId()) - .setLifeState(lifeState.getValue()) - .setSourceEntityId(attacker.getId()) - .build(); - - this.setData(proto); - } - - public PacketLifeStateChangeNotify(int attackerId, GameEntity target, LifeState lifeState) { - super(PacketOpcodes.LifeStateChangeNotify); - - LifeStateChangeNotify proto = - LifeStateChangeNotify.newBuilder() - .setEntityId(target.getId()) - .setLifeState(lifeState.getValue()) - .setSourceEntityId(attackerId) - .build(); - - this.setData(proto); - } - - public PacketLifeStateChangeNotify( - GameEntity entity, LifeState lifeState, PlayerDieType dieType) { - this(entity, lifeState, null, "", dieType); - } - - public PacketLifeStateChangeNotify( - GameEntity entity, - LifeState lifeState, - GameEntity sourceEntity, - String attackTag, - PlayerDieType dieType) { - super(PacketOpcodes.LifeStateChangeNotify); - - LifeStateChangeNotify.Builder proto = LifeStateChangeNotify.newBuilder(); - - proto.setEntityId(entity.getId()); - proto.setLifeState(lifeState.getValue()); - if (sourceEntity != null) { - proto.setSourceEntityId(sourceEntity.getId()); - } - proto.setAttackTag(attackTag); - proto.setDieType(dieType); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.props.LifeState; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.LifeStateChangeNotifyOuterClass.LifeStateChangeNotify; +import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; + +public class PacketLifeStateChangeNotify extends BasePacket { + public PacketLifeStateChangeNotify(GameEntity target, LifeState lifeState) { + super(PacketOpcodes.LifeStateChangeNotify); + + LifeStateChangeNotify proto = + LifeStateChangeNotify.newBuilder() + .setEntityId(target.getId()) + .setLifeState(lifeState.getValue()) + .build(); + + this.setData(proto); + } + + public PacketLifeStateChangeNotify(GameEntity attacker, GameEntity target, LifeState lifeState) { + super(PacketOpcodes.LifeStateChangeNotify); + + LifeStateChangeNotify proto = + LifeStateChangeNotify.newBuilder() + .setEntityId(target.getId()) + .setLifeState(lifeState.getValue()) + .setSourceEntityId(attacker.getId()) + .build(); + + this.setData(proto); + } + + public PacketLifeStateChangeNotify(int attackerId, GameEntity target, LifeState lifeState) { + super(PacketOpcodes.LifeStateChangeNotify); + + LifeStateChangeNotify proto = + LifeStateChangeNotify.newBuilder() + .setEntityId(target.getId()) + .setLifeState(lifeState.getValue()) + .setSourceEntityId(attackerId) + .build(); + + this.setData(proto); + } + + public PacketLifeStateChangeNotify( + GameEntity entity, LifeState lifeState, PlayerDieType dieType) { + this(entity, lifeState, null, "", dieType); + } + + public PacketLifeStateChangeNotify( + GameEntity entity, + LifeState lifeState, + GameEntity sourceEntity, + String attackTag, + PlayerDieType dieType) { + super(PacketOpcodes.LifeStateChangeNotify); + + LifeStateChangeNotify.Builder proto = LifeStateChangeNotify.newBuilder(); + + proto.setEntityId(entity.getId()); + proto.setLifeState(lifeState.getValue()); + if (sourceEntity != null) { + proto.setSourceEntityId(sourceEntity.getId()); + } + proto.setAttackTag(attackTag); + proto.setDieType(dieType); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java index 8c5566ec6..a6d337e8a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java @@ -1,76 +1,76 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.mail.Mail; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EquipParamOuterClass.EquipParam; -import emu.grasscutter.net.proto.MailChangeNotifyOuterClass.MailChangeNotify; -import emu.grasscutter.net.proto.MailDataOuterClass.MailData; -import emu.grasscutter.net.proto.MailItemOuterClass.MailItem; -import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; -import java.util.ArrayList; -import java.util.List; - -public class PacketMailChangeNotify extends BasePacket { - - public PacketMailChangeNotify(Player player, Mail message) { - this( - player, - new ArrayList() { - { - add(message); - } - }); - } - - public PacketMailChangeNotify(Player player, List mailList) { - this(player, mailList, null); - } - - public PacketMailChangeNotify(Player player, List mailList, List delMailIdList) { - super(PacketOpcodes.MailChangeNotify); - - var proto = MailChangeNotify.newBuilder(); - - if (mailList != null) { - for (Mail message : mailList) { - var mailTextContent = MailTextContent.newBuilder(); - mailTextContent.setTitle(message.mailContent.title); - mailTextContent.setContent(message.mailContent.content); - mailTextContent.setSender(message.mailContent.sender); - - List mailItems = new ArrayList<>(); - - for (Mail.MailItem item : message.itemList) { - var mailItem = MailItem.newBuilder(); - var itemParam = EquipParam.newBuilder(); - itemParam.setItemId(item.itemId); - itemParam.setItemNum(item.itemCount); - mailItem.setEquipParam(itemParam.build()); - - mailItems.add(mailItem.build()); - } - - var mailData = MailData.newBuilder(); - mailData.setMailId(player.getMailId(message)); - mailData.setMailTextContent(mailTextContent.build()); - mailData.addAllItemList(mailItems); - mailData.setSendTime((int) message.sendTime); - mailData.setExpireTime((int) message.expireTime); - mailData.setImportance(message.importance); - mailData.setIsRead(message.isRead); - mailData.setIsAttachmentGot(message.isAttachmentGot); - mailData.setCollectStateValue(message.stateValue); - - proto.addMailList(mailData.build()); - } - } - - if (delMailIdList != null) { - proto.addAllDelMailIdList(delMailIdList); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.mail.Mail; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EquipParamOuterClass.EquipParam; +import emu.grasscutter.net.proto.MailChangeNotifyOuterClass.MailChangeNotify; +import emu.grasscutter.net.proto.MailDataOuterClass.MailData; +import emu.grasscutter.net.proto.MailItemOuterClass.MailItem; +import emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent; +import java.util.ArrayList; +import java.util.List; + +public class PacketMailChangeNotify extends BasePacket { + + public PacketMailChangeNotify(Player player, Mail message) { + this( + player, + new ArrayList() { + { + add(message); + } + }); + } + + public PacketMailChangeNotify(Player player, List mailList) { + this(player, mailList, null); + } + + public PacketMailChangeNotify(Player player, List mailList, List delMailIdList) { + super(PacketOpcodes.MailChangeNotify); + + var proto = MailChangeNotify.newBuilder(); + + if (mailList != null) { + for (Mail message : mailList) { + var mailTextContent = MailTextContent.newBuilder(); + mailTextContent.setTitle(message.mailContent.title); + mailTextContent.setContent(message.mailContent.content); + mailTextContent.setSender(message.mailContent.sender); + + List mailItems = new ArrayList<>(); + + for (Mail.MailItem item : message.itemList) { + var mailItem = MailItem.newBuilder(); + var itemParam = EquipParam.newBuilder(); + itemParam.setItemId(item.itemId); + itemParam.setItemNum(item.itemCount); + mailItem.setEquipParam(itemParam.build()); + + mailItems.add(mailItem.build()); + } + + var mailData = MailData.newBuilder(); + mailData.setMailId(player.getMailId(message)); + mailData.setMailTextContent(mailTextContent.build()); + mailData.addAllItemList(mailItems); + mailData.setSendTime((int) message.sendTime); + mailData.setExpireTime((int) message.expireTime); + mailData.setImportance(message.importance); + mailData.setIsRead(message.isRead); + mailData.setIsAttachmentGot(message.isAttachmentGot); + mailData.setCollectStateValue(message.stateValue); + + proto.addMailList(mailData.build()); + } + } + + if (delMailIdList != null) { + proto.addAllDelMailIdList(delMailIdList); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMarkMapRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMarkMapRsp.java index 90b39244f..94ed1c902 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMarkMapRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMarkMapRsp.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.managers.mapmark.MapMark; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint; -import emu.grasscutter.net.proto.MarkMapRspOuterClass.MarkMapRsp; -import java.util.Map; - -public class PacketMarkMapRsp extends BasePacket { - - public PacketMarkMapRsp(Map mapMarks) { - super(PacketOpcodes.MarkMapRsp); - - var proto = MarkMapRsp.newBuilder(); - proto.setRetcode(0); - - if (mapMarks != null) { - for (MapMark mapMark : mapMarks.values()) { - var markPoint = MapMarkPoint.newBuilder(); - markPoint.setSceneId(mapMark.getSceneId()); - markPoint.setName(mapMark.getName()); - markPoint.setPos(mapMark.getPosition().toProto()); - markPoint.setPointType(mapMark.getMapMarkPointType()); - markPoint.setFromType(mapMark.getMapMarkFromType()); - markPoint.setMonsterId(mapMark.getMonsterId()); - markPoint.setQuestId(mapMark.getQuestId()); - - proto.addMarkList(markPoint.build()); - } - } - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.managers.mapmark.MapMark; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.MapMarkPointOuterClass.MapMarkPoint; +import emu.grasscutter.net.proto.MarkMapRspOuterClass.MarkMapRsp; +import java.util.Map; + +public class PacketMarkMapRsp extends BasePacket { + + public PacketMarkMapRsp(Map mapMarks) { + super(PacketOpcodes.MarkMapRsp); + + var proto = MarkMapRsp.newBuilder(); + proto.setRetcode(0); + + if (mapMarks != null) { + for (MapMark mapMark : mapMarks.values()) { + var markPoint = MapMarkPoint.newBuilder(); + markPoint.setSceneId(mapMark.getSceneId()); + markPoint.setName(mapMark.getName()); + markPoint.setPos(mapMark.getPosition().toProto()); + markPoint.setPointType(mapMark.getMapMarkPointType()); + markPoint.setFromType(mapMark.getMapMarkFromType()); + markPoint.setMonsterId(mapMark.getMonsterId()); + markPoint.setQuestId(mapMark.getQuestId()); + + proto.addMarkList(markPoint.build()); + } + } + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMarkNewNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMarkNewNotify.java index 4c847c1f2..e6f8daa85 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMarkNewNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMarkNewNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.MarkNewNotifyOuterClass.MarkNewNotify; -import java.util.ArrayList; - -public class PacketMarkNewNotify extends BasePacket { - - public PacketMarkNewNotify(Player player, int markNewType, ArrayList idList) { - super(PacketOpcodes.MarkNewNotify); - - var proto = MarkNewNotify.newBuilder(); - proto.setMarkNewType(markNewType); - proto.addAllIdList(idList); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.MarkNewNotifyOuterClass.MarkNewNotify; +import java.util.ArrayList; + +public class PacketMarkNewNotify extends BasePacket { + + public PacketMarkNewNotify(Player player, int markNewType, ArrayList idList) { + super(PacketOpcodes.MarkNewNotify); + + var proto = MarkNewNotify.newBuilder(); + proto.setMarkNewType(markNewType); + proto.addAllIdList(idList); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMcoinExchangeHcoinRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMcoinExchangeHcoinRsp.java index 7d7ebe937..eac0c8948 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMcoinExchangeHcoinRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMcoinExchangeHcoinRsp.java @@ -1,19 +1,19 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.McoinExchangeHcoinRspOuterClass; - -public class PacketMcoinExchangeHcoinRsp extends BasePacket { - - public PacketMcoinExchangeHcoinRsp(int retCode) { - super(PacketOpcodes.McoinExchangeHcoinRsp); - - McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp proto = - McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp.newBuilder() - .setRetcode(retCode) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.McoinExchangeHcoinRspOuterClass; + +public class PacketMcoinExchangeHcoinRsp extends BasePacket { + + public PacketMcoinExchangeHcoinRsp(int retCode) { + super(PacketOpcodes.McoinExchangeHcoinRsp); + + McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp proto = + McoinExchangeHcoinRspOuterClass.McoinExchangeHcoinRsp.newBuilder() + .setRetcode(retCode) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameCreateBeatmapRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameCreateBeatmapRsp.java index c106f6caf..1e170a299 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameCreateBeatmapRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameCreateBeatmapRsp.java @@ -1,21 +1,21 @@ -// package emu.grasscutter.server.packet.send; -// -// import emu.grasscutter.net.packet.BasePacket; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameCreateBeatmapRspOuterClass; -// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; -// -// public class PacketMusicGameCreateBeatmapRsp extends BasePacket { -// -// public PacketMusicGameCreateBeatmapRsp(long musicShareId, -// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { -// super(PacketOpcodes.MusicGameCreateBeatmapRsp); -// -// var proto = MusicGameCreateBeatmapRspOuterClass.MusicGameCreateBeatmapRsp.newBuilder(); -// -// proto.setMusicShareId(musicShareId) -// .setUnknownEnum1(unknownEnum1); -// -// this.setData(proto); -// } -// } +// package emu.grasscutter.server.packet.send; +// +// import emu.grasscutter.net.packet.BasePacket; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameCreateBeatmapRspOuterClass; +// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; +// +// public class PacketMusicGameCreateBeatmapRsp extends BasePacket { +// +// public PacketMusicGameCreateBeatmapRsp(long musicShareId, +// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { +// super(PacketOpcodes.MusicGameCreateBeatmapRsp); +// +// var proto = MusicGameCreateBeatmapRspOuterClass.MusicGameCreateBeatmapRsp.newBuilder(); +// +// proto.setMusicShareId(musicShareId) +// .setUnknownEnum1(unknownEnum1); +// +// this.setData(proto); +// } +// } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameGetBeatmapRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameGetBeatmapRsp.java index bbafd4f2e..564034511 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameGetBeatmapRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameGetBeatmapRsp.java @@ -1,29 +1,29 @@ -// package emu.grasscutter.server.packet.send; -// -// import emu.grasscutter.net.packet.BasePacket; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicBeatmapOuterClass; -// import emu.grasscutter.net.proto.MusicBriefInfoOuterClass; -// import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass; -// import emu.grasscutter.net.proto.MusicGameGetBeatmapRspOuterClass; -// -// public class PacketMusicGameGetBeatmapRsp extends BasePacket { -// -// public PacketMusicGameGetBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, -// MusicBeatmapOuterClass.MusicBeatmap musicRecord, -// MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq req) { -// super(PacketOpcodes.MusicGameGetBeatmapRsp); -// -// var proto = MusicGameGetBeatmapRspOuterClass.MusicGameGetBeatmapRsp.newBuilder(); -// -// proto.setMusicBriefInfo(briefInfo) -// .setMusicShareId(briefInfo.getMusicShareId()) -// .setMusicRecord(musicRecord) -// .setUnknownEnum1(req.getUnknownEnum1()) -// .setReqType(req.getReqType()) -// ; -// -// -// this.setData(proto); -// } -// } +// package emu.grasscutter.server.packet.send; +// +// import emu.grasscutter.net.packet.BasePacket; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicBeatmapOuterClass; +// import emu.grasscutter.net.proto.MusicBriefInfoOuterClass; +// import emu.grasscutter.net.proto.MusicGameGetBeatmapReqOuterClass; +// import emu.grasscutter.net.proto.MusicGameGetBeatmapRspOuterClass; +// +// public class PacketMusicGameGetBeatmapRsp extends BasePacket { +// +// public PacketMusicGameGetBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, +// MusicBeatmapOuterClass.MusicBeatmap musicRecord, +// MusicGameGetBeatmapReqOuterClass.MusicGameGetBeatmapReq req) { +// super(PacketOpcodes.MusicGameGetBeatmapRsp); +// +// var proto = MusicGameGetBeatmapRspOuterClass.MusicGameGetBeatmapRsp.newBuilder(); +// +// proto.setMusicBriefInfo(briefInfo) +// .setMusicShareId(briefInfo.getMusicShareId()) +// .setMusicRecord(musicRecord) +// .setUnknownEnum1(req.getUnknownEnum1()) +// .setReqType(req.getReqType()) +// ; +// +// +// this.setData(proto); +// } +// } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameSearchBeatmapRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameSearchBeatmapRsp.java index 9bfd9ce18..7009a08af 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameSearchBeatmapRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameSearchBeatmapRsp.java @@ -1,36 +1,36 @@ -// package emu.grasscutter.server.packet.send; -// -// import emu.grasscutter.net.packet.BasePacket; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicBriefInfoOuterClass; -// import emu.grasscutter.net.proto.MusicGameSearchBeatmapRspOuterClass; -// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; -// -// public class PacketMusicGameSearchBeatmapRsp extends BasePacket { -// -// public PacketMusicGameSearchBeatmapRsp(int ret, -// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { -// super(PacketOpcodes.MusicGameSearchBeatmapRsp); -// -// var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder(); -// -// proto.setRetcode(ret) -// .setUnknownEnum1(unknownEnum1); -// -// this.setData(proto); -// } -// -// public PacketMusicGameSearchBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, -// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { -// super(PacketOpcodes.MusicGameSearchBeatmapRsp); -// -// var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder(); -// -// proto.setMusicBriefInfo(briefInfo) -// .setUnknownEnum1(unknownEnum1); -// -// this.setData(proto); -// } -// -// -// } +// package emu.grasscutter.server.packet.send; +// +// import emu.grasscutter.net.packet.BasePacket; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicBriefInfoOuterClass; +// import emu.grasscutter.net.proto.MusicGameSearchBeatmapRspOuterClass; +// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; +// +// public class PacketMusicGameSearchBeatmapRsp extends BasePacket { +// +// public PacketMusicGameSearchBeatmapRsp(int ret, +// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { +// super(PacketOpcodes.MusicGameSearchBeatmapRsp); +// +// var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder(); +// +// proto.setRetcode(ret) +// .setUnknownEnum1(unknownEnum1); +// +// this.setData(proto); +// } +// +// public PacketMusicGameSearchBeatmapRsp(MusicBriefInfoOuterClass.MusicBriefInfo briefInfo, +// MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum unknownEnum1) { +// super(PacketOpcodes.MusicGameSearchBeatmapRsp); +// +// var proto = MusicGameSearchBeatmapRspOuterClass.MusicGameSearchBeatmapRsp.newBuilder(); +// +// proto.setMusicBriefInfo(briefInfo) +// .setUnknownEnum1(unknownEnum1); +// +// this.setData(proto); +// } +// +// +// } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartRsp.java index 05052dc1a..137cfdb22 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.MusicGameStartRspOuterClass; - -public class PacketMusicGameStartRsp extends BasePacket { - - public PacketMusicGameStartRsp(int musicBasicId, long musicShareId) { - super(PacketOpcodes.MusicGameStartRsp); - - var proto = MusicGameStartRspOuterClass.MusicGameStartRsp.newBuilder(); - - proto.setMusicBasicId(musicBasicId).setUgcGuid(musicShareId); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.MusicGameStartRspOuterClass; + +public class PacketMusicGameStartRsp extends BasePacket { + + public PacketMusicGameStartRsp(int musicBasicId, long musicShareId) { + super(PacketOpcodes.MusicGameStartRsp); + + var proto = MusicGameStartRspOuterClass.MusicGameStartRsp.newBuilder(); + + proto.setMusicBasicId(musicBasicId).setUgcGuid(musicShareId); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartToPlayOthersBeatmapRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartToPlayOthersBeatmapRsp.java index a0a90a69f..4dd248ff2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartToPlayOthersBeatmapRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketMusicGameStartToPlayOthersBeatmapRsp.java @@ -1,22 +1,22 @@ -// package emu.grasscutter.server.packet.send; -// -// import emu.grasscutter.net.packet.BasePacket; -// import emu.grasscutter.net.packet.PacketOpcodes; -// import emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapRspOuterClass; -// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; -// -// public class PacketMusicGameStartToPlayOthersBeatmapRsp extends BasePacket { -// -// public -// PacketMusicGameStartToPlayOthersBeatmapRsp(MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum -// unknownEnum1) { -// super(PacketOpcodes.MusicGameStartToPlayOthersBeatmapRsp); -// -// var proto = -// MusicGameStartToPlayOthersBeatmapRspOuterClass.MusicGameStartToPlayOthersBeatmapRsp.newBuilder(); -// -// proto.setUnknownEnum1(unknownEnum1); -// -// this.setData(proto); -// } -// } +// package emu.grasscutter.server.packet.send; +// +// import emu.grasscutter.net.packet.BasePacket; +// import emu.grasscutter.net.packet.PacketOpcodes; +// import emu.grasscutter.net.proto.MusicGameStartToPlayOthersBeatmapRspOuterClass; +// import emu.grasscutter.net.proto.MusicGameUnknown1EnumOuterClass; +// +// public class PacketMusicGameStartToPlayOthersBeatmapRsp extends BasePacket { +// +// public +// PacketMusicGameStartToPlayOthersBeatmapRsp(MusicGameUnknown1EnumOuterClass.MusicGameUnknown1Enum +// unknownEnum1) { +// super(PacketOpcodes.MusicGameStartToPlayOthersBeatmapRsp); +// +// var proto = +// MusicGameStartToPlayOthersBeatmapRspOuterClass.MusicGameStartToPlayOthersBeatmapRsp.newBuilder(); +// +// proto.setUnknownEnum1(unknownEnum1); +// +// this.setData(proto); +// } +// } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketNpcTalkRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketNpcTalkRsp.java index c32416758..6c707f998 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketNpcTalkRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketNpcTalkRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.NpcTalkRspOuterClass.NpcTalkRsp; - -public class PacketNpcTalkRsp extends BasePacket { - public PacketNpcTalkRsp(int npcEntityId, int curTalkId, int entityId) { - super(PacketOpcodes.NpcTalkRsp); - - NpcTalkRsp p = - NpcTalkRsp.newBuilder() - .setNpcEntityId(npcEntityId) - .setCurTalkId(curTalkId) - .setEntityId(entityId) - .build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.NpcTalkRspOuterClass.NpcTalkRsp; + +public class PacketNpcTalkRsp extends BasePacket { + public PacketNpcTalkRsp(int npcEntityId, int curTalkId, int entityId) { + super(PacketOpcodes.NpcTalkRsp); + + NpcTalkRsp p = + NpcTalkRsp.newBuilder() + .setNpcEntityId(npcEntityId) + .setCurTalkId(curTalkId) + .setEntityId(entityId) + .build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketOpenStateChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketOpenStateChangeNotify.java index c1ecf5d25..1751b2c78 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketOpenStateChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketOpenStateChangeNotify.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.OpenStateChangeNotifyOuterClass.OpenStateChangeNotify; -import java.util.Map; - -// Sets openState to value -public class PacketOpenStateChangeNotify extends BasePacket { - - public PacketOpenStateChangeNotify(int openState, int value) { - super(PacketOpcodes.OpenStateChangeNotify); - - OpenStateChangeNotify proto = - OpenStateChangeNotify.newBuilder().putOpenStateMap(openState, value).build(); - - this.setData(proto); - } - - public PacketOpenStateChangeNotify(Map map) { - super(PacketOpcodes.OpenStateChangeNotify); - - OpenStateChangeNotify proto = - OpenStateChangeNotify.newBuilder().putAllOpenStateMap(map).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.OpenStateChangeNotifyOuterClass.OpenStateChangeNotify; +import java.util.Map; + +// Sets openState to value +public class PacketOpenStateChangeNotify extends BasePacket { + + public PacketOpenStateChangeNotify(int openState, int value) { + super(PacketOpcodes.OpenStateChangeNotify); + + OpenStateChangeNotify proto = + OpenStateChangeNotify.newBuilder().putOpenStateMap(openState, value).build(); + + this.setData(proto); + } + + public PacketOpenStateChangeNotify(Map map) { + super(PacketOpcodes.OpenStateChangeNotify); + + OpenStateChangeNotify proto = + OpenStateChangeNotify.newBuilder().putAllOpenStateMap(map).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPathfindingEnterSceneRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPathfindingEnterSceneRsp.java index 75daebb19..eb9458f21 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPathfindingEnterSceneRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPathfindingEnterSceneRsp.java @@ -1,11 +1,11 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketPathfindingEnterSceneRsp extends BasePacket { - - public PacketPathfindingEnterSceneRsp(int clientSequence) { - super(PacketOpcodes.PathfindingEnterSceneRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketPathfindingEnterSceneRsp extends BasePacket { + + public PacketPathfindingEnterSceneRsp(int clientSequence) { + super(PacketOpcodes.PathfindingEnterSceneRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalLineAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalLineAllDataRsp.java index dfd588c44..20f1e09e4 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalLineAllDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalLineAllDataRsp.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.data.GameData; -import emu.grasscutter.game.quest.GameMainQuest; -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PersonalLineAllDataRspOuterClass; -import java.util.Collection; -import java.util.Map; -import java.util.stream.Collectors; - -public class PacketPersonalLineAllDataRsp extends BasePacket { - - public PacketPersonalLineAllDataRsp(Collection gameMainQuestList) { - super(PacketOpcodes.PersonalLineAllDataRsp); - - var proto = PersonalLineAllDataRspOuterClass.PersonalLineAllDataRsp.newBuilder(); - - var questList = - gameMainQuestList.stream() - .map(GameMainQuest::getChildQuests) - .map(Map::values) - .flatMap(Collection::stream) - .map(GameQuest::getSubQuestId) - .collect(Collectors.toSet()); - - GameData.getPersonalLineDataMap().values().stream() - .filter(i -> !questList.contains(i.getStartQuestId())) - .forEach(i -> proto.addCanBeUnlockedPersonalLineList(i.getId())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.data.GameData; +import emu.grasscutter.game.quest.GameMainQuest; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PersonalLineAllDataRspOuterClass; +import java.util.Collection; +import java.util.Map; +import java.util.stream.Collectors; + +public class PacketPersonalLineAllDataRsp extends BasePacket { + + public PacketPersonalLineAllDataRsp(Collection gameMainQuestList) { + super(PacketOpcodes.PersonalLineAllDataRsp); + + var proto = PersonalLineAllDataRspOuterClass.PersonalLineAllDataRsp.newBuilder(); + + var questList = + gameMainQuestList.stream() + .map(GameMainQuest::getChildQuests) + .map(Map::values) + .flatMap(Collection::stream) + .map(GameQuest::getSubQuestId) + .collect(Collectors.toSet()); + + GameData.getPersonalLineDataMap().values().stream() + .filter(i -> !questList.contains(i.getStartQuestId())) + .forEach(i -> proto.addCanBeUnlockedPersonalLineList(i.getId())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java index c633980c9..3ef09d755 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPersonalSceneJumpRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PersonalSceneJumpRspOuterClass.PersonalSceneJumpRsp; -import emu.grasscutter.utils.Position; - -public class PacketPersonalSceneJumpRsp extends BasePacket { - - public PacketPersonalSceneJumpRsp(int sceneId, Position pos) { - super(PacketOpcodes.PersonalSceneJumpRsp); - - PersonalSceneJumpRsp proto = - PersonalSceneJumpRsp.newBuilder().setDestSceneId(sceneId).setDestPos(pos.toProto()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PersonalSceneJumpRspOuterClass.PersonalSceneJumpRsp; +import emu.grasscutter.utils.Position; + +public class PacketPersonalSceneJumpRsp extends BasePacket { + + public PacketPersonalSceneJumpRsp(int sceneId, Position pos) { + super(PacketOpcodes.PersonalSceneJumpRsp); + + PersonalSceneJumpRsp proto = + PersonalSceneJumpRsp.newBuilder().setDestSceneId(sceneId).setDestPos(pos.toProto()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPingRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPingRsp.java index 539739b6b..8fb1744ea 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPingRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPingRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PingRspOuterClass.PingRsp; - -public class PacketPingRsp extends BasePacket { - - public PacketPingRsp(int clientSeq, int time) { - super(PacketOpcodes.PingRsp, clientSeq); - - PingRsp p = PingRsp.newBuilder().setClientTime(time).build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PingRspOuterClass.PingRsp; + +public class PacketPingRsp extends BasePacket { + + public PacketPingRsp(int clientSeq, int time) { + super(PacketOpcodes.PingRsp, clientSeq); + + PingRsp p = PingRsp.newBuilder().setClientTime(time).build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpNotify.java index 6f7c9e80c..8b76f1796 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpNotify.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpNotifyOuterClass.PlayerApplyEnterMpNotify; - -public class PacketPlayerApplyEnterMpNotify extends BasePacket { - - public PacketPlayerApplyEnterMpNotify(Player srcPlayer) { - super(PacketOpcodes.PlayerApplyEnterMpNotify); - - PlayerApplyEnterMpNotify proto = - PlayerApplyEnterMpNotify.newBuilder() - .setSrcPlayerInfo(srcPlayer.getOnlinePlayerInfo()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpNotifyOuterClass.PlayerApplyEnterMpNotify; + +public class PacketPlayerApplyEnterMpNotify extends BasePacket { + + public PacketPlayerApplyEnterMpNotify(Player srcPlayer) { + super(PacketOpcodes.PlayerApplyEnterMpNotify); + + PlayerApplyEnterMpNotify proto = + PlayerApplyEnterMpNotify.newBuilder() + .setSrcPlayerInfo(srcPlayer.getOnlinePlayerInfo()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultNotify.java index 2b0e9a8c8..871ed0d80 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultNotify.java @@ -1,45 +1,45 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass; -import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify; - -public class PacketPlayerApplyEnterMpResultNotify extends BasePacket { - - public PacketPlayerApplyEnterMpResultNotify( - Player target, - boolean isAgreed, - PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason reason) { - super(PacketOpcodes.PlayerApplyEnterMpResultNotify); - - PlayerApplyEnterMpResultNotify proto = - PlayerApplyEnterMpResultNotify.newBuilder() - .setTargetUid(target.getUid()) - .setTargetNickname(target.getNickname()) - .setIsAgreed(isAgreed) - .setReason(reason) - .build(); - - this.setData(proto); - } - - public PacketPlayerApplyEnterMpResultNotify( - int targetId, - String targetName, - boolean isAgreed, - PlayerApplyEnterMpResultNotify.Reason reason) { - super(PacketOpcodes.PlayerApplyEnterMpResultNotify); - - PlayerApplyEnterMpResultNotify proto = - PlayerApplyEnterMpResultNotify.newBuilder() - .setTargetUid(targetId) - .setTargetNickname(targetName) - .setIsAgreed(isAgreed) - .setReason(reason) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass; +import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify; + +public class PacketPlayerApplyEnterMpResultNotify extends BasePacket { + + public PacketPlayerApplyEnterMpResultNotify( + Player target, + boolean isAgreed, + PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason reason) { + super(PacketOpcodes.PlayerApplyEnterMpResultNotify); + + PlayerApplyEnterMpResultNotify proto = + PlayerApplyEnterMpResultNotify.newBuilder() + .setTargetUid(target.getUid()) + .setTargetNickname(target.getNickname()) + .setIsAgreed(isAgreed) + .setReason(reason) + .build(); + + this.setData(proto); + } + + public PacketPlayerApplyEnterMpResultNotify( + int targetId, + String targetName, + boolean isAgreed, + PlayerApplyEnterMpResultNotify.Reason reason) { + super(PacketOpcodes.PlayerApplyEnterMpResultNotify); + + PlayerApplyEnterMpResultNotify proto = + PlayerApplyEnterMpResultNotify.newBuilder() + .setTargetUid(targetId) + .setTargetNickname(targetName) + .setIsAgreed(isAgreed) + .setReason(reason) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultRsp.java index f6a799a20..20b05c53e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpResultRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpResultRspOuterClass.PlayerApplyEnterMpResultRsp; - -public class PacketPlayerApplyEnterMpResultRsp extends BasePacket { - - public PacketPlayerApplyEnterMpResultRsp(int applyUid, boolean isAgreed) { - super(PacketOpcodes.PlayerApplyEnterMpResultRsp); - - PlayerApplyEnterMpResultRsp proto = - PlayerApplyEnterMpResultRsp.newBuilder() - .setApplyUid(applyUid) - .setIsAgreed(isAgreed) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpResultRspOuterClass.PlayerApplyEnterMpResultRsp; + +public class PacketPlayerApplyEnterMpResultRsp extends BasePacket { + + public PacketPlayerApplyEnterMpResultRsp(int applyUid, boolean isAgreed) { + super(PacketOpcodes.PlayerApplyEnterMpResultRsp); + + PlayerApplyEnterMpResultRsp proto = + PlayerApplyEnterMpResultRsp.newBuilder() + .setApplyUid(applyUid) + .setIsAgreed(isAgreed) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpRsp.java index 6c423425f..f7f687c0f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerApplyEnterMpRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerApplyEnterMpRspOuterClass.PlayerApplyEnterMpRsp; - -public class PacketPlayerApplyEnterMpRsp extends BasePacket { - - public PacketPlayerApplyEnterMpRsp(int targetUid) { - super(PacketOpcodes.PlayerApplyEnterMpRsp); - - PlayerApplyEnterMpRsp proto = - PlayerApplyEnterMpRsp.newBuilder().setTargetUid(targetUid).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerApplyEnterMpRspOuterClass.PlayerApplyEnterMpRsp; + +public class PacketPlayerApplyEnterMpRsp extends BasePacket { + + public PacketPlayerApplyEnterMpRsp(int targetUid) { + super(PacketOpcodes.PlayerApplyEnterMpRsp); + + PlayerApplyEnterMpRsp proto = + PlayerApplyEnterMpRsp.newBuilder().setTargetUid(targetUid).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatNotify.java index f257362e1..f54138e7c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatNotify.java @@ -1,58 +1,58 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; -import emu.grasscutter.net.proto.PlayerChatNotifyOuterClass.PlayerChatNotify; - -public class PacketPlayerChatNotify extends BasePacket { - - public PacketPlayerChatNotify(Player sender, int channelId, String message) { - super(PacketOpcodes.PlayerChatNotify); - - ChatInfo info = - ChatInfo.newBuilder() - .setTime((int) (System.currentTimeMillis() / 1000)) - .setUid(sender.getUid()) - .setText(message) - .build(); - - PlayerChatNotify proto = - PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); - - this.setData(proto); - } - - public PacketPlayerChatNotify(Player sender, int channelId, int emote) { - super(PacketOpcodes.PlayerChatNotify); - - ChatInfo info = - ChatInfo.newBuilder() - .setTime((int) (System.currentTimeMillis() / 1000)) - .setUid(sender.getUid()) - .setIcon(emote) - .build(); - - PlayerChatNotify proto = - PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); - - this.setData(proto); - } - - public PacketPlayerChatNotify(Player sender, int channelId, ChatInfo.SystemHint systemHint) { - super(PacketOpcodes.PlayerChatNotify); - - ChatInfo info = - ChatInfo.newBuilder() - .setTime((int) (System.currentTimeMillis() / 1000)) - .setUid(sender.getUid()) - .setSystemHint(systemHint) - .build(); - - PlayerChatNotify proto = - PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; +import emu.grasscutter.net.proto.PlayerChatNotifyOuterClass.PlayerChatNotify; + +public class PacketPlayerChatNotify extends BasePacket { + + public PacketPlayerChatNotify(Player sender, int channelId, String message) { + super(PacketOpcodes.PlayerChatNotify); + + ChatInfo info = + ChatInfo.newBuilder() + .setTime((int) (System.currentTimeMillis() / 1000)) + .setUid(sender.getUid()) + .setText(message) + .build(); + + PlayerChatNotify proto = + PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); + + this.setData(proto); + } + + public PacketPlayerChatNotify(Player sender, int channelId, int emote) { + super(PacketOpcodes.PlayerChatNotify); + + ChatInfo info = + ChatInfo.newBuilder() + .setTime((int) (System.currentTimeMillis() / 1000)) + .setUid(sender.getUid()) + .setIcon(emote) + .build(); + + PlayerChatNotify proto = + PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); + + this.setData(proto); + } + + public PacketPlayerChatNotify(Player sender, int channelId, ChatInfo.SystemHint systemHint) { + super(PacketOpcodes.PlayerChatNotify); + + ChatInfo info = + ChatInfo.newBuilder() + .setTime((int) (System.currentTimeMillis() / 1000)) + .setUid(sender.getUid()) + .setSystemHint(systemHint) + .build(); + + PlayerChatNotify proto = + PlayerChatNotify.newBuilder().setChannelId(channelId).setChatInfo(info).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatRsp.java index f89427fb9..abf86cac0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerChatRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerChatRspOuterClass.PlayerChatRsp; - -public class PacketPlayerChatRsp extends BasePacket { - - public PacketPlayerChatRsp() { - super(PacketOpcodes.PlayerChatRsp); - - PlayerChatRsp proto = PlayerChatRsp.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerChatRspOuterClass.PlayerChatRsp; + +public class PacketPlayerChatRsp extends BasePacket { + + public PacketPlayerChatRsp() { + super(PacketOpcodes.PlayerChatRsp); + + PlayerChatRsp proto = PlayerChatRsp.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCompoundMaterialRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCompoundMaterialRsp.java index 7c46bc5ef..e42efb565 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCompoundMaterialRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCompoundMaterialRsp.java @@ -1,36 +1,36 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; -import emu.grasscutter.net.proto.PlayerCompoundMaterialRspOuterClass.PlayerCompoundMaterialRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; - -public class PacketPlayerCompoundMaterialRsp extends BasePacket { - /** - * Builder for successful message. - * - * @param compoundQueueData new compound queue - */ - public PacketPlayerCompoundMaterialRsp(CompoundQueueData compoundQueueData) { - super(PacketOpcodes.PlayerCompoundMaterialRsp); - PlayerCompoundMaterialRsp proto = - PlayerCompoundMaterialRsp.newBuilder() - .setCompoundQueueData(compoundQueueData) - .setRetcode(Retcode.RET_SUCC_VALUE) - .build(); - setData(proto); - } - - /** - * Builder for failed message. - * - * @param retcode error code - */ - public PacketPlayerCompoundMaterialRsp(int retcode) { - super(PacketOpcodes.PlayerCompoundMaterialRsp); - PlayerCompoundMaterialRsp proto = - PlayerCompoundMaterialRsp.newBuilder().setRetcode(retcode).build(); - setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CompoundQueueDataOuterClass.CompoundQueueData; +import emu.grasscutter.net.proto.PlayerCompoundMaterialRspOuterClass.PlayerCompoundMaterialRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +public class PacketPlayerCompoundMaterialRsp extends BasePacket { + /** + * Builder for successful message. + * + * @param compoundQueueData new compound queue + */ + public PacketPlayerCompoundMaterialRsp(CompoundQueueData compoundQueueData) { + super(PacketOpcodes.PlayerCompoundMaterialRsp); + PlayerCompoundMaterialRsp proto = + PlayerCompoundMaterialRsp.newBuilder() + .setCompoundQueueData(compoundQueueData) + .setRetcode(Retcode.RET_SUCC_VALUE) + .build(); + setData(proto); + } + + /** + * Builder for failed message. + * + * @param retcode error code + */ + public PacketPlayerCompoundMaterialRsp(int retcode) { + super(PacketOpcodes.PlayerCompoundMaterialRsp); + PlayerCompoundMaterialRsp proto = + PlayerCompoundMaterialRsp.newBuilder().setRetcode(retcode).build(); + setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookArgsRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookArgsRsp.java index 0fdcb5172..8b9c1c84b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookArgsRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookArgsRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerCookArgsRspOuterClass.PlayerCookArgsRsp; - -public class PacketPlayerCookArgsRsp extends BasePacket { - - public PacketPlayerCookArgsRsp() { - super(PacketOpcodes.PlayerCookArgsRsp); - - PlayerCookArgsRsp proto = PlayerCookArgsRsp.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerCookArgsRspOuterClass.PlayerCookArgsRsp; + +public class PacketPlayerCookArgsRsp extends BasePacket { + + public PacketPlayerCookArgsRsp() { + super(PacketOpcodes.PlayerCookArgsRsp); + + PlayerCookArgsRsp proto = PlayerCookArgsRsp.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookRsp.java index 32cc5a518..b27b25fa2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerCookRsp.java @@ -1,39 +1,39 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.PlayerCookRspOuterClass.PlayerCookRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; - -public class PacketPlayerCookRsp extends BasePacket { - public PacketPlayerCookRsp(Retcode retcode) { - super(PacketOpcodes.PlayerCookRsp); - - PlayerCookRsp proto = PlayerCookRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } - - public PacketPlayerCookRsp( - List output, int quality, int count, int recipeId, int proficiency) { - super(PacketOpcodes.PlayerCookRsp); - - PlayerCookRsp.Builder proto = - PlayerCookRsp.newBuilder() - .setRecipeData( - CookRecipeData.newBuilder().setRecipeId(recipeId).setProficiency(proficiency)) - .setQteQuality(quality) - .setCookCount(count); - - for (var item : output) { - proto.addItemList( - ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount())); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.CookRecipeDataOuterClass.CookRecipeData; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.PlayerCookRspOuterClass.PlayerCookRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; + +public class PacketPlayerCookRsp extends BasePacket { + public PacketPlayerCookRsp(Retcode retcode) { + super(PacketOpcodes.PlayerCookRsp); + + PlayerCookRsp proto = PlayerCookRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } + + public PacketPlayerCookRsp( + List output, int quality, int count, int recipeId, int proficiency) { + super(PacketOpcodes.PlayerCookRsp); + + PlayerCookRsp.Builder proto = + PlayerCookRsp.newBuilder() + .setRecipeData( + CookRecipeData.newBuilder().setRecipeId(recipeId).setProficiency(proficiency)) + .setQteQuality(quality) + .setCookCount(count); + + for (var item : output) { + proto.addItemList( + ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount())); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java index c9275033b..f2cb61cbb 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerDataNotify.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerDataNotifyOuterClass.PlayerDataNotify; -import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; - -public class PacketPlayerDataNotify extends BasePacket { - - public PacketPlayerDataNotify(Player player) { - super(PacketOpcodes.PlayerDataNotify, 2); - - PlayerDataNotify.Builder p = - PlayerDataNotify.newBuilder() - .setNickName(player.getNickname()) - .setServerTime(System.currentTimeMillis()) - .setIsFirstLoginToday(true) - .setRegionId(player.getRegionId()); - - player - .getProperties() - .forEach( - (key, value) -> { - p.putPropMap( - key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build()); - }); - - this.setData(p.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerDataNotifyOuterClass.PlayerDataNotify; +import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; + +public class PacketPlayerDataNotify extends BasePacket { + + public PacketPlayerDataNotify(Player player) { + super(PacketOpcodes.PlayerDataNotify, 2); + + PlayerDataNotify.Builder p = + PlayerDataNotify.newBuilder() + .setNickName(player.getNickname()) + .setServerTime(System.currentTimeMillis()) + .setIsFirstLoginToday(true) + .setRegionId(player.getRegionId()); + + player + .getProperties() + .forEach( + (key, value) -> { + p.putPropMap( + key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build()); + }); + + this.setData(p.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneInfoNotify.java index 9b8db75f6..988b6322d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneInfoNotify.java @@ -1,58 +1,58 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilityControlBlockOuterClass; -import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; -import emu.grasscutter.net.proto.AvatarEnterSceneInfoOuterClass.AvatarEnterSceneInfo; -import emu.grasscutter.net.proto.MPLevelEntityInfoOuterClass.MPLevelEntityInfo; -import emu.grasscutter.net.proto.PlayerEnterSceneInfoNotifyOuterClass.PlayerEnterSceneInfoNotify; -import emu.grasscutter.net.proto.TeamEnterSceneInfoOuterClass.TeamEnterSceneInfo; - -public class PacketPlayerEnterSceneInfoNotify extends BasePacket { - - public PacketPlayerEnterSceneInfoNotify(Player player) { - super(PacketOpcodes.PlayerEnterSceneInfoNotify); - - AbilitySyncStateInfo empty = AbilitySyncStateInfo.newBuilder().build(); - - PlayerEnterSceneInfoNotify.Builder proto = - PlayerEnterSceneInfoNotify.newBuilder() - .setCurAvatarEntityId(player.getTeamManager().getCurrentAvatarEntity().getId()) - .setEnterSceneToken(player.getEnterSceneToken()); - - proto.setTeamEnterInfo( - TeamEnterSceneInfo.newBuilder() - .setTeamEntityId(player.getTeamManager().getEntityId()) // 150995833 - .setTeamAbilityInfo(empty) - .setAbilityControlBlock( - AbilityControlBlockOuterClass.AbilityControlBlock.newBuilder().build())); - proto.setMpLevelEntityInfo( - MPLevelEntityInfo.newBuilder() - .setEntityId(player.getWorld().getLevelEntityId()) // 184550274 - .setAuthorityPeerId(player.getWorld().getHostPeerId()) - .setAbilityInfo(empty)); - - for (EntityAvatar avatarEntity : player.getTeamManager().getActiveTeam()) { - GameItem weapon = avatarEntity.getAvatar().getWeapon(); - long weaponGuid = weapon != null ? weapon.getGuid() : 0; - - AvatarEnterSceneInfo avatarInfo = - AvatarEnterSceneInfo.newBuilder() - .setAvatarGuid(avatarEntity.getAvatar().getGuid()) - .setAvatarEntityId(avatarEntity.getId()) - .setWeaponGuid(weaponGuid) - .setWeaponEntityId(avatarEntity.getWeaponEntityId()) - .setAvatarAbilityInfo(empty) - .setWeaponAbilityInfo(empty) - .build(); - - proto.addAvatarEnterInfo(avatarInfo); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilityControlBlockOuterClass; +import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; +import emu.grasscutter.net.proto.AvatarEnterSceneInfoOuterClass.AvatarEnterSceneInfo; +import emu.grasscutter.net.proto.MPLevelEntityInfoOuterClass.MPLevelEntityInfo; +import emu.grasscutter.net.proto.PlayerEnterSceneInfoNotifyOuterClass.PlayerEnterSceneInfoNotify; +import emu.grasscutter.net.proto.TeamEnterSceneInfoOuterClass.TeamEnterSceneInfo; + +public class PacketPlayerEnterSceneInfoNotify extends BasePacket { + + public PacketPlayerEnterSceneInfoNotify(Player player) { + super(PacketOpcodes.PlayerEnterSceneInfoNotify); + + AbilitySyncStateInfo empty = AbilitySyncStateInfo.newBuilder().build(); + + PlayerEnterSceneInfoNotify.Builder proto = + PlayerEnterSceneInfoNotify.newBuilder() + .setCurAvatarEntityId(player.getTeamManager().getCurrentAvatarEntity().getId()) + .setEnterSceneToken(player.getEnterSceneToken()); + + proto.setTeamEnterInfo( + TeamEnterSceneInfo.newBuilder() + .setTeamEntityId(player.getTeamManager().getEntityId()) // 150995833 + .setTeamAbilityInfo(empty) + .setAbilityControlBlock( + AbilityControlBlockOuterClass.AbilityControlBlock.newBuilder().build())); + proto.setMpLevelEntityInfo( + MPLevelEntityInfo.newBuilder() + .setEntityId(player.getWorld().getLevelEntityId()) // 184550274 + .setAuthorityPeerId(player.getWorld().getHostPeerId()) + .setAbilityInfo(empty)); + + for (EntityAvatar avatarEntity : player.getTeamManager().getActiveTeam()) { + GameItem weapon = avatarEntity.getAvatar().getWeapon(); + long weaponGuid = weapon != null ? weapon.getGuid() : 0; + + AvatarEnterSceneInfo avatarInfo = + AvatarEnterSceneInfo.newBuilder() + .setAvatarGuid(avatarEntity.getAvatar().getGuid()) + .setAvatarEntityId(avatarEntity.getId()) + .setWeaponGuid(weaponGuid) + .setWeaponEntityId(avatarEntity.getWeaponEntityId()) + .setAvatarAbilityInfo(empty) + .setWeaponAbilityInfo(empty) + .build(); + + proto.addAvatarEnterInfo(avatarInfo); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerGetForceQuitBanInfoRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerGetForceQuitBanInfoRsp.java index 49cf83d40..8f66c5479 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerGetForceQuitBanInfoRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerGetForceQuitBanInfoRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerGetForceQuitBanInfoRspOuterClass.PlayerGetForceQuitBanInfoRsp; - -public class PacketPlayerGetForceQuitBanInfoRsp extends BasePacket { - - public PacketPlayerGetForceQuitBanInfoRsp(int retcode) { - super(PacketOpcodes.PlayerGetForceQuitBanInfoRsp); - - PlayerGetForceQuitBanInfoRsp proto = - PlayerGetForceQuitBanInfoRsp.newBuilder().setRetcode(retcode).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerGetForceQuitBanInfoRspOuterClass.PlayerGetForceQuitBanInfoRsp; + +public class PacketPlayerGetForceQuitBanInfoRsp extends BasePacket { + + public PacketPlayerGetForceQuitBanInfoRsp(int retcode) { + super(PacketOpcodes.PlayerGetForceQuitBanInfoRsp); + + PlayerGetForceQuitBanInfoRsp proto = + PlayerGetForceQuitBanInfoRsp.newBuilder().setRetcode(retcode).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java index a05c6c923..3ba251101 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLevelRewardUpdateNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerLevelRewardUpdateNotifyOuterClass.PlayerLevelRewardUpdateNotify; -import java.util.Set; - -public class PacketPlayerLevelRewardUpdateNotify extends BasePacket { - - public PacketPlayerLevelRewardUpdateNotify(Set rewardedLevels) { - super(PacketOpcodes.PlayerLevelRewardUpdateNotify); - - PlayerLevelRewardUpdateNotify.Builder proto = PlayerLevelRewardUpdateNotify.newBuilder(); - - for (Integer level : rewardedLevels) { - proto.addLevelList(level); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerLevelRewardUpdateNotifyOuterClass.PlayerLevelRewardUpdateNotify; +import java.util.Set; + +public class PacketPlayerLevelRewardUpdateNotify extends BasePacket { + + public PacketPlayerLevelRewardUpdateNotify(Set rewardedLevels) { + super(PacketOpcodes.PlayerLevelRewardUpdateNotify); + + PlayerLevelRewardUpdateNotify.Builder proto = PlayerLevelRewardUpdateNotify.newBuilder(); + + for (Integer level : rewardedLevels) { + proto.addLevelList(level); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java index 71a1b363e..e134ad064 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java @@ -1,74 +1,74 @@ -package emu.grasscutter.server.packet.send; - -import static emu.grasscutter.config.Configuration.*; - -import com.google.protobuf.ByteString; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.Grasscutter.ServerRunMode; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp; -import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass; -import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo; -import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.http.dispatch.RegionHandler; -import emu.grasscutter.utils.Crypto; -import java.util.Objects; - -public class PacketPlayerLoginRsp extends BasePacket { - - private static QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp regionCache; - - public PacketPlayerLoginRsp(GameSession session) { - super(PacketOpcodes.PlayerLoginRsp, 1); - - this.setUseDispatchKey(true); - - RegionInfo info; - - if (SERVER.runMode == ServerRunMode.GAME_ONLY) { - if (regionCache == null) { - try { - // todo: we might want to push custom config to client - RegionInfo serverRegion = - RegionInfo.newBuilder() - .setGateserverIp(lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress)) - .setGateserverPort(lr(GAME_INFO.accessPort, GAME_INFO.bindPort)) - .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) - .build(); - - regionCache = - QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.newBuilder() - .setRegionInfo(serverRegion) - .build(); - } catch (Exception e) { - Grasscutter.getLogger().error("Error while initializing region cache!", e); - } - } - - info = regionCache.getRegionInfo(); - } else { - info = Objects.requireNonNull(RegionHandler.getCurrentRegion()).getRegionInfo(); - } - - PlayerLoginRsp p = - PlayerLoginRsp.newBuilder() - .setIsUseAbilityHash(true) // true - .setAbilityHashCode(1844674) // 1844674 - .setGameBiz("hk4e_global") - .setClientDataVersion(info.getClientDataVersion()) - .setClientSilenceDataVersion(info.getClientSilenceDataVersion()) - .setClientMd5(info.getClientDataMd5()) - .setClientSilenceMd5(info.getClientSilenceDataMd5()) - .setResVersionConfig(info.getResVersionConfig()) - .setClientVersionSuffix(info.getClientVersionSuffix()) - .setClientSilenceVersionSuffix(info.getClientSilenceVersionSuffix()) - .setIsScOpen(false) - // .setScInfo(ByteString.copyFrom(new byte[] {})) - .setRegisterCps("mihoyo") - .setCountryCode("US") - .build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import static emu.grasscutter.config.Configuration.*; + +import com.google.protobuf.ByteString; +import emu.grasscutter.Grasscutter; +import emu.grasscutter.Grasscutter.ServerRunMode; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerLoginRspOuterClass.PlayerLoginRsp; +import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass; +import emu.grasscutter.net.proto.RegionInfoOuterClass.RegionInfo; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.http.dispatch.RegionHandler; +import emu.grasscutter.utils.Crypto; +import java.util.Objects; + +public class PacketPlayerLoginRsp extends BasePacket { + + private static QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp regionCache; + + public PacketPlayerLoginRsp(GameSession session) { + super(PacketOpcodes.PlayerLoginRsp, 1); + + this.setUseDispatchKey(true); + + RegionInfo info; + + if (SERVER.runMode == ServerRunMode.GAME_ONLY) { + if (regionCache == null) { + try { + // todo: we might want to push custom config to client + RegionInfo serverRegion = + RegionInfo.newBuilder() + .setGateserverIp(lr(GAME_INFO.accessAddress, GAME_INFO.bindAddress)) + .setGateserverPort(lr(GAME_INFO.accessPort, GAME_INFO.bindPort)) + .setSecretKey(ByteString.copyFrom(Crypto.DISPATCH_SEED)) + .build(); + + regionCache = + QueryCurrRegionHttpRspOuterClass.QueryCurrRegionHttpRsp.newBuilder() + .setRegionInfo(serverRegion) + .build(); + } catch (Exception e) { + Grasscutter.getLogger().error("Error while initializing region cache!", e); + } + } + + info = regionCache.getRegionInfo(); + } else { + info = Objects.requireNonNull(RegionHandler.getCurrentRegion()).getRegionInfo(); + } + + PlayerLoginRsp p = + PlayerLoginRsp.newBuilder() + .setIsUseAbilityHash(true) // true + .setAbilityHashCode(1844674) // 1844674 + .setGameBiz("hk4e_global") + .setClientDataVersion(info.getClientDataVersion()) + .setClientSilenceDataVersion(info.getClientSilenceDataVersion()) + .setClientMd5(info.getClientDataMd5()) + .setClientSilenceMd5(info.getClientSilenceDataMd5()) + .setResVersionConfig(info.getResVersionConfig()) + .setClientVersionSuffix(info.getClientVersionSuffix()) + .setClientSilenceVersionSuffix(info.getClientSilenceVersionSuffix()) + .setIsScOpen(false) + // .setScInfo(ByteString.copyFrom(new byte[] {})) + .setRegisterCps("mihoyo") + .setCountryCode("US") + .build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeNotify.java index f83d79c18..64e43a728 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.PlayerProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerPropChangeNotifyOuterClass.PlayerPropChangeNotify; - -public class PacketPlayerPropChangeNotify extends BasePacket { - - public PacketPlayerPropChangeNotify(Player player, PlayerProperty prop, int delta) { - super(PacketOpcodes.PlayerPropChangeNotify); - - this.buildHeader(0); - - PlayerPropChangeNotify proto = - PlayerPropChangeNotify.newBuilder().setPropType(prop.getId()).setPropDelta(delta).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerPropChangeNotifyOuterClass.PlayerPropChangeNotify; + +public class PacketPlayerPropChangeNotify extends BasePacket { + + public PacketPlayerPropChangeNotify(Player player, PlayerProperty prop, int delta) { + super(PacketOpcodes.PlayerPropChangeNotify); + + this.buildHeader(0); + + PlayerPropChangeNotify proto = + PlayerPropChangeNotify.newBuilder().setPropType(prop.getId()).setPropDelta(delta).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeReasonNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeReasonNotify.java index 705471797..bbc03b907 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeReasonNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropChangeReasonNotify.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.PlayerProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerPropChangeReasonNotifyOuterClass.PlayerPropChangeReasonNotify; -import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; - -public class PacketPlayerPropChangeReasonNotify extends BasePacket { - - public PacketPlayerPropChangeReasonNotify( - Player player, - PlayerProperty prop, - int oldValue, - int newValue, - PropChangeReason changeReason) { - super(PacketOpcodes.PlayerPropChangeReasonNotify); - - this.buildHeader(0); - - PlayerPropChangeReasonNotify proto = - PlayerPropChangeReasonNotify.newBuilder() - .setPropType(prop.getId()) - .setReason(changeReason) - .setOldValue(oldValue) - .setCurValue(newValue) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerPropChangeReasonNotifyOuterClass.PlayerPropChangeReasonNotify; +import emu.grasscutter.net.proto.PropChangeReasonOuterClass.PropChangeReason; + +public class PacketPlayerPropChangeReasonNotify extends BasePacket { + + public PacketPlayerPropChangeReasonNotify( + Player player, + PlayerProperty prop, + int oldValue, + int newValue, + PropChangeReason changeReason) { + super(PacketOpcodes.PlayerPropChangeReasonNotify); + + this.buildHeader(0); + + PlayerPropChangeReasonNotify proto = + PlayerPropChangeReasonNotify.newBuilder() + .setPropType(prop.getId()) + .setReason(changeReason) + .setOldValue(oldValue) + .setCurValue(newValue) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropNotify.java index 01d4b6da6..47127f489 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerPropNotify.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.props.PlayerProperty; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerPropNotifyOuterClass.PlayerPropNotify; -import emu.grasscutter.utils.ProtoHelper; - -public class PacketPlayerPropNotify extends BasePacket { - - public PacketPlayerPropNotify(Player player, PlayerProperty prop) { - super(PacketOpcodes.PlayerPropNotify); - - this.buildHeader(0); - - PlayerPropNotify proto = - PlayerPropNotify.newBuilder() - .putPropMap(prop.getId(), ProtoHelper.newPropValue(prop, player.getProperty(prop))) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.PlayerProperty; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerPropNotifyOuterClass.PlayerPropNotify; +import emu.grasscutter.utils.ProtoHelper; + +public class PacketPlayerPropNotify extends BasePacket { + + public PacketPlayerPropNotify(Player player, PlayerProperty prop) { + super(PacketOpcodes.PlayerPropNotify); + + this.buildHeader(0); + + PlayerPropNotify proto = + PlayerPropNotify.newBuilder() + .putPropMap(prop.getId(), ProtoHelper.newPropValue(prop, player.getProperty(prop))) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerStoreNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerStoreNotify.java index 1b357aa0a..7cf87ef19 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerStoreNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerStoreNotify.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import static emu.grasscutter.config.Configuration.GAME_OPTIONS; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemOuterClass.Item; -import emu.grasscutter.net.proto.PlayerStoreNotifyOuterClass.PlayerStoreNotify; -import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; - -public class PacketPlayerStoreNotify extends BasePacket { - - public PacketPlayerStoreNotify(Player player) { - super(PacketOpcodes.PlayerStoreNotify); - - this.buildHeader(2); - - PlayerStoreNotify.Builder p = - PlayerStoreNotify.newBuilder() - .setStoreType(StoreType.STORE_TYPE_PACK) - .setWeightLimit(GAME_OPTIONS.inventoryLimits.all); - - for (GameItem item : player.getInventory()) { - Item itemProto = item.toProto(); - p.addItemList(itemProto); - } - - this.setData(p.build()); - } -} +package emu.grasscutter.server.packet.send; + +import static emu.grasscutter.config.Configuration.GAME_OPTIONS; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemOuterClass.Item; +import emu.grasscutter.net.proto.PlayerStoreNotifyOuterClass.PlayerStoreNotify; +import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; + +public class PacketPlayerStoreNotify extends BasePacket { + + public PacketPlayerStoreNotify(Player player) { + super(PacketOpcodes.PlayerStoreNotify); + + this.buildHeader(2); + + PlayerStoreNotify.Builder p = + PlayerStoreNotify.newBuilder() + .setStoreType(StoreType.STORE_TYPE_PACK) + .setWeightLimit(GAME_OPTIONS.inventoryLimits.all); + + for (GameItem item : player.getInventory()) { + Item itemProto = item.toProto(); + p.addItemList(itemProto); + } + + this.setData(p.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerTimeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerTimeNotify.java index 370a48838..d13ee68aa 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerTimeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerTimeNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerTimeNotifyOuterClass.PlayerTimeNotify; - -public class PacketPlayerTimeNotify extends BasePacket { - - public PacketPlayerTimeNotify(Player player) { - super(PacketOpcodes.PlayerTimeNotify); - - PlayerTimeNotify proto = - PlayerTimeNotify.newBuilder() - .setIsPaused(player.isPaused()) - .setPlayerTime(player.getClientTime()) - .setServerTime(System.currentTimeMillis()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerTimeNotifyOuterClass.PlayerTimeNotify; + +public class PacketPlayerTimeNotify extends BasePacket { + + public PacketPlayerTimeNotify(Player player) { + super(PacketOpcodes.PlayerTimeNotify); + + PlayerTimeNotify proto = + PlayerTimeNotify.newBuilder() + .setIsPaused(player.isPaused()) + .setPlayerTime(player.getClientTime()) + .setServerTime(System.currentTimeMillis()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java index 0e32a0a01..f791bcaf2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerWorldSceneInfoListNotify.java @@ -1,62 +1,62 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerWorldSceneInfoListNotifyOuterClass.PlayerWorldSceneInfoListNotify; -import emu.grasscutter.net.proto.PlayerWorldSceneInfoOuterClass.PlayerWorldSceneInfo; -import java.util.stream.IntStream; - -public class PacketPlayerWorldSceneInfoListNotify extends BasePacket { - - public PacketPlayerWorldSceneInfoListNotify() { - super(PacketOpcodes.PlayerWorldSceneInfoListNotify); // Rename opcode later - - PlayerWorldSceneInfoListNotify.Builder proto = - PlayerWorldSceneInfoListNotify.newBuilder() - .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build()) - .addInfoList( - PlayerWorldSceneInfo.newBuilder() - .setSceneId(3) - .setIsLocked(false) - .addSceneTagIdList(102) // Jade chamber - .addSceneTagIdList(113) - .addSceneTagIdList(117) - - // Vanarana (Sumeru tree) - .addSceneTagIdList(1093) // Vana_real - // .addSceneTagIdList(1094) // Vana_dream - // .addSceneTagIdList(1095) // Vana_first - // .addSceneTagIdList(1096) // Vana_festival - - // 3.1 event - .addSceneTagIdList(152) - .addSceneTagIdList(153) - - // Pyramid - .addSceneTagIdList(1164) // Arena (XMSM_CWLTop) - .addSceneTagIdList(1166) // Pyramid (CWL_Trans_02) - - // Brute force - // .addAllSceneTagIdList(IntStream.range(1150, 1250).boxed().toList()) - .build()) - .addInfoList( - PlayerWorldSceneInfo.newBuilder() - .setSceneId(4) - .setIsLocked(false) - .addSceneTagIdList(106) - .addSceneTagIdList(109) - .addSceneTagIdList(117) - .build()) - .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(5).setIsLocked(false).build()) - .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(6).setIsLocked(false).build()) - .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(7).setIsLocked(false).build()) - .addInfoList( - PlayerWorldSceneInfo.newBuilder() - .setSceneId(9) - .setIsLocked(false) - .addAllSceneTagIdList(IntStream.range(0, 3000).boxed().toList()) - .build()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerWorldSceneInfoListNotifyOuterClass.PlayerWorldSceneInfoListNotify; +import emu.grasscutter.net.proto.PlayerWorldSceneInfoOuterClass.PlayerWorldSceneInfo; +import java.util.stream.IntStream; + +public class PacketPlayerWorldSceneInfoListNotify extends BasePacket { + + public PacketPlayerWorldSceneInfoListNotify() { + super(PacketOpcodes.PlayerWorldSceneInfoListNotify); // Rename opcode later + + PlayerWorldSceneInfoListNotify.Builder proto = + PlayerWorldSceneInfoListNotify.newBuilder() + .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build()) + .addInfoList( + PlayerWorldSceneInfo.newBuilder() + .setSceneId(3) + .setIsLocked(false) + .addSceneTagIdList(102) // Jade chamber + .addSceneTagIdList(113) + .addSceneTagIdList(117) + + // Vanarana (Sumeru tree) + .addSceneTagIdList(1093) // Vana_real + // .addSceneTagIdList(1094) // Vana_dream + // .addSceneTagIdList(1095) // Vana_first + // .addSceneTagIdList(1096) // Vana_festival + + // 3.1 event + .addSceneTagIdList(152) + .addSceneTagIdList(153) + + // Pyramid + .addSceneTagIdList(1164) // Arena (XMSM_CWLTop) + .addSceneTagIdList(1166) // Pyramid (CWL_Trans_02) + + // Brute force + // .addAllSceneTagIdList(IntStream.range(1150, 1250).boxed().toList()) + .build()) + .addInfoList( + PlayerWorldSceneInfo.newBuilder() + .setSceneId(4) + .setIsLocked(false) + .addSceneTagIdList(106) + .addSceneTagIdList(109) + .addSceneTagIdList(117) + .build()) + .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(5).setIsLocked(false).build()) + .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(6).setIsLocked(false).build()) + .addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(7).setIsLocked(false).build()) + .addInfoList( + PlayerWorldSceneInfo.newBuilder() + .setSceneId(9) + .setIsLocked(false) + .addAllSceneTagIdList(IntStream.range(0, 3000).boxed().toList()) + .build()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPostEnterSceneRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPostEnterSceneRsp.java index c1485653d..234d7e89e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPostEnterSceneRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPostEnterSceneRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PostEnterSceneRspOuterClass.PostEnterSceneRsp; - -public class PacketPostEnterSceneRsp extends BasePacket { - - public PacketPostEnterSceneRsp(Player player) { - super(PacketOpcodes.PostEnterSceneRsp); - - PostEnterSceneRsp p = - PostEnterSceneRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PostEnterSceneRspOuterClass.PostEnterSceneRsp; + +public class PacketPostEnterSceneRsp extends BasePacket { + + public PacketPostEnterSceneRsp(Player player) { + super(PacketOpcodes.PostEnterSceneRsp); + + PostEnterSceneRsp p = + PostEnterSceneRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillChangeNotify.java index 17b0a67a9..709da44f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillChangeNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ProudSkillChangeNotifyOuterClass.ProudSkillChangeNotify; - -public class PacketProudSkillChangeNotify extends BasePacket { - - public PacketProudSkillChangeNotify(Avatar avatar) { - super(PacketOpcodes.ProudSkillChangeNotify); - - ProudSkillChangeNotify proto = - ProudSkillChangeNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setEntityId(avatar.getEntityId()) - .setSkillDepotId(avatar.getSkillDepotId()) - .addAllProudSkillList(avatar.getProudSkillList()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ProudSkillChangeNotifyOuterClass.ProudSkillChangeNotify; + +public class PacketProudSkillChangeNotify extends BasePacket { + + public PacketProudSkillChangeNotify(Avatar avatar) { + super(PacketOpcodes.ProudSkillChangeNotify); + + ProudSkillChangeNotify proto = + ProudSkillChangeNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setEntityId(avatar.getEntityId()) + .setSkillDepotId(avatar.getSkillDepotId()) + .addAllProudSkillList(avatar.getProudSkillList()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillExtraLevelNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillExtraLevelNotify.java index ebe553565..713a70055 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillExtraLevelNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketProudSkillExtraLevelNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ProudSkillExtraLevelNotifyOuterClass.ProudSkillExtraLevelNotify; - -public class PacketProudSkillExtraLevelNotify extends BasePacket { - - public PacketProudSkillExtraLevelNotify(Avatar avatar, int talentIndex) { - super(PacketOpcodes.ProudSkillExtraLevelNotify); - - ProudSkillExtraLevelNotify proto = - ProudSkillExtraLevelNotify.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setTalentType(3) // Talent type = 3 - .setTalentIndex(talentIndex) - .setExtraLevel(3) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ProudSkillExtraLevelNotifyOuterClass.ProudSkillExtraLevelNotify; + +public class PacketProudSkillExtraLevelNotify extends BasePacket { + + public PacketProudSkillExtraLevelNotify(Avatar avatar, int talentIndex) { + super(PacketOpcodes.ProudSkillExtraLevelNotify); + + ProudSkillExtraLevelNotify proto = + ProudSkillExtraLevelNotify.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setTalentType(3) // Talent type = 3 + .setTalentIndex(talentIndex) + .setExtraLevel(3) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPullPrivateChatRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPullPrivateChatRsp.java index a716c98eb..326c3b291 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPullPrivateChatRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPullPrivateChatRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; -import emu.grasscutter.net.proto.PullPrivateChatRspOuterClass.PullPrivateChatRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; - -public class PacketPullPrivateChatRsp extends BasePacket { - - public PacketPullPrivateChatRsp(List history) { - super(PacketOpcodes.PullPrivateChatRsp); - - PullPrivateChatRsp.Builder builder = PullPrivateChatRsp.newBuilder(); - - if (history == null) { - builder.setRetcode(Retcode.RET_FAIL_VALUE); - } else { - for (var info : history) { - builder.addChatInfo(info); - } - } - - this.setData(builder.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; +import emu.grasscutter.net.proto.PullPrivateChatRspOuterClass.PullPrivateChatRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; + +public class PacketPullPrivateChatRsp extends BasePacket { + + public PacketPullPrivateChatRsp(List history) { + super(PacketOpcodes.PullPrivateChatRsp); + + PullPrivateChatRsp.Builder builder = PullPrivateChatRsp.newBuilder(); + + if (history == null) { + builder.setRetcode(Retcode.RET_FAIL_VALUE); + } else { + for (var info : history) { + builder.addChatInfo(info); + } + } + + this.setData(builder.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPullRecentChatRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPullRecentChatRsp.java index af3d091df..cc46c1e32 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPullRecentChatRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPullRecentChatRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; -import emu.grasscutter.net.proto.PullRecentChatRspOuterClass.PullRecentChatRsp; -import java.util.List; - -public class PacketPullRecentChatRsp extends BasePacket { - public PacketPullRecentChatRsp(List messages) { - super(PacketOpcodes.PullRecentChatRsp); - - PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder().addAllChatInfo(messages); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo; +import emu.grasscutter.net.proto.PullRecentChatRspOuterClass.PullRecentChatRsp; +import java.util.List; + +public class PacketPullRecentChatRsp extends BasePacket { + public PacketPullRecentChatRsp(List messages) { + super(PacketOpcodes.PullRecentChatRsp); + + PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder().addAllChatInfo(messages); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQueryCodexMonsterBeKilledNumRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQueryCodexMonsterBeKilledNumRsp.java index 4afa53890..92d481aba 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQueryCodexMonsterBeKilledNumRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQueryCodexMonsterBeKilledNumRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QueryCodexMonsterBeKilledNumRspOuterClass.QueryCodexMonsterBeKilledNumRsp; -import java.util.List; - -public class PacketQueryCodexMonsterBeKilledNumRsp extends BasePacket { - - public PacketQueryCodexMonsterBeKilledNumRsp(Player player, List codexList) { - super(PacketOpcodes.QueryCodexMonsterBeKilledNumRsp); - QueryCodexMonsterBeKilledNumRsp.Builder proto = QueryCodexMonsterBeKilledNumRsp.newBuilder(); - - codexList.forEach( - animal -> { - if (player.getCodex().getUnlockedAnimal().containsKey(animal)) { - proto - .addCodexIdList(animal) - .addBeKilledNumList(player.getCodex().getUnlockedAnimal().get(animal)) - .addBeCapturedNumList(0); - } - }); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QueryCodexMonsterBeKilledNumRspOuterClass.QueryCodexMonsterBeKilledNumRsp; +import java.util.List; + +public class PacketQueryCodexMonsterBeKilledNumRsp extends BasePacket { + + public PacketQueryCodexMonsterBeKilledNumRsp(Player player, List codexList) { + super(PacketOpcodes.QueryCodexMonsterBeKilledNumRsp); + QueryCodexMonsterBeKilledNumRsp.Builder proto = QueryCodexMonsterBeKilledNumRsp.newBuilder(); + + codexList.forEach( + animal -> { + if (player.getCodex().getUnlockedAnimal().containsKey(animal)) { + proto + .addCodexIdList(animal) + .addBeKilledNumList(player.getCodex().getUnlockedAnimal().get(animal)) + .addBeCapturedNumList(0); + } + }); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQueryPathRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQueryPathRsp.java index 6545eb5a5..52cb5838c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQueryPathRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQueryPathRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PathStatusTypeOuterClass; -import emu.grasscutter.net.proto.QueryPathReqOuterClass; -import emu.grasscutter.net.proto.QueryPathRspOuterClass; - -public class PacketQueryPathRsp extends BasePacket { - - public PacketQueryPathRsp(QueryPathReqOuterClass.QueryPathReq req) { - super(PacketOpcodes.QueryPathRsp); - - var proto = QueryPathRspOuterClass.QueryPathRsp.newBuilder(); - - proto - .addCorners(req.getSourcePos()) - .addCorners(req.getDestinationPos(0)) - .setQueryId(req.getQueryId()) - .setQueryStatus(PathStatusTypeOuterClass.PathStatusType.PATH_STATUS_TYPE_SUCC); - // .setQueryStatus(QueryPathRspOuterClass.QueryPathRsp.PathStatusType.PATH_STATUS_TYPE_SUCC); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PathStatusTypeOuterClass; +import emu.grasscutter.net.proto.QueryPathReqOuterClass; +import emu.grasscutter.net.proto.QueryPathRspOuterClass; + +public class PacketQueryPathRsp extends BasePacket { + + public PacketQueryPathRsp(QueryPathReqOuterClass.QueryPathReq req) { + super(PacketOpcodes.QueryPathRsp); + + var proto = QueryPathRspOuterClass.QueryPathRsp.newBuilder(); + + proto + .addCorners(req.getSourcePos()) + .addCorners(req.getDestinationPos(0)) + .setQueryId(req.getQueryId()) + .setQueryStatus(PathStatusTypeOuterClass.PathStatusType.PATH_STATUS_TYPE_SUCC); + // .setQueryStatus(QueryPathRspOuterClass.QueryPathRsp.PathStatusType.PATH_STATUS_TYPE_SUCC); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListNotify.java index 75332ec6d..fb68b11f9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.quest.enums.QuestState; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuestListNotifyOuterClass.QuestListNotify; - -public class PacketQuestListNotify extends BasePacket { - - public PacketQuestListNotify(Player player) { - super(PacketOpcodes.QuestListNotify, true); - - QuestListNotify.Builder proto = QuestListNotify.newBuilder(); - - player - .getQuestManager() - .forEachQuest( - quest -> { - if (quest.getState() != QuestState.QUEST_STATE_UNSTARTED) { - proto.addQuestList(quest.toProto()); - } - }); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.enums.QuestState; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestListNotifyOuterClass.QuestListNotify; + +public class PacketQuestListNotify extends BasePacket { + + public PacketQuestListNotify(Player player) { + super(PacketOpcodes.QuestListNotify, true); + + QuestListNotify.Builder proto = QuestListNotify.newBuilder(); + + player + .getQuestManager() + .forEachQuest( + quest -> { + if (quest.getState() != QuestState.QUEST_STATE_UNSTARTED) { + proto.addQuestList(quest.toProto()); + } + }); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListUpdateNotify.java index f08ebe6f6..95d94fc36 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestListUpdateNotify.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuestListUpdateNotifyOuterClass.QuestListUpdateNotify; -import java.util.List; - -public class PacketQuestListUpdateNotify extends BasePacket { - - public PacketQuestListUpdateNotify(GameQuest quest) { - super(PacketOpcodes.QuestListUpdateNotify); - - QuestListUpdateNotify proto = - QuestListUpdateNotify.newBuilder().addQuestList(quest.toProto()).build(); - - this.setData(proto); - } - - public PacketQuestListUpdateNotify(List quests) { - super(PacketOpcodes.QuestListUpdateNotify); - var proto = QuestListUpdateNotify.newBuilder(); - for (GameQuest quest : quests) { - proto.addQuestList(quest.toProto()); - } - proto.build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestListUpdateNotifyOuterClass.QuestListUpdateNotify; +import java.util.List; + +public class PacketQuestListUpdateNotify extends BasePacket { + + public PacketQuestListUpdateNotify(GameQuest quest) { + super(PacketOpcodes.QuestListUpdateNotify); + + QuestListUpdateNotify proto = + QuestListUpdateNotify.newBuilder().addQuestList(quest.toProto()).build(); + + this.setData(proto); + } + + public PacketQuestListUpdateNotify(List quests) { + super(PacketOpcodes.QuestListUpdateNotify); + var proto = QuestListUpdateNotify.newBuilder(); + for (GameQuest quest : quests) { + proto.addQuestList(quest.toProto()); + } + proto.build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestProgressUpdateNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestProgressUpdateNotify.java index 89e5c54c1..d71039e85 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketQuestProgressUpdateNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketQuestProgressUpdateNotify.java @@ -1,30 +1,30 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.quest.GameQuest; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.QuestProgressUpdateNotifyOuterClass.QuestProgressUpdateNotify; - -public class PacketQuestProgressUpdateNotify extends BasePacket { - - public PacketQuestProgressUpdateNotify(GameQuest quest) { - super(PacketOpcodes.QuestProgressUpdateNotify); - - QuestProgressUpdateNotify.Builder proto = - QuestProgressUpdateNotify.newBuilder().setQuestId(quest.getSubQuestId()); - - if (quest.getFinishProgressList() != null) { - for (int i : quest.getFinishProgressList()) { - proto.addFinishProgressList(i); - } - } - - if (quest.getFailProgressList() != null) { - for (int i : quest.getFailProgressList()) { - proto.addFailProgressList(i); - } - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuestProgressUpdateNotifyOuterClass.QuestProgressUpdateNotify; + +public class PacketQuestProgressUpdateNotify extends BasePacket { + + public PacketQuestProgressUpdateNotify(GameQuest quest) { + super(PacketOpcodes.QuestProgressUpdateNotify); + + QuestProgressUpdateNotify.Builder proto = + QuestProgressUpdateNotify.newBuilder().setQuestId(quest.getSubQuestId()); + + if (quest.getFinishProgressList() != null) { + for (int i : quest.getFinishProgressList()) { + proto.addFinishProgressList(i); + } + } + + if (quest.getFailProgressList() != null) { + for (int i : quest.getFailProgressList()) { + proto.addFailProgressList(i); + } + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryDecomposeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryDecomposeRsp.java index 285e73361..2989b4f7f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryDecomposeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryDecomposeRsp.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ReliquaryDecomposeRspOuterClass.ReliquaryDecomposeRsp; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import java.util.List; - -public class PacketReliquaryDecomposeRsp extends BasePacket { - public PacketReliquaryDecomposeRsp(Retcode retcode) { - super(PacketOpcodes.ReliquaryDecomposeRsp); - - ReliquaryDecomposeRsp proto = - ReliquaryDecomposeRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } - - public PacketReliquaryDecomposeRsp(List output) { - super(PacketOpcodes.ReliquaryDecomposeRsp); - - ReliquaryDecomposeRsp proto = ReliquaryDecomposeRsp.newBuilder().addAllGuidList(output).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReliquaryDecomposeRspOuterClass.ReliquaryDecomposeRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import java.util.List; + +public class PacketReliquaryDecomposeRsp extends BasePacket { + public PacketReliquaryDecomposeRsp(Retcode retcode) { + super(PacketOpcodes.ReliquaryDecomposeRsp); + + ReliquaryDecomposeRsp proto = + ReliquaryDecomposeRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } + + public PacketReliquaryDecomposeRsp(List output) { + super(PacketOpcodes.ReliquaryDecomposeRsp); + + ReliquaryDecomposeRsp proto = ReliquaryDecomposeRsp.newBuilder().addAllGuidList(output).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryUpgradeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryUpgradeRsp.java index 42690c1a5..dd2978e24 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryUpgradeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketReliquaryUpgradeRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ReliquaryUpgradeRspOuterClass.ReliquaryUpgradeRsp; -import java.util.List; - -public class PacketReliquaryUpgradeRsp extends BasePacket { - - public PacketReliquaryUpgradeRsp( - GameItem relic, int rate, int oldLevel, List oldAppendPropIdList) { - super(PacketOpcodes.ReliquaryUpgradeRsp); - - ReliquaryUpgradeRsp proto = - ReliquaryUpgradeRsp.newBuilder() - .setTargetReliquaryGuid(relic.getGuid()) - .setOldLevel(oldLevel) - .setCurLevel(relic.getLevel()) - .setPowerUpRate(rate) - .addAllOldAppendPropList(oldAppendPropIdList) - .addAllCurAppendPropList(relic.getAppendPropIdList()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ReliquaryUpgradeRspOuterClass.ReliquaryUpgradeRsp; +import java.util.List; + +public class PacketReliquaryUpgradeRsp extends BasePacket { + + public PacketReliquaryUpgradeRsp( + GameItem relic, int rate, int oldLevel, List oldAppendPropIdList) { + super(PacketOpcodes.ReliquaryUpgradeRsp); + + ReliquaryUpgradeRsp proto = + ReliquaryUpgradeRsp.newBuilder() + .setTargetReliquaryGuid(relic.getGuid()) + .setOldLevel(oldLevel) + .setCurLevel(relic.getLevel()) + .setPowerUpRate(rate) + .addAllOldAppendPropList(oldAppendPropIdList) + .addAllCurAppendPropList(relic.getAppendPropIdList()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaUnlockNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaUnlockNotify.java index d42b2f324..b57543b5f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaUnlockNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaUnlockNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneAreaUnlockNotifyOuterClass.SceneAreaUnlockNotify; - -public class PacketSceneAreaUnlockNotify extends BasePacket { - public PacketSceneAreaUnlockNotify(int sceneId, int areaId) { - super(PacketOpcodes.SceneAreaUnlockNotify); - - SceneAreaUnlockNotify.Builder p = - SceneAreaUnlockNotify.newBuilder().setSceneId(sceneId).addAreaList(areaId); - - this.setData(p); - } - - public PacketSceneAreaUnlockNotify(int sceneId, Iterable areaIds) { - super(PacketOpcodes.SceneAreaUnlockNotify); - - SceneAreaUnlockNotify.Builder p = - SceneAreaUnlockNotify.newBuilder().setSceneId(sceneId).addAllAreaList(areaIds); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneAreaUnlockNotifyOuterClass.SceneAreaUnlockNotify; + +public class PacketSceneAreaUnlockNotify extends BasePacket { + public PacketSceneAreaUnlockNotify(int sceneId, int areaId) { + super(PacketOpcodes.SceneAreaUnlockNotify); + + SceneAreaUnlockNotify.Builder p = + SceneAreaUnlockNotify.newBuilder().setSceneId(sceneId).addAreaList(areaId); + + this.setData(p); + } + + public PacketSceneAreaUnlockNotify(int sceneId, Iterable areaIds) { + super(PacketOpcodes.SceneAreaUnlockNotify); + + SceneAreaUnlockNotify.Builder p = + SceneAreaUnlockNotify.newBuilder().setSceneId(sceneId).addAllAreaList(areaIds); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java index 9202c05e8..78b04426c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneAreaWeatherNotifyOuterClass.SceneAreaWeatherNotify; - -public class PacketSceneAreaWeatherNotify extends BasePacket { - - public PacketSceneAreaWeatherNotify(Player player) { - super(PacketOpcodes.SceneAreaWeatherNotify); - - SceneAreaWeatherNotify proto = - SceneAreaWeatherNotify.newBuilder() - .setWeatherAreaId(player.getWeatherId()) - .setClimateType(player.getClimate().getValue()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneAreaWeatherNotifyOuterClass.SceneAreaWeatherNotify; + +public class PacketSceneAreaWeatherNotify extends BasePacket { + + public PacketSceneAreaWeatherNotify(Player player) { + super(PacketOpcodes.SceneAreaWeatherNotify); + + SceneAreaWeatherNotify proto = + SceneAreaWeatherNotify.newBuilder() + .setWeatherAreaId(player.getWeatherId()) + .setClimateType(player.getClimate().getValue()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityAppearNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityAppearNotify.java index 4a72f8ffe..d1d6ca8f6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityAppearNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityAppearNotify.java @@ -1,51 +1,51 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneEntityAppearNotifyOuterClass.SceneEntityAppearNotify; -import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; -import java.util.Collection; - -public class PacketSceneEntityAppearNotify extends BasePacket { - - public PacketSceneEntityAppearNotify(GameEntity entity) { - super(PacketOpcodes.SceneEntityAppearNotify, true); - - SceneEntityAppearNotify.Builder proto = - SceneEntityAppearNotify.newBuilder() - .setAppearType(VisionType.VISION_TYPE_BORN) - .addEntityList(entity.toProto()); - - this.setData(proto.build()); - } - - public PacketSceneEntityAppearNotify(GameEntity entity, VisionType vision, int param) { - super(PacketOpcodes.SceneEntityAppearNotify, true); - - SceneEntityAppearNotify.Builder proto = - SceneEntityAppearNotify.newBuilder() - .setAppearType(vision) - .setParam(param) - .addEntityList(entity.toProto()); - - this.setData(proto.build()); - } - - public PacketSceneEntityAppearNotify(Player player) { - this(player.getTeamManager().getCurrentAvatarEntity()); - } - - public PacketSceneEntityAppearNotify( - Collection entities, VisionType visionType) { - super(PacketOpcodes.SceneEntityAppearNotify, true); - - SceneEntityAppearNotify.Builder proto = - SceneEntityAppearNotify.newBuilder().setAppearType(visionType); - - entities.forEach(e -> proto.addEntityList(e.toProto())); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityAppearNotifyOuterClass.SceneEntityAppearNotify; +import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; +import java.util.Collection; + +public class PacketSceneEntityAppearNotify extends BasePacket { + + public PacketSceneEntityAppearNotify(GameEntity entity) { + super(PacketOpcodes.SceneEntityAppearNotify, true); + + SceneEntityAppearNotify.Builder proto = + SceneEntityAppearNotify.newBuilder() + .setAppearType(VisionType.VISION_TYPE_BORN) + .addEntityList(entity.toProto()); + + this.setData(proto.build()); + } + + public PacketSceneEntityAppearNotify(GameEntity entity, VisionType vision, int param) { + super(PacketOpcodes.SceneEntityAppearNotify, true); + + SceneEntityAppearNotify.Builder proto = + SceneEntityAppearNotify.newBuilder() + .setAppearType(vision) + .setParam(param) + .addEntityList(entity.toProto()); + + this.setData(proto.build()); + } + + public PacketSceneEntityAppearNotify(Player player) { + this(player.getTeamManager().getCurrentAvatarEntity()); + } + + public PacketSceneEntityAppearNotify( + Collection entities, VisionType visionType) { + super(PacketOpcodes.SceneEntityAppearNotify, true); + + SceneEntityAppearNotify.Builder proto = + SceneEntityAppearNotify.newBuilder().setAppearType(visionType); + + entities.forEach(e -> proto.addEntityList(e.toProto())); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDisappearNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDisappearNotify.java index 8d5f8ac0a..e0e2a48c0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDisappearNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDisappearNotify.java @@ -1,35 +1,35 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.GameEntity; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneEntityDisappearNotifyOuterClass.SceneEntityDisappearNotify; -import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; -import java.util.Collection; - -public class PacketSceneEntityDisappearNotify extends BasePacket { - - public PacketSceneEntityDisappearNotify(GameEntity entity, VisionType disappearType) { - super(PacketOpcodes.SceneEntityDisappearNotify); - - SceneEntityDisappearNotify proto = - SceneEntityDisappearNotify.newBuilder() - .setDisappearType(disappearType) - .addEntityList(entity.getId()) - .build(); - - this.setData(proto); - } - - public PacketSceneEntityDisappearNotify( - Collection entities, VisionType disappearType) { - super(PacketOpcodes.SceneEntityDisappearNotify); - - SceneEntityDisappearNotify.Builder proto = - SceneEntityDisappearNotify.newBuilder().setDisappearType(disappearType); - - entities.forEach(e -> proto.addEntityList(e.getId())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.GameEntity; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityDisappearNotifyOuterClass.SceneEntityDisappearNotify; +import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; +import java.util.Collection; + +public class PacketSceneEntityDisappearNotify extends BasePacket { + + public PacketSceneEntityDisappearNotify(GameEntity entity, VisionType disappearType) { + super(PacketOpcodes.SceneEntityDisappearNotify); + + SceneEntityDisappearNotify proto = + SceneEntityDisappearNotify.newBuilder() + .setDisappearType(disappearType) + .addEntityList(entity.getId()) + .build(); + + this.setData(proto); + } + + public PacketSceneEntityDisappearNotify( + Collection entities, VisionType disappearType) { + super(PacketOpcodes.SceneEntityDisappearNotify); + + SceneEntityDisappearNotify.Builder proto = + SceneEntityDisappearNotify.newBuilder().setDisappearType(disappearType); + + entities.forEach(e -> proto.addEntityList(e.getId())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java index 11439996a..30610d37b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneEntityDrownRspOuterClass.SceneEntityDrownRsp; - -public class PacketSceneEntityDrownRsp extends BasePacket { - - public PacketSceneEntityDrownRsp(int entityId) { - super(PacketOpcodes.SceneEntityDrownRsp); - - SceneEntityDrownRsp proto = SceneEntityDrownRsp.newBuilder().setEntityId(entityId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityDrownRspOuterClass.SceneEntityDrownRsp; + +public class PacketSceneEntityDrownRsp extends BasePacket { + + public PacketSceneEntityDrownRsp(int entityId) { + super(PacketOpcodes.SceneEntityDrownRsp); + + SceneEntityDrownRsp proto = SceneEntityDrownRsp.newBuilder().setEntityId(entityId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityMoveNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityMoveNotify.java index 1a55fe862..7f681e054 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityMoveNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityMoveNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.EntityMoveInfoOuterClass.EntityMoveInfo; -import emu.grasscutter.net.proto.SceneEntityMoveNotifyOuterClass.SceneEntityMoveNotify; - -public class PacketSceneEntityMoveNotify extends BasePacket { - - public PacketSceneEntityMoveNotify(EntityMoveInfo moveInfo) { - super(PacketOpcodes.SceneEntityMoveNotify, true); - - SceneEntityMoveNotify proto = - SceneEntityMoveNotify.newBuilder() - .setMotionInfo(moveInfo.getMotionInfo()) - .setEntityId(moveInfo.getEntityId()) - .setSceneTime(moveInfo.getSceneTime()) - .setReliableSeq(moveInfo.getReliableSeq()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EntityMoveInfoOuterClass.EntityMoveInfo; +import emu.grasscutter.net.proto.SceneEntityMoveNotifyOuterClass.SceneEntityMoveNotify; + +public class PacketSceneEntityMoveNotify extends BasePacket { + + public PacketSceneEntityMoveNotify(EntityMoveInfo moveInfo) { + super(PacketOpcodes.SceneEntityMoveNotify, true); + + SceneEntityMoveNotify proto = + SceneEntityMoveNotify.newBuilder() + .setMotionInfo(moveInfo.getMotionInfo()) + .setEntityId(moveInfo.getEntityId()) + .setSceneTime(moveInfo.getSceneTime()) + .setReliableSeq(moveInfo.getReliableSeq()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneInitFinishRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneInitFinishRsp.java index 12552190e..6f53067fe 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneInitFinishRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneInitFinishRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SceneInitFinishRspOuterClass.SceneInitFinishRsp; - -public class PacketSceneInitFinishRsp extends BasePacket { - - public PacketSceneInitFinishRsp(Player player) { - super(PacketOpcodes.SceneInitFinishRsp, 11); - - SceneInitFinishRsp p = - SceneInitFinishRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); - - this.setData(p.toByteArray()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneInitFinishRspOuterClass.SceneInitFinishRsp; + +public class PacketSceneInitFinishRsp extends BasePacket { + + public PacketSceneInitFinishRsp(Player player) { + super(PacketOpcodes.SceneInitFinishRsp, 11); + + SceneInitFinishRsp p = + SceneInitFinishRsp.newBuilder().setEnterSceneToken(player.getEnterSceneToken()).build(); + + this.setData(p.toByteArray()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneKickPlayerRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneKickPlayerRsp.java index 6c56b89d6..e03e834b9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneKickPlayerRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneKickPlayerRsp.java @@ -1,28 +1,28 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.SceneKickPlayerRspOuterClass.SceneKickPlayerRsp; - -public class PacketSceneKickPlayerRsp extends BasePacket { - - public PacketSceneKickPlayerRsp(int targetUid) { - super(PacketOpcodes.SceneKickPlayerRsp); - - SceneKickPlayerRsp proto = SceneKickPlayerRsp.newBuilder().setTargetUid(targetUid).build(); - - this.setData(proto); - } - - public PacketSceneKickPlayerRsp() { - super(PacketOpcodes.SceneKickPlayerRsp); - - SceneKickPlayerRsp proto = - SceneKickPlayerRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.SceneKickPlayerRspOuterClass.SceneKickPlayerRsp; + +public class PacketSceneKickPlayerRsp extends BasePacket { + + public PacketSceneKickPlayerRsp(int targetUid) { + super(PacketOpcodes.SceneKickPlayerRsp); + + SceneKickPlayerRsp proto = SceneKickPlayerRsp.newBuilder().setTargetUid(targetUid).build(); + + this.setData(proto); + } + + public PacketSceneKickPlayerRsp() { + super(PacketOpcodes.SceneKickPlayerRsp); + + SceneKickPlayerRsp proto = + SceneKickPlayerRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerInfoNotify.java index 1ab99a309..7dcdb377a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerInfoNotify.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ScenePlayerInfoNotifyOuterClass.ScenePlayerInfoNotify; -import emu.grasscutter.net.proto.ScenePlayerInfoOuterClass.ScenePlayerInfo; - -public class PacketScenePlayerInfoNotify extends BasePacket { - - public PacketScenePlayerInfoNotify(World world) { - super(PacketOpcodes.ScenePlayerInfoNotify); - - ScenePlayerInfoNotify.Builder proto = ScenePlayerInfoNotify.newBuilder(); - - for (int i = 0; i < world.getPlayers().size(); i++) { - Player p = world.getPlayers().get(i); - - ScenePlayerInfo pInfo = - ScenePlayerInfo.newBuilder() - .setUid(p.getUid()) - .setPeerId(p.getPeerId()) - .setName(p.getNickname()) - .setSceneId(p.getSceneId()) - .setOnlinePlayerInfo(p.getOnlinePlayerInfo()) - .build(); - - proto.addPlayerInfoList(pInfo); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ScenePlayerInfoNotifyOuterClass.ScenePlayerInfoNotify; +import emu.grasscutter.net.proto.ScenePlayerInfoOuterClass.ScenePlayerInfo; + +public class PacketScenePlayerInfoNotify extends BasePacket { + + public PacketScenePlayerInfoNotify(World world) { + super(PacketOpcodes.ScenePlayerInfoNotify); + + ScenePlayerInfoNotify.Builder proto = ScenePlayerInfoNotify.newBuilder(); + + for (int i = 0; i < world.getPlayers().size(); i++) { + Player p = world.getPlayers().get(i); + + ScenePlayerInfo pInfo = + ScenePlayerInfo.newBuilder() + .setUid(p.getUid()) + .setPeerId(p.getPeerId()) + .setName(p.getNickname()) + .setSceneId(p.getSceneId()) + .setOnlinePlayerInfo(p.getOnlinePlayerInfo()) + .build(); + + proto.addPlayerInfoList(pInfo); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerLocationNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerLocationNotify.java index f925c043c..c1aafbf98 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerLocationNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerLocationNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.Scene; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ScenePlayerLocationNotifyOuterClass.ScenePlayerLocationNotify; - -public class PacketScenePlayerLocationNotify extends BasePacket { - - public PacketScenePlayerLocationNotify(Scene scene) { - super(PacketOpcodes.ScenePlayerLocationNotify); - - ScenePlayerLocationNotify.Builder proto = - ScenePlayerLocationNotify.newBuilder().setSceneId(scene.getId()); - - for (Player p : scene.getPlayers()) { - proto.addPlayerLocList(p.getPlayerLocationInfo()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.Scene; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ScenePlayerLocationNotifyOuterClass.ScenePlayerLocationNotify; + +public class PacketScenePlayerLocationNotify extends BasePacket { + + public PacketScenePlayerLocationNotify(Scene scene) { + super(PacketOpcodes.ScenePlayerLocationNotify); + + ScenePlayerLocationNotify.Builder proto = + ScenePlayerLocationNotify.newBuilder().setSceneId(scene.getId()); + + for (Player p : scene.getPlayers()) { + proto.addPlayerLocList(p.getPlayerLocationInfo()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java index 9ffe45d65..88726d44d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java @@ -1,34 +1,34 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp; - -public class PacketSceneTransToPointRsp extends BasePacket { - - public PacketSceneTransToPointRsp(Player player, int pointId, int sceneId) { - super(PacketOpcodes.SceneTransToPointRsp); - - SceneTransToPointRsp proto = - SceneTransToPointRsp.newBuilder() - .setRetcode(0) - .setPointId(pointId) - .setSceneId(sceneId) - .build(); - - this.setData(proto); - } - - public PacketSceneTransToPointRsp() { - super(PacketOpcodes.SceneTransToPointRsp); - - SceneTransToPointRsp proto = - SceneTransToPointRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) // Internal server error - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp; + +public class PacketSceneTransToPointRsp extends BasePacket { + + public PacketSceneTransToPointRsp(Player player, int pointId, int sceneId) { + super(PacketOpcodes.SceneTransToPointRsp); + + SceneTransToPointRsp proto = + SceneTransToPointRsp.newBuilder() + .setRetcode(0) + .setPointId(pointId) + .setSceneId(sceneId) + .build(); + + this.setData(proto); + } + + public PacketSceneTransToPointRsp() { + super(PacketOpcodes.SceneTransToPointRsp); + + SceneTransToPointRsp proto = + SceneTransToPointRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) // Internal server error + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSelectWorktopOptionRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSelectWorktopOptionRsp.java index e65a85c6b..f4b19d297 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSelectWorktopOptionRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSelectWorktopOptionRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SelectWorktopOptionRspOuterClass.SelectWorktopOptionRsp; - -public class PacketSelectWorktopOptionRsp extends BasePacket { - - public PacketSelectWorktopOptionRsp(int entityId, int optionId) { - super(PacketOpcodes.SelectWorktopOptionRsp); - - SelectWorktopOptionRsp proto = - SelectWorktopOptionRsp.newBuilder() - .setGadgetEntityId(entityId) - .setOptionId(optionId) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SelectWorktopOptionRspOuterClass.SelectWorktopOptionRsp; + +public class PacketSelectWorktopOptionRsp extends BasePacket { + + public PacketSelectWorktopOptionRsp(int entityId, int optionId) { + super(PacketOpcodes.SelectWorktopOptionRsp); + + SelectWorktopOptionRsp proto = + SelectWorktopOptionRsp.newBuilder() + .setGadgetEntityId(entityId) + .setOptionId(optionId) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceNotify.java index 790fa1254..61962bbf6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceNotify.java @@ -1,38 +1,38 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AnnounceDataOuterClass; -import emu.grasscutter.net.proto.ServerAnnounceNotifyOuterClass; -import emu.grasscutter.utils.Utils; -import java.util.List; - -public class PacketServerAnnounceNotify extends BasePacket { - - public PacketServerAnnounceNotify(List data) { - super(PacketOpcodes.ServerAnnounceNotify); - - var proto = ServerAnnounceNotifyOuterClass.ServerAnnounceNotify.newBuilder(); - - proto.addAllAnnounceDataList(data); - - this.setData(proto); - } - - public PacketServerAnnounceNotify(String msg, int configId) { - super(PacketOpcodes.ServerAnnounceNotify); - - var proto = ServerAnnounceNotifyOuterClass.ServerAnnounceNotify.newBuilder(); - - proto.addAnnounceDataList( - AnnounceDataOuterClass.AnnounceData.newBuilder() - .setConfigId(configId) - .setBeginTime(Utils.getCurrentSeconds() + 1) - .setEndTime(Utils.getCurrentSeconds() + 2) - .setCenterSystemText(msg) - .setCenterSystemFrequency(1) - .build()); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AnnounceDataOuterClass; +import emu.grasscutter.net.proto.ServerAnnounceNotifyOuterClass; +import emu.grasscutter.utils.Utils; +import java.util.List; + +public class PacketServerAnnounceNotify extends BasePacket { + + public PacketServerAnnounceNotify(List data) { + super(PacketOpcodes.ServerAnnounceNotify); + + var proto = ServerAnnounceNotifyOuterClass.ServerAnnounceNotify.newBuilder(); + + proto.addAllAnnounceDataList(data); + + this.setData(proto); + } + + public PacketServerAnnounceNotify(String msg, int configId) { + super(PacketOpcodes.ServerAnnounceNotify); + + var proto = ServerAnnounceNotifyOuterClass.ServerAnnounceNotify.newBuilder(); + + proto.addAnnounceDataList( + AnnounceDataOuterClass.AnnounceData.newBuilder() + .setConfigId(configId) + .setBeginTime(Utils.getCurrentSeconds() + 1) + .setEndTime(Utils.getCurrentSeconds() + 2) + .setCenterSystemText(msg) + .setCenterSystemFrequency(1) + .build()); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceRevokeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceRevokeNotify.java index a66178a1b..70eb64c32 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceRevokeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerAnnounceRevokeNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ServerAnnounceRevokeNotifyOuterClass; - -public class PacketServerAnnounceRevokeNotify extends BasePacket { - - public PacketServerAnnounceRevokeNotify(int tplId) { - super(PacketOpcodes.ServerAnnounceRevokeNotify); - - var proto = ServerAnnounceRevokeNotifyOuterClass.ServerAnnounceRevokeNotify.newBuilder(); - - proto.addConfigIdList(tplId); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ServerAnnounceRevokeNotifyOuterClass; + +public class PacketServerAnnounceRevokeNotify extends BasePacket { + + public PacketServerAnnounceRevokeNotify(int tplId) { + super(PacketOpcodes.ServerAnnounceRevokeNotify); + + var proto = ServerAnnounceRevokeNotifyOuterClass.ServerAnnounceRevokeNotify.newBuilder(); + + proto.addConfigIdList(tplId); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerBuffChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerBuffChangeNotify.java index 18d5964be..87aea963c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerBuffChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerBuffChangeNotify.java @@ -1,39 +1,39 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.player.PlayerBuffManager.PlayerBuff; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChangeNotify; -import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChangeNotify.ServerBuffChangeType; -import java.util.Collection; -import java.util.stream.Stream; - -public class PacketServerBuffChangeNotify extends BasePacket { - - public PacketServerBuffChangeNotify( - Player player, ServerBuffChangeType changeType, PlayerBuff buff) { - this(player, changeType, Stream.of(buff)); - } - - public PacketServerBuffChangeNotify( - Player player, ServerBuffChangeType changeType, Collection buffs) { - this(player, changeType, buffs.stream()); - } - - public PacketServerBuffChangeNotify( - Player player, ServerBuffChangeType changeType, Stream buffs) { - super(PacketOpcodes.ServerBuffChangeNotify); - - var proto = ServerBuffChangeNotify.newBuilder(); - - player.getTeamManager().getActiveTeam().stream() - .mapToLong(entity -> entity.getAvatar().getGuid()) - .forEach(proto::addAvatarGuidList); - - proto.setServerBuffChangeType(changeType); - buffs.map(PlayerBuff::toProto).forEach(proto::addServerBuffList); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.player.PlayerBuffManager.PlayerBuff; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChangeNotify; +import emu.grasscutter.net.proto.ServerBuffChangeNotifyOuterClass.ServerBuffChangeNotify.ServerBuffChangeType; +import java.util.Collection; +import java.util.stream.Stream; + +public class PacketServerBuffChangeNotify extends BasePacket { + + public PacketServerBuffChangeNotify( + Player player, ServerBuffChangeType changeType, PlayerBuff buff) { + this(player, changeType, Stream.of(buff)); + } + + public PacketServerBuffChangeNotify( + Player player, ServerBuffChangeType changeType, Collection buffs) { + this(player, changeType, buffs.stream()); + } + + public PacketServerBuffChangeNotify( + Player player, ServerBuffChangeType changeType, Stream buffs) { + super(PacketOpcodes.ServerBuffChangeNotify); + + var proto = ServerBuffChangeNotify.newBuilder(); + + player.getTeamManager().getActiveTeam().stream() + .mapToLong(entity -> entity.getAvatar().getGuid()) + .forEach(proto::addAvatarGuidList); + + proto.setServerBuffChangeType(changeType); + buffs.map(PlayerBuff::toProto).forEach(proto::addServerBuffList); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerTimeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerTimeNotify.java index f88c7c7f1..fdfcc4a38 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerTimeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerTimeNotify.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ServerTimeNotifyOuterClass.ServerTimeNotify; - -public class PacketServerTimeNotify extends BasePacket { - - public PacketServerTimeNotify() { - super(PacketOpcodes.ServerTimeNotify); - - ServerTimeNotify proto = - ServerTimeNotify.newBuilder().setServerTime(System.currentTimeMillis()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ServerTimeNotifyOuterClass.ServerTimeNotify; + +public class PacketServerTimeNotify extends BasePacket { + + public PacketServerTimeNotify() { + super(PacketOpcodes.ServerTimeNotify); + + ServerTimeNotify proto = + ServerTimeNotify.newBuilder().setServerTime(System.currentTimeMillis()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetBattlePassViewedRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetBattlePassViewedRsp.java index 7a119a88c..059828d32 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetBattlePassViewedRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetBattlePassViewedRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetBattlePassViewedRspOuterClass.SetBattlePassViewedRsp; - -public class PacketSetBattlePassViewedRsp extends BasePacket { - - public PacketSetBattlePassViewedRsp(int scheduleId) { - super(PacketOpcodes.SetBattlePassViewedRsp); - - SetBattlePassViewedRsp proto = - SetBattlePassViewedRsp.newBuilder().setScheduleId(scheduleId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetBattlePassViewedRspOuterClass.SetBattlePassViewedRsp; + +public class PacketSetBattlePassViewedRsp extends BasePacket { + + public PacketSetBattlePassViewedRsp(int scheduleId) { + super(PacketOpcodes.SetBattlePassViewedRsp); + + SetBattlePassViewedRsp proto = + SetBattlePassViewedRsp.newBuilder().setScheduleId(scheduleId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetEquipLockStateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetEquipLockStateRsp.java index 6267d85dd..beb76d86e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetEquipLockStateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetEquipLockStateRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetEquipLockStateRspOuterClass.SetEquipLockStateRsp; - -public class PacketSetEquipLockStateRsp extends BasePacket { - - public PacketSetEquipLockStateRsp(GameItem equip) { - super(PacketOpcodes.SetEquipLockStateRsp); - - this.buildHeader(0); - - SetEquipLockStateRsp proto = - SetEquipLockStateRsp.newBuilder() - .setTargetEquipGuid(equip.getGuid()) - .setIsLocked(equip.isLocked()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetEquipLockStateRspOuterClass.SetEquipLockStateRsp; + +public class PacketSetEquipLockStateRsp extends BasePacket { + + public PacketSetEquipLockStateRsp(GameItem equip) { + super(PacketOpcodes.SetEquipLockStateRsp); + + this.buildHeader(0); + + SetEquipLockStateRsp proto = + SetEquipLockStateRsp.newBuilder() + .setTargetEquipGuid(equip.getGuid()) + .setIsLocked(equip.isLocked()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetNameCardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetNameCardRsp.java index 28fee035f..49dcc1f4d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetNameCardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetNameCardRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetNameCardRspOuterClass.SetNameCardRsp; - -public class PacketSetNameCardRsp extends BasePacket { - - public PacketSetNameCardRsp(int nameCardId) { - super(PacketOpcodes.SetNameCardRsp); - - SetNameCardRsp proto = SetNameCardRsp.newBuilder().setNameCardId(nameCardId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetNameCardRspOuterClass.SetNameCardRsp; + +public class PacketSetNameCardRsp extends BasePacket { + + public PacketSetNameCardRsp(int nameCardId) { + super(PacketOpcodes.SetNameCardRsp); + + SetNameCardRsp proto = SetNameCardRsp.newBuilder().setNameCardId(nameCardId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetOpenStateRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetOpenStateRsp.java index af1aa153c..8328f325f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetOpenStateRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetOpenStateRsp.java @@ -1,24 +1,24 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.SetOpenStateRspOuterClass.SetOpenStateRsp; - -public class PacketSetOpenStateRsp extends BasePacket { - public PacketSetOpenStateRsp(int openState, int value) { - super(PacketOpcodes.SetOpenStateRsp); - - SetOpenStateRsp proto = SetOpenStateRsp.newBuilder().setKey(openState).setValue(value).build(); - - this.setData(proto); - } - - public PacketSetOpenStateRsp(Retcode retcode) { - super(PacketOpcodes.SetOpenStateRsp); - - SetOpenStateRsp proto = SetOpenStateRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.net.proto.SetOpenStateRspOuterClass.SetOpenStateRsp; + +public class PacketSetOpenStateRsp extends BasePacket { + public PacketSetOpenStateRsp(int openState, int value) { + super(PacketOpcodes.SetOpenStateRsp); + + SetOpenStateRsp proto = SetOpenStateRsp.newBuilder().setKey(openState).setValue(value).build(); + + this.setData(proto); + } + + public PacketSetOpenStateRsp(Retcode retcode) { + super(PacketOpcodes.SetOpenStateRsp); + + SetOpenStateRsp proto = SetOpenStateRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java index 02d4cf7c1..3f4941a14 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java @@ -1,26 +1,26 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp; - -public class PacketSetPlayerBirthdayRsp extends BasePacket { - - public PacketSetPlayerBirthdayRsp(int retCode) { - super(PacketOpcodes.SetPlayerBirthdayRsp); - - SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder().setRetcode(retCode).build(); - - this.setData(proto); - } - - public PacketSetPlayerBirthdayRsp(Player player) { - super(PacketOpcodes.SetPlayerBirthdayRsp); - - SetPlayerBirthdayRsp proto = - SetPlayerBirthdayRsp.newBuilder().setBirthday(player.getBirthday().toProto()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp; + +public class PacketSetPlayerBirthdayRsp extends BasePacket { + + public PacketSetPlayerBirthdayRsp(int retCode) { + super(PacketOpcodes.SetPlayerBirthdayRsp); + + SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder().setRetcode(retCode).build(); + + this.setData(proto); + } + + public PacketSetPlayerBirthdayRsp(Player player) { + super(PacketOpcodes.SetPlayerBirthdayRsp); + + SetPlayerBirthdayRsp proto = + SetPlayerBirthdayRsp.newBuilder().setBirthday(player.getBirthday().toProto()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerHeadImageRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerHeadImageRsp.java index b23b6d2db..713e5af73 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerHeadImageRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerHeadImageRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; -import emu.grasscutter.net.proto.SetPlayerHeadImageRspOuterClass.SetPlayerHeadImageRsp; - -public class PacketSetPlayerHeadImageRsp extends BasePacket { - - public PacketSetPlayerHeadImageRsp(Player player) { - super(PacketOpcodes.SetPlayerHeadImageRsp); - - SetPlayerHeadImageRsp proto = - SetPlayerHeadImageRsp.newBuilder() - .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(player.getHeadImage())) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; +import emu.grasscutter.net.proto.SetPlayerHeadImageRspOuterClass.SetPlayerHeadImageRsp; + +public class PacketSetPlayerHeadImageRsp extends BasePacket { + + public PacketSetPlayerHeadImageRsp(Player player) { + super(PacketOpcodes.SetPlayerHeadImageRsp); + + SetPlayerHeadImageRsp proto = + SetPlayerHeadImageRsp.newBuilder() + .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(player.getHeadImage())) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerNameRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerNameRsp.java index d2d09ce05..52a7e4414 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerNameRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerNameRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerNameRspOuterClass.SetPlayerNameRsp; - -public class PacketSetPlayerNameRsp extends BasePacket { - - public PacketSetPlayerNameRsp(Player player) { - super(PacketOpcodes.SetPlayerNameRsp); - - SetPlayerNameRsp proto = - SetPlayerNameRsp.newBuilder().setNickName(player.getNickname()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerNameRspOuterClass.SetPlayerNameRsp; + +public class PacketSetPlayerNameRsp extends BasePacket { + + public PacketSetPlayerNameRsp(Player player) { + super(PacketOpcodes.SetPlayerNameRsp); + + SetPlayerNameRsp proto = + SetPlayerNameRsp.newBuilder().setNickName(player.getNickname()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerPropRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerPropRsp.java index a67c6721e..21a58a090 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerPropRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerPropRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerPropRspOuterClass; - -public class PacketSetPlayerPropRsp extends BasePacket { - - public PacketSetPlayerPropRsp(int retCode) { - super(PacketOpcodes.SetPlayerPropRsp); - SetPlayerPropRspOuterClass.SetPlayerPropRsp.Builder proto = - SetPlayerPropRspOuterClass.SetPlayerPropRsp.newBuilder(); - if (retCode != 0) { - proto.setRetcode(retCode); - } - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerPropRspOuterClass; + +public class PacketSetPlayerPropRsp extends BasePacket { + + public PacketSetPlayerPropRsp(int retCode) { + super(PacketOpcodes.SetPlayerPropRsp); + SetPlayerPropRspOuterClass.SetPlayerPropRsp.Builder proto = + SetPlayerPropRspOuterClass.SetPlayerPropRsp.newBuilder(); + if (retCode != 0) { + proto.setRetcode(retCode); + } + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerSignatureRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerSignatureRsp.java index 90f0199fa..878a2ca29 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerSignatureRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerSignatureRsp.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetPlayerSignatureRspOuterClass.SetPlayerSignatureRsp; - -public class PacketSetPlayerSignatureRsp extends BasePacket { - - public PacketSetPlayerSignatureRsp(Player player) { - super(PacketOpcodes.SetPlayerSignatureRsp); - - SetPlayerSignatureRsp proto = - SetPlayerSignatureRsp.newBuilder().setSignature(player.getSignature()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetPlayerSignatureRspOuterClass.SetPlayerSignatureRsp; + +public class PacketSetPlayerSignatureRsp extends BasePacket { + + public PacketSetPlayerSignatureRsp(Player player) { + super(PacketOpcodes.SetPlayerSignatureRsp); + + SetPlayerSignatureRsp proto = + SetPlayerSignatureRsp.newBuilder().setSignature(player.getSignature()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpAvatarTeamRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpAvatarTeamRsp.java index b6eec924b..fe796ad9e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpAvatarTeamRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpAvatarTeamRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.player.TeamInfo; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetUpAvatarTeamRspOuterClass.SetUpAvatarTeamRsp; - -public class PacketSetUpAvatarTeamRsp extends BasePacket { - - public PacketSetUpAvatarTeamRsp(Player player, int teamId, TeamInfo teamInfo) { - super(PacketOpcodes.SetUpAvatarTeamRsp); - - SetUpAvatarTeamRsp.Builder proto = - SetUpAvatarTeamRsp.newBuilder() - .setTeamId(teamId) - .setCurAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()); - - for (int avatarId : teamInfo.getAvatars()) { - proto.addAvatarTeamGuidList(player.getAvatars().getAvatarById(avatarId).getGuid()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.player.TeamInfo; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetUpAvatarTeamRspOuterClass.SetUpAvatarTeamRsp; + +public class PacketSetUpAvatarTeamRsp extends BasePacket { + + public PacketSetUpAvatarTeamRsp(Player player, int teamId, TeamInfo teamInfo) { + super(PacketOpcodes.SetUpAvatarTeamRsp); + + SetUpAvatarTeamRsp.Builder proto = + SetUpAvatarTeamRsp.newBuilder() + .setTeamId(teamId) + .setCurAvatarGuid(player.getTeamManager().getCurrentCharacterGuid()); + + for (int avatarId : teamInfo.getAvatars()) { + proto.addAvatarTeamGuidList(player.getAvatars().getAvatarById(avatarId).getGuid()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpLunchBoxWidgetRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpLunchBoxWidgetRsp.java index bfe2f1d63..51396a46d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpLunchBoxWidgetRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetUpLunchBoxWidgetRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.LunchBoxDataOuterClass; -import emu.grasscutter.net.proto.SetUpLunchBoxWidgetRspOuterClass; - -public class PacketSetUpLunchBoxWidgetRsp extends BasePacket { - - public PacketSetUpLunchBoxWidgetRsp(LunchBoxDataOuterClass.LunchBoxData lunchBoxData) { - super(PacketOpcodes.SetUpLunchBoxWidgetRsp); - var rsp = SetUpLunchBoxWidgetRspOuterClass.SetUpLunchBoxWidgetRsp.newBuilder(); - rsp.setLunchBoxData(lunchBoxData); - - setData(rsp.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.LunchBoxDataOuterClass; +import emu.grasscutter.net.proto.SetUpLunchBoxWidgetRspOuterClass; + +public class PacketSetUpLunchBoxWidgetRsp extends BasePacket { + + public PacketSetUpLunchBoxWidgetRsp(LunchBoxDataOuterClass.LunchBoxData lunchBoxData) { + super(PacketOpcodes.SetUpLunchBoxWidgetRsp); + var rsp = SetUpLunchBoxWidgetRspOuterClass.SetUpLunchBoxWidgetRsp.newBuilder(); + rsp.setLunchBoxData(lunchBoxData); + + setData(rsp.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetWidgetSlotRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetWidgetSlotRsp.java index 7dbb7746a..f8262865c 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetWidgetSlotRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetWidgetSlotRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SetWidgetSlotRspOuterClass; - -public class PacketSetWidgetSlotRsp extends BasePacket { - - public PacketSetWidgetSlotRsp(int materialId) { - super(PacketOpcodes.SetWidgetSlotRsp); - - SetWidgetSlotRspOuterClass.SetWidgetSlotRsp proto = - SetWidgetSlotRspOuterClass.SetWidgetSlotRsp.newBuilder().setMaterialId(materialId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SetWidgetSlotRspOuterClass; + +public class PacketSetWidgetSlotRsp extends BasePacket { + + public PacketSetWidgetSlotRsp(int materialId) { + super(PacketOpcodes.SetWidgetSlotRsp); + + SetWidgetSlotRspOuterClass.SetWidgetSlotRsp proto = + SetWidgetSlotRspOuterClass.SetWidgetSlotRsp.newBuilder().setMaterialId(materialId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSkipPlayerGameTimeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSkipPlayerGameTimeRsp.java index b89b6cf96..d301b0c24 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSkipPlayerGameTimeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSkipPlayerGameTimeRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SkipPlayerGameTimeReqOuterClass; -import emu.grasscutter.net.proto.SkipPlayerGameTimeRspOuterClass; - -public class PacketSkipPlayerGameTimeRsp extends BasePacket { - public PacketSkipPlayerGameTimeRsp(SkipPlayerGameTimeReqOuterClass.SkipPlayerGameTimeReq req) { - super(PacketOpcodes.SkipPlayerGameTimeRsp); - - var proto = - SkipPlayerGameTimeRspOuterClass.SkipPlayerGameTimeRsp.newBuilder() - .setClientGameTime(req.getClientGameTime()) - .setGameTime(req.getGameTime()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SkipPlayerGameTimeReqOuterClass; +import emu.grasscutter.net.proto.SkipPlayerGameTimeRspOuterClass; + +public class PacketSkipPlayerGameTimeRsp extends BasePacket { + public PacketSkipPlayerGameTimeRsp(SkipPlayerGameTimeReqOuterClass.SkipPlayerGameTimeReq req) { + super(PacketOpcodes.SkipPlayerGameTimeRsp); + + var proto = + SkipPlayerGameTimeRspOuterClass.SkipPlayerGameTimeRsp.newBuilder() + .setClientGameTime(req.getClientGameTime()) + .setGameTime(req.getGameTime()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemChangeNotify.java index 6f691db84..5130c78a9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemChangeNotify.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.StoreItemChangeNotifyOuterClass.StoreItemChangeNotify; -import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; -import java.util.Collection; - -public class PacketStoreItemChangeNotify extends BasePacket { - - private PacketStoreItemChangeNotify() { - super(PacketOpcodes.StoreItemChangeNotify); - } - - public PacketStoreItemChangeNotify(GameItem item) { - this(); - - StoreItemChangeNotify.Builder proto = - StoreItemChangeNotify.newBuilder() - .setStoreType(StoreType.STORE_TYPE_PACK) - .addItemList(item.toProto()); - - this.setData(proto); - } - - public PacketStoreItemChangeNotify(Collection items) { - this(); - - StoreItemChangeNotify.Builder proto = - StoreItemChangeNotify.newBuilder().setStoreType(StoreType.STORE_TYPE_PACK); - - items.forEach(item -> proto.addItemList(item.toProto())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.StoreItemChangeNotifyOuterClass.StoreItemChangeNotify; +import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; +import java.util.Collection; + +public class PacketStoreItemChangeNotify extends BasePacket { + + private PacketStoreItemChangeNotify() { + super(PacketOpcodes.StoreItemChangeNotify); + } + + public PacketStoreItemChangeNotify(GameItem item) { + this(); + + StoreItemChangeNotify.Builder proto = + StoreItemChangeNotify.newBuilder() + .setStoreType(StoreType.STORE_TYPE_PACK) + .addItemList(item.toProto()); + + this.setData(proto); + } + + public PacketStoreItemChangeNotify(Collection items) { + this(); + + StoreItemChangeNotify.Builder proto = + StoreItemChangeNotify.newBuilder().setStoreType(StoreType.STORE_TYPE_PACK); + + items.forEach(item -> proto.addItemList(item.toProto())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java index daa566357..c61e9e704 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreItemDelNotify.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.StoreItemDelNotifyOuterClass.StoreItemDelNotify; -import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; -import java.util.Collection; - -public class PacketStoreItemDelNotify extends BasePacket { - - private PacketStoreItemDelNotify() { - super(PacketOpcodes.StoreItemDelNotify); - } - - public PacketStoreItemDelNotify(GameItem item) { - this(); - - StoreItemDelNotify.Builder proto = - StoreItemDelNotify.newBuilder() - .setStoreType(StoreType.STORE_TYPE_PACK) - .addGuidList(item.getGuid()); - - this.setData(proto); - } - - public PacketStoreItemDelNotify(Collection items) { - this(); - - StoreItemDelNotify.Builder proto = - StoreItemDelNotify.newBuilder().setStoreType(StoreType.STORE_TYPE_PACK); - - items.stream().forEach(item -> proto.addGuidList(item.getGuid())); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.StoreItemDelNotifyOuterClass.StoreItemDelNotify; +import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; +import java.util.Collection; + +public class PacketStoreItemDelNotify extends BasePacket { + + private PacketStoreItemDelNotify() { + super(PacketOpcodes.StoreItemDelNotify); + } + + public PacketStoreItemDelNotify(GameItem item) { + this(); + + StoreItemDelNotify.Builder proto = + StoreItemDelNotify.newBuilder() + .setStoreType(StoreType.STORE_TYPE_PACK) + .addGuidList(item.getGuid()); + + this.setData(proto); + } + + public PacketStoreItemDelNotify(Collection items) { + this(); + + StoreItemDelNotify.Builder proto = + StoreItemDelNotify.newBuilder().setStoreType(StoreType.STORE_TYPE_PACK); + + items.stream().forEach(item -> proto.addGuidList(item.getGuid())); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreWeightLimitNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreWeightLimitNotify.java index 964afcceb..3d95a1e03 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketStoreWeightLimitNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketStoreWeightLimitNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; -import emu.grasscutter.net.proto.StoreWeightLimitNotifyOuterClass.StoreWeightLimitNotify; - -public class PacketStoreWeightLimitNotify extends BasePacket { - - public PacketStoreWeightLimitNotify() { - super(PacketOpcodes.StoreWeightLimitNotify); - - StoreWeightLimitNotify p = - StoreWeightLimitNotify.newBuilder() - .setStoreType(StoreType.STORE_TYPE_PACK) - .setWeightLimit(INVENTORY_LIMITS.all) - .setWeaponCountLimit(INVENTORY_LIMITS.weapons) - .setReliquaryCountLimit(INVENTORY_LIMITS.relics) - .setMaterialCountLimit(INVENTORY_LIMITS.materials) - .setFurnitureCountLimit(INVENTORY_LIMITS.furniture) - .build(); - - this.setData(p); - } -} +package emu.grasscutter.server.packet.send; + +import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.StoreTypeOuterClass.StoreType; +import emu.grasscutter.net.proto.StoreWeightLimitNotifyOuterClass.StoreWeightLimitNotify; + +public class PacketStoreWeightLimitNotify extends BasePacket { + + public PacketStoreWeightLimitNotify() { + super(PacketOpcodes.StoreWeightLimitNotify); + + StoreWeightLimitNotify p = + StoreWeightLimitNotify.newBuilder() + .setStoreType(StoreType.STORE_TYPE_PACK) + .setWeightLimit(INVENTORY_LIMITS.all) + .setWeaponCountLimit(INVENTORY_LIMITS.weapons) + .setReliquaryCountLimit(INVENTORY_LIMITS.relics) + .setMaterialCountLimit(INVENTORY_LIMITS.materials) + .setFurnitureCountLimit(INVENTORY_LIMITS.furniture) + .build(); + + this.setData(p); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSyncScenePlayTeamEntityNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSyncScenePlayTeamEntityNotify.java index 0bc2303de..d39df9254 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSyncScenePlayTeamEntityNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSyncScenePlayTeamEntityNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.SyncScenePlayTeamEntityNotifyOuterClass.SyncScenePlayTeamEntityNotify; - -public class PacketSyncScenePlayTeamEntityNotify extends BasePacket { - - public PacketSyncScenePlayTeamEntityNotify(Player player) { - super(PacketOpcodes.SyncScenePlayTeamEntityNotify); - - SyncScenePlayTeamEntityNotify proto = - SyncScenePlayTeamEntityNotify.newBuilder().setSceneId(player.getSceneId()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SyncScenePlayTeamEntityNotifyOuterClass.SyncScenePlayTeamEntityNotify; + +public class PacketSyncScenePlayTeamEntityNotify extends BasePacket { + + public PacketSyncScenePlayTeamEntityNotify(Player player) { + super(PacketOpcodes.SyncScenePlayTeamEntityNotify); + + SyncScenePlayTeamEntityNotify proto = + SyncScenePlayTeamEntityNotify.newBuilder().setSceneId(player.getSceneId()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSyncTeamEntityNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSyncTeamEntityNotify.java index 517d663b0..33ba6f2c6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSyncTeamEntityNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSyncTeamEntityNotify.java @@ -1,39 +1,39 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; -import emu.grasscutter.net.proto.SyncTeamEntityNotifyOuterClass.SyncTeamEntityNotify; -import emu.grasscutter.net.proto.TeamEntityInfoOuterClass.TeamEntityInfo; - -public class PacketSyncTeamEntityNotify extends BasePacket { - - public PacketSyncTeamEntityNotify(Player player) { - super(PacketOpcodes.SyncTeamEntityNotify); - - SyncTeamEntityNotify.Builder proto = - SyncTeamEntityNotify.newBuilder().setSceneId(player.getSceneId()); - - if (player.getWorld().isMultiplayer()) { - for (Player p : player.getWorld().getPlayers()) { - // Skip if same player - if (player == p) { - continue; - } - - // Set info - TeamEntityInfo info = - TeamEntityInfo.newBuilder() - .setTeamEntityId(p.getTeamManager().getEntityId()) - .setAuthorityPeerId(p.getPeerId()) - .setTeamAbilityInfo(AbilitySyncStateInfo.newBuilder()) - .build(); - - proto.addTeamEntityInfoList(info); - } - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; +import emu.grasscutter.net.proto.SyncTeamEntityNotifyOuterClass.SyncTeamEntityNotify; +import emu.grasscutter.net.proto.TeamEntityInfoOuterClass.TeamEntityInfo; + +public class PacketSyncTeamEntityNotify extends BasePacket { + + public PacketSyncTeamEntityNotify(Player player) { + super(PacketOpcodes.SyncTeamEntityNotify); + + SyncTeamEntityNotify.Builder proto = + SyncTeamEntityNotify.newBuilder().setSceneId(player.getSceneId()); + + if (player.getWorld().isMultiplayer()) { + for (Player p : player.getWorld().getPlayers()) { + // Skip if same player + if (player == p) { + continue; + } + + // Set info + TeamEntityInfo info = + TeamEntityInfo.newBuilder() + .setTeamEntityId(p.getTeamManager().getEntityId()) + .setAuthorityPeerId(p.getPeerId()) + .setTeamAbilityInfo(AbilitySyncStateInfo.newBuilder()) + .build(); + + proto.addTeamEntityInfoList(info); + } + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementGoalRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementGoalRewardRsp.java index 7fb2e8a90..e6ec4f841 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementGoalRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementGoalRewardRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.TakeAchievementGoalRewardRspOuterClass; -import java.util.List; - -public class PacketTakeAchievementGoalRewardRsp extends BasePacket { - public PacketTakeAchievementGoalRewardRsp() { - super(PacketOpcodes.TakeAchievementGoalRewardRsp); - this.setData( - TakeAchievementGoalRewardRspOuterClass.TakeAchievementGoalRewardRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_REWARD_HAS_TAKEN_VALUE) - .build()); - } - - public PacketTakeAchievementGoalRewardRsp( - List ids, List items) { - super(PacketOpcodes.TakeAchievementGoalRewardRsp); - - var rsp = - TakeAchievementGoalRewardRspOuterClass.TakeAchievementGoalRewardRsp.newBuilder() - .addAllIdList(ids) - .addAllItemList(items) - .build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.TakeAchievementGoalRewardRspOuterClass; +import java.util.List; + +public class PacketTakeAchievementGoalRewardRsp extends BasePacket { + public PacketTakeAchievementGoalRewardRsp() { + super(PacketOpcodes.TakeAchievementGoalRewardRsp); + this.setData( + TakeAchievementGoalRewardRspOuterClass.TakeAchievementGoalRewardRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_REWARD_HAS_TAKEN_VALUE) + .build()); + } + + public PacketTakeAchievementGoalRewardRsp( + List ids, List items) { + super(PacketOpcodes.TakeAchievementGoalRewardRsp); + + var rsp = + TakeAchievementGoalRewardRspOuterClass.TakeAchievementGoalRewardRsp.newBuilder() + .addAllIdList(ids) + .addAllItemList(items) + .build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardReq.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardReq.java index a49bdd347..16f42f376 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardReq.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardReq.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeAchievementRewardReqOuterClass.TakeAchievementRewardReq; -import emu.grasscutter.server.game.GameSession; - -public class PacketTakeAchievementRewardReq extends BasePacket { - - public PacketTakeAchievementRewardReq(GameSession session) { - super(PacketOpcodes.TakeAchievementRewardReq); - - TakeAchievementRewardReq proto = TakeAchievementRewardReq.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeAchievementRewardReqOuterClass.TakeAchievementRewardReq; +import emu.grasscutter.server.game.GameSession; + +public class PacketTakeAchievementRewardReq extends BasePacket { + + public PacketTakeAchievementRewardReq(GameSession session) { + super(PacketOpcodes.TakeAchievementRewardReq); + + TakeAchievementRewardReq proto = TakeAchievementRewardReq.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardRsp.java index 651a70579..df0f02c42 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeAchievementRewardRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.TakeAchievementRewardRspOuterClass; -import java.util.List; - -public class PacketTakeAchievementRewardRsp extends BasePacket { - public PacketTakeAchievementRewardRsp() { - super(PacketOpcodes.TakeAchievementRewardRsp); - this.setData( - TakeAchievementRewardRspOuterClass.TakeAchievementRewardRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_REWARD_HAS_TAKEN_VALUE) - .build()); - } - - public PacketTakeAchievementRewardRsp( - List idList, List items) { - super(PacketOpcodes.TakeAchievementRewardRsp); - - var rsp = - TakeAchievementRewardRspOuterClass.TakeAchievementRewardRsp.newBuilder() - .addAllIdList(idList) - .addAllItemList(items) - .build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.TakeAchievementRewardRspOuterClass; +import java.util.List; + +public class PacketTakeAchievementRewardRsp extends BasePacket { + public PacketTakeAchievementRewardRsp() { + super(PacketOpcodes.TakeAchievementRewardRsp); + this.setData( + TakeAchievementRewardRspOuterClass.TakeAchievementRewardRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_REWARD_HAS_TAKEN_VALUE) + .build()); + } + + public PacketTakeAchievementRewardRsp( + List idList, List items) { + super(PacketOpcodes.TakeAchievementRewardRsp); + + var rsp = + TakeAchievementRewardRspOuterClass.TakeAchievementRewardRsp.newBuilder() + .addAllIdList(idList) + .addAllItemList(items) + .build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassMissionPointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassMissionPointRsp.java index d1d6d52e3..faeefd7de 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassMissionPointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassMissionPointRsp.java @@ -1,10 +1,10 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; - -public class PacketTakeBattlePassMissionPointRsp extends BasePacket { - public PacketTakeBattlePassMissionPointRsp() { - super(PacketOpcodes.TakeBattlePassMissionPointRsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; + +public class PacketTakeBattlePassMissionPointRsp extends BasePacket { + public PacketTakeBattlePassMissionPointRsp() { + super(PacketOpcodes.TakeBattlePassMissionPointRsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassRewardRsp.java index 2340e32ab..a9a2b9df6 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeBattlePassRewardRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.BattlePassRewardTakeOptionOuterClass.BattlePassRewardTakeOption; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.TakeBattlePassRewardRspOuterClass.TakeBattlePassRewardRsp; -import java.util.List; - -public class PacketTakeBattlePassRewardRsp extends BasePacket { - public PacketTakeBattlePassRewardRsp( - List takeOptionList, List rewardItems) { - super(PacketOpcodes.TakeBattlePassRewardRsp); - - var proto = TakeBattlePassRewardRsp.newBuilder().addAllTakeOptionList(takeOptionList); - - if (rewardItems != null) { - for (var item : rewardItems) { - proto.addItemList( - ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount())); - } - } - - setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.BattlePassRewardTakeOptionOuterClass.BattlePassRewardTakeOption; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.TakeBattlePassRewardRspOuterClass.TakeBattlePassRewardRsp; +import java.util.List; + +public class PacketTakeBattlePassRewardRsp extends BasePacket { + public PacketTakeBattlePassRewardRsp( + List takeOptionList, List rewardItems) { + super(PacketOpcodes.TakeBattlePassRewardRsp); + + var proto = TakeBattlePassRewardRsp.newBuilder().addAllTakeOptionList(takeOptionList); + + if (rewardItems != null) { + for (var item : rewardItems) { + proto.addItemList( + ItemParam.newBuilder().setItemId(item.getItemId()).setCount(item.getCount())); + } + } + + setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeFurnitureMakeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeFurnitureMakeRsp.java index ecb1aa8ca..8bbd89d7b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeFurnitureMakeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeFurnitureMakeRsp.java @@ -1,37 +1,37 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.FurnitureMakeDataOuterClass; -import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.TakeFurnitureMakeRspOuterClass; -import java.util.List; - -public class PacketTakeFurnitureMakeRsp extends BasePacket { - - public PacketTakeFurnitureMakeRsp( - int ret, - int makeId, - List output, - List others) { - super(PacketOpcodes.TakeFurnitureMakeRsp); - - var proto = TakeFurnitureMakeRspOuterClass.TakeFurnitureMakeRsp.newBuilder(); - - proto.setRetcode(ret).setMakeId(makeId); - - if (output != null) { - proto.addAllOutputItemList(output); - } - - if (others != null) { - proto.setFurnitureMakeSlot( - FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() - .addAllFurnitureMakeDataList(others) - .build()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.FurnitureMakeDataOuterClass; +import emu.grasscutter.net.proto.FurnitureMakeSlotOuterClass; +import emu.grasscutter.net.proto.ItemParamOuterClass; +import emu.grasscutter.net.proto.TakeFurnitureMakeRspOuterClass; +import java.util.List; + +public class PacketTakeFurnitureMakeRsp extends BasePacket { + + public PacketTakeFurnitureMakeRsp( + int ret, + int makeId, + List output, + List others) { + super(PacketOpcodes.TakeFurnitureMakeRsp); + + var proto = TakeFurnitureMakeRspOuterClass.TakeFurnitureMakeRsp.newBuilder(); + + proto.setRetcode(ret).setMakeId(makeId); + + if (output != null) { + proto.addAllOutputItemList(output); + } + + if (others != null) { + proto.setFurnitureMakeSlot( + FurnitureMakeSlotOuterClass.FurnitureMakeSlot.newBuilder() + .addAllFurnitureMakeDataList(others) + .build()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java index 98754094e..e0352dd22 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp; - -public class PacketTakePlayerLevelRewardRsp extends BasePacket { - - public PacketTakePlayerLevelRewardRsp(int level, int rewardId) { - super(PacketOpcodes.TakePlayerLevelRewardRsp); - - int retcode = 0; - - if (rewardId == 0) { - retcode = 1; - } - - TakePlayerLevelRewardRsp proto = - TakePlayerLevelRewardRsp.newBuilder() - .setLevel(level) - .setRewardId(rewardId) - .setRetcode(retcode) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp; + +public class PacketTakePlayerLevelRewardRsp extends BasePacket { + + public PacketTakePlayerLevelRewardRsp(int level, int rewardId) { + super(PacketOpcodes.TakePlayerLevelRewardRsp); + + int retcode = 0; + + if (rewardId == 0) { + retcode = 1; + } + + TakePlayerLevelRewardRsp proto = + TakePlayerLevelRewardRsp.newBuilder() + .setLevel(level) + .setRewardId(rewardId) + .setRetcode(retcode) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeoffEquipRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeoffEquipRsp.java index 69285b537..b2bc1658b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTakeoffEquipRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTakeoffEquipRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TakeoffEquipRspOuterClass.TakeoffEquipRsp; - -public class PacketTakeoffEquipRsp extends BasePacket { - - public PacketTakeoffEquipRsp(long avatarGuid, int slot) { - super(PacketOpcodes.TakeoffEquipRsp); - - TakeoffEquipRsp proto = - TakeoffEquipRsp.newBuilder().setAvatarGuid(avatarGuid).setSlot(slot).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TakeoffEquipRspOuterClass.TakeoffEquipRsp; + +public class PacketTakeoffEquipRsp extends BasePacket { + + public PacketTakeoffEquipRsp(long avatarGuid, int slot) { + super(PacketOpcodes.TakeoffEquipRsp); + + TakeoffEquipRsp proto = + TakeoffEquipRsp.newBuilder().setAvatarGuid(avatarGuid).setSlot(slot).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerAllDataRsp.java index 6702a7173..d1a641e16 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerAllDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerAllDataRsp.java @@ -1,74 +1,74 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.tower.TowerManager; -import emu.grasscutter.game.tower.TowerSystem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerAllDataRspOuterClass.TowerAllDataRsp; -import emu.grasscutter.net.proto.TowerCurLevelRecordOuterClass.TowerCurLevelRecord; -import emu.grasscutter.net.proto.TowerFloorRecordOuterClass.TowerFloorRecord; -import emu.grasscutter.net.proto.TowerLevelRecordOuterClass; -import emu.grasscutter.utils.DateHelper; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -public class PacketTowerAllDataRsp extends BasePacket { - - public PacketTowerAllDataRsp(TowerSystem towerScheduleManager, TowerManager towerManager) { - super(PacketOpcodes.TowerAllDataRsp); - - var recordList = - towerManager.getRecordMap().values().stream() - .map( - rec -> - TowerFloorRecord.newBuilder() - .setFloorId(rec.getFloorId()) - .setFloorStarRewardProgress(rec.getFloorStarRewardProgress()) - .putAllPassedLevelMap(rec.getPassedLevelMap()) - .addAllPassedLevelRecordList( - buildFromPassedLevelMap(rec.getPassedLevelMap())) - .build()) - .toList(); - - var openTimeMap = - towerScheduleManager.getScheduleFloors().stream() - .collect( - Collectors.toMap( - x -> x, - y -> - DateHelper.getUnixTime( - towerScheduleManager.getTowerScheduleConfig().getScheduleStartTime()))); - - TowerAllDataRsp proto = - TowerAllDataRsp.newBuilder() - .setTowerScheduleId(towerScheduleManager.getCurrentTowerScheduleData().getScheduleId()) - .addAllTowerFloorRecordList(recordList) - .setCurLevelRecord(TowerCurLevelRecord.newBuilder().setIsEmpty(true)) - .setScheduleStartTime( - DateHelper.getUnixTime( - towerScheduleManager.getTowerScheduleConfig().getScheduleStartTime())) - .setNextScheduleChangeTime( - DateHelper.getUnixTime( - towerScheduleManager.getTowerScheduleConfig().getNextScheduleChangeTime())) - .putAllFloorOpenTimeMap(openTimeMap) - .setIsFinishedEntranceFloor(towerManager.canEnterScheduleFloor()) - .build(); - - this.setData(proto); - } - - private List buildFromPassedLevelMap( - Map map) { - return map.entrySet().stream() - .map( - item -> - TowerLevelRecordOuterClass.TowerLevelRecord.newBuilder() - .setLevelId(item.getKey()) - .addAllSatisfiedCondList( - IntStream.range(1, item.getValue() + 1).boxed().toList()) - .build()) - .toList(); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.tower.TowerManager; +import emu.grasscutter.game.tower.TowerSystem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerAllDataRspOuterClass.TowerAllDataRsp; +import emu.grasscutter.net.proto.TowerCurLevelRecordOuterClass.TowerCurLevelRecord; +import emu.grasscutter.net.proto.TowerFloorRecordOuterClass.TowerFloorRecord; +import emu.grasscutter.net.proto.TowerLevelRecordOuterClass; +import emu.grasscutter.utils.DateHelper; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class PacketTowerAllDataRsp extends BasePacket { + + public PacketTowerAllDataRsp(TowerSystem towerScheduleManager, TowerManager towerManager) { + super(PacketOpcodes.TowerAllDataRsp); + + var recordList = + towerManager.getRecordMap().values().stream() + .map( + rec -> + TowerFloorRecord.newBuilder() + .setFloorId(rec.getFloorId()) + .setFloorStarRewardProgress(rec.getFloorStarRewardProgress()) + .putAllPassedLevelMap(rec.getPassedLevelMap()) + .addAllPassedLevelRecordList( + buildFromPassedLevelMap(rec.getPassedLevelMap())) + .build()) + .toList(); + + var openTimeMap = + towerScheduleManager.getScheduleFloors().stream() + .collect( + Collectors.toMap( + x -> x, + y -> + DateHelper.getUnixTime( + towerScheduleManager.getTowerScheduleConfig().getScheduleStartTime()))); + + TowerAllDataRsp proto = + TowerAllDataRsp.newBuilder() + .setTowerScheduleId(towerScheduleManager.getCurrentTowerScheduleData().getScheduleId()) + .addAllTowerFloorRecordList(recordList) + .setCurLevelRecord(TowerCurLevelRecord.newBuilder().setIsEmpty(true)) + .setScheduleStartTime( + DateHelper.getUnixTime( + towerScheduleManager.getTowerScheduleConfig().getScheduleStartTime())) + .setNextScheduleChangeTime( + DateHelper.getUnixTime( + towerScheduleManager.getTowerScheduleConfig().getNextScheduleChangeTime())) + .putAllFloorOpenTimeMap(openTimeMap) + .setIsFinishedEntranceFloor(towerManager.canEnterScheduleFloor()) + .build(); + + this.setData(proto); + } + + private List buildFromPassedLevelMap( + Map map) { + return map.entrySet().stream() + .map( + item -> + TowerLevelRecordOuterClass.TowerLevelRecord.newBuilder() + .setLevelId(item.getKey()) + .addAllSatisfiedCondList( + IntStream.range(1, item.getValue() + 1).boxed().toList()) + .build()) + .toList(); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerCurLevelRecordChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerCurLevelRecordChangeNotify.java index 53ed3508e..816b15120 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerCurLevelRecordChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerCurLevelRecordChangeNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerCurLevelRecordChangeNotifyOuterClass.TowerCurLevelRecordChangeNotify; -import emu.grasscutter.net.proto.TowerCurLevelRecordOuterClass.TowerCurLevelRecord; - -public class PacketTowerCurLevelRecordChangeNotify extends BasePacket { - - public PacketTowerCurLevelRecordChangeNotify(int curFloorId, int curLevelIndex) { - super(PacketOpcodes.TowerCurLevelRecordChangeNotify); - - TowerCurLevelRecordChangeNotify proto = - TowerCurLevelRecordChangeNotify.newBuilder() - .setCurLevelRecord( - TowerCurLevelRecord.newBuilder() - .setCurFloorId(curFloorId) - .setCurLevelIndex(curLevelIndex) - // TODO team info - .build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerCurLevelRecordChangeNotifyOuterClass.TowerCurLevelRecordChangeNotify; +import emu.grasscutter.net.proto.TowerCurLevelRecordOuterClass.TowerCurLevelRecord; + +public class PacketTowerCurLevelRecordChangeNotify extends BasePacket { + + public PacketTowerCurLevelRecordChangeNotify(int curFloorId, int curLevelIndex) { + super(PacketOpcodes.TowerCurLevelRecordChangeNotify); + + TowerCurLevelRecordChangeNotify proto = + TowerCurLevelRecordChangeNotify.newBuilder() + .setCurLevelRecord( + TowerCurLevelRecord.newBuilder() + .setCurFloorId(curFloorId) + .setCurLevelIndex(curLevelIndex) + // TODO team info + .build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerEnterLevelRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerEnterLevelRsp.java index eae82e783..796d9a291 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerEnterLevelRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerEnterLevelRsp.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerEnterLevelRspOuterClass.TowerEnterLevelRsp; - -public class PacketTowerEnterLevelRsp extends BasePacket { - - public PacketTowerEnterLevelRsp(int floorId, int levelIndex) { - super(PacketOpcodes.TowerEnterLevelRsp); - - TowerEnterLevelRsp proto = - TowerEnterLevelRsp.newBuilder() - .setFloorId(floorId) - .setLevelIndex(levelIndex) - .addTowerBuffIdList(4) - .addTowerBuffIdList(28) - .addTowerBuffIdList(18) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerEnterLevelRspOuterClass.TowerEnterLevelRsp; + +public class PacketTowerEnterLevelRsp extends BasePacket { + + public PacketTowerEnterLevelRsp(int floorId, int levelIndex) { + super(PacketOpcodes.TowerEnterLevelRsp); + + TowerEnterLevelRsp proto = + TowerEnterLevelRsp.newBuilder() + .setFloorId(floorId) + .setLevelIndex(levelIndex) + .addTowerBuffIdList(4) + .addTowerBuffIdList(28) + .addTowerBuffIdList(18) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerFloorRecordChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerFloorRecordChangeNotify.java index 7b343f7b1..6c81740e3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerFloorRecordChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerFloorRecordChangeNotify.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerFloorRecordChangeNotifyOuterClass.TowerFloorRecordChangeNotify; -import emu.grasscutter.net.proto.TowerFloorRecordOuterClass.TowerFloorRecord; -import emu.grasscutter.net.proto.TowerLevelRecordOuterClass.TowerLevelRecord; - -public class PacketTowerFloorRecordChangeNotify extends BasePacket { - - public PacketTowerFloorRecordChangeNotify(int floorId, int stars, boolean canEnterScheduleFloor) { - super(PacketOpcodes.TowerFloorRecordChangeNotify); - - TowerFloorRecordChangeNotify proto = - TowerFloorRecordChangeNotify.newBuilder() - .addTowerFloorRecordList( - TowerFloorRecord.newBuilder() - .setFloorId(floorId) - .setFloorStarRewardProgress(stars) - .addPassedLevelRecordList( - TowerLevelRecord.newBuilder() - .setLevelId(1) - .addSatisfiedCondList(1) - .addSatisfiedCondList(2) - .addSatisfiedCondList(3) - .build()) - .build()) - .setIsFinishedEntranceFloor(canEnterScheduleFloor) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerFloorRecordChangeNotifyOuterClass.TowerFloorRecordChangeNotify; +import emu.grasscutter.net.proto.TowerFloorRecordOuterClass.TowerFloorRecord; +import emu.grasscutter.net.proto.TowerLevelRecordOuterClass.TowerLevelRecord; + +public class PacketTowerFloorRecordChangeNotify extends BasePacket { + + public PacketTowerFloorRecordChangeNotify(int floorId, int stars, boolean canEnterScheduleFloor) { + super(PacketOpcodes.TowerFloorRecordChangeNotify); + + TowerFloorRecordChangeNotify proto = + TowerFloorRecordChangeNotify.newBuilder() + .addTowerFloorRecordList( + TowerFloorRecord.newBuilder() + .setFloorId(floorId) + .setFloorStarRewardProgress(stars) + .addPassedLevelRecordList( + TowerLevelRecord.newBuilder() + .setLevelId(1) + .addSatisfiedCondList(1) + .addSatisfiedCondList(2) + .addSatisfiedCondList(3) + .build()) + .build()) + .setIsFinishedEntranceFloor(canEnterScheduleFloor) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerLevelStarCondNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerLevelStarCondNotify.java index f04e5ed70..115c39e96 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerLevelStarCondNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerLevelStarCondNotify.java @@ -1,33 +1,33 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerLevelStarCondDataOuterClass.TowerLevelStarCondData; -import emu.grasscutter.net.proto.TowerLevelStarCondNotifyOuterClass.TowerLevelStarCondNotify; - -public class PacketTowerLevelStarCondNotify extends BasePacket { - - public PacketTowerLevelStarCondNotify(int floorId, int levelIndex) { - super(PacketOpcodes.TowerLevelStarCondNotify); - - TowerLevelStarCondNotify proto = - TowerLevelStarCondNotify.newBuilder() - .setFloorId(floorId) - .setLevelIndex(levelIndex) - .addCondDataList( - TowerLevelStarCondData.newBuilder() - // .setCondValue(1) - .build()) - .addCondDataList( - TowerLevelStarCondData.newBuilder() - // .setCondValue(2) - .build()) - .addCondDataList( - TowerLevelStarCondData.newBuilder() - // .setCondValue(3) - .build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerLevelStarCondDataOuterClass.TowerLevelStarCondData; +import emu.grasscutter.net.proto.TowerLevelStarCondNotifyOuterClass.TowerLevelStarCondNotify; + +public class PacketTowerLevelStarCondNotify extends BasePacket { + + public PacketTowerLevelStarCondNotify(int floorId, int levelIndex) { + super(PacketOpcodes.TowerLevelStarCondNotify); + + TowerLevelStarCondNotify proto = + TowerLevelStarCondNotify.newBuilder() + .setFloorId(floorId) + .setLevelIndex(levelIndex) + .addCondDataList( + TowerLevelStarCondData.newBuilder() + // .setCondValue(1) + .build()) + .addCondDataList( + TowerLevelStarCondData.newBuilder() + // .setCondValue(2) + .build()) + .addCondDataList( + TowerLevelStarCondData.newBuilder() + // .setCondValue(3) + .build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerMiddleLevelChangeTeamNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerMiddleLevelChangeTeamNotify.java index c20bd1ad5..c03c39632 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerMiddleLevelChangeTeamNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerMiddleLevelChangeTeamNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerMiddleLevelChangeTeamNotifyOuterClass; - -public class PacketTowerMiddleLevelChangeTeamNotify extends BasePacket { - - public PacketTowerMiddleLevelChangeTeamNotify() { - super(PacketOpcodes.TowerMiddleLevelChangeTeamNotify); - - TowerMiddleLevelChangeTeamNotifyOuterClass.TowerMiddleLevelChangeTeamNotify proto = - TowerMiddleLevelChangeTeamNotifyOuterClass.TowerMiddleLevelChangeTeamNotify.newBuilder() - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerMiddleLevelChangeTeamNotifyOuterClass; + +public class PacketTowerMiddleLevelChangeTeamNotify extends BasePacket { + + public PacketTowerMiddleLevelChangeTeamNotify() { + super(PacketOpcodes.TowerMiddleLevelChangeTeamNotify); + + TowerMiddleLevelChangeTeamNotifyOuterClass.TowerMiddleLevelChangeTeamNotify proto = + TowerMiddleLevelChangeTeamNotifyOuterClass.TowerMiddleLevelChangeTeamNotify.newBuilder() + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerTeamSelectRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerTeamSelectRsp.java index 93ab0a16d..1784a964a 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTowerTeamSelectRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTowerTeamSelectRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.TowerTeamSelectRspOuterClass.TowerTeamSelectRsp; - -public class PacketTowerTeamSelectRsp extends BasePacket { - - public PacketTowerTeamSelectRsp() { - super(PacketOpcodes.TowerTeamSelectRsp); - - TowerTeamSelectRsp proto = TowerTeamSelectRsp.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.TowerTeamSelectRspOuterClass.TowerTeamSelectRsp; + +public class PacketTowerTeamSelectRsp extends BasePacket { + + public PacketTowerTeamSelectRsp() { + super(PacketOpcodes.TowerTeamSelectRsp); + + TowerTeamSelectRsp proto = TowerTeamSelectRsp.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketTryEnterHomeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketTryEnterHomeRsp.java index dad190498..76e4ada48 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketTryEnterHomeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketTryEnterHomeRsp.java @@ -1,44 +1,44 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.TryEnterHomeRspOuterClass; - -public class PacketTryEnterHomeRsp extends BasePacket { - - public PacketTryEnterHomeRsp() { - super(PacketOpcodes.TryEnterHomeRsp); - - TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = - TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() - .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) - .build(); - - this.setData(proto); - } - - public PacketTryEnterHomeRsp(int uid) { - super(PacketOpcodes.TryEnterHomeRsp); - - TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = - TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() - .setRetcode(0) - .setTargetUid(uid) - .build(); - - this.setData(proto); - } - - public PacketTryEnterHomeRsp(int retCode, int uid) { - super(PacketOpcodes.TryEnterHomeRsp); - - TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = - TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() - .setRetcode(retCode) - .setTargetUid(uid) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.TryEnterHomeRspOuterClass; + +public class PacketTryEnterHomeRsp extends BasePacket { + + public PacketTryEnterHomeRsp() { + super(PacketOpcodes.TryEnterHomeRsp); + + TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = + TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() + .setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE) + .build(); + + this.setData(proto); + } + + public PacketTryEnterHomeRsp(int uid) { + super(PacketOpcodes.TryEnterHomeRsp); + + TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = + TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() + .setRetcode(0) + .setTargetUid(uid) + .build(); + + this.setData(proto); + } + + public PacketTryEnterHomeRsp(int retCode, int uid) { + super(PacketOpcodes.TryEnterHomeRsp); + + TryEnterHomeRspOuterClass.TryEnterHomeRsp proto = + TryEnterHomeRspOuterClass.TryEnterHomeRsp.newBuilder() + .setRetcode(retCode) + .setTargetUid(uid) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockAvatarTalentRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockAvatarTalentRsp.java index eb1ddfeea..870476e0b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockAvatarTalentRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockAvatarTalentRsp.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnlockAvatarTalentRspOuterClass.UnlockAvatarTalentRsp; - -public class PacketUnlockAvatarTalentRsp extends BasePacket { - - public PacketUnlockAvatarTalentRsp(Avatar avatar, int talentId) { - super(PacketOpcodes.UnlockAvatarTalentRsp); - - UnlockAvatarTalentRsp proto = - UnlockAvatarTalentRsp.newBuilder() - .setAvatarGuid(avatar.getGuid()) - .setTalentId(talentId) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnlockAvatarTalentRspOuterClass.UnlockAvatarTalentRsp; + +public class PacketUnlockAvatarTalentRsp extends BasePacket { + + public PacketUnlockAvatarTalentRsp(Avatar avatar, int talentId) { + super(PacketOpcodes.UnlockAvatarTalentRsp); + + UnlockAvatarTalentRsp proto = + UnlockAvatarTalentRsp.newBuilder() + .setAvatarGuid(avatar.getGuid()) + .setTalentId(talentId) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockNameCardNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockNameCardNotify.java index f626badec..f435af212 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockNameCardNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockNameCardNotify.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnlockNameCardNotifyOuterClass.UnlockNameCardNotify; - -public class PacketUnlockNameCardNotify extends BasePacket { - - public PacketUnlockNameCardNotify(int nameCard) { - super(PacketOpcodes.UnlockNameCardNotify); - - UnlockNameCardNotify proto = UnlockNameCardNotify.newBuilder().setNameCardId(nameCard).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnlockNameCardNotifyOuterClass.UnlockNameCardNotify; + +public class PacketUnlockNameCardNotify extends BasePacket { + + public PacketUnlockNameCardNotify(int nameCard) { + super(PacketOpcodes.UnlockNameCardNotify); + + UnlockNameCardNotify proto = UnlockNameCardNotify.newBuilder().setNameCardId(nameCard).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockTransPointRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockTransPointRsp.java index 650f678f7..fe7f52fe1 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockTransPointRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockTransPointRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; -import emu.grasscutter.net.proto.UnlockTransPointRspOuterClass.UnlockTransPointRsp; - -public class PacketUnlockTransPointRsp extends BasePacket { - public PacketUnlockTransPointRsp(Retcode retcode) { - super(PacketOpcodes.UnlockTransPointRsp); - - UnlockTransPointRsp proto = - UnlockTransPointRsp.newBuilder().setRetcode(retcode.getNumber()).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.net.proto.UnlockTransPointRspOuterClass.UnlockTransPointRsp; + +public class PacketUnlockTransPointRsp extends BasePacket { + public PacketUnlockTransPointRsp(Retcode retcode) { + super(PacketOpcodes.UnlockTransPointRsp); + + UnlockTransPointRsp proto = + UnlockTransPointRsp.newBuilder().setRetcode(retcode.getNumber()).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureFormulaDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureFormulaDataNotify.java index 285c785ee..6be0fb949 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureFormulaDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureFormulaDataNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnlockedFurnitureFormulaDataNotifyOuterClass; -import java.util.Set; - -public class PacketUnlockedFurnitureFormulaDataNotify extends BasePacket { - - public PacketUnlockedFurnitureFormulaDataNotify(Set unlockList) { - super(PacketOpcodes.UnlockedFurnitureFormulaDataNotify); - - var proto = - UnlockedFurnitureFormulaDataNotifyOuterClass.UnlockedFurnitureFormulaDataNotify - .newBuilder(); - - proto.addAllFurnitureIdList(unlockList); - proto.setIsAll(true); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnlockedFurnitureFormulaDataNotifyOuterClass; +import java.util.Set; + +public class PacketUnlockedFurnitureFormulaDataNotify extends BasePacket { + + public PacketUnlockedFurnitureFormulaDataNotify(Set unlockList) { + super(PacketOpcodes.UnlockedFurnitureFormulaDataNotify); + + var proto = + UnlockedFurnitureFormulaDataNotifyOuterClass.UnlockedFurnitureFormulaDataNotify + .newBuilder(); + + proto.addAllFurnitureIdList(unlockList); + proto.setIsAll(true); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureSuiteDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureSuiteDataNotify.java index 93ff73476..59a9cfe05 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureSuiteDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUnlockedFurnitureSuiteDataNotify.java @@ -1,21 +1,21 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UnlockedFurnitureSuiteDataNotifyOuterClass; -import java.util.Set; - -public class PacketUnlockedFurnitureSuiteDataNotify extends BasePacket { - - public PacketUnlockedFurnitureSuiteDataNotify(Set unlockList) { - super(PacketOpcodes.UnlockedFurnitureSuiteDataNotify); - - var proto = - UnlockedFurnitureSuiteDataNotifyOuterClass.UnlockedFurnitureSuiteDataNotify.newBuilder(); - - proto.addAllFurnitureSuiteIdList(unlockList); - proto.setIsAll(true); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UnlockedFurnitureSuiteDataNotifyOuterClass; +import java.util.Set; + +public class PacketUnlockedFurnitureSuiteDataNotify extends BasePacket { + + public PacketUnlockedFurnitureSuiteDataNotify(Set unlockList) { + super(PacketOpcodes.UnlockedFurnitureSuiteDataNotify); + + var proto = + UnlockedFurnitureSuiteDataNotifyOuterClass.UnlockedFurnitureSuiteDataNotify.newBuilder(); + + proto.addAllFurnitureSuiteIdList(unlockList); + proto.setIsAll(true); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java index 405aa86a5..5fafa206d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListRspOuterClass.UpdatePlayerShowAvatarListRsp; -import java.util.List; - -public class PacketUpdatePlayerShowAvatarListRsp extends BasePacket { - - public PacketUpdatePlayerShowAvatarListRsp(boolean isShowAvatar, List avatarIds) { - super(PacketOpcodes.UpdatePlayerShowAvatarListRsp); - - UpdatePlayerShowAvatarListRsp proto = - UpdatePlayerShowAvatarListRsp.newBuilder() - .setIsShowAvatar(isShowAvatar) - .addAllShowAvatarIdList(avatarIds) - .setRetcode(0) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListRspOuterClass.UpdatePlayerShowAvatarListRsp; +import java.util.List; + +public class PacketUpdatePlayerShowAvatarListRsp extends BasePacket { + + public PacketUpdatePlayerShowAvatarListRsp(boolean isShowAvatar, List avatarIds) { + super(PacketOpcodes.UpdatePlayerShowAvatarListRsp); + + UpdatePlayerShowAvatarListRsp proto = + UpdatePlayerShowAvatarListRsp.newBuilder() + .setIsShowAvatar(isShowAvatar) + .addAllShowAvatarIdList(avatarIds) + .setRetcode(0) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowNameCardListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowNameCardListRsp.java index 736d39535..95b395e0b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowNameCardListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowNameCardListRsp.java @@ -1,20 +1,20 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.UpdatePlayerShowNameCardListRspOuterClass; -import java.util.List; - -public class PacketUpdatePlayerShowNameCardListRsp extends BasePacket { - public PacketUpdatePlayerShowNameCardListRsp(List cardIds) { - super(PacketOpcodes.UpdatePlayerShowNameCardListRsp); - - var rsp = - UpdatePlayerShowNameCardListRspOuterClass.UpdatePlayerShowNameCardListRsp.newBuilder() - .addAllShowNameCardIdList(cardIds) - .setRetcode(0) - .build(); - - this.setData(rsp); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.UpdatePlayerShowNameCardListRspOuterClass; +import java.util.List; + +public class PacketUpdatePlayerShowNameCardListRsp extends BasePacket { + public PacketUpdatePlayerShowNameCardListRsp(List cardIds) { + super(PacketOpcodes.UpdatePlayerShowNameCardListRsp); + + var rsp = + UpdatePlayerShowNameCardListRspOuterClass.UpdatePlayerShowNameCardListRsp.newBuilder() + .addAllShowNameCardIdList(cardIds) + .setRetcode(0) + .build(); + + this.setData(rsp); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketUseItemRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUseItemRsp.java index 8841c09cf..9147438ed 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketUseItemRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUseItemRsp.java @@ -1,32 +1,32 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.RetcodeOuterClass; -import emu.grasscutter.net.proto.UseItemRspOuterClass.UseItemRsp; - -public class PacketUseItemRsp extends BasePacket { - - public PacketUseItemRsp(long targetGuid, GameItem useItem) { - super(PacketOpcodes.UseItemRsp); - - UseItemRsp proto = - UseItemRsp.newBuilder() - .setTargetGuid(targetGuid) - .setItemId(useItem.getItemId()) - .setGuid(useItem.getGuid()) - .build(); - - this.setData(proto); - } - - public PacketUseItemRsp() { - super(PacketOpcodes.UseItemRsp); - - UseItemRsp proto = - UseItemRsp.newBuilder().setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.RetcodeOuterClass; +import emu.grasscutter.net.proto.UseItemRspOuterClass.UseItemRsp; + +public class PacketUseItemRsp extends BasePacket { + + public PacketUseItemRsp(long targetGuid, GameItem useItem) { + super(PacketOpcodes.UseItemRsp); + + UseItemRsp proto = + UseItemRsp.newBuilder() + .setTargetGuid(targetGuid) + .setItemId(useItem.getItemId()) + .setGuid(useItem.getGuid()) + .build(); + + this.setData(proto); + } + + public PacketUseItemRsp() { + super(PacketOpcodes.UseItemRsp); + + UseItemRsp proto = + UseItemRsp.newBuilder().setRetcode(RetcodeOuterClass.Retcode.RET_SVR_ERROR_VALUE).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleStaminaNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleStaminaNotify.java index af596dbbd..1510b1cc9 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleStaminaNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketVehicleStaminaNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.VehicleStaminaNotifyOuterClass.VehicleStaminaNotify; - -public class PacketVehicleStaminaNotify extends BasePacket { - - public PacketVehicleStaminaNotify(int vehicleId, float newStamina) { - super(PacketOpcodes.VehicleStaminaNotify); - VehicleStaminaNotify.Builder proto = VehicleStaminaNotify.newBuilder(); - - proto.setEntityId(vehicleId); - proto.setCurStamina(newStamina); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.VehicleStaminaNotifyOuterClass.VehicleStaminaNotify; + +public class PacketVehicleStaminaNotify extends BasePacket { + + public PacketVehicleStaminaNotify(int vehicleId, float newStamina) { + super(PacketOpcodes.VehicleStaminaNotify); + VehicleStaminaNotify.Builder proto = VehicleStaminaNotify.newBuilder(); + + proto.setEntityId(vehicleId); + proto.setCurStamina(newStamina); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponAwakenRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponAwakenRsp.java index 5ef496539..3bf49d12d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponAwakenRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponAwakenRsp.java @@ -1,31 +1,31 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.avatar.Avatar; -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WeaponAwakenRspOuterClass.WeaponAwakenRsp; - -public class PacketWeaponAwakenRsp extends BasePacket { - - public PacketWeaponAwakenRsp( - Avatar avatar, GameItem item, GameItem feedWeapon, int oldRefineLevel) { - super(PacketOpcodes.WeaponAwakenRsp); - - WeaponAwakenRsp.Builder proto = - WeaponAwakenRsp.newBuilder() - .setTargetWeaponGuid(item.getGuid()) - .setTargetWeaponAwakenLevel(item.getRefinement()); - - for (int affixId : item.getAffixes()) { - proto.putOldAffixLevelMap(affixId, oldRefineLevel); - proto.putCurAffixLevelMap(affixId, item.getRefinement()); - } - - if (avatar != null) { - proto.setAvatarGuid(avatar.getGuid()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.avatar.Avatar; +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WeaponAwakenRspOuterClass.WeaponAwakenRsp; + +public class PacketWeaponAwakenRsp extends BasePacket { + + public PacketWeaponAwakenRsp( + Avatar avatar, GameItem item, GameItem feedWeapon, int oldRefineLevel) { + super(PacketOpcodes.WeaponAwakenRsp); + + WeaponAwakenRsp.Builder proto = + WeaponAwakenRsp.newBuilder() + .setTargetWeaponGuid(item.getGuid()) + .setTargetWeaponAwakenLevel(item.getRefinement()); + + for (int affixId : item.getAffixes()) { + proto.putOldAffixLevelMap(affixId, oldRefineLevel); + proto.putCurAffixLevelMap(affixId, item.getRefinement()); + } + + if (avatar != null) { + proto.setAvatarGuid(avatar.getGuid()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponPromoteRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponPromoteRsp.java index 7ea85b386..dac904f24 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponPromoteRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponPromoteRsp.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WeaponPromoteRspOuterClass.WeaponPromoteRsp; - -public class PacketWeaponPromoteRsp extends BasePacket { - - public PacketWeaponPromoteRsp(GameItem item, int oldPromoteLevel) { - super(PacketOpcodes.WeaponPromoteRsp); - - WeaponPromoteRsp proto = - WeaponPromoteRsp.newBuilder() - .setTargetWeaponGuid(item.getGuid()) - .setCurPromoteLevel(item.getPromoteLevel()) - .setOldPromoteLevel(oldPromoteLevel) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WeaponPromoteRspOuterClass.WeaponPromoteRsp; + +public class PacketWeaponPromoteRsp extends BasePacket { + + public PacketWeaponPromoteRsp(GameItem item, int oldPromoteLevel) { + super(PacketOpcodes.WeaponPromoteRsp); + + WeaponPromoteRsp proto = + WeaponPromoteRsp.newBuilder() + .setTargetWeaponGuid(item.getGuid()) + .setCurPromoteLevel(item.getPromoteLevel()) + .setOldPromoteLevel(oldPromoteLevel) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponUpgradeRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponUpgradeRsp.java index 4e70f5365..0abe162d0 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponUpgradeRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWeaponUpgradeRsp.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; -import emu.grasscutter.net.proto.WeaponUpgradeRspOuterClass.WeaponUpgradeRsp; -import java.util.List; - -public class PacketWeaponUpgradeRsp extends BasePacket { - - public PacketWeaponUpgradeRsp(GameItem item, int oldLevel, List leftoverOres) { - super(PacketOpcodes.WeaponUpgradeRsp); - - WeaponUpgradeRsp proto = - WeaponUpgradeRsp.newBuilder() - .setTargetWeaponGuid(item.getGuid()) - .setCurLevel(item.getLevel()) - .setOldLevel(oldLevel) - .addAllItemParamList(leftoverOres) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; +import emu.grasscutter.net.proto.WeaponUpgradeRspOuterClass.WeaponUpgradeRsp; +import java.util.List; + +public class PacketWeaponUpgradeRsp extends BasePacket { + + public PacketWeaponUpgradeRsp(GameItem item, int oldLevel, List leftoverOres) { + super(PacketOpcodes.WeaponUpgradeRsp); + + WeaponUpgradeRsp proto = + WeaponUpgradeRsp.newBuilder() + .setTargetWeaponGuid(item.getGuid()) + .setCurLevel(item.getLevel()) + .setOldLevel(oldLevel) + .addAllItemParamList(leftoverOres) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWearEquipRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWearEquipRsp.java index 49adfaa11..81d2ea2f2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWearEquipRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWearEquipRsp.java @@ -1,17 +1,17 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WearEquipRspOuterClass.WearEquipRsp; - -public class PacketWearEquipRsp extends BasePacket { - - public PacketWearEquipRsp(long avatarGuid, long equipGuid) { - super(PacketOpcodes.WearEquipRsp); - - WearEquipRsp proto = - WearEquipRsp.newBuilder().setAvatarGuid(avatarGuid).setEquipGuid(equipGuid).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WearEquipRspOuterClass.WearEquipRsp; + +public class PacketWearEquipRsp extends BasePacket { + + public PacketWearEquipRsp(long avatarGuid, long equipGuid) { + super(PacketOpcodes.WearEquipRsp); + + WearEquipRsp proto = + WearEquipRsp.newBuilder().setAvatarGuid(avatarGuid).setEquipGuid(equipGuid).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetCoolDownNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetCoolDownNotify.java index 407e7c398..0162ba09b 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetCoolDownNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetCoolDownNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WidgetCoolDownDataOuterClass; -import emu.grasscutter.net.proto.WidgetCoolDownNotifyOuterClass; - -public class PacketWidgetCoolDownNotify extends BasePacket { - - public PacketWidgetCoolDownNotify(int id, long coolDownTime, boolean isSuccess) { - super(PacketOpcodes.WidgetCoolDownNotify); - - WidgetCoolDownNotifyOuterClass.WidgetCoolDownNotify proto = - WidgetCoolDownNotifyOuterClass.WidgetCoolDownNotify.newBuilder() - .addGroupCoolDownDataList( - WidgetCoolDownDataOuterClass.WidgetCoolDownData.newBuilder() - .setId(id) - .setCoolDownTime(coolDownTime) - .setIsSuccess(isSuccess) - .build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WidgetCoolDownDataOuterClass; +import emu.grasscutter.net.proto.WidgetCoolDownNotifyOuterClass; + +public class PacketWidgetCoolDownNotify extends BasePacket { + + public PacketWidgetCoolDownNotify(int id, long coolDownTime, boolean isSuccess) { + super(PacketOpcodes.WidgetCoolDownNotify); + + WidgetCoolDownNotifyOuterClass.WidgetCoolDownNotify proto = + WidgetCoolDownNotifyOuterClass.WidgetCoolDownNotify.newBuilder() + .addGroupCoolDownDataList( + WidgetCoolDownDataOuterClass.WidgetCoolDownData.newBuilder() + .setId(id) + .setCoolDownTime(coolDownTime) + .setIsSuccess(isSuccess) + .build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetDoBagRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetDoBagRsp.java index 37f74ade2..f26053c17 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetDoBagRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetDoBagRsp.java @@ -1,29 +1,29 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WidgetDoBagRspOuterClass; - -public class PacketWidgetDoBagRsp extends BasePacket { - - public PacketWidgetDoBagRsp(int materialId) { - super(PacketOpcodes.WidgetDoBagRsp); - - WidgetDoBagRspOuterClass.WidgetDoBagRsp proto = - WidgetDoBagRspOuterClass.WidgetDoBagRsp.newBuilder() - .setMaterialId(materialId) - .setRetcode(0) - .build(); - - this.setData(proto); - } - - public PacketWidgetDoBagRsp() { - super(PacketOpcodes.WidgetDoBagRsp); - - WidgetDoBagRspOuterClass.WidgetDoBagRsp proto = - WidgetDoBagRspOuterClass.WidgetDoBagRsp.newBuilder().build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WidgetDoBagRspOuterClass; + +public class PacketWidgetDoBagRsp extends BasePacket { + + public PacketWidgetDoBagRsp(int materialId) { + super(PacketOpcodes.WidgetDoBagRsp); + + WidgetDoBagRspOuterClass.WidgetDoBagRsp proto = + WidgetDoBagRspOuterClass.WidgetDoBagRsp.newBuilder() + .setMaterialId(materialId) + .setRetcode(0) + .build(); + + this.setData(proto); + } + + public PacketWidgetDoBagRsp() { + super(PacketOpcodes.WidgetDoBagRsp); + + WidgetDoBagRspOuterClass.WidgetDoBagRsp proto = + WidgetDoBagRspOuterClass.WidgetDoBagRsp.newBuilder().build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetGadgetDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetGadgetDataNotify.java index bef05ba6c..5d40772e2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetGadgetDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetGadgetDataNotify.java @@ -1,42 +1,42 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WidgetGadgetDataNotifyOuterClass; -import emu.grasscutter.net.proto.WidgetGadgetDataOuterClass; -import java.io.IOException; -import java.util.List; - -public class PacketWidgetGadgetDataNotify extends BasePacket { - - public PacketWidgetGadgetDataNotify(int gadgetId, List gadgetEntityIdList) - throws IOException { - super(PacketOpcodes.WidgetGadgetDataNotify); - - WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify proto = - WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify.newBuilder() - .setWidgetGadgetData( - WidgetGadgetDataOuterClass.WidgetGadgetData.newBuilder() - .setGadgetId(gadgetId) - .addAllGadgetEntityIdList(gadgetEntityIdList) - .build()) - .build(); - - this.setData(proto); - } - - public PacketWidgetGadgetDataNotify(int gadgetId, int gadgetEntityIdList) throws IOException { - super(PacketOpcodes.WidgetGadgetDataNotify); - - WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify proto = - WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify.newBuilder() - .setWidgetGadgetData( - WidgetGadgetDataOuterClass.WidgetGadgetData.newBuilder() - .setGadgetId(gadgetId) - .addGadgetEntityIdList(gadgetEntityIdList) - .build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WidgetGadgetDataNotifyOuterClass; +import emu.grasscutter.net.proto.WidgetGadgetDataOuterClass; +import java.io.IOException; +import java.util.List; + +public class PacketWidgetGadgetDataNotify extends BasePacket { + + public PacketWidgetGadgetDataNotify(int gadgetId, List gadgetEntityIdList) + throws IOException { + super(PacketOpcodes.WidgetGadgetDataNotify); + + WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify proto = + WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify.newBuilder() + .setWidgetGadgetData( + WidgetGadgetDataOuterClass.WidgetGadgetData.newBuilder() + .setGadgetId(gadgetId) + .addAllGadgetEntityIdList(gadgetEntityIdList) + .build()) + .build(); + + this.setData(proto); + } + + public PacketWidgetGadgetDataNotify(int gadgetId, int gadgetEntityIdList) throws IOException { + super(PacketOpcodes.WidgetGadgetDataNotify); + + WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify proto = + WidgetGadgetDataNotifyOuterClass.WidgetGadgetDataNotify.newBuilder() + .setWidgetGadgetData( + WidgetGadgetDataOuterClass.WidgetGadgetData.newBuilder() + .setGadgetId(gadgetId) + .addGadgetEntityIdList(gadgetEntityIdList) + .build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetSlotChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetSlotChangeNotify.java index 8448b288c..07b97e226 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetSlotChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWidgetSlotChangeNotify.java @@ -1,44 +1,44 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WidgetSlotChangeNotifyOuterClass; -import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; -import emu.grasscutter.net.proto.WidgetSlotOpOuterClass; - -public class PacketWidgetSlotChangeNotify extends BasePacket { - - public PacketWidgetSlotChangeNotify( - WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto) { - super(PacketOpcodes.WidgetSlotChangeNotify); - - this.setData(proto); - } - - public PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp op) { - super(PacketOpcodes.WidgetSlotChangeNotify); - - WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = - WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder() - .setOp(op) - .setSlot(WidgetSlotDataOuterClass.WidgetSlotData.newBuilder().setIsActive(true).build()) - .build(); - - this.setData(proto); - } - - public PacketWidgetSlotChangeNotify(int materialId) { - super(PacketOpcodes.WidgetSlotChangeNotify); - - WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = - WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder() - .setSlot( - WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() - .setIsActive(true) - .setMaterialId(materialId) - .build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WidgetSlotChangeNotifyOuterClass; +import emu.grasscutter.net.proto.WidgetSlotDataOuterClass; +import emu.grasscutter.net.proto.WidgetSlotOpOuterClass; + +public class PacketWidgetSlotChangeNotify extends BasePacket { + + public PacketWidgetSlotChangeNotify( + WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto) { + super(PacketOpcodes.WidgetSlotChangeNotify); + + this.setData(proto); + } + + public PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp op) { + super(PacketOpcodes.WidgetSlotChangeNotify); + + WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = + WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder() + .setOp(op) + .setSlot(WidgetSlotDataOuterClass.WidgetSlotData.newBuilder().setIsActive(true).build()) + .build(); + + this.setData(proto); + } + + public PacketWidgetSlotChangeNotify(int materialId) { + super(PacketOpcodes.WidgetSlotChangeNotify); + + WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = + WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder() + .setSlot( + WidgetSlotDataOuterClass.WidgetSlotData.newBuilder() + .setIsActive(true) + .setMaterialId(materialId) + .build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWindSeedClientNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWindSeedClientNotify.java index aa7439145..f9cee669d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWindSeedClientNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWindSeedClientNotify.java @@ -10,9 +10,12 @@ public final class PacketWindSeedClientNotify extends BasePacket { public PacketWindSeedClientNotify(byte[] compiledLua) { super(PacketOpcodes.WindSeedClientNotify); - this.setData(WindSeedClientNotify.newBuilder() - .setAreaNotify(AreaNotify.newBuilder() - .setAreaId(1).setAreaType(1) - .setAreaCode(ByteString.copyFrom(compiledLua)))); + this.setData( + WindSeedClientNotify.newBuilder() + .setAreaNotify( + AreaNotify.newBuilder() + .setAreaId(1) + .setAreaType(1) + .setAreaCode(ByteString.copyFrom(compiledLua)))); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorktopOptionNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorktopOptionNotify.java index 06762a0e7..52135e423 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorktopOptionNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorktopOptionNotify.java @@ -1,23 +1,23 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.entity.EntityGadget; -import emu.grasscutter.game.entity.gadget.GadgetWorktop; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify; - -public class PacketWorktopOptionNotify extends BasePacket { - - public PacketWorktopOptionNotify(EntityGadget gadget) { - super(PacketOpcodes.WorktopOptionNotify); - - WorktopOptionNotify.Builder proto = - WorktopOptionNotify.newBuilder().setGadgetEntityId(gadget.getId()); - - if (gadget.getContent() instanceof GadgetWorktop worktop) { - proto.addAllOptionList(worktop.getWorktopOptions()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.game.entity.gadget.GadgetWorktop; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WorktopOptionNotifyOuterClass.WorktopOptionNotify; + +public class PacketWorktopOptionNotify extends BasePacket { + + public PacketWorktopOptionNotify(EntityGadget gadget) { + super(PacketOpcodes.WorktopOptionNotify); + + WorktopOptionNotify.Builder proto = + WorktopOptionNotify.newBuilder().setGadgetEntityId(gadget.getId()); + + if (gadget.getContent() instanceof GadgetWorktop worktop) { + proto.addAllOptionList(worktop.getWorktopOptions()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldDataNotify.java index 176844954..5ad2dc95d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldDataNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; -import emu.grasscutter.net.proto.WorldDataNotifyOuterClass.WorldDataNotify; - -public class PacketWorldDataNotify extends BasePacket { - - public PacketWorldDataNotify(World world) { - super(PacketOpcodes.WorldDataNotify); - - int worldLevel = world.getWorldLevel(); - int isMp = world.isMultiplayer() ? 1 : 0; - - WorldDataNotify proto = - WorldDataNotify.newBuilder() - .putWorldPropMap( - 1, PropValue.newBuilder().setType(1).setIval(worldLevel).setVal(worldLevel).build()) - .putWorldPropMap( - 2, PropValue.newBuilder().setType(2).setIval(isMp).setVal(isMp).build()) - .build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PropValueOuterClass.PropValue; +import emu.grasscutter.net.proto.WorldDataNotifyOuterClass.WorldDataNotify; + +public class PacketWorldDataNotify extends BasePacket { + + public PacketWorldDataNotify(World world) { + super(PacketOpcodes.WorldDataNotify); + + int worldLevel = world.getWorldLevel(); + int isMp = world.isMultiplayer() ? 1 : 0; + + WorldDataNotify proto = + WorldDataNotify.newBuilder() + .putWorldPropMap( + 1, PropValue.newBuilder().setType(1).setIval(worldLevel).setVal(worldLevel).build()) + .putWorldPropMap( + 2, PropValue.newBuilder().setType(2).setIval(isMp).setVal(isMp).build()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerDieNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerDieNotify.java index 1ed6935f2..df973baa2 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerDieNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerDieNotify.java @@ -1,18 +1,18 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; -import emu.grasscutter.net.proto.WorldPlayerDieNotifyOuterClass.WorldPlayerDieNotify; - -public class PacketWorldPlayerDieNotify extends BasePacket { - - public PacketWorldPlayerDieNotify(PlayerDieType playerDieType, int killerId) { - super(PacketOpcodes.WorldPlayerDieNotify); - - WorldPlayerDieNotify proto = - WorldPlayerDieNotify.newBuilder().setDieType(playerDieType).setMonsterId(killerId).build(); - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; +import emu.grasscutter.net.proto.WorldPlayerDieNotifyOuterClass.WorldPlayerDieNotify; + +public class PacketWorldPlayerDieNotify extends BasePacket { + + public PacketWorldPlayerDieNotify(PlayerDieType playerDieType, int killerId) { + super(PacketOpcodes.WorldPlayerDieNotify); + + WorldPlayerDieNotify proto = + WorldPlayerDieNotify.newBuilder().setDieType(playerDieType).setMonsterId(killerId).build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerInfoNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerInfoNotify.java index 40357fe0c..a1e44e8b3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerInfoNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerInfoNotify.java @@ -1,25 +1,25 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WorldPlayerInfoNotifyOuterClass.WorldPlayerInfoNotify; - -public class PacketWorldPlayerInfoNotify extends BasePacket { - - public PacketWorldPlayerInfoNotify(World world) { - super(PacketOpcodes.WorldPlayerInfoNotify); - - WorldPlayerInfoNotify.Builder proto = WorldPlayerInfoNotify.newBuilder(); - - for (int i = 0; i < world.getPlayers().size(); i++) { - Player p = world.getPlayers().get(i); - - proto.addPlayerInfoList(p.getOnlinePlayerInfo()); - proto.addPlayerUidList(p.getUid()); - } - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WorldPlayerInfoNotifyOuterClass.WorldPlayerInfoNotify; + +public class PacketWorldPlayerInfoNotify extends BasePacket { + + public PacketWorldPlayerInfoNotify(World world) { + super(PacketOpcodes.WorldPlayerInfoNotify); + + WorldPlayerInfoNotify.Builder proto = WorldPlayerInfoNotify.newBuilder(); + + for (int i = 0; i < world.getPlayers().size(); i++) { + Player p = world.getPlayers().get(i); + + proto.addPlayerInfoList(p.getOnlinePlayerInfo()); + proto.addPlayerUidList(p.getUid()); + } + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerLocationNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerLocationNotify.java index 96b91c685..25d8b673f 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerLocationNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerLocationNotify.java @@ -1,22 +1,22 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WorldPlayerLocationNotifyOuterClass.WorldPlayerLocationNotify; - -public class PacketWorldPlayerLocationNotify extends BasePacket { - - public PacketWorldPlayerLocationNotify(World world) { - super(PacketOpcodes.WorldPlayerLocationNotify); - - WorldPlayerLocationNotify.Builder proto = WorldPlayerLocationNotify.newBuilder(); - - for (Player p : world.getPlayers()) { - proto.addPlayerWorldLocList(p.getWorldPlayerLocationInfo()); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WorldPlayerLocationNotifyOuterClass.WorldPlayerLocationNotify; + +public class PacketWorldPlayerLocationNotify extends BasePacket { + + public PacketWorldPlayerLocationNotify(World world) { + super(PacketOpcodes.WorldPlayerLocationNotify); + + WorldPlayerLocationNotify.Builder proto = WorldPlayerLocationNotify.newBuilder(); + + for (Player p : world.getPlayers()) { + proto.addPlayerWorldLocList(p.getWorldPlayerLocationInfo()); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerRTTNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerRTTNotify.java index c7ef9b18c..4b2ae556d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerRTTNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerRTTNotify.java @@ -1,27 +1,27 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.game.player.Player; -import emu.grasscutter.game.world.World; -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.PlayerRTTInfoOuterClass.PlayerRTTInfo; -import emu.grasscutter.net.proto.WorldPlayerRTTNotifyOuterClass.WorldPlayerRTTNotify; - -public class PacketWorldPlayerRTTNotify extends BasePacket { - - public PacketWorldPlayerRTTNotify(World world) { - super(PacketOpcodes.WorldPlayerRTTNotify); - - WorldPlayerRTTNotify.Builder proto = WorldPlayerRTTNotify.newBuilder(); - - for (Player player : world.getPlayers()) { - proto.addPlayerRttList( - PlayerRTTInfo.newBuilder() - .setUid(player.getUid()) - .setRtt(10) // TODO - put player ping here - ); - } - - this.setData(proto); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.world.World; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.PlayerRTTInfoOuterClass.PlayerRTTInfo; +import emu.grasscutter.net.proto.WorldPlayerRTTNotifyOuterClass.WorldPlayerRTTNotify; + +public class PacketWorldPlayerRTTNotify extends BasePacket { + + public PacketWorldPlayerRTTNotify(World world) { + super(PacketOpcodes.WorldPlayerRTTNotify); + + WorldPlayerRTTNotify.Builder proto = WorldPlayerRTTNotify.newBuilder(); + + for (Player player : world.getPlayers()) { + proto.addPlayerRttList( + PlayerRTTInfo.newBuilder() + .setUid(player.getUid()) + .setRtt(10) // TODO - put player ping here + ); + } + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerReviveRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerReviveRsp.java index 0621ba10f..4c57f3f13 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerReviveRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerReviveRsp.java @@ -1,16 +1,16 @@ -package emu.grasscutter.server.packet.send; - -import emu.grasscutter.net.packet.BasePacket; -import emu.grasscutter.net.packet.PacketOpcodes; -import emu.grasscutter.net.proto.WorldPlayerReviveRspOuterClass.WorldPlayerReviveRsp; - -public class PacketWorldPlayerReviveRsp extends BasePacket { - - public PacketWorldPlayerReviveRsp() { - super(PacketOpcodes.WorldPlayerReviveRsp); - - WorldPlayerReviveRsp.Builder proto = WorldPlayerReviveRsp.newBuilder(); - - this.setData(proto.build()); - } -} +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.WorldPlayerReviveRspOuterClass.WorldPlayerReviveRsp; + +public class PacketWorldPlayerReviveRsp extends BasePacket { + + public PacketWorldPlayerReviveRsp() { + super(PacketOpcodes.WorldPlayerReviveRsp); + + WorldPlayerReviveRsp.Builder proto = WorldPlayerReviveRsp.newBuilder(); + + this.setData(proto.build()); + } +} diff --git a/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java b/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java index 7d4929801..38e4c2a02 100644 --- a/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java +++ b/src/main/java/emu/grasscutter/server/scheduler/AsyncServerTask.java @@ -1,97 +1,97 @@ -package emu.grasscutter.server.scheduler; - -import javax.annotation.Nullable; -import lombok.Getter; - -/** A server task that should be run asynchronously. */ -public final class AsyncServerTask implements Runnable { - /* The runnable to run. */ - private final Runnable task; - /* This ID is assigned by the scheduler. */ - @Getter private final int taskId; - /* The result callback to run. */ - @Nullable private final Runnable callback; - - /* Has the task already been started? */ - private boolean started = false; - /* Has the task finished execution? */ - private boolean finished = false; - /* The result produced in the async task. */ - @Nullable private Object result = null; - - /** - * For tasks without a callback. - * - * @param task The task to run. - */ - public AsyncServerTask(Runnable task, int taskId) { - this(task, null, taskId); - } - - /** - * For tasks with a callback. - * - * @param task The task to run. - * @param callback The task to run after the task is complete. - */ - public AsyncServerTask(Runnable task, @Nullable Runnable callback, int taskId) { - this.task = task; - this.callback = callback; - this.taskId = taskId; - } - - /** - * Returns the state of the task. - * - * @return True if the task has been started, false otherwise. - */ - public boolean hasStarted() { - return this.started; - } - - /** - * Returns the state of the task. - * - * @return True if the task has finished execution, false otherwise. - */ - public boolean isFinished() { - return this.finished; - } - - /** Runs the task. */ - @Override - public void run() { - // Declare the task as started. - this.started = true; - - // Run the runnable. - this.task.run(); - - // Declare the task as finished. - this.finished = true; - } - - /** Runs the callback. */ - public void complete() { - // Run the callback. - if (this.callback != null) this.callback.run(); - } - - /** - * Returns the set result of the async task. - * - * @return The result, or null if it has not been set. - */ - @Nullable public Object getResult() { - return this.result; - } - - /** - * Sets the result of the async task. - * - * @param result The result of the async task. - */ - public void setResult(@Nullable Object result) { - this.result = result; - } -} +package emu.grasscutter.server.scheduler; + +import javax.annotation.Nullable; +import lombok.Getter; + +/** A server task that should be run asynchronously. */ +public final class AsyncServerTask implements Runnable { + /* The runnable to run. */ + private final Runnable task; + /* This ID is assigned by the scheduler. */ + @Getter private final int taskId; + /* The result callback to run. */ + @Nullable private final Runnable callback; + + /* Has the task already been started? */ + private boolean started = false; + /* Has the task finished execution? */ + private boolean finished = false; + /* The result produced in the async task. */ + @Nullable private Object result = null; + + /** + * For tasks without a callback. + * + * @param task The task to run. + */ + public AsyncServerTask(Runnable task, int taskId) { + this(task, null, taskId); + } + + /** + * For tasks with a callback. + * + * @param task The task to run. + * @param callback The task to run after the task is complete. + */ + public AsyncServerTask(Runnable task, @Nullable Runnable callback, int taskId) { + this.task = task; + this.callback = callback; + this.taskId = taskId; + } + + /** + * Returns the state of the task. + * + * @return True if the task has been started, false otherwise. + */ + public boolean hasStarted() { + return this.started; + } + + /** + * Returns the state of the task. + * + * @return True if the task has finished execution, false otherwise. + */ + public boolean isFinished() { + return this.finished; + } + + /** Runs the task. */ + @Override + public void run() { + // Declare the task as started. + this.started = true; + + // Run the runnable. + this.task.run(); + + // Declare the task as finished. + this.finished = true; + } + + /** Runs the callback. */ + public void complete() { + // Run the callback. + if (this.callback != null) this.callback.run(); + } + + /** + * Returns the set result of the async task. + * + * @return The result, or null if it has not been set. + */ + @Nullable public Object getResult() { + return this.result; + } + + /** + * Sets the result of the async task. + * + * @param result The result of the async task. + */ + public void setResult(@Nullable Object result) { + this.result = result; + } +} diff --git a/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java b/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java index cb0fa2bb6..4474cc5cb 100644 --- a/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java +++ b/src/main/java/emu/grasscutter/server/scheduler/ServerTaskScheduler.java @@ -1,151 +1,151 @@ -package emu.grasscutter.server.scheduler; - -import java.util.concurrent.ConcurrentHashMap; - -/** - * A class to manage all time-based tasks scheduled on the server. This handles both synchronous and - * asynchronous tasks. - * - *

Developers note: A server tick is ONE REAL-TIME SECOND. - */ -public final class ServerTaskScheduler { - /* A map to contain all running tasks. */ - private final ConcurrentHashMap tasks = new ConcurrentHashMap<>(); - /* A map to contain all async tasks. */ - private final ConcurrentHashMap asyncTasks = new ConcurrentHashMap<>(); - - /* The ID assigned to the next runnable. */ - private int nextTaskId = 0; - - /** - * Ran every server tick. Attempts to run all scheduled tasks. This method is synchronous and will - * block until all tasks are complete. - */ - public void runTasks() { - // Skip if there are no tasks. - if (this.tasks.size() == 0) return; - - // Run all tasks. - for (ServerTask task : this.tasks.values()) { - // Check if the task should run. - if (task.shouldRun()) { - // Run the task. - task.run(); - } - - // Check if the task should be canceled. - if (task.shouldCancel()) { - // Cancel the task. - this.cancelTask(task.getTaskId()); - } - } - - // Run all async tasks. - for (AsyncServerTask task : this.asyncTasks.values()) { - if (!task.hasStarted()) { - // Create a thread for the task. - Thread thread = new Thread(task); - // Start the thread. - thread.start(); - } else if (task.isFinished()) { - // Cancel the task. - this.asyncTasks.remove(task.getTaskId()); - // Run the task's callback. - task.complete(); - } - } - } - - /** - * Gets a task from the scheduler. - * - * @param taskId The ID of the task to get. - * @return The task, or null if it does not exist. - */ - public ServerTask getTask(int taskId) { - return this.tasks.get(taskId); - } - - /** - * Gets an async task from the scheduler. - * - * @param taskId The ID of the task to get. - * @return The task, or null if it does not exist. - */ - public AsyncServerTask getAsyncTask(int taskId) { - return this.asyncTasks.get(taskId); - } - - /** - * Removes a task from the scheduler. - * - * @param taskId The ID of the task to remove. - */ - public void cancelTask(int taskId) { - this.tasks.remove(taskId); - } - - /** - * Schedules a task to be run on a separate thread. The task runs on the next server tick. - * - * @param runnable The runnable to run. - * @return The ID of the task. - */ - public int scheduleAsyncTask(Runnable runnable) { - // Get the next task ID. - var taskId = this.nextTaskId++; - // Create a new task. - this.asyncTasks.put(taskId, new AsyncServerTask(runnable, taskId)); - // Return the task ID. - return taskId; - } - - /** - * Schedules a task to be run on the next server tick. - * - * @param runnable The runnable to run. - * @return The ID of the task. - */ - public int scheduleTask(Runnable runnable) { - return this.scheduleDelayedRepeatingTask(runnable, -1, -1); - } - - /** - * Schedules a task to be run after the amount of ticks has passed. - * - * @param runnable The runnable to run. - * @param delay The amount of ticks to wait before running. - * @return The ID of the task. - */ - public int scheduleDelayedTask(Runnable runnable, int delay) { - return this.scheduleDelayedRepeatingTask(runnable, -1, delay); - } - - /** - * Schedules a task to be run every amount of ticks. - * - * @param runnable The runnable to run. - * @param period The amount of ticks to wait before running again. - * @return The ID of the task. - */ - public int scheduleRepeatingTask(Runnable runnable, int period) { - return this.scheduleDelayedRepeatingTask(runnable, period, 0); - } - - /** - * Schedules a task to be run after the amount of ticks has passed. - * - * @param runnable The runnable to run. - * @param period The amount of ticks to wait before running again. - * @param delay The amount of ticks to wait before running the first time. - * @return The ID of the task. - */ - public int scheduleDelayedRepeatingTask(Runnable runnable, int period, int delay) { - // Get the next task ID. - var taskId = this.nextTaskId++; - // Create a new task. - this.tasks.put(taskId, new ServerTask(runnable, taskId, period, delay)); - // Return the task ID. - return taskId; - } -} +package emu.grasscutter.server.scheduler; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * A class to manage all time-based tasks scheduled on the server. This handles both synchronous and + * asynchronous tasks. + * + *

Developers note: A server tick is ONE REAL-TIME SECOND. + */ +public final class ServerTaskScheduler { + /* A map to contain all running tasks. */ + private final ConcurrentHashMap tasks = new ConcurrentHashMap<>(); + /* A map to contain all async tasks. */ + private final ConcurrentHashMap asyncTasks = new ConcurrentHashMap<>(); + + /* The ID assigned to the next runnable. */ + private int nextTaskId = 0; + + /** + * Ran every server tick. Attempts to run all scheduled tasks. This method is synchronous and will + * block until all tasks are complete. + */ + public void runTasks() { + // Skip if there are no tasks. + if (this.tasks.size() == 0) return; + + // Run all tasks. + for (ServerTask task : this.tasks.values()) { + // Check if the task should run. + if (task.shouldRun()) { + // Run the task. + task.run(); + } + + // Check if the task should be canceled. + if (task.shouldCancel()) { + // Cancel the task. + this.cancelTask(task.getTaskId()); + } + } + + // Run all async tasks. + for (AsyncServerTask task : this.asyncTasks.values()) { + if (!task.hasStarted()) { + // Create a thread for the task. + Thread thread = new Thread(task); + // Start the thread. + thread.start(); + } else if (task.isFinished()) { + // Cancel the task. + this.asyncTasks.remove(task.getTaskId()); + // Run the task's callback. + task.complete(); + } + } + } + + /** + * Gets a task from the scheduler. + * + * @param taskId The ID of the task to get. + * @return The task, or null if it does not exist. + */ + public ServerTask getTask(int taskId) { + return this.tasks.get(taskId); + } + + /** + * Gets an async task from the scheduler. + * + * @param taskId The ID of the task to get. + * @return The task, or null if it does not exist. + */ + public AsyncServerTask getAsyncTask(int taskId) { + return this.asyncTasks.get(taskId); + } + + /** + * Removes a task from the scheduler. + * + * @param taskId The ID of the task to remove. + */ + public void cancelTask(int taskId) { + this.tasks.remove(taskId); + } + + /** + * Schedules a task to be run on a separate thread. The task runs on the next server tick. + * + * @param runnable The runnable to run. + * @return The ID of the task. + */ + public int scheduleAsyncTask(Runnable runnable) { + // Get the next task ID. + var taskId = this.nextTaskId++; + // Create a new task. + this.asyncTasks.put(taskId, new AsyncServerTask(runnable, taskId)); + // Return the task ID. + return taskId; + } + + /** + * Schedules a task to be run on the next server tick. + * + * @param runnable The runnable to run. + * @return The ID of the task. + */ + public int scheduleTask(Runnable runnable) { + return this.scheduleDelayedRepeatingTask(runnable, -1, -1); + } + + /** + * Schedules a task to be run after the amount of ticks has passed. + * + * @param runnable The runnable to run. + * @param delay The amount of ticks to wait before running. + * @return The ID of the task. + */ + public int scheduleDelayedTask(Runnable runnable, int delay) { + return this.scheduleDelayedRepeatingTask(runnable, -1, delay); + } + + /** + * Schedules a task to be run every amount of ticks. + * + * @param runnable The runnable to run. + * @param period The amount of ticks to wait before running again. + * @return The ID of the task. + */ + public int scheduleRepeatingTask(Runnable runnable, int period) { + return this.scheduleDelayedRepeatingTask(runnable, period, 0); + } + + /** + * Schedules a task to be run after the amount of ticks has passed. + * + * @param runnable The runnable to run. + * @param period The amount of ticks to wait before running again. + * @param delay The amount of ticks to wait before running the first time. + * @return The ID of the task. + */ + public int scheduleDelayedRepeatingTask(Runnable runnable, int period, int delay) { + // Get the next task ID. + var taskId = this.nextTaskId++; + // Create a new task. + this.tasks.put(taskId, new ServerTask(runnable, taskId, period, delay)); + // Return the task ID. + return taskId; + } +} diff --git a/src/main/java/emu/grasscutter/task/Task.java b/src/main/java/emu/grasscutter/task/Task.java index b74b6d114..92c2a1a6a 100644 --- a/src/main/java/emu/grasscutter/task/Task.java +++ b/src/main/java/emu/grasscutter/task/Task.java @@ -1,35 +1,35 @@ -package emu.grasscutter.task; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/* -* So what is cron expression? -The format of a Cron expression is as follows. -Second Minute Hour Day Month Week Year -Seconds: 0-59 -Minute: 0-59 -hour: 0-23 -Day: 1-31 -Month: 1-12 -Week: 1-7 (0-6 sometimes) -Year: Specify your own - -If you want to express every second or every minute or something like that, use the * symbol in that position; -if you want to express more than one such as every 15 minutes and every 30 minutes, you can write:`15, 30`. - -For the rest of the wildcard characters, please Google them yourself -*/ - -@Retention(RetentionPolicy.RUNTIME) -public @interface Task { - String taskName() default "NO_NAME"; - - String taskCronExpression() default "0 0 0 0 0 ?"; - - String triggerName() default "NO_NAME"; - - boolean executeImmediatelyAfterReset() default false; - - boolean executeImmediately() default false; -} +package emu.grasscutter.task; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/* +* So what is cron expression? +The format of a Cron expression is as follows. +Second Minute Hour Day Month Week Year +Seconds: 0-59 +Minute: 0-59 +hour: 0-23 +Day: 1-31 +Month: 1-12 +Week: 1-7 (0-6 sometimes) +Year: Specify your own + +If you want to express every second or every minute or something like that, use the * symbol in that position; +if you want to express more than one such as every 15 minutes and every 30 minutes, you can write:`15, 30`. + +For the rest of the wildcard characters, please Google them yourself +*/ + +@Retention(RetentionPolicy.RUNTIME) +public @interface Task { + String taskName() default "NO_NAME"; + + String taskCronExpression() default "0 0 0 0 0 ?"; + + String triggerName() default "NO_NAME"; + + boolean executeImmediatelyAfterReset() default false; + + boolean executeImmediately() default false; +} diff --git a/src/main/java/emu/grasscutter/task/TaskMap.java b/src/main/java/emu/grasscutter/task/TaskMap.java index a65e0e251..f9da26241 100644 --- a/src/main/java/emu/grasscutter/task/TaskMap.java +++ b/src/main/java/emu/grasscutter/task/TaskMap.java @@ -1,173 +1,173 @@ -package emu.grasscutter.task; - -import emu.grasscutter.Grasscutter; -import java.util.*; -import org.quartz.*; -import org.quartz.impl.StdSchedulerFactory; -import org.reflections.Reflections; - -@SuppressWarnings({"UnusedReturnValue", "unused"}) -public final class TaskMap { - private final Map tasks = new HashMap<>(); - private final Map annotations = new HashMap<>(); - private final Map afterReset = new HashMap<>(); - private final SchedulerFactory schedulerFactory = new StdSchedulerFactory(); - - public TaskMap() { - this(false); - } - - public TaskMap(boolean scan) { - if (scan) this.scan(); - } - - public static TaskMap getInstance() { - return Grasscutter.getGameServer().getTaskMap(); - } - - public void resetNow() { - // Unregister all tasks - for (TaskHandler task : this.tasks.values()) { - unregisterTask(task); - } - - // Run all afterReset tasks - for (TaskHandler task : this.afterReset.values()) { - try { - task.restartExecute(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - // Remove all afterReset tasks - this.afterReset.clear(); - - // Register all tasks - for (TaskHandler task : this.tasks.values()) { - registerTask(task.getClass().getAnnotation(Task.class).taskName(), task); - } - } - - public TaskMap unregisterTask(TaskHandler task) { - this.tasks.remove(task.getClass().getAnnotation(Task.class).taskName()); - this.annotations.remove(task.getClass().getAnnotation(Task.class).taskName()); - - try { - Scheduler scheduler = schedulerFactory.getScheduler(); - scheduler.deleteJob(new JobKey(task.getClass().getAnnotation(Task.class).taskName())); - } catch (SchedulerException e) { - e.printStackTrace(); - } - - task.onDisable(); - - return this; - } - - public boolean pauseTask(String taskName) { - try { - Scheduler scheduler = schedulerFactory.getScheduler(); - scheduler.pauseJob(new JobKey(taskName)); - } catch (SchedulerException e) { - e.printStackTrace(); - return false; - } - return true; - } - - public boolean resumeTask(String taskName) { - try { - Scheduler scheduler = schedulerFactory.getScheduler(); - scheduler.resumeJob(new JobKey(taskName)); - } catch (SchedulerException e) { - e.printStackTrace(); - return false; - } - return true; - } - - public boolean cancelTask(String taskName) { - Task task = this.annotations.get(taskName); - if (task == null) return false; - try { - this.unregisterTask(this.tasks.get(taskName)); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - return true; - } - - public TaskMap registerTask(String taskName, TaskHandler task) { - Task annotation = task.getClass().getAnnotation(Task.class); - this.annotations.put(taskName, annotation); - this.tasks.put(taskName, task); - - // register task - try { - Scheduler scheduler = schedulerFactory.getScheduler(); - JobDetail job = JobBuilder.newJob(task.getClass()).withIdentity(taskName).build(); - - Trigger convTrigger = - TriggerBuilder.newTrigger() - .withIdentity(annotation.triggerName()) - .withSchedule(CronScheduleBuilder.cronSchedule(annotation.taskCronExpression())) - .build(); - - scheduler.scheduleJob(job, convTrigger); - - if (annotation.executeImmediately()) { - task.execute(null); - } - task.onEnable(); - } catch (SchedulerException e) { - e.printStackTrace(); - } - - return this; - } - - public List getHandlersAsList() { - return new ArrayList<>(this.tasks.values()); - } - - public HashMap getHandlers() { - return new LinkedHashMap<>(this.tasks); - } - - public TaskHandler getHandler(String taskName) { - return this.tasks.get(taskName); - } - - private void scan() { - Reflections reflector = Grasscutter.reflector; - Set> classes = reflector.getTypesAnnotatedWith(Task.class); - classes.forEach( - annotated -> { - try { - Task taskData = annotated.getAnnotation(Task.class); - Object object = annotated.getDeclaredConstructor().newInstance(); - if (object instanceof TaskHandler) { - this.registerTask(taskData.taskName(), (TaskHandler) object); - if (taskData.executeImmediatelyAfterReset()) { - this.afterReset.put(taskData.taskName(), (TaskHandler) object); - } - } else { - Grasscutter.getLogger() - .error("Class " + annotated.getName() + " is not a TaskHandler!"); - } - } catch (Exception exception) { - Grasscutter.getLogger() - .error( - "Failed to register task handler for " + annotated.getSimpleName(), exception); - } - }); - try { - Scheduler scheduler = schedulerFactory.getScheduler(); - scheduler.start(); - } catch (SchedulerException e) { - e.printStackTrace(); - } - } -} +package emu.grasscutter.task; + +import emu.grasscutter.Grasscutter; +import java.util.*; +import org.quartz.*; +import org.quartz.impl.StdSchedulerFactory; +import org.reflections.Reflections; + +@SuppressWarnings({"UnusedReturnValue", "unused"}) +public final class TaskMap { + private final Map tasks = new HashMap<>(); + private final Map annotations = new HashMap<>(); + private final Map afterReset = new HashMap<>(); + private final SchedulerFactory schedulerFactory = new StdSchedulerFactory(); + + public TaskMap() { + this(false); + } + + public TaskMap(boolean scan) { + if (scan) this.scan(); + } + + public static TaskMap getInstance() { + return Grasscutter.getGameServer().getTaskMap(); + } + + public void resetNow() { + // Unregister all tasks + for (TaskHandler task : this.tasks.values()) { + unregisterTask(task); + } + + // Run all afterReset tasks + for (TaskHandler task : this.afterReset.values()) { + try { + task.restartExecute(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // Remove all afterReset tasks + this.afterReset.clear(); + + // Register all tasks + for (TaskHandler task : this.tasks.values()) { + registerTask(task.getClass().getAnnotation(Task.class).taskName(), task); + } + } + + public TaskMap unregisterTask(TaskHandler task) { + this.tasks.remove(task.getClass().getAnnotation(Task.class).taskName()); + this.annotations.remove(task.getClass().getAnnotation(Task.class).taskName()); + + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + scheduler.deleteJob(new JobKey(task.getClass().getAnnotation(Task.class).taskName())); + } catch (SchedulerException e) { + e.printStackTrace(); + } + + task.onDisable(); + + return this; + } + + public boolean pauseTask(String taskName) { + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + scheduler.pauseJob(new JobKey(taskName)); + } catch (SchedulerException e) { + e.printStackTrace(); + return false; + } + return true; + } + + public boolean resumeTask(String taskName) { + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + scheduler.resumeJob(new JobKey(taskName)); + } catch (SchedulerException e) { + e.printStackTrace(); + return false; + } + return true; + } + + public boolean cancelTask(String taskName) { + Task task = this.annotations.get(taskName); + if (task == null) return false; + try { + this.unregisterTask(this.tasks.get(taskName)); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public TaskMap registerTask(String taskName, TaskHandler task) { + Task annotation = task.getClass().getAnnotation(Task.class); + this.annotations.put(taskName, annotation); + this.tasks.put(taskName, task); + + // register task + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + JobDetail job = JobBuilder.newJob(task.getClass()).withIdentity(taskName).build(); + + Trigger convTrigger = + TriggerBuilder.newTrigger() + .withIdentity(annotation.triggerName()) + .withSchedule(CronScheduleBuilder.cronSchedule(annotation.taskCronExpression())) + .build(); + + scheduler.scheduleJob(job, convTrigger); + + if (annotation.executeImmediately()) { + task.execute(null); + } + task.onEnable(); + } catch (SchedulerException e) { + e.printStackTrace(); + } + + return this; + } + + public List getHandlersAsList() { + return new ArrayList<>(this.tasks.values()); + } + + public HashMap getHandlers() { + return new LinkedHashMap<>(this.tasks); + } + + public TaskHandler getHandler(String taskName) { + return this.tasks.get(taskName); + } + + private void scan() { + Reflections reflector = Grasscutter.reflector; + Set> classes = reflector.getTypesAnnotatedWith(Task.class); + classes.forEach( + annotated -> { + try { + Task taskData = annotated.getAnnotation(Task.class); + Object object = annotated.getDeclaredConstructor().newInstance(); + if (object instanceof TaskHandler) { + this.registerTask(taskData.taskName(), (TaskHandler) object); + if (taskData.executeImmediatelyAfterReset()) { + this.afterReset.put(taskData.taskName(), (TaskHandler) object); + } + } else { + Grasscutter.getLogger() + .error("Class " + annotated.getName() + " is not a TaskHandler!"); + } + } catch (Exception exception) { + Grasscutter.getLogger() + .error( + "Failed to register task handler for " + annotated.getSimpleName(), exception); + } + }); + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + scheduler.start(); + } catch (SchedulerException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java index 9faa3b83c..42becd681 100644 --- a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java +++ b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java @@ -1,36 +1,36 @@ -package emu.grasscutter.task.tasks; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.task.Task; -import emu.grasscutter.task.TaskHandler; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") -// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) -public final class MoonCard extends TaskHandler { - - @Override - public void onEnable() { - Grasscutter.getLogger().debug("[Task] MoonCard task enabled."); - } - - @Override - public void onDisable() { - Grasscutter.getLogger().debug("[Task] MoonCard task disabled."); - } - - @Override - public synchronized void execute(JobExecutionContext context) throws JobExecutionException { - Grasscutter.getGameServer() - .getPlayers() - .forEach( - (uid, player) -> { - if (player.isOnline()) { - if (player.inMoonCard()) { - player.getTodayMoonCard(); - } - } - }); - } -} +package emu.grasscutter.task.tasks; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.task.Task; +import emu.grasscutter.task.TaskHandler; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger") +// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system) +public final class MoonCard extends TaskHandler { + + @Override + public void onEnable() { + Grasscutter.getLogger().debug("[Task] MoonCard task enabled."); + } + + @Override + public void onDisable() { + Grasscutter.getLogger().debug("[Task] MoonCard task disabled."); + } + + @Override + public synchronized void execute(JobExecutionContext context) throws JobExecutionException { + Grasscutter.getGameServer() + .getPlayers() + .forEach( + (uid, player) -> { + if (player.isOnline()) { + if (player.inMoonCard()) { + player.getTodayMoonCard(); + } + } + }); + } +} diff --git a/src/main/java/emu/grasscutter/tools/Dumpers.java b/src/main/java/emu/grasscutter/tools/Dumpers.java index c7e3bf752..9ceb86486 100644 --- a/src/main/java/emu/grasscutter/tools/Dumpers.java +++ b/src/main/java/emu/grasscutter/tools/Dumpers.java @@ -9,8 +9,6 @@ import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.props.SceneType; import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.Language; -import lombok.AllArgsConstructor; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -19,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import lombok.AllArgsConstructor; public interface Dumpers { // See `src/handbook/data/README.md` for attributions. @@ -50,8 +49,8 @@ public interface Dumpers { */ private static String miniEncode(Map dump) { return dump.entrySet().stream() - .map(entry -> entry.getKey() + "," + entry.getValue().toString()) - .collect(Collectors.joining("\n")); + .map(entry -> entry.getKey() + "," + entry.getValue().toString()) + .collect(Collectors.joining("\n")); } /** @@ -66,25 +65,34 @@ public interface Dumpers { // Convert all registered commands to an info map. var dump = new HashMap(); - commandMap.getAnnotationsAsList().forEach(command -> { - var description = Dumpers.commandDescription(locale, command); - var labels = new ArrayList(){{ - this.add(command.label()); - this.addAll(List.of(command.aliases())); - }}; + commandMap + .getAnnotationsAsList() + .forEach( + command -> { + var description = Dumpers.commandDescription(locale, command); + var labels = + new ArrayList() { + { + this.add(command.label()); + this.addAll(List.of(command.aliases())); + } + }; - // Add the command info to the list. - dump.put(command.label(), new CommandInfo( - labels, description, List.of(command.usage()), List.of( - command.permission(), command.permissionTargeted()), - command.targetRequirement())); - }); + // Add the command info to the list. + dump.put( + command.label(), + new CommandInfo( + labels, + description, + List.of(command.usage()), + List.of(command.permission(), command.permissionTargeted()), + command.targetRequirement())); + }); try { // Create a file for the dump. var file = new File("commands.json"); - if (file.exists() && !file.delete()) - throw new RuntimeException("Failed to delete file."); + if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file."); if (!file.exists() && !file.createNewFile()) throw new RuntimeException("Failed to create file."); @@ -107,19 +115,25 @@ public interface Dumpers { // Convert all known avatars to an avatar map. var dump = new HashMap(); - GameData.getAvatarDataMap().forEach((id, avatar) -> { - var langHash = avatar.getNameTextMapHash(); - dump.put(id, new AvatarInfo( - langHash == 0 ? avatar.getName() : Language.getTextMapKey(langHash).get(locale), - avatar.getQualityType().equals("QUALITY_PURPLE") ? Quality.EPIC : Quality.LEGENDARY - )); - }); + GameData.getAvatarDataMap() + .forEach( + (id, avatar) -> { + var langHash = avatar.getNameTextMapHash(); + dump.put( + id, + new AvatarInfo( + langHash == 0 + ? avatar.getName() + : Language.getTextMapKey(langHash).get(locale), + avatar.getQualityType().equals("QUALITY_PURPLE") + ? Quality.EPIC + : Quality.LEGENDARY)); + }); try { // Create a file for the dump. var file = new File("avatars.csv"); - if (file.exists() && !file.delete()) - throw new RuntimeException("Failed to delete file."); + if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file."); if (!file.exists() && !file.createNewFile()) throw new RuntimeException("Failed to create file."); @@ -142,30 +156,35 @@ public interface Dumpers { // Convert all known items to an item map. var originalDump = new ArrayList(); - GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemInfo(id, - Language.getTextMapKey(item.getNameTextMapHash()).get(locale), - Quality.from(item.getRankLevel()), item.getItemType(), - item.getIcon().length() > 0 ? item.getIcon().substring(3) : "" - ))); + GameData.getItemDataMap() + .forEach( + (id, item) -> + originalDump.add( + new ItemInfo( + id, + Language.getTextMapKey(item.getNameTextMapHash()).get(locale), + Quality.from(item.getRankLevel()), + item.getItemType(), + item.getIcon().length() > 0 ? item.getIcon().substring(3) : ""))); // Create a new dump with filtered duplicates. var names = new ArrayList(); var dump = new HashMap(); - originalDump.forEach(item -> { - // Validate the item. - if (item.name.contains("[CHS]")) return; - if (names.contains(item.name)) return; - if (dump.containsKey(item.id)) return; - // Add the item to the dump. - names.add(item.name); - dump.put(item.id, item); - }); + originalDump.forEach( + item -> { + // Validate the item. + if (item.name.contains("[CHS]")) return; + if (names.contains(item.name)) return; + if (dump.containsKey(item.id)) return; + // Add the item to the dump. + names.add(item.name); + dump.put(item.id, item); + }); try { // Create a file for the dump. var file = new File("items.csv"); - if (file.exists() && !file.delete()) - throw new RuntimeException("Failed to delete file."); + if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file."); if (!file.exists() && !file.createNewFile()) throw new RuntimeException("Failed to create file."); @@ -176,9 +195,7 @@ public interface Dumpers { } } - /** - * Dumps all scenes to a JSON file. - */ + /** Dumps all scenes to a JSON file. */ static void dumpScenes() { // Reload resources. ResourceLoader.loadAll(); @@ -186,14 +203,15 @@ public interface Dumpers { // Convert all known scenes to a scene map. var dump = new HashMap(); - GameData.getSceneDataMap().forEach((id, scene) -> - dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType()))); + GameData.getSceneDataMap() + .forEach( + (id, scene) -> + dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType()))); try { // Create a file for the dump. var file = new File("scenes.csv"); - if (file.exists() && !file.delete()) - throw new RuntimeException("Failed to delete file."); + if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file."); if (!file.exists() && !file.createNewFile()) throw new RuntimeException("Failed to create file."); @@ -216,20 +234,23 @@ public interface Dumpers { // Convert all known avatars to an avatar map. var dump = new HashMap(); - GameData.getMonsterDataMap().forEach((id, monster) -> { - var langHash = monster.getNameTextMapHash(); - dump.put(id, new EntityInfo( - langHash == 0 ? monster.getMonsterName() : - Language.getTextMapKey(langHash).get(locale), - monster.getMonsterName() - )); - }); + GameData.getMonsterDataMap() + .forEach( + (id, monster) -> { + var langHash = monster.getNameTextMapHash(); + dump.put( + id, + new EntityInfo( + langHash == 0 + ? monster.getMonsterName() + : Language.getTextMapKey(langHash).get(locale), + monster.getMonsterName())); + }); try { // Create a file for the dump. var file = new File("entities.csv"); - if (file.exists() && !file.delete()) - throw new RuntimeException("Failed to delete file."); + if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file."); if (!file.exists() && !file.createNewFile()) throw new RuntimeException("Failed to create file."); @@ -256,8 +277,7 @@ public interface Dumpers { @Override public String toString() { - return this.name + "," - + this.quality; + return this.name + "," + this.quality; } } @@ -271,10 +291,7 @@ public interface Dumpers { @Override public String toString() { - return this.name + "," - + this.quality + "," - + this.type + "," - + this.icon; + return this.name + "," + this.quality + "," + this.type + "," + this.icon; } } @@ -285,8 +302,7 @@ public interface Dumpers { @Override public String toString() { - return this.identifier + "," - + this.type; + return this.identifier + "," + this.type; } } @@ -297,13 +313,17 @@ public interface Dumpers { @Override public String toString() { - return this.name + "," - + this.internal; + return this.name + "," + this.internal; } } enum Quality { - LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN; + LEGENDARY, + EPIC, + RARE, + UNCOMMON, + COMMON, + UNKNOWN; /** * Convert a rank level to a quality. diff --git a/src/main/java/emu/grasscutter/utils/DateHelper.java b/src/main/java/emu/grasscutter/utils/DateHelper.java index a8a0062b3..f78eec584 100644 --- a/src/main/java/emu/grasscutter/utils/DateHelper.java +++ b/src/main/java/emu/grasscutter/utils/DateHelper.java @@ -1,20 +1,20 @@ -package emu.grasscutter.utils; - -import java.util.Calendar; -import java.util.Date; - -public final class DateHelper { - public static Date onlyYearMonthDay(Date now) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(now); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - return calendar.getTime(); - } - - public static int getUnixTime(Date localDateTime) { - return (int) (localDateTime.getTime() / 1000L); - } -} +package emu.grasscutter.utils; + +import java.util.Calendar; +import java.util.Date; + +public final class DateHelper { + public static Date onlyYearMonthDay(Date now) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(now); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTime(); + } + + public static int getUnixTime(Date localDateTime) { + return (int) (localDateTime.getTime() / 1000L); + } +} diff --git a/src/main/java/emu/grasscutter/utils/StartupArguments.java b/src/main/java/emu/grasscutter/utils/StartupArguments.java index 13392fd36..d7532e836 100644 --- a/src/main/java/emu/grasscutter/utils/StartupArguments.java +++ b/src/main/java/emu/grasscutter/utils/StartupArguments.java @@ -8,10 +8,9 @@ import emu.grasscutter.BuildConfig; import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter.ServerRunMode; import emu.grasscutter.net.packet.PacketOpcodesUtils; +import emu.grasscutter.tools.Dumpers; import java.util.Map; import java.util.function.Function; - -import emu.grasscutter.tools.Dumpers; import org.slf4j.LoggerFactory; /** A parser for start-up arguments. */