mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 04:57:18 +00:00
Add PlayerOpenChestEvent
This commit is contained in:
parent
bda963adca
commit
8b9ca5ec7e
@ -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());
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user