Migrated all EffectScript.ScriptType hooks to EnumScriptType

This commit is contained in:
bigguy345 committed 2026-01-22 20:48:17 +02:00
1 parent 50e9f1b3e5
commit d835d2acb0
5 files changed
+17 -31

No files matched your search

+3 -3
View File
@@ -491,21 +491,21 @@ public class EventHooks {
public static boolean onEffectAdded(IPlayer player, IPlayerEffect effect) {
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(player, effect);
handler.callScript(EffectScript.ScriptType.OnEffectAdd.function, event);
handler.callScript(EnumScriptType.ON_EFFECT_ADD.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onEffectTick(IPlayer player, IPlayerEffect effect) {
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(player, effect);
handler.callScript(EffectScript.ScriptType.OnEffectTick.function, event);
handler.callScript(EnumScriptType.ON_EFFECT_TICK.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onEffectRemove(IPlayer player, IPlayerEffect effect, EffectEvent.ExpirationType type) {
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(player, effect, type);
handler.callScript(EffectScript.ScriptType.OnEffectRemove.function, event);
handler.callScript(EnumScriptType.ON_EFFECT_REMOVE.function, event);
return NpcAPI.EVENT_BUS.post(event);
}
@@ -116,6 +116,10 @@ public enum EnumScriptType {
PROFILE_REMOVE("profileRemove"),
PROFILE_CREATE("profileCreate"),
ON_EFFECT_ADD("onEffectAdd"),
ON_EFFECT_TICK("onEffectTick"),
ON_EFFECT_REMOVE("onEffectRemove"),
ABILITY_START("abilityStart"),
ABILITY_EXECUTE("abilityExecute"),
ABILITY_INTERRUPT("abilityInterrupt"),
@@ -2,7 +2,6 @@ package noppes.npcs.controllers;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.data.EffectScript;
import noppes.npcs.controllers.data.RecipeScript;
import java.util.ArrayList;
@@ -145,9 +144,9 @@ public class ScriptHookController implements IScriptHookHandler {
EnumScriptType.PROFILE_CHANGE.function,
EnumScriptType.PROFILE_REMOVE.function,
EnumScriptType.PROFILE_CREATE.function,
EffectScript.ScriptType.OnEffectAdd.function,
EffectScript.ScriptType.OnEffectTick.function,
EffectScript.ScriptType.OnEffectRemove.function
EnumScriptType.ON_EFFECT_ADD.function,
EnumScriptType.ON_EFFECT_TICK.function,
EnumScriptType.ON_EFFECT_REMOVE.function
);
// Block hooks
@@ -209,9 +208,9 @@ public class ScriptHookController implements IScriptHookHandler {
// Effect hooks
registerBuiltIn(CONTEXT_EFFECT,
EffectScript.ScriptType.OnEffectAdd.function,
EffectScript.ScriptType.OnEffectTick.function,
EffectScript.ScriptType.OnEffectRemove.function
EnumScriptType.ON_EFFECT_ADD.function,
EnumScriptType.ON_EFFECT_TICK.function,
EnumScriptType.ON_EFFECT_REMOVE.function
);
// Forge hooks - just init, the rest are dynamically discovered
@@ -7,6 +7,7 @@ import noppes.npcs.EventHooks;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomEffect;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.scripted.event.player.PlayerEvent;
@@ -193,7 +194,7 @@ public class CustomEffect implements ICustomEffect {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectAdd, event);
script.callScript(EnumScriptType.ON_EFFECT_ADD, event);
}
EventHooks.onEffectAdded(iPlayer, playerEffect);
@@ -213,7 +214,7 @@ public class CustomEffect implements ICustomEffect {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectTick, event);
script.callScript(EnumScriptType.ON_EFFECT_TICK, event);
}
EventHooks.onEffectTick(iPlayer, playerEffect);
@@ -234,7 +235,7 @@ public class CustomEffect implements ICustomEffect {
return;
}
script.callScript(EffectScript.ScriptType.OnEffectRemove, event);
script.callScript(EnumScriptType.ON_EFFECT_REMOVE, event);
}
EventHooks.onEffectRemove(iPlayer, playerEffect, type);
@@ -3,7 +3,6 @@ package noppes.npcs.controllers.data;
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.scripted.event.player.PlayerEvent;
/**
* Script handler for CustomEffect scripts.
@@ -33,12 +32,6 @@ public class EffectScript extends SingleScriptHandler implements IScriptHandlerP
return IScriptHookHandler.CONTEXT_EFFECT;
}
/**
* Convenience method to call a script with a typed event.
*/
public void callScript(ScriptType type, PlayerEvent.EffectEvent event) {
callScript(type.function, event);
}
@Override
public void requestData() {
@@ -52,15 +45,4 @@ public class EffectScript extends SingleScriptHandler implements IScriptHandlerP
EffectScriptPacket.Save(effectId, index, totalCount, nbt);
}
public enum ScriptType {
OnEffectAdd("onEffectAdd"),
OnEffectTick("onEffectTick"),
OnEffectRemove("onEffectRemove");
public final String function;
ScriptType(String functionName) {
this.function = functionName;
}
}
}