mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 18:09:44 +00:00
Change Hooks for Effects
This commit is contained in:
1 parent
d9aea174f4
commit
7432373533
5 files changed
+68
-28
No files matched your search
@@ -21,6 +21,7 @@ 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.IPlayerEffect;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.api.item.IItemLinked;
|
||||
@@ -406,6 +407,27 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectAdded(IPlayer player, IPlayerEffect effect) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(player, effect);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectAdd.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectTick(IPlayer player, IPlayerEffect effect) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(player, effect);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectTick.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onEffectRemove(IPlayer player, IPlayerEffect effect, EffectEvent.ExpirationType type) {
|
||||
PlayerDataScript handler = ScriptController.Instance.playerScripts;
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(player, effect, type);
|
||||
handler.callScript(EffectScript.ScriptType.OnEffectRemove.function, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onStartUsingItem(PlayerDataScript handler, IPlayer player, int duration, ItemStack item) {
|
||||
PlayerEvent.StartUsingItem event = new PlayerEvent.StartUsingItem(player, item, duration);
|
||||
handler.callScript(EnumScriptType.START_USING_ITEM, event);
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
|
||||
import java.util.List;
|
||||
@@ -80,6 +81,9 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
hookList.add(EnumScriptType.PROFILE_CHANGE.function);
|
||||
hookList.add(EnumScriptType.PROFILE_REMOVE.function);
|
||||
hookList.add(EnumScriptType.PROFILE_CREATE.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectAdd.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectTick.function);
|
||||
hookList.add(EffectScript.ScriptType.OnEffectRemove.function);
|
||||
|
||||
this.handler = this.script;
|
||||
PlayerScriptPacket.Get();
|
||||
|
||||
@@ -251,7 +251,6 @@ public class CustomEffectController implements ICustomEffectHandler {
|
||||
CustomEffect parent = get(id, index);
|
||||
if (parent != null) {
|
||||
PlayerEffect playerEffect = new PlayerEffect(id, duration, level, index);
|
||||
playerEffect.index = index;
|
||||
currentEffects.put(new EffectKey(id, index), playerEffect);
|
||||
parent.onAdded(player, playerEffect);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.controllers.data;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ICustomEffect;
|
||||
@@ -181,48 +182,62 @@ public class CustomEffect implements ICustomEffect {
|
||||
|
||||
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
if (onAddedConsumer != null) onAddedConsumer.accept(event);
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
if (onAddedConsumer != null)
|
||||
onAddedConsumer.accept(event);
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectAdd, event);
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnAdd, event);
|
||||
EventHooks.onEffectAdded(iPlayer, playerEffect);
|
||||
}
|
||||
|
||||
public void onTick(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectTick, event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnTick, event);
|
||||
EventHooks.onEffectTick(iPlayer, playerEffect);
|
||||
}
|
||||
|
||||
public void onRemoved(EntityPlayer player, PlayerEffect playerEffect, PlayerEvent.EffectEvent.ExpirationType type) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
if(playerEffect.index == 0){
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnEffectRemove, event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
script.callScript(EffectScript.ScriptType.OnRemove, event);
|
||||
EventHooks.onEffectRemove(iPlayer, playerEffect, type);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(boolean saveScripts) {
|
||||
|
||||
@@ -165,9 +165,9 @@ public class EffectScript implements INpcScriptHandler {
|
||||
}
|
||||
|
||||
public enum ScriptType {
|
||||
OnAdd("onAdded"),
|
||||
OnTick("onTick"),
|
||||
OnRemove("onRemove");
|
||||
OnEffectAdd("onEffectAdd"),
|
||||
OnEffectTick("onEffectTick"),
|
||||
OnEffectRemove("onEffectRemove");
|
||||
|
||||
public final String function;
|
||||
|
||||
|
||||
Reference in new issue
Block a user