From bca7aea95b5475c86a9dc66102e0e49df2996b63 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Wed, 27 Apr 2022 13:10:50 +0800 Subject: [PATCH 01/10] Task Improvement --- src/main/java/emu/grasscutter/task/Task.java | 4 + .../emu/grasscutter/task/TaskHandler.java | 19 +++-- .../java/emu/grasscutter/task/TaskMap.java | 73 +++++++++++++++---- .../emu/grasscutter/task/tasks/MoonCard.java | 13 ++-- 4 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/main/java/emu/grasscutter/task/Task.java b/src/main/java/emu/grasscutter/task/Task.java index 34638a777..1f35d16ce 100644 --- a/src/main/java/emu/grasscutter/task/Task.java +++ b/src/main/java/emu/grasscutter/task/Task.java @@ -1,5 +1,7 @@ package emu.grasscutter.task; +import org.quartz.JobDataMap; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -27,4 +29,6 @@ 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/TaskHandler.java b/src/main/java/emu/grasscutter/task/TaskHandler.java index e1a160a07..c61f45534 100644 --- a/src/main/java/emu/grasscutter/task/TaskHandler.java +++ b/src/main/java/emu/grasscutter/task/TaskHandler.java @@ -1,11 +1,18 @@ package emu.grasscutter.task; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; +import org.quartz.*; -public interface TaskHandler extends Job { - default void execute(JobExecutionContext context) throws JobExecutionException { - +@PersistJobDataAfterExecution +public class TaskHandler implements Job { + + public void restartExecute() throws JobExecutionException { + execute(null); } + + @Override + public void execute(JobExecutionContext context) throws JobExecutionException { + // TODO Auto-generated method stub + + } + } diff --git a/src/main/java/emu/grasscutter/task/TaskMap.java b/src/main/java/emu/grasscutter/task/TaskMap.java index 077ff1f59..9e6c1efca 100644 --- a/src/main/java/emu/grasscutter/task/TaskMap.java +++ b/src/main/java/emu/grasscutter/task/TaskMap.java @@ -1,20 +1,9 @@ package emu.grasscutter.task; import emu.grasscutter.Grasscutter; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.player.Player; -import org.quartz.CronScheduleBuilder; -import org.quartz.CronTrigger; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.SchedulerFactory; -import org.quartz.Trigger; -import org.quartz.TriggerBuilder; +import org.quartz.*; import org.quartz.impl.StdSchedulerFactory; -import org.quartz.spi.MutableTrigger; import org.reflections.Reflections; import java.util.*; @@ -23,6 +12,7 @@ import java.util.*; 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() { @@ -37,6 +27,44 @@ public final class TaskMap { return Grasscutter.getGameServer().getTaskMap(); } + public void resetNow() { + // Unregister all tasks + for (TaskHandler task : this.tasks.values()) { + unregisterTask(task.getClass().getAnnotation(Task.class).taskName()); + } + + // 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(String taskName) { + this.tasks.remove(taskName); + this.annotations.remove(taskName); + + try { + Scheduler scheduler = schedulerFactory.getScheduler(); + scheduler.deleteJob(new JobKey(taskName)); + } catch (SchedulerException e) { + e.printStackTrace(); + } + + return this; + } + public TaskMap registerTask(String taskName, TaskHandler task) { Task annotation = task.getClass().getAnnotation(Task.class); this.annotations.put(taskName, annotation); @@ -56,7 +84,10 @@ public final class TaskMap { .build(); scheduler.scheduleJob(job, convTrigger); - scheduler.start(); + + if (annotation.executeImmediately()) { + task.execute(null); + } } catch (SchedulerException e) { e.printStackTrace(); } @@ -83,12 +114,24 @@ public final class TaskMap { try { Task taskData = annotated.getAnnotation(Task.class); Object object = annotated.newInstance(); - if (object instanceof TaskHandler) + if (object instanceof TaskHandler) { this.registerTask(taskData.taskName(), (TaskHandler) object); - else Grasscutter.getLogger().error("Class " + annotated.getName() + " is not a TaskHandler!"); + 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 45c04586e..21ac60c97 100644 --- a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java +++ b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java @@ -1,27 +1,24 @@ package emu.grasscutter.task.tasks; -import emu.grasscutter.database.DatabaseManager; -import emu.grasscutter.game.player.Player; +import emu.grasscutter.Grasscutter; import emu.grasscutter.task.Task; import emu.grasscutter.task.TaskHandler; -import java.util.List; 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 implements TaskHandler { +public class MoonCard extends TaskHandler { @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - List players = DatabaseManager.getDatastore().find(Player.class).stream().toList(); - for (Player player : players) { + public synchronized void execute(JobExecutionContext context) throws JobExecutionException { + Grasscutter.getGameServer().getPlayers().forEach((uid, player) -> { if (player.isOnline()) { if (player.inMoonCard()) { player.getTodayMoonCard(); } } - } + }); } } From 01e411b9b8e153b4914d261b4c99dcc33e0a2e61 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Wed, 27 Apr 2022 17:30:16 +0800 Subject: [PATCH 02/10] onEnable & onDisable --- src/main/java/emu/grasscutter/task/TaskHandler.java | 8 ++++++++ src/main/java/emu/grasscutter/task/TaskMap.java | 13 ++++++++----- .../java/emu/grasscutter/task/tasks/MoonCard.java | 11 +++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/task/TaskHandler.java b/src/main/java/emu/grasscutter/task/TaskHandler.java index c61f45534..ea6fe22cd 100644 --- a/src/main/java/emu/grasscutter/task/TaskHandler.java +++ b/src/main/java/emu/grasscutter/task/TaskHandler.java @@ -9,6 +9,14 @@ public class TaskHandler implements Job { execute(null); } + public void onEnable() { + + } + + public void onDisable() { + + } + @Override public void execute(JobExecutionContext context) throws JobExecutionException { // TODO Auto-generated method stub diff --git a/src/main/java/emu/grasscutter/task/TaskMap.java b/src/main/java/emu/grasscutter/task/TaskMap.java index 9e6c1efca..fe067e795 100644 --- a/src/main/java/emu/grasscutter/task/TaskMap.java +++ b/src/main/java/emu/grasscutter/task/TaskMap.java @@ -30,7 +30,7 @@ public final class TaskMap { public void resetNow() { // Unregister all tasks for (TaskHandler task : this.tasks.values()) { - unregisterTask(task.getClass().getAnnotation(Task.class).taskName()); + unregisterTask(task); } // Run all afterReset tasks @@ -51,17 +51,19 @@ public final class TaskMap { } } - public TaskMap unregisterTask(String taskName) { - this.tasks.remove(taskName); - this.annotations.remove(taskName); + 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(taskName)); + scheduler.deleteJob(new JobKey(task.getClass().getAnnotation(Task.class).taskName())); } catch (SchedulerException e) { e.printStackTrace(); } + task.onDisable(); + return this; } @@ -88,6 +90,7 @@ public final class TaskMap { if (annotation.executeImmediately()) { task.execute(null); } + task.onEnable(); } 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 21ac60c97..51088f46d 100644 --- a/src/main/java/emu/grasscutter/task/tasks/MoonCard.java +++ b/src/main/java/emu/grasscutter/task/tasks/MoonCard.java @@ -11,6 +11,17 @@ 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 class MoonCard extends TaskHandler { + + @Override + public void onEnable() { + Grasscutter.getLogger().info("[Task] MoonCard task enabled."); + } + + @Override + public void onDisable() { + Grasscutter.getLogger().info("[Task] MoonCard task disabled."); + } + @Override public synchronized void execute(JobExecutionContext context) throws JobExecutionException { Grasscutter.getGameServer().getPlayers().forEach((uid, player) -> { From 3ea5a6cc79547336ab453c2ce6cd42de881d470e Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Wed, 27 Apr 2022 17:52:04 +0800 Subject: [PATCH 03/10] comment & mooncard --- src/main/java/emu/grasscutter/game/player/Player.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 5970c3f13..e226b0eaf 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -901,6 +901,8 @@ public class Player { session.send(new PacketPlayerStoreNotify(this)); session.send(new PacketAvatarDataNotify(this)); + getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward. + session.send(new PacketPlayerEnterSceneNotify(this)); // Enter game world session.send(new PacketPlayerLevelRewardUpdateNotify(rewardedLevels)); session.send(new PacketOpenStateUpdateNotify()); From 3c3c884fc109117a772b4b7c65fde64224517caf Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:21:51 +0800 Subject: [PATCH 04/10] Player show avatar list --- proto/UpdatePlayerShowAvatarListReq.proto | 17 +++++++++ proto/UpdatePlayerShowAvatarListRsp.proto | 17 +++++++++ .../emu/grasscutter/game/player/Player.java | 35 ++++++++++++++++++- .../HandlerUpdatePlayerShowAvatarListReq.java | 22 ++++++++++++ .../PacketUpdatePlayerShowAvatarListRsp.java | 22 ++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 proto/UpdatePlayerShowAvatarListReq.proto create mode 100644 proto/UpdatePlayerShowAvatarListRsp.proto create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java diff --git a/proto/UpdatePlayerShowAvatarListReq.proto b/proto/UpdatePlayerShowAvatarListReq.proto new file mode 100644 index 000000000..199ed2059 --- /dev/null +++ b/proto/UpdatePlayerShowAvatarListReq.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +option java_package = "emu.grasscutter.net.proto"; + +message UpdatePlayerShowAvatarListReq { + enum CmdId { + option allow_alias = true; + ENET_CHANNEL_ID = 0; + NONE = 0; + ENET_IS_RELIABLE = 1; + IS_ALLOW_CLIENT = 1; + CMD_ID = 4093; + } + + repeated uint32 show_avatar_id_list = 1; + bool is_show_avatar = 2; +} diff --git a/proto/UpdatePlayerShowAvatarListRsp.proto b/proto/UpdatePlayerShowAvatarListRsp.proto new file mode 100644 index 000000000..edb7cf323 --- /dev/null +++ b/proto/UpdatePlayerShowAvatarListRsp.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +option java_package = "emu.grasscutter.net.proto"; + +message UpdatePlayerShowAvatarListRsp { + enum CmdId { + option allow_alias = true; + NONE = 0; + ENET_CHANNEL_ID = 0; + ENET_IS_RELIABLE = 1; + CMD_ID = 4053; + } + + int32 retcode = 1; + repeated uint32 show_avatar_id_list = 2; + bool is_show_avatar = 3; +} diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 2715ba6e6..198992766 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -93,6 +93,9 @@ public class Player { private int moonCardDuration; private Set moonCardGetTimes; + private List showAvatarList; + private boolean showAvatars; + @Transient private boolean paused; @Transient private int enterSceneToken; @Transient private SceneLoadState sceneState; @@ -513,6 +516,22 @@ public class Player { this.regionId = regionId; } + public void setShowAvatars(boolean showAvatars) { + this.showAvatars = showAvatars; + } + + public boolean isShowAvatars() { + return showAvatars; + } + + public void setShowAvatarList(List showAvatarList) { + this.showAvatarList = showAvatarList; + } + + public List getShowAvatarList() { + return showAvatarList; + } + public boolean inMoonCard() { return moonCard; } @@ -832,15 +851,29 @@ public class Player { } public SocialDetail.Builder getSocialDetail() { + List socialShowAvatarInfoList = new ArrayList<>(); + for (int avatarId : this.getShowAvatarList()) { + socialShowAvatarInfoList.add( + socialShowAvatarInfoList.size(), + SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo.newBuilder() + .setAvatarId(avatarId) + .setLevel(getAvatars().getAvatarById(avatarId).getLevel()) + .setCostumeId(getAvatars().getAvatarById(avatarId).getCostume()) + .build() + ); + } + SocialDetail.Builder social = SocialDetail.newBuilder() .setUid(this.getUid()) - .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(this.getHeadImage())) + .setAvatarId(HeadImage.newBuilder().setAvatarId(this.getHeadImage()).getAvatarId()) .setNickname(this.getNickname()) .setSignature(this.getSignature()) .setLevel(this.getLevel()) .setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty()) .setWorldLevel(this.getWorldLevel()) .setNameCardId(this.getNameCardId()) + .setIsShowAvatar(this.isShowAvatars()) + .addAllShowAvatarInfoList(socialShowAvatarInfoList) .setFinishAchievementNum(0); return social; } diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java new file mode 100644 index 000000000..d04fb7308 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerUpdatePlayerShowAvatarListReq.java @@ -0,0 +1,22 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +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/send/PacketUpdatePlayerShowAvatarListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java new file mode 100644 index 000000000..d04fb7308 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketUpdatePlayerShowAvatarListRsp.java @@ -0,0 +1,22 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.Grasscutter; +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())); + } +} From 80aaa0d856381c739097954bd76249627b3035a8 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:31:36 +0800 Subject: [PATCH 05/10] import --- src/main/java/emu/grasscutter/game/player/Player.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 198992766..573dd830e 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -35,6 +35,7 @@ import emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo import emu.grasscutter.net.proto.PlayerWorldLocationInfoOuterClass; import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; +import emu.grasscutter.net.proto.SocialShowAvatarInfoOuterClass; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.*; From 6e73d4221deb11ae1f225539faf9ed3850ca62cc Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:37:09 +0800 Subject: [PATCH 06/10] Next time I'll never use github.dev again --- .../PacketUpdatePlayerShowAvatarListRsp.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 d04fb7308..1785c9f45 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.recv; +package emu.grasscutter.server.packet.send; -import emu.grasscutter.Grasscutter; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.BasePacket; 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; +import emu.grasscutter.net.proto.UpdatePlayerShowAvatarListRspOuterClass.UpdatePlayerShowAvatarListRsp; -@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); +import java.util.List; - session.getPlayer().setShowAvatars(req.getIsShowAvatar()); - session.getPlayer().setShowAvatarList(req.getShowAvatarIdListList()); +public class PacketUpdatePlayerShowAvatarListRsp extends BasePacket { - session.send(new PacketUpdatePlayerShowAvatarListRsp(req.getIsShowAvatar(), req.getShowAvatarIdListList())); + public PacketUpdatePlayerShowAvatarListRsp(boolean isShowAvatar, List avatarIds) { + super(PacketOpcodes.UpdatePlayerShowAvatarListRsp); + + UpdatePlayerShowAvatarListRsp proto = UpdatePlayerShowAvatarListRsp.newBuilder() + .setIsShowAvatar(isShowAvatar) + .addAllShowAvatarIdList(avatarIds) + .setRetcode(0) + .build(); + + this.setData(proto); } } From 97086d7baa5c3b2da684ac6c96964024be708b32 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:40:32 +0800 Subject: [PATCH 07/10] Headimage --- src/main/java/emu/grasscutter/game/player/Player.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 573dd830e..3677d3801 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -27,6 +27,7 @@ import emu.grasscutter.game.world.World; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry; +import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; import emu.grasscutter.net.proto.MpSettingTypeOuterClass.MpSettingType; import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo; From a4cbf1a58e7961f38592f050ea69d190281432c2 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:45:17 +0800 Subject: [PATCH 08/10] no headimage okay --- src/main/java/emu/grasscutter/game/player/Player.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 3677d3801..79696093b 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -867,7 +867,7 @@ public class Player { SocialDetail.Builder social = SocialDetail.newBuilder() .setUid(this.getUid()) - .setAvatarId(HeadImage.newBuilder().setAvatarId(this.getHeadImage()).getAvatarId()) + .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(this.getHeadImage())) .setNickname(this.getNickname()) .setSignature(this.getSignature()) .setLevel(this.getLevel()) From ba95637dd35ad1b02ca6098d5bea78235838536e Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 03:46:24 +0800 Subject: [PATCH 09/10] kill me plz --- src/main/java/emu/grasscutter/game/player/Player.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 79696093b..d550e5914 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -27,7 +27,6 @@ import emu.grasscutter.game.world.World; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry; -import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType; import emu.grasscutter.net.proto.MpSettingTypeOuterClass.MpSettingType; import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo; From c2a159be138be9bb5d9f7861a66628e12bed8484 Mon Sep 17 00:00:00 2001 From: Yazawazi <47273265+Yazawazi@users.noreply.github.com> Date: Thu, 28 Apr 2022 06:40:25 +0800 Subject: [PATCH 10/10] Should be OK --- .../emu/grasscutter/game/player/Player.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index d550e5914..75c9c21ad 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -853,15 +853,35 @@ public class Player { public SocialDetail.Builder getSocialDetail() { List socialShowAvatarInfoList = new ArrayList<>(); - for (int avatarId : this.getShowAvatarList()) { - socialShowAvatarInfoList.add( - socialShowAvatarInfoList.size(), - SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo.newBuilder() - .setAvatarId(avatarId) - .setLevel(getAvatars().getAvatarById(avatarId).getLevel()) - .setCostumeId(getAvatars().getAvatarById(avatarId).getCostume()) - .build() - ); + if (this.isOnline()) { + if (this.getShowAvatarList() != null) { + for (int avatarId : this.getShowAvatarList()) { + socialShowAvatarInfoList.add( + socialShowAvatarInfoList.size(), + SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo.newBuilder() + .setAvatarId(avatarId) + .setLevel(getAvatars().getAvatarById(avatarId).getLevel()) + .setCostumeId(getAvatars().getAvatarById(avatarId).getCostume()) + .build() + ); + } + } + } else { + List showAvatarList = DatabaseHelper.getPlayerById(id).getShowAvatarList(); + AvatarStorage avatars = DatabaseHelper.getPlayerById(id).getAvatars(); + avatars.loadFromDatabase(); + if (showAvatarList != null) { + for (int avatarId : showAvatarList) { + socialShowAvatarInfoList.add( + socialShowAvatarInfoList.size(), + SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo.newBuilder() + .setAvatarId(avatarId) + .setLevel(avatars.getAvatarById(avatarId).getLevel()) + .setCostumeId(avatars.getAvatarById(avatarId).getCostume()) + .build() + ); + } + } } SocialDetail.Builder social = SocialDetail.newBuilder()