From 40887b17fea11d9adbaee07fef6fd88fdaaf6336 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sun, 27 Aug 2023 23:22:35 -0400 Subject: [PATCH] Add `PlayerForgeItemEvent` --- .../game/managers/forging/ForgingManager.java | 9 ++++++++- .../event/player/PlayerForgeItemEvent.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java diff --git a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java index f7d3c3041..083238997 100644 --- a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java @@ -14,6 +14,7 @@ import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueMan import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType; import emu.grasscutter.net.proto.ForgeStartReqOuterClass.ForgeStartReq; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; +import emu.grasscutter.server.event.player.PlayerForgeItemEvent; import emu.grasscutter.server.packet.send.*; import emu.grasscutter.utils.Utils; import java.util.ArrayList; @@ -21,7 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class ForgingManager extends BasePlayerManager { +public final class ForgingManager extends BasePlayerManager { public ForgingManager(Player player) { super(player); @@ -186,6 +187,12 @@ public class ForgingManager extends BasePlayerManager { int resultId = data.getResultItemId() > 0 ? data.getResultItemId() : data.getShowItemId(); ItemData resultItemData = GameData.getItemDataMap().get(resultId); GameItem addItem = new GameItem(resultItemData, data.getResultItemCount() * finished); + + // Call the PlayerForgeItemEvent. + var event = new PlayerForgeItemEvent(this.player, addItem); + if (!event.call()) return; + + addItem = event.getItemForged(); this.player.getInventory().addItem(addItem); // Battle pass trigger handler diff --git a/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java b/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java new file mode 100644 index 000000000..d669762a4 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/event/player/PlayerForgeItemEvent.java @@ -0,0 +1,16 @@ +package emu.grasscutter.server.event.player; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.server.event.types.PlayerEvent; +import lombok.*; + +public final class PlayerForgeItemEvent extends PlayerEvent { + @Getter @Setter private GameItem itemForged; + + public PlayerForgeItemEvent(Player player, GameItem itemForged) { + super(player); + + this.itemForged = itemForged; + } +}