Add PlayerObtainItemEvent

This commit is contained in:
KingRainbow44 2023-08-27 23:29:21 -04:00
parent 9c8a29c864
commit 0ad8eb443b
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 26 additions and 4 deletions

View File

@ -1,7 +1,5 @@
package emu.grasscutter.game.inventory;
import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
@ -13,14 +11,18 @@ import emu.grasscutter.game.props.*;
import emu.grasscutter.game.props.ItemUseAction.UseItemParams;
import emu.grasscutter.game.quest.enums.QuestContent;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.server.event.player.PlayerObtainItemEvent;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.longs.*;
import java.util.*;
import javax.annotation.Nullable;
import lombok.val;
import javax.annotation.Nullable;
import java.util.*;
import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS;
public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
private final Long2ObjectMap<GameItem> store;
private final Int2ObjectMap<InventoryTab> inventoryTypes;
@ -121,6 +123,9 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
if (result != null) {
this.triggerAddItemEvents(result);
getPlayer().sendPacket(new PacketStoreItemChangeNotify(result));
// Call PlayerObtainItemEvent.
new PlayerObtainItemEvent(this.getPlayer(), item).call();
return true;
}

View File

@ -0,0 +1,17 @@
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.Getter;
@Getter
public final class PlayerObtainItemEvent extends PlayerEvent {
private final GameItem item;
public PlayerObtainItemEvent(Player player, GameItem item) {
super(player);
this.item = item;
}
}