Add PlayerOpenChestEvent

This commit is contained in:
KingRainbow44 2023-05-19 19:32:07 -04:00
parent bda963adca
commit 8b9ca5ec7e
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 39 additions and 0 deletions

View File

@ -3,6 +3,8 @@ package emu.grasscutter.game.entity.gadget.chest;
import emu.grasscutter.game.entity.gadget.GadgetChest; import emu.grasscutter.game.entity.gadget.GadgetChest;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.ChestReward; import emu.grasscutter.game.world.ChestReward;
import emu.grasscutter.server.event.player.PlayerOpenChestEvent;
import java.util.Random; import java.util.Random;
public class NormalChestInteractHandler implements ChestInteractHandler { public class NormalChestInteractHandler implements ChestInteractHandler {
@ -19,6 +21,10 @@ public class NormalChestInteractHandler implements ChestInteractHandler {
@Override @Override
public boolean onInteract(GadgetChest chest, Player player) { public boolean onInteract(GadgetChest chest, Player player) {
// Invoke open chest event.
var event = new PlayerOpenChestEvent(player, chest, this.chestReward);
event.call(); if (event.isCanceled()) return true;
player.earnExp(chestReward.getAdvExp()); player.earnExp(chestReward.getAdvExp());
player.getInventory().addItem(201, chestReward.getResin()); player.getInventory().addItem(201, chestReward.getResin());

View File

@ -0,0 +1,33 @@
package emu.grasscutter.server.event.player;
import emu.grasscutter.game.entity.gadget.GadgetChest;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.ChestReward;
import emu.grasscutter.server.event.Cancellable;
import emu.grasscutter.server.event.types.PlayerEvent;
public final class PlayerOpenChestEvent extends PlayerEvent implements Cancellable {
private final GadgetChest chest;
private ChestReward reward;
public PlayerOpenChestEvent(Player player,
GadgetChest chest, ChestReward reward
) {
super(player);
this.chest = chest;
this.reward = reward;
}
public GadgetChest getChest() {
return this.chest;
}
public void setReward(ChestReward reward) {
this.reward = reward;
}
public ChestReward getReward() {
return this.reward;
}
}