From 9b84deaab326c84e6cd0278bfcf9e7d245e71e82 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 27 Aug 2023 23:22:18 -0400 Subject: [PATCH] Add `PlayerCompleteQuestEvent` --- .../emu/grasscutter/game/quest/GameQuest.java | 10 ++++++++-- .../event/player/PlayerCompleteQuestEvent.java | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java diff --git a/src/main/java/emu/grasscutter/game/quest/GameQuest.java b/src/main/java/emu/grasscutter/game/quest/GameQuest.java index 6a052e85d..2cf59fd2e 100644 --- a/src/main/java/emu/grasscutter/game/quest/GameQuest.java +++ b/src/main/java/emu/grasscutter/game/quest/GameQuest.java @@ -12,13 +12,15 @@ import emu.grasscutter.game.quest.enums.*; import emu.grasscutter.net.proto.ChapterStateOuterClass; import emu.grasscutter.net.proto.QuestOuterClass.Quest; import emu.grasscutter.scripts.data.SceneGroup; +import emu.grasscutter.server.event.player.PlayerCompleteQuestEvent; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; -import java.util.*; -import javax.script.Bindings; import lombok.*; +import javax.script.Bindings; +import java.util.*; + @Entity public class GameQuest { @Transient @Getter @Setter private GameMainQuest mainQuest; @@ -195,6 +197,10 @@ public class GameQuest { } public void finish() { + // Call PlayerCompleteQuestEvent. + var event = new PlayerCompleteQuestEvent(this.getOwner(), this); + if (!event.call()) return; + // Check if the quest has been finished. synchronized (this) { if (this.state == QuestState.QUEST_STATE_FINISHED) { diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java new file mode 100644 index 000000000..255d1b281 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerCompleteQuestEvent.java @@ -0,0 +1,17 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.quest.GameQuest; +import emu.grasscutter.server.event.Cancellable; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.Getter; + +public final class PlayerCompleteQuestEvent extends PlayerEvent implements Cancellable { + @Getter private final GameQuest quest; + + public PlayerCompleteQuestEvent(Player player, GameQuest quest) { + super(player); + + this.quest = quest; + } +}