Organize Player Events

This commit is contained in:
Kam committed 2025-04-08 22:37:26 -04:00
1 parent 04bfbef219
commit 94d9d93360
16 files changed
+51 -68

No files matched your search

@@ -6,7 +6,7 @@ import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.CustomEffect;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType;
import noppes.npcs.scripted.event.player.PlayerEvent.EffectEvent.ExpirationType;
import java.util.*;
+16 -15
View File
@@ -35,7 +35,8 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.EntityProjectile;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.*;
import noppes.npcs.scripted.event.PlayerEvent.*;
import noppes.npcs.scripted.event.player.*;
import noppes.npcs.scripted.event.player.PlayerEvent.*;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
@@ -373,18 +374,18 @@ public class EventHooks {
}
public static void onPlayerInit(PlayerDataScript handler, IPlayer player) {
noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(player);
PlayerEvent.InitEvent event = new PlayerEvent.InitEvent(player);
handler.callScript(EnumScriptType.INIT, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onPlayerTick(PlayerDataScript handler, IPlayer player) {
noppes.npcs.scripted.event.PlayerEvent.UpdateEvent event = new noppes.npcs.scripted.event.PlayerEvent.UpdateEvent(player);
PlayerEvent.UpdateEvent event = new PlayerEvent.UpdateEvent(player);
handler.callScript(EnumScriptType.TICK, event);
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onPlayerInteract(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) {
public static boolean onPlayerInteract(PlayerDataScript handler, PlayerEvent.InteractEvent event) {
handler.callScript(EnumScriptType.INTERACT, event);
return NpcAPI.EVENT_BUS.post(event);
}
@@ -488,41 +489,41 @@ public class EventHooks {
}
public static void onPlayerUseHoe(PlayerDataScript handler, IPlayer player, ItemStack hoe, int x, int y, int z) {
noppes.npcs.scripted.event.PlayerEvent.UseHoe event = new noppes.npcs.scripted.event.PlayerEvent.UseHoe(player, hoe, x, y, z);
PlayerEvent.UseHoe event = new PlayerEvent.UseHoe(player, hoe, x, y, z);
handler.callScript(EnumScriptType.USE_HOE, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onPlayerSleep(PlayerDataScript handler, IPlayer player, int x, int y, int z) {
noppes.npcs.scripted.event.PlayerEvent.Sleep event = new noppes.npcs.scripted.event.PlayerEvent.Sleep(player, x, y, z);
PlayerEvent.Sleep event = new PlayerEvent.Sleep(player, x, y, z);
handler.callScript(EnumScriptType.SLEEP, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onPlayerWakeUp(PlayerDataScript handler, IPlayer player, boolean setSpawn) {
noppes.npcs.scripted.event.PlayerEvent.WakeUp event = new noppes.npcs.scripted.event.PlayerEvent.WakeUp(player, setSpawn);
PlayerEvent.WakeUp event = new PlayerEvent.WakeUp(player, setSpawn);
handler.callScript(EnumScriptType.WAKE_UP, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onPlayerDeath(PlayerDataScript handler, IPlayer player, DamageSource source, Entity entity) {
noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(player, source, entity);
PlayerEvent.DiedEvent event = new PlayerEvent.DiedEvent(player, source, entity);
handler.callScript(EnumScriptType.KILLED, event);
NpcAPI.EVENT_BUS.post(event);
}
public static void onPlayerKills(PlayerDataScript handler, IPlayer player, EntityLivingBase entityLiving) {
noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(player, entityLiving);
PlayerEvent.KilledEntityEvent event = new PlayerEvent.KilledEntityEvent(player, entityLiving);
handler.callScript(EnumScriptType.KILLS, event);
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onPlayerAttacked(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.AttackedEvent event) {
public static boolean onPlayerAttacked(PlayerDataScript handler, PlayerEvent.AttackedEvent event) {
handler.callScript(EnumScriptType.ATTACKED, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) {
public static boolean onPlayerDamaged(PlayerDataScript handler, PlayerEvent.DamagedEvent event) {
handler.callScript(EnumScriptType.DAMAGED, event);
return NpcAPI.EVENT_BUS.post(event);
}
@@ -592,12 +593,12 @@ public class EventHooks {
NpcAPI.EVENT_BUS.post(event);
}
public static boolean onPlayerBowCharge(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent event) {
public static boolean onPlayerBowCharge(PlayerDataScript handler, PlayerEvent.RangedChargeEvent event) {
handler.callScript(EnumScriptType.RANGED_CHARGE, event);
return NpcAPI.EVENT_BUS.post(event);
}
public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) {
public static boolean onPlayerRanged(PlayerDataScript handler, PlayerEvent.RangedLaunchedEvent event) {
handler.callScript(EnumScriptType.RANGED_LAUNCHED, event);
return NpcAPI.EVENT_BUS.post(event);
}
@@ -634,7 +635,7 @@ public class EventHooks {
public static void onPlayerTimer(PlayerData data, int id) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
noppes.npcs.scripted.event.PlayerEvent.TimerEvent event = new noppes.npcs.scripted.event.PlayerEvent.TimerEvent((IPlayer) NpcAPI.Instance().getIEntity(data.player), id);
PlayerEvent.TimerEvent event = new PlayerEvent.TimerEvent((IPlayer) NpcAPI.Instance().getIEntity(data.player), id);
handler.callScript(EnumScriptType.TIMER, event);
NpcAPI.EVENT_BUS.post(event);
}
@@ -721,7 +722,7 @@ public class EventHooks {
}
public static void onCustomGuiClose(IPlayer player, ICustomGui gui) {
noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent event = new noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent(player, gui);
CustomGuiEvent.CloseEvent event = new CustomGuiEvent.CloseEvent(player, gui);
CustomGuiController.onClose(event);
}
@@ -34,9 +34,9 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleFollower;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptSound;
import noppes.npcs.scripted.event.DialogEvent;
import noppes.npcs.scripted.event.player.DialogEvent;
import noppes.npcs.scripted.event.PartyEvent;
import noppes.npcs.scripted.event.QuestEvent;
import noppes.npcs.scripted.event.player.QuestEvent;
import java.io.IOException;
import java.util.*;
@@ -55,7 +55,7 @@ import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTransporter;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.ScriptSound;
import noppes.npcs.scripted.event.DialogEvent;
import noppes.npcs.scripted.event.player.DialogEvent;
import java.io.File;
import java.io.IOException;
@@ -123,7 +123,7 @@ public class ScriptPlayerEventHandler {
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
noppes.npcs.scripted.event.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.PlayerEvent.InteractEvent(scriptPlayer, 1, NpcAPI.Instance().getIEntity(event.target));
noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.InteractEvent(scriptPlayer, 1, NpcAPI.Instance().getIEntity(event.target));
event.setCanceled(EventHooks.onPlayerInteract(handler, ev));
}
}
@@ -136,7 +136,7 @@ public class ScriptPlayerEventHandler {
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent ev = new noppes.npcs.scripted.event.PlayerEvent.RangedChargeEvent(scriptPlayer);
noppes.npcs.scripted.event.player.PlayerEvent.RangedChargeEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.RangedChargeEvent(scriptPlayer);
EventHooks.onPlayerBowCharge(handler, ev);
}
}
@@ -149,7 +149,7 @@ public class ScriptPlayerEventHandler {
if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer && event.entityPlayer instanceof EntityPlayerMP) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer);
noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent ev = new noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent(scriptPlayer, event.bow, event.charge);
noppes.npcs.scripted.event.player.PlayerEvent.RangedLaunchedEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.RangedLaunchedEvent(scriptPlayer, event.bow, event.charge);
EventHooks.onPlayerRanged(handler, ev);
}
}
@@ -167,7 +167,7 @@ public class ScriptPlayerEventHandler {
if (!event.getPlayer().worldObj.isRemote && event.world instanceof WorldServer && event.getPlayer() instanceof EntityPlayerMP) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.getPlayer());
noppes.npcs.scripted.event.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.world), NpcAPI.Instance().getIPos(event.x, event.y, event.z)), event.getExpToDrop());
noppes.npcs.scripted.event.player.PlayerEvent.BreakEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.BreakEvent(scriptPlayer, NpcAPI.Instance().getIBlock(NpcAPI.Instance().getIWorld(event.world), NpcAPI.Instance().getIPos(event.x, event.y, event.z)), event.getExpToDrop());
event.setCanceled(EventHooks.onPlayerBreak(handler, ev));
event.setExpToDrop(ev.exp);
}
@@ -472,7 +472,7 @@ public class ScriptPlayerEventHandler {
Entity source = NoppesUtilServer.GetDamageSource(event.source);
PlayerDataScript handler = ScriptController.Instance.playerScripts;
if (event.entityLiving instanceof EntityPlayerMP) {
noppes.npcs.scripted.event.PlayerEvent.AttackedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.AttackedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
noppes.npcs.scripted.event.player.PlayerEvent.AttackedEvent pevent = new noppes.npcs.scripted.event.player.PlayerEvent.AttackedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
cancel = EventHooks.onPlayerAttacked(handler, pevent);
}
@@ -481,7 +481,7 @@ public class ScriptPlayerEventHandler {
if (ConfigMain.AttributesEnabled)
attackAmount = AttributeAttackUtil.calculateOutgoing((EntityPlayer) event.source.getEntity(), attackAmount);
noppes.npcs.scripted.event.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.AttackEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.source.getEntity()), event.entityLiving, attackAmount, event.source);
noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.source.getEntity()), event.entityLiving, attackAmount, event.source);
cancel = cancel || EventHooks.onPlayerAttack(handler, pevent1);
}
event.setCanceled(cancel);
@@ -508,13 +508,13 @@ public class ScriptPlayerEventHandler {
}
if (event.entityLiving instanceof EntityPlayerMP) {
noppes.npcs.scripted.event.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.PlayerEvent.DamagedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
noppes.npcs.scripted.event.player.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.player.PlayerEvent.DamagedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
cancel = EventHooks.onPlayerDamaged(handler, pevent);
event.ammount = pevent.damage;
}
if (source instanceof EntityPlayerMP) {
noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent pevent1 = new noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent((IPlayer) NpcAPI.Instance().getIEntity(source), event.entityLiving, event.ammount, event.source);
noppes.npcs.scripted.event.player.PlayerEvent.DamagedEntityEvent pevent1 = new noppes.npcs.scripted.event.player.PlayerEvent.DamagedEntityEvent((IPlayer) NpcAPI.Instance().getIEntity(source), event.entityLiving, event.ammount, event.source);
cancel = cancel || EventHooks.onPlayerDamagedEntity(handler, pevent1);
event.ammount = pevent1.damage;
}
@@ -583,7 +583,7 @@ public class ScriptPlayerEventHandler {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.player);
String message = event.message;
noppes.npcs.scripted.event.PlayerEvent.ChatEvent ev = new noppes.npcs.scripted.event.PlayerEvent.ChatEvent(scriptPlayer, event.message);
noppes.npcs.scripted.event.player.PlayerEvent.ChatEvent ev = new noppes.npcs.scripted.event.player.PlayerEvent.ChatEvent(scriptPlayer, event.message);
EventHooks.onPlayerChat(handler, ev);
event.setCanceled(ev.isCanceled());
if (!message.equals(ev.message)) {
@@ -26,7 +26,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.zip.GZIPInputStream;
import static noppes.npcs.scripted.event.PlayerEvent.EffectEvent.ExpirationType;
import static noppes.npcs.scripted.event.player.PlayerEvent.EffectEvent.ExpirationType;
public class CustomEffectController implements ICustomEffectHandler {
@@ -15,7 +15,7 @@ import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.containers.ContainerCustomGui;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.CustomGuiEvent;
import noppes.npcs.scripted.event.player.CustomGuiEvent;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.scripted.overlay.ScriptOverlay;
@@ -8,7 +8,7 @@ import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.data.ICustomEffect;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.scripted.event.PlayerEvent;
import noppes.npcs.scripted.event.player.PlayerEvent;
import java.util.function.Consumer;
@@ -10,7 +10,7 @@ import noppes.npcs.config.ConfigScript;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.event.PlayerEvent;
import noppes.npcs.scripted.event.player.PlayerEvent;
import java.io.IOException;
import java.util.*;
@@ -13,6 +13,7 @@ import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.player.PlayerEvent;
import javax.annotation.CheckForNull;
import java.lang.reflect.Array;
@@ -84,8 +85,8 @@ public class PlayerDataScript implements INpcScriptHandler {
scriptContainer.errored = false;
}
if (!Objects.equals(hookName, EnumScriptType.INIT.function) && event instanceof noppes.npcs.scripted.event.PlayerEvent) {
noppes.npcs.scripted.event.PlayerEvent playerEvent = (noppes.npcs.scripted.event.PlayerEvent) event;
if (!Objects.equals(hookName, EnumScriptType.INIT.function) && event instanceof PlayerEvent) {
PlayerEvent playerEvent = (PlayerEvent) event;
EventHooks.onPlayerInit(this, playerEvent.player);
}
}
@@ -9,7 +9,7 @@ import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.IPlayerFactionData;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.FactionEvent;
import noppes.npcs.scripted.event.player.FactionEvent;
import java.util.HashMap;
@@ -1,4 +1,4 @@
package noppes.npcs.scripted.event;
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.item.ItemStack;
@@ -10,12 +10,11 @@ import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
public final IPlayer player;
public class CustomGuiEvent extends PlayerEvent implements ICustomGuiEvent {
public final ICustomGui gui;
public CustomGuiEvent(IPlayer player, ICustomGui gui) {
this.player = player;
super(player);
this.gui = gui;
}
@@ -23,10 +22,6 @@ public class CustomGuiEvent extends CustomNPCsEvent implements ICustomGuiEvent {
return EnumScriptType.CUSTOM_GUI_EVENT.function;
}
public IPlayer getPlayer() {
return this.player;
}
public ICustomGui getGui() {
return gui;
}
@@ -1,4 +1,4 @@
package noppes.npcs.scripted.event;
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.api.entity.IPlayer;
@@ -6,17 +6,12 @@ import noppes.npcs.api.event.IDialogEvent;
import noppes.npcs.api.handler.data.IDialog;
import noppes.npcs.constants.EnumScriptType;
public class DialogEvent extends CustomNPCsEvent implements IDialogEvent {
public class DialogEvent extends PlayerEvent implements IDialogEvent {
public final IDialog dialog;
public final IPlayer player;
public DialogEvent(IPlayer player, IDialog dialog) {
super(player);
this.dialog = dialog;
this.player = player;
}
public IPlayer getPlayer() {
return player;
}
public IDialog getDialog() {
@@ -1,4 +1,4 @@
package noppes.npcs.scripted.event;
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.api.entity.IPlayer;
@@ -6,17 +6,12 @@ import noppes.npcs.api.event.IFactionEvent;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.constants.EnumScriptType;
public class FactionEvent extends CustomNPCsEvent implements IFactionEvent {
public class FactionEvent extends PlayerEvent implements IFactionEvent {
public final IFaction faction;
public final IPlayer player;
public FactionEvent(IPlayer player, IFaction faction) {
super(player);
this.faction = faction;
this.player = player;
}
public IPlayer getPlayer() {
return player;
}
public IFaction getFaction() {
@@ -1,4 +1,4 @@
package noppes.npcs.scripted.event;
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
@@ -19,6 +19,7 @@ import noppes.npcs.api.handler.data.IProfile;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.event.CustomNPCsEvent;
public class PlayerEvent extends CustomNPCsEvent implements IPlayerEvent {
public final IPlayer player;
@@ -1,4 +1,4 @@
package noppes.npcs.scripted.event;
package noppes.npcs.scripted.event.player;
import cpw.mods.fml.common.eventhandler.Cancelable;
import noppes.npcs.api.entity.IPlayer;
@@ -7,17 +7,12 @@ import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.constants.EnumScriptType;
public class QuestEvent extends CustomNPCsEvent implements IQuestEvent {
public class QuestEvent extends PlayerEvent implements IQuestEvent {
public final IQuest quest;
public final IPlayer player;
public QuestEvent(IPlayer player, IQuest quest) {
super(player);
this.quest = quest;
this.player = player;
}
public IPlayer getPlayer() {
return player;
}
public IQuest getQuest() {