From 67a1650fb600ed2d32051d4809471e03087945a4 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 6 Mar 2025 01:24:51 -0500 Subject: [PATCH] Profile Events --- src/main/java/noppes/npcs/EventHooks.java | 20 ++++++ .../noppes/npcs/constants/EnumScriptType.java | 7 +- .../npcs/scripted/event/PlayerEvent.java | 70 +++++++++++++++++++ todo.txt | 8 +-- 4 files changed, 100 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 465fa1f47..bbf68fa9c 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -17,10 +17,12 @@ import net.minecraftforge.event.world.WorldEvent; import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.*; import noppes.npcs.api.event.IAnimationEvent; +import noppes.npcs.api.event.IPlayerEvent; import noppes.npcs.api.gui.ICustomGui; import noppes.npcs.api.gui.IItemSlot; import noppes.npcs.api.handler.data.IAnimation; import noppes.npcs.api.handler.data.IFrame; +import noppes.npcs.api.handler.data.IProfile; import noppes.npcs.api.item.IItemCustomizable; import noppes.npcs.api.item.IItemLinked; import noppes.npcs.api.item.IItemStack; @@ -917,4 +919,22 @@ public class EventHooks { } postAnimationEvent(new AnimationEvent.FrameEvent.Exited(animation, frame)); } + + public static boolean onProfileChange(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) { + PlayerEvent.ProfileEvent.Changed event = new PlayerEvent.ProfileEvent.Changed(player, profile, slot, profile.getCurrentSlotId()); + handler.callScript(EnumScriptType.PROFILE_CHANGE, event); + return NpcAPI.EVENT_BUS.post(event); + } + + public static boolean onProfileRemove(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) { + PlayerEvent.ProfileEvent.Removed event = new PlayerEvent.ProfileEvent.Removed(player, profile, slot); + handler.callScript(EnumScriptType.PROFILE_REMOVE, event); + return NpcAPI.EVENT_BUS.post(event); + } + + public static boolean onProfileCreate(PlayerDataScript handler, IPlayer player, IProfile profile, int slot) { + PlayerEvent.ProfileEvent.Create event = new PlayerEvent.ProfileEvent.Create(player, profile, slot); + handler.callScript(EnumScriptType.PROFILE_CREATE, event); + return NpcAPI.EVENT_BUS.post(event); + } } diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index f0270d443..170f8c0ff 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -109,7 +109,12 @@ public enum EnumScriptType { ANIMATION_FRAME_EXIT("frameExit"), LINKED_ITEM_VERSION("versionChanged"), - LINKED_ITEM_BUILD("buildingItem"); + LINKED_ITEM_BUILD("buildingItem"), + + PROFILE("profile"), + PROFILE_CHANGE("profileChange"), + PROFILE_REMOVE("profileRemove"), + PROFILE_CREATE("profileCreate"); public String function; diff --git a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java index a0d1fcfbb..8ed22fe95 100644 --- a/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/PlayerEvent.java @@ -15,6 +15,7 @@ import noppes.npcs.api.entity.IEntityLivingBase; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.event.IPlayerEvent; import noppes.npcs.api.handler.data.IPlayerEffect; +import noppes.npcs.api.handler.data.IProfile; import noppes.npcs.api.item.IItemStack; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.scripted.NpcAPI; @@ -1005,4 +1006,73 @@ public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent { DEATH } } + + @Cancelable + public static class ProfileEvent extends PlayerEvent implements IPlayerEvent.ProfileEvent { + public final IProfile profile; + public final int slot; + + public ProfileEvent(IPlayer player, IProfile profile, int slot) { + super(player); + this.profile = profile; + this.slot = slot; + } + + public String getHookName() { + return EnumScriptType.PROFILE.function; + } + + @Override + public IProfile getProfile() { + return this.profile; + } + + @Override + public int getSlot() { + return this.slot; + } + + @Cancelable + public static class Changed extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Changed { + public final int prevSlot; + + public Changed(IPlayer player, IProfile profile, int slot, int prevSlot) { + super(player, profile, slot); + this.prevSlot = prevSlot; + } + + @Override + public int getPrevSlot() { + return this.prevSlot; + } + + public String getHookName() { + return EnumScriptType.PROFILE_CHANGE.function; + } + } + + @Cancelable + public static class Removed extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Removed { + + public Removed(IPlayer player, IProfile profile, int slot) { + super(player, profile, slot); + } + + public String getHookName() { + return EnumScriptType.PROFILE_REMOVE.function; + } + } + + @Cancelable + public static class Create extends PlayerEvent.ProfileEvent implements IPlayerEvent.ProfileEvent.Create { + + public Create(IPlayer player, IProfile profile, int slot) { + super(player, profile, slot); + } + + public String getHookName() { + return EnumScriptType.PROFILE_CREATE.function; + } + } + } } diff --git a/todo.txt b/todo.txt index fa102580d..8484c73c9 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,10 @@ TODO List Magic: -- Create MagicData Class +- Create MagicData Class -- Done -- Magic Data: Magic ID, % Split, Bonus Damage -- Store Magic on PlayerData and NPCs +- Store Magic on PlayerData and NPCs -- Done Profile: - On Profile Slot Change Event @@ -16,5 +16,5 @@ ScriptPlayer and ScriptNPC Interfaces: - IMagic -- IProfile -- ISlot +- IProfile -- Need Work +- ISlot -- Done