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

55 lines
1.5 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;
2026-01-22 14:27:48 -05:00
import noppes.npcs.constants.ScriptContext;
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 {
2026-01-22 14:27:48 -05:00
2026-01-18 17:57:10 +02:00
/** The effect ID for packet communication. -1 if not bound to an effect. */
private int effectId = -1;
2026-01-22 14:27:48 -05:00
2026-01-18 17:57:10 +02:00
/**
* Create an unbound EffectScript (for server-side use).
*/
public EffectScript() {
2025-02-10 14:58:45 -05:00
}
2026-01-22 14:27:48 -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-22 14:27:48 -05:00
@Override
public ScriptContext getContext() {
return ScriptContext.EFFECT;
}
2026-01-18 17:57:10 +02:00
@Override
2026-01-22 14:27:48 -05:00
public String noticeString() {
return effectId >= 0 ? "CustomEffect[" + effectId + "]" : "CustomEffect";
2026-01-18 17:57:10 +02:00
}
2026-01-22 14:27:48 -05:00
2026-01-18 17:57:10 +02:00
@Override
public void requestData() {
2026-01-22 14:27:48 -05:00
if (effectId >= 0)
2026-01-18 17:57:10 +02:00
EffectScriptPacket.Get(effectId);
}
2026-01-22 14:27:48 -05:00
2026-01-18 17:57:10 +02:00
@Override
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
2026-01-22 14:27:48 -05:00
if (effectId >= 0)
2026-01-18 17:57:10 +02:00
EffectScriptPacket.Save(effectId, index, totalCount, nbt);
2025-02-10 14:58:45 -05:00
}
2026-01-18 17:57:10 +02:00
}