From f0775f70f3fe162d72714bb25350c6523a127a79 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Fri, 14 Jul 2023 21:22:45 -0400 Subject: [PATCH] Send packet after scene load & Directly send back entity ID to clients --- src/main/java/emu/grasscutter/scripts/ScriptLib.java | 6 ++---- .../send/PacketServerGlobalValueChangeNotify.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/emu/grasscutter/scripts/ScriptLib.java b/src/main/java/emu/grasscutter/scripts/ScriptLib.java index 7a102e1c3..e37c8be3c 100644 --- a/src/main/java/emu/grasscutter/scripts/ScriptLib.java +++ b/src/main/java/emu/grasscutter/scripts/ScriptLib.java @@ -527,11 +527,9 @@ public class ScriptLib { if (scriptManager == null) return 1; var scene = scriptManager.getScene(); - var entity = scene.getEntityById(entityId); - if (entity == null) return 2; - scene.broadcastPacket( - new PacketServerGlobalValueChangeNotify(entity, sgvName, value)); + scene.runWhenFinished(() -> scene.broadcastPacket( + new PacketServerGlobalValueChangeNotify(entityId, sgvName, value))); return 0; } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java index 58dc12f98..e1498ca91 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketServerGlobalValueChangeNotify.java @@ -16,4 +16,14 @@ public final class PacketServerGlobalValueChangeNotify extends BasePacket { .setValue(value) .setKeyHash(Utils.abilityHash(abilityHash))); } + + public PacketServerGlobalValueChangeNotify(int entityId, String abilityHash, int value) { + super(PacketOpcodes.ServerGlobalValueChangeNotify); + + this.setData( + ServerGlobalValueChangeNotify.newBuilder() + .setEntityId(entityId) + .setValue(value) + .setKeyHash(Utils.abilityHash(abilityHash))); + } }