Files
CustomNPC-Plus/src/main/java/noppes/npcs/controllers/data/EffectScript.java
T

66 lines
1.9 KiB
Java
Raw Normal View History

2025-02-10 14:58:45 -05:00
package noppes.npcs.controllers.data;
2026-01-18 17:57:10 +02:00
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
2025-02-10 14:58:45 -05:00
import net.minecraft.nbt.NBTTagCompound;
2026-01-18 17:57:10 +02:00
import noppes.npcs.api.handler.IScriptHookHandler;
2025-04-08 22:37:26 -04:00
import noppes.npcs.scripted.event.player.PlayerEvent;
2025-02-10 14:58:45 -05:00
2026-01-18 17:57:10 +02:00
/**
* Script handler for CustomEffect scripts.
* Manages a single script container for effect hooks (onEffectAdd, onEffectTick, onEffectRemove).
*/
public class EffectScript extends SingleScriptHandler implements IScriptHandlerPacket {
/** The effect ID for packet communication. -1 if not bound to an effect. */
private int effectId = -1;
/**
* Create an unbound EffectScript (for server-side use).
*/
public EffectScript() {
2025-02-10 14:58:45 -05:00
}
2026-01-18 17:57:10 +02:00
/**
* Create an EffectScript bound to a specific effect (for GUI use).
* @param effectId The ID of the CustomEffect
*/
public EffectScript(int effectId) {
this.effectId = effectId;
2025-02-10 14:58:45 -05:00
}
2026-01-18 17:57:10 +02:00
@Override
public String getHookContext() {
return IScriptHookHandler.CONTEXT_EFFECT;
}
/**
* Convenience method to call a script with a typed event.
*/
2025-02-10 14:58:45 -05:00
public void callScript(ScriptType type, PlayerEvent.EffectEvent event) {
callScript(type.function, event);
}
2026-01-18 17:57:10 +02:00
@Override
public void requestData() {
if (effectId >= 0)
EffectScriptPacket.Get(effectId);
}
@Override
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
if (effectId >= 0)
EffectScriptPacket.Save(effectId, index, totalCount, nbt);
2025-02-10 14:58:45 -05:00
}
public enum ScriptType {
2025-03-14 03:33:10 -04:00
OnEffectAdd("onEffectAdd"),
OnEffectTick("onEffectTick"),
OnEffectRemove("onEffectRemove");
2025-02-10 14:58:45 -05:00
public final String function;
2025-03-13 17:14:45 -04:00
2025-02-10 14:58:45 -05:00
ScriptType(String functionName) {
this.function = functionName;
}
}
2026-01-18 17:57:10 +02:00
}